corosync + drbd + mysql集群
规划:
vip:192.168.1.254
rs1:192.168.1.215
rs2:192.168.1.216
一、主机绑定 (rs2相同)
[root@rs1 ~]# cat /etc/hosts 192.168.1.215 rs1.china-kody.com rs1 192.168.1.216 rs2.china-kody.com rs2
二、配置双机互信(rs2相同)
[root@rs1 ~]# ssh-key -t rsa -P ‘‘ -f /root/.ssh/id_rsa [root@rs1 ~]# ssh-copy-id -f /root/.ssh/id_rsa.pub rs2
三、配置corosync
[root@rs1 ~]# vim /etc/corosync/corosync.conf service { ver: 0 name: pacemaker } aisexec { user: root group: root } [root@rs1 ~]# vim /etc/corosync/corosync.conf [root@rs1 ~]# scp /etc/corosync/{authkey,corosync.conf} rs2:/etc/corosync
四、配置drbd与mysql
[root@rs1 ~]# vim /etc/drbd.d/global_common.conf handlers { pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-; } disk { on-io-error detach; } net { cram-hmac-alg "sha1"; shared-secret "d0CJpSlaSod4Xg"; } [root@rs1 ~]# drbdadm create-md mysqldrbd [root@rs2 ~]# drbdadm create-md mysqldrbd [root@rs1 ~]# service drbd start [root@rs2 ~]# service drbd start [root@rs1 ~]# chkconfig drbd off [root@rs2 ~]# chkconfig drbd off [root@rs1 ~]# drbdadm -- --overwrite-data-of-peer primary all [root@rs1 ~]# mke2fs -j /dev/drbd0 [root@rs1 ~]# mount /dev/drbd0 /mydata/data 配置mysql... [root@rs1 ~]# umount /dev/drbd0 [root@rs1 ^]# drbdadm seconary mysqlbd
五、配置mysql
[root@rs1 ~]# groupadd -g 306 mysql [root@rs1 ~]# useradd -u 306 -g mysql -s /sbin/nologin mysql [root@rs1 ~]# id mysql uid=306(mysql) gid=306(mysql) group=306(mysql) [root@rs1 ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql datadir=/mydata/data [root@rs1 /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql [root@rs1 /]# chkconfig --add mysql [root@rs1 /]# chkconfig mysql off [root@rs1 /]# cp /usr/local/mysql/support-files/my-default.cnf/etc/my.cnf [root@rs1 /]# vim /etc/my.cnf 添加 datadir = /mydata/data rs1、rs2、同样配置,测试是否正常。 停止服务,关闭开机启动.
六、crm命令行corosync
1、配置drbd主从自动切换
primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysqldrbd 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 ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true crm(live)# status Online: [ rs1.china-kody.com rs2.china-kody.com ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ rs1.china-kody.com ] Slaves: [ rs2.china-kody.com ]
2、配置drbd自动挂载
primitive mysqlstore Filesystem params device="/dev/drbd0" directory="/mydata" fstype=ext3 op start timeout=60 interval=0 op stop timeout=60 interval=0 colocation mysqlstore_with_ms_mysqldrbd inf: mysqlstore ms_mysqldrbd:Master order mystore_after_ms_mysqldrbd Mandatory: ms_mysqldrbd:promote mysqlstore:start Online: [ rs1.china-kody.com rs2.china-kody.com ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ rs2.china-kody.com ] Slaves: [ rs1.china-kody.com ] mysqlstore (ocf::heartbeat:Filesystem): Started rs2.china-kody.com
3、配置mysql资源
primitive mysqld lsb:mysql meta target-role=Started colocation mysqld_with_mysqlstore inf: mysqld mysqlstore order mysqld_after_mysqlstore Mandatory: mysqlstore mysqld Node rs2.china-kody.com: standby Online: [ rs1.china-kody.com ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ rs1.china-kody.com ] Stopped: [ rs2.china-kody.com ] mysqlstore (ocf::heartbeat:Filesystem): Started rs1.china-kody.com mysqld (lsb:mysql): Started rs1.china-kody.com
4、配置vip资源
colocation mysqlvip_with_mysqld inf: mysqlvip mysqld Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ rs1.china-kody.com ] Slaves: [ rs2.china-kody.com ] mysqlstore (ocf::heartbeat:Filesystem): Started rs1.china-kody.com mysqld (lsb:mysql): Started rs1.china-kody.com mysqlvip (ocf::heartbeat:IPaddr): Started rs1.china-kody.com
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。