一、准备工作
承接上文:corosync+pacemaker使用crmsh构建高可用集群
二、MariaDB server配置(基于nfs)
nfs server准备
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
1、在nfs server准备LVM存储空间
[root@node3 ~]
# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x61284c6a.
Changes will remain
in
memory only,
until
you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (
command
'c'
) and change display
units
to
sectors (
command
'u'
).
Command (m
for
help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +10G
Value out of range.
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G
Command (m
for
help): t
Selected partition 3
Hex code (
type
L to list codes): 8e
Changed system
type
of partition 3 to 8e (Linux LVM)
Command (m
for
help): w
The partition table has been altered!
Calling ioctl() to re-
read
partition table.
Syncing disks.
[root@node3 ~]
# partx -a /dev/sdb
[root@node3 ~]
# pvcreate /dev/sdb3
Physical volume
"/dev/sdb3"
successfully created
[root@node3 ~]
# vgcreate myvg /dev/sdb3
Volume group
"myvg"
successfully created
[root@node3 ~]
# lvcreate -L 5G -n mydata myvg
Logical volume
"mydata"
created.
[root@node3 ~]
# mke2fs -t ext4 /dev/myvg/mydata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS
type
: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved
for
the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block
groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables:
done
Creating journal (32768 blocks):
done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
2、开机自动挂载,并nfs导出
[root@node3 ~]
# mkdir /mydata
[root@node3 ~]
# vim /etc/fstab
/dev/myvg/mydata
/mydata
ext4 defaults 0 0
[root@node3 ~]
# mount -a
[root@node3 ~]
# mount | grep /mydata
/dev/mapper/myvg-mydata
on
/mydata
type
ext4 (rw)
[root@node3 ~]
# vim /etc/exports
/mydata
192.168.0.0
/24
(rw,no_root_squash)
#共享给192.168.0.0/24网段,可读可写,允许root用户登录便于初始化,配置结束可取消root用户登录
3、导出nfs共享目录
#创建mysql用户,指明uid,gid。各节点的mysql用户uid,gid一致。
[root@node3 ~]
# groupadd -r -g 306 mysql
[root@node3 ~]
# useradd -r -g 306 -u 306 mysql
#创建共享目录,并修改属主属组。
[root@node3 ~]
# mkdir /mydata/data
[root@node3 ~]
# chown -R mysql.mysql /mydata/data
#导出nfs共享目录
[root@node3 ~]
# exportfs -arv
exporting 192.168.0.0
/24
:
/mydata
[root@node3 ~]
# service nfs start
|
三、各节点准备mysql
node1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
创建mysql用户,uid和gid与nfs server的mysql用户保持一致
[root@node1 ~]
# groupadd -r -g 306 mysql
[root@node1 ~]
# useradd -r -g 306 -u 306 mysql
安装mariadb
[root@node1 ~]
# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/
[root@node1 ~]
# cd /usr/local
[root@node1
local
]
# ln -sv mariadb-5.5.46-linux-x86_64 mysql
`mysql
' -> `mariadb-5.5.46-linux-x86_64'
[root@node1
local
]
# cd mysql/
[root@node1 mysql]
# chown -R root.mysql ./*
挂载nfs文件系统
[root@node1 mysql]
# mount -t nfs 192.168.0.20:/mydata /mydata
[root@node1 mysql]
# mount | grep /mydata
192.168.0.20:
/mydata
on
/mydata
type
nfs (rw,vers=4,addr=192.168.0.20,clientaddr=192.168.0.15)
初始化mysql至nfs,此步骤只需一个节点操作即可,本文node1执行,那么node2就不需要执行
初始化操作后,可以将nfs server的共享选项中的no_root_squash移除了
[root@node1 mysql]
# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql
nfs server端查看
[root@node3 ~]
# cd /mydata/data
[root@node3 data]
# ll
total 32
-rw-rw---- 1 mysql mysql 16384 Nov 21 20:32 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Nov 21 20:32 aria_log_control
drwx------ 2 mysql root 4096 Nov 21 20:32 mysql
drwx------ 2 mysql mysql 4096 Nov 21 20:32 performance_schema
drwx------ 2 mysql root 4096 Nov 21 20:32
test
node1节点配置mysql
[root@node1 mysql]
# mkdir /etc/mysql
[root@node1 mysql]
# cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@node1 mysql]
# vim /etc/mysql/my.cnf
datadir =
/mydata/data
innodb_file_per_table = on
skip_name_resolve = on
为mysql提供服务脚本,并禁止其开机启动
[root@node1 mysql]
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@node1 mysql]
# chkconfig --add mysqld
[root@node1 mysql]
# chkconfig mysqld off
启动mysql,创建mydb数据库
[root@node1 mysql]
# service mysqld start
Starting MySQL..... SUCCESS!
[root@node1 mysql]
# vim /root/.bashrc
PATH=
/usr/local/mysql/bin
:$PATH
export
PATH
[root@node1 mysql]
# source /root/.bashrc
[root@node1 mysql]
# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection
id
is 2
Server version: 5.5.46-MariaDB-log MariaDB Server
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
MariaDB [(none)]> create database mydb;
Query OK, 1 row affected (0.16 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]>
exit
Bye
[root@node1 mysql]
# service mysqld stop
Shutting down MySQL.. SUCCESS!
卸载共享目录
[root@node1 mysql]
# umount /mydata
|
node2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
[root@node2 ~]
# groupadd -r -g 306 mysql
[root@node2 ~]
# useradd -r -g 306 -u 306 mysql
[root@node2 ~]
# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local
[root@node2 ~]
# cd /usr/local/
[root@node2
local
]
# ln -sv mariadb-5.5.46-linux-x86_64 mysql
`mysql
' -> `mariadb-5.5.46-linux-x86_64'
[root@node2
local
]
# cd mysql/
[root@node2 mysql]
# chown root.mysql ./*
将node1的配置文件复制给node2
[root@node2 mysql]
# mkdir /etc/mysql/
[root@node1 mysql]
# scp /etc/mysql/my.cnf node2:/etc/mysql/
为node2节点准备服务脚本,并禁止开机启动
[root@node2 mysql]
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@node2 mysql]
# chkconfig --add mysqld
[root@node2 mysql]
# chkconfig mysqld off
挂在共享文件系统,启动mysql
[root@node2 mysql]
# mkdir /mydata
[root@node2 mysql]
# mount -t nfs 192.168.0.20:/mydata /mydata
[root@node2 mysql]
# service mysqld start
Starting MySQL.. SUCCESS!
[root@node2 mysql]
# vim /root/.bashrc
PATH=
/usr/local/mysql/bin
:$PATH
export
PATH
[root@node2 mysql]
# source /root/.bashrc
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
|
test
|
+--------------------+
5 rows
in
set
(0.02 sec)
授权远程访问
MariaDB [(none)]> grant all on *.* to
'root'
@
'192.168.%.%'
identified by
'jymlinux'
;
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]>
exit
Bye
停止mysql,并卸载共享目录
[root@node2 mysql]
# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@node2 mysql]
# umount /mydata
|
四、使用crmsh配置mariadb高可用
本文转自 元婴期 51CTO博客,原文链接:http://blog.51cto.com/jiayimeng/1875183