RHEL6
node1 192.168.1.7
node2 192.168.1.8
双机互信
进192.168.1.7 # ssh-keygen -t rsa ~/.ssh/id_rsa # ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] 进192.168.1.8 # ssh-keygen -t rsa ~/.ssh/id_rsa # ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
编辑/etc/hosts文件
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.7 node1.mingxiao.info node1 192.168.1.8 node2.mingxiao.info node2
# ssh /etc/hosts node2:/etc/
时间同步 # ntpdate time.windows.com # ssh node2 ‘ntpdate time.windows.com‘ # crontab -e */5 * * * * /usr/sbin/ntpdate time.windows.com && /dev/null
配置corosync
# yum install corosync pacemaker
# rpm -ivh crmsh-2.1-1.6.x86_64.rpm
编辑/etc/corosync/corosync.conf
# Please read the corosync.conf.5 manual page compatibility: whitetank totem { version: 2 secauth: off threads: 0 interface { ringnumber: 0 bindnetaddr: 192.168.1.0 mcastaddr: 239.255.1.1 mcastport: 5405 ttl: 1 } } logging { fileline: off to_stderr: no to_logfile: yes logfile: /var/log/cluster/corosync.log to_syslog: no debug: off timestamp: on logger_subsys { subsys: AMF debug: off } } service { ver: 0 name: pacemaker } sisexec { user: root group: root }
# scp /etc/corosync/corosync.conf node2:/etc/corosync/
# /etc/init.d/corosync start
# ssh node2 ‘/etc/init.d/corosync start‘
请确保corosync启动正常
# crm status
Last updated: Sun May 3 18:53:33 2015 Last change: Sun May 3 12:53:05 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 0 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ]
crm(live)configure# property no-quorum-policy=ignore crm(live)configure# property stonith-enabled=false
配置drbd
# yum install drbd84-utils kmod-drbd84 # ssh node2 ‘yum -y install drbd84-utils kmod-drbd84‘
node1和node2创建两个一样的分区,这里为sdb1,分区过程不再说明。
编辑/etc/drbd.d/global_common.conf
global { usage-count no; } common { 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-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f"; } startup { # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb } options { # cpu-mask on-no-data-accessible } disk { on-io-error detach; } net { cram-hmac-alg "sha1"; shared-secret "mydrbdlab"; } syncer { rate 200M; } }
编辑/etc/drbd.d/drbd.res
resource mydrbd { device /dev/drbd0; disk /dev/sdb1; meta-disk internal; on node1.mingxiao.info { address 192.168.1.7:7789; } on node2.mingxiao.info { address 192.168.1.8:7789; } }
# drbdadm create-md mydrbd # ssh node2 ‘drbdadm create-md mydrbd‘
node1和node2节点执行
# /etc/init.d/drbd start
node1
# drbd-overview 0:mydrbd/0 Connected Secondary/Secondary UpToDate/UpToDate
将node1提升为主节点
# drbdadm -- --overwrite-data-of-peer primary mydrbd
# mkfs.ext4 /dev/drbd0 # mkdir /mydata # ssh node2 ‘mkdir /mydata # mount /dev/drbd0 /mydata # drbd-overview 0:mydrbd/0 Connected Primary/Secondary UpToDate/UpToDate # umount /mydata # drbdadm secondary mydrbd
配置drbd资源和主从属性
crm(live)configure# primitive mysqldrbd ocf:linbit:drbd > params drbd_resource=mydrbd > op start interval=0 timeout=240 > op stop interval=0 timeout=100 > op monitor interval=20 role=Master timeout=30 > op monitor interval=30 role=Slave timeout=30 crm(live)configure# ms ms_mysqldrbd mysqldrbd > meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
查看状态
crm(live)# status Last updated: Sun May 3 19:55:32 2015 Last change: Sun May 3 19:55:19 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 2 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node1.mingxiao.info ] Slaves: [ node2.mingxiao.info ]
配置文件系统资源
crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/mydata fstype=ext4 op start timeout=60 op stop timeout=60 crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start crm(live)configure# verify crm(live)configure# commit crm(live)# status Last updated: Sun May 3 19:59:13 2015 Last change: Sun May 3 19:58:54 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 3 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node1.mingxiao.info ] Slaves: [ node2.mingxiao.info ] mystore(ocf::heartbeat:Filesystem):Started node1.mingxiao.info
node1初始化mysql
# tar xf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/mysql
# groupadd -r -g 306 mysql # useradd -g 306 -r -u 306 mysql # mkdir /mydata/data # chown -R mysql.mysql /mydata/data
MySQL初始化:
# cd /usr/local/mysql # scripts/mysql_install_db --user=mysql --datadir=/mydata/data # chown -R root /usr/local/mysql/*
提供SysV风格服务脚本
# cp support-files/mysql.server /etc/init.d/mysqld
提供MySQL配置文件
# cp my.cnf /etc/my.cnf # vim /etc/my.cnf basedir = /usr/local/mysql datadir = /mydata/data port = 3306 sock=/var/lib/mysql/mysql.sock
编辑/etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
编辑/etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
# su
man帮助文档,编辑/etc/man.config
MANPATH /usr/local/mysql/man
头文件
ln -sv /usr/local/mysql/include/ /usr/include/mysql
mysql> use mysql; mysql> GRANT ALL ON *.* TO [email protected]‘%‘ IDENTIFIED BY ‘xiaoming‘; mysql> CREATE DATABASE xiaoming; mysql> show database; mysql> show DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | xiaoming | +--------------------+ 5 rows in set (0.00 sec)
# crm node standby # crm node online # crm status Last updated: Sun May 3 20:09:58 2015 Last change: Sun May 3 20:09:56 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 3 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node2.mingxiao.info ] Slaves: [ node1.mingxiao.info ] mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info
node2配置mysql
# groupadd -r -g 306 mysql # useradd -g 306 -r -u 306 mysql # tar xf mysql-5.6.14-linux-glibc2.5-x86_64 /usr/local/mysql # cd /usr/local/mysql # chown -R root:mysql ./
提供SysV风格服务脚本
# cp support-files/mysql.server /etc/init.d/mysqld
提供MySQL配置文件
# cp my.cnf /etc/my.cnf # vim /etc/my.cnf basedir = /usr/local/mysql datadir = /mydata/data port = 3306 sock=/var/lib/mysql/mysql.sock
编辑/etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
编辑/etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
# su
man帮助文档,编辑/etc/man.config
MANPATH /usr/local/mysql/man
头文件
ln -sv /usr/local/mysql/include/ /usr/include/mysql
由于node1已经初始化过mysql,这里不用重新初始化,可以直接启动。
# service mysqld start Starting MySQL.. SUCCESS! mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | xiaoming | +--------------------+ 5 rows in set (0.02 sec)
配置mysqld资源:
crm(live)configure# primitive mysqld lsb:mysqld crm(live)configure# colocation mysqld_with_mystore inf: mysqld mystore crm(live)configure# order mysqld_after_mystore mandatory: mystore: mysqld crm(live)configure# verify crm(live)configure# commit crm(live)configure# cd crm(live)# status Last updated: Sun May 3 20:19:41 2015 Last change: Sun May 3 20:19:34 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 4 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node2.mingxiao.info ] Slaves: [ node1.mingxiao.info ] mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info mysqld(lsb:mysqld):Started node2.mingxiao.info
配置IP,从此IP访问可连接至mysql
crm(live)configure# primitive myip IPaddr2 params ip=192.168.1.20 nic=eth1 cidr_netmask=24 crm(live)configure# colocation myip_with_mysqld inf: mysqld myip crm(live)# status Last updated: Sun May 3 20:36:26 2015 Last change: Sun May 3 20:36:23 2015 Stack: classic openais (with plugin) Current DC: node2.mingxiao.info - partition with quorum Version: 1.1.11-97629de 2 Nodes configured, 2 expected votes 5 Resources configured Online: [ node1.mingxiao.info node2.mingxiao.info ] Master/Slave Set: ms_mysqldrbd [mysqldrbd] Masters: [ node2.mingxiao.info ] Slaves: [ node1.mingxiao.info ] mystore(ocf::heartbeat:Filesystem):Started node2.mingxiao.info mysqld(lsb:mysqld):Started node2.mingxiao.info myip(ocf::heartbeat:IPaddr2):Started node2.mingxiao.info
一切都已配置完毕