[iyunv@node3 ~]# rpm -ivh crmsh-1.2.6-4.el6.x86_64.rpm
error: Failed dependencies:
pssh is needed by crmsh-1.2.6-4.el6.x86_64
python-dateutil is needed by crmsh-1.2.6-4.el6.x86_64
python-lxml is needed by crmsh-1.2.6-4.el6.x86_64
[iyunv@node3 ~]# service corosync start
[iyunv@node4 ~]# service corosync start
查看corosync引擎是否成功启动
1
2
3
[iyunv@node3 ~]# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
Oct 11 20:19:35 corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and ready to provide service. #说明已经启动准备好了
Oct 11 20:19:35 corosync [MAIN ] Successfully read main configuration file '/etc/corosync/corosync.conf'
查看初始化成员节点通知是否正常发出
1
2
3
4
[iyunv@node3 ~]# grep TOTEM /var/log/cluster/corosync.log
Oct 11 20:19:35 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
Oct 11 20:19:35 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Oct 11 20:19:35 corosync [TOTEM ] The network interface [172.16.16.3] is now up.
查看pacemaker是否正常启动
1
2
3
4
5
6
[iyunv@node3 ~]# grep pcmk_startup /var/log/cluster/corosync.log
Oct 11 20:19:35 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Oct 11 20:19:35 corosync [pcmk ] Logging: Initialized pcmk_startup
Oct 11 20:19:35 corosync [pcmk ] info: pcmk_startup: Maximum core file size is: 18446744073709551615
Oct 11 20:19:35 corosync [pcmk ] info: pcmk_startup: Service: 9
Oct 11 20:19:35 corosync [pcmk ] info: pcmk_startup: Local hostname: node3
查看集群状态
1
2
3
4
5
6
7
8
9
[iyunv@node3 ~]# crm status
Last updated: Sat Oct 11 20:29:24 2014
Last change: Sat Oct 11 20:19:35 2014 via crmd on node4
Stack: classic openais (with plugin)
Current DC: node4 - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
0 Resources configured
Online: [ node3 node4 ] #在线
[iyunv@node3 ~]# groupadd -g 3306 mysql
[iyunv@node3 ~]# useradd -u 3306 -g mysql -s /sbin/nologin -M mysql
[iyunv@node3 ~]# id mysql
uid=3306(mysql) gid=3306(mysql) groups=3306(mysql)
[iyunv@node3 ~]# tar xf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local/
[iyunv@node3 ~]# cd /usr/local/
[iyunv@node3 local]# ln -sv mariadb-5.5.36-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.36-linux-x86_64'
[iyunv@node3 local]# cd mysql
[iyunv@node3 mysql]# chown root.mysql ./*
[iyunv@node3 mysql]# ll
total 212
drwxr-xr-x 2 root mysql 4096 Oct 11 21:54 bin
-rw-r--r-- 1 root mysql 17987 Feb 24 2014 COPYING
-rw-r--r-- 1 root mysql 26545 Feb 24 2014 COPYING.LESSER
drwxr-xr-x 3 root mysql 4096 Oct 11 21:54 data
drwxr-xr-x 2 root mysql 4096 Oct 11 21:55 docs
drwxr-xr-x 3 root mysql 4096 Oct 11 21:55 include
-rw-r--r-- 1 root mysql 8694 Feb 24 2014 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Oct 11 21:55 lib
drwxr-xr-x 4 root mysql 4096 Oct 11 21:54 man
drwxr-xr-x 11 root mysql 4096 Oct 11 21:55 mysql-test
-rw-r--r-- 1 root mysql 108813 Feb 24 2014 README
drwxr-xr-x 2 root mysql 4096 Oct 11 21:55 scripts
drwxr-xr-x 27 root mysql 4096 Oct 11 21:55 share
drwxr-xr-x 4 root mysql 4096 Oct 11 21:55 sql-bench
drwxr-xr-x 4 root mysql 4096 Oct 11 21:54 support-files
提供配置文件
1
2
3
4
5
[iyunv@node3 mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? y
[iyunv@node3 mysql]# vim /etc/my.cnf
增加一行
datadir = /mydata/data
crm(live)configure# show
node node3
attributes standby="on"
node node4
primitive myip ocf:heartbeat:IPaddr
params ip="172.16.16.8"
op monitor interval="30s" timeout="20s"
primitive mysqld lsb:mysqld
primitive mysqldrbd ocf:linbit:drbd
params drbd_resource="web"
op start timeout="240" interval="0"
op stop timeout="100" interval="0"
op monitor role="Master" interval="20" timeout="30"
op monitor role="Slave" interval="30" timeout="30"
primitive mystore ocf:heartbeat:Filesystem
params device="/dev/drbd0" directory="/mydata/data" fstype="ext4"
op start timeout="60" interval="0"
op stop timeout="60" interval="0"
ms ms_mysqldrbd mysqldrbd
meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" target-role="Started"
colocation myip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master myip
colocation mysqld_with_mystore inf: mysqld mystore
colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master
order mysqld_after_mystore inf: mystore mysqld
order mystore_after_ms_mysqldrbd inf: ms_mysqldrbd:promote mystore:start
property $id="cib-bootstrap-options"
stonith-enabled="false"
no-quorum-policy="ignore"
dc-version="1.1.10-14.el6-368c726"
cluster-infrastructure="classic openais (with plugin)"
expected-quorum-votes="2"
last-lrm-refresh="1413090998"
rsc_defaults $id="rsc-options"
resource-stickiness="100"
10)测试一下高可用mysql能否使用
首先查看一下高可用集群的状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
crm(live)# status
Last updated: Sun Oct 12 14:27:51 2014
Last change: Sun Oct 12 14:27:47 2014 via crm_attribute on node3
Stack: classic openais (with plugin)
Current DC: node3 - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
5 Resources configured
Online: [ node3 node4 ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node3 ]
Slaves: [ node4 ]
mystore (ocf::heartbeat:Filesystem): Started node3
myip (ocf::heartbeat:IPaddr): Started node3
[iyunv@node4 ~]# crm status
Last updated: Sun Oct 12 14:39:38 2014
Last change: Sun Oct 12 14:39:22 2014 via crm_attribute on node3
Stack: classic openais (with plugin)
Current DC: node3 - partition with quorum
Version: 1.1.10-14.el6-368c726
2 Nodes configured, 2 expected votes
5 Resources configured
Node node3: standby
Online: [ node4 ]
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ node4 ]
Stopped: [ node3 ]
mystore(ocf::heartbeat:Filesystem):Started node4
myip(ocf::heartbeat:IPaddr):Started node4
可以看到node4成为了主节点,node3处于standby状态,资源都转移到了node4上面.
可以看到mysql在node4节点上依然工作起来..
11)测试一下能否写入数据
给连接的IP地址授权
1
2
3
4
5
6
7
8
[iyunv@node4 ~]# /usr/local/mysql/bin/mysql
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.36-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> grant all on *.* to root@"172.16.16.%" identified by "123456";
Query OK, 0 rows affected (0.12 sec)