环境:
master
eth0 192.168.253.140
eth1 192.168.254.140
slave
eth0 192.168.253.141
eth1 192.168.254.141
--------------------------------------
在master和savle安装配置步骤一样。
1)安装DRBD
[root@master ~]# mkdir /soft[root@master ~]# cd /soft
[root@master soft]# yum -y install gcc kernel-devel kernel-headers flex perl
[root@master soft]# tar fzvx drbd-8.4.4.tar.gz
[root@master soft]# cd drbd-8.4.4
[root@master drbd-8.4.4]# ./configure --prefix=/usr/local/drbd-8.4 --with-km
[root@master drbd-8.4.4]# make KDIR=/usr/src/kernels/2.6.32-358.el6.x86_64/
[root@master drbd-8.4.4]# make install
[root@master drbd-8.4.4# mkdir -p /usr/local/drbd-8.4/var/run/drbd
[root@master drbd-8.4.4]# cp /usr/local/drbd-8.4/etc/rc.d/init.d/drbd /etc/init.d/
[root@master drbd-8.4.4]# chkconfig --add drbd
[root@master drbd-8.4.4]# chkconfig drbd on
[root@master drbd-8.4.4]# cd drbd
[root@master drbd]# make clean
[root@master drbd]# make KDIR=/usr/src/kernels/2.6.32-358.el6.x86_64/
[root@master drbd]# cp drbd.ko /lib/modules/2.6.32-358.el6.x86_64/kernel/lib/
[root@master drbd]# depmod
2)配置DRBD
[root@master drbd]# cd /usr/local/drbd-8.4/etc/drbd.d/[root@master drbd.d]# cp global_common.conf global_common.conf.bak[root@master drbd.d]# vi global_common.confglobal { 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"; fence-peer "/usr/lib/drbd/crm-fence-peer.sh"; split-brain "/usr/lib/drbd/notify-split-brain.sh root"; out-of-sync "/usr/lib/drbd/notify-out-of-sync.sh root"; } startup { wfc-timeout 30; degr-wfc-timeout 30; outdated-wfc-timeout 30; } disk { resync-rate 30M; on-io-error detach; fencing resource-only; } net { protocol C; cram-hmac-alg sha1; shared-secret "mysql-ha"; csums-alg sha1; verify-alg crc32c; }}#创建r0资源[root@master drbd.d]# vi r0.resresource r0{ on master{ device /dev/drbd0; #逻辑设备的路径 disk /dev/sdb1; #物理设备 address 192.168.254.140:7788; meta-disk internal; } on slave{ device /dev/drbd0; disk /dev/sb1; address 192.168.254.141:7788; meta-disk internal; }}
3)创建设置DRBD
#创建 drbd resource[root@master drbd.d]# modprobe drbd [root@master drbd.d]# drbdadm create-md r0[root@master drbd.d]# drbdadm up r0 #设置Primary [在master节点操作][root@master drbd.d]# drbdadm primary --force r0 #创建DRBD文件系统 [在Mysql主节点的master上执行][root@master drbd.d]# mkfs.ext4 /dev/drbd0[root@master drbd.d]# mount /dev/drbd0 /drbd
4)DRBD同步测试
#首先,在主服务器上先将设备卸载,同时将主服务器降为备用服务器:[root@master drbd]# mkdir -p /drbd/mynode1[root@master drbd]# cd /[root@master /]# umount /dev/drbd0 [root@master /]# drbdadm secondary r0#然后,登录备用服务器,将备用服务器升为主服务器,同时挂载drbd0设备到 /drbd目录:[root@slave drbd]# drbdadm up r0[root@slave drbd]# drbdadm primary r0[root@slave drbd]# mount /dev/drbd0 /drbd/[root@slave drbd]# cd /drbd/[root@slave drbd]# lldrwx------ 2 root root 16384 1月 29 10:15 lost+founddrwxr-xr-x 2 root root 4096 1月 29 10:16 mynode1
――安装heartbeat
1)添加用户和组
[root@master soft]# groupadd haclient[root@master soft]# useradd -g haclient -M -s /sbin/nologin hacluster
2)安装依赖包
[root@master soft]# yum install libtool automake autoconf glib2-devel libxml2-devel bzip2-devel libtool-ltdl-devel libxslt-devel docbook* -y
3)安装glue
[root@master soft]# tar jfvx glue-1.0.9.tar.bz2[root@master soft]# cd Reusable-Cluster-Components-glue--glue-1.0.9/[root@master Reusable-Cluster-Components-glue--glue-1.0.9]# ./autogen.sh[root@master Reusable-Cluster-Components-glue--glue-1.0.9]# ./configure LIBS='/lib64/libuuid.so.1'[root@master Reusable-Cluster-Components-glue--glue-1.0.9]# make && mek install
4)安装agents
[root@master Reusable-Cluster-Components-glue--glue-1.0.9]# cd ..[root@master soft]# tar zfvx ClusterLabs-resource-agents-v3.9.2-0-ge261943.tar.gz [root@master soft]# cd ClusterLabs-resource-agents-b735277/[root@master ClusterLabs-resource-agents-b735277]# ./autogen.sh [root@master ClusterLabs-resource-agents-b735277]# ./configure LIBS='/lib64/libuuid.so.1'[root@master ClusterLabs-resource-agents-b735277]# make && make install
5)安装heartbeat
[root@master soft]# tar jfvx heartbeat-3.0.5.tar.bz2 [root@master soft]# cd Heartbeat-3-0-7e3a82377fa8/[root@master Heartbeat-3-0-7e3a82377fa8]# ./bootstrap [root@master Heartbeat-3-0-7e3a82377fa8]# ./ConfigureMe configure LIBS='/lib64/libuuid.so.1'[root@master Heartbeat-3-0-7e3a82377fa8]# make && mek install
6)配置heartbeat
[root@master Heartbeat-3-0-7e3a82377fa8]# cd doc[root@master doc]# cp authkeys haresources ha.cf /etc/ha.d/[root@master doc]# cp /usr/etc/ha.d/shellfuncs /etc/ha.d/[root@master doc]# rm -rf /usr/etc/ha.d[root@master doc]# vi /etc/ha.d/ha.cf#开启日志logfile /var/log/ha-log#设置syslog()/logger 设备logfacility local0#心跳发送时间间隔/秒keepalive 2#15 秒没有收到主机心跳、确认主机故障deadtime 15#警告次数warntime 5#守护进程启动30 后启动服务资源initdead 30#监听端口udpport 694#另一个节点IP、通过检测来保证心跳的可用性ucast eth0 192.168.1.11ucast eth1 192.168.2.11#两个节点的名字[uname -n 获取]node masternode slave#开启DPODrespawn hacluster /usr/lib64/heartbeat/ipfailrespawn hacluster /usr/lib64/heartbeat/dopdapiauth ipfail gid=haclient uid=haclusterapiauth dopd gid=haclient uid=hacluster[root@master doc]# vi /etc/ha.d/authkeysauth 11 sha1 My_Passwd![root@master doc]# chmod 600 /etc/ha.d/authkeys[root@master doc]# vi /etc/ha.d/haresourcesmaster drbddisk::r0 Filesystem::/dev/drbd0::/raid10::ext4 nfsIPaddr::192.168.254.200/24/eth1[root@master doc]# cd /soft/drbd-8.4.4/scripts/[root@master scripts]# cp drbddisk /etc/ha.d/resource.d/[root@master scripts]# cp /etc/init.d/nfs /etc/ha.d/resource.d/[root@master scripts]# cp /etc/init.d/rpcbind /etc/ha.d/resource.d/
7)启动shellfuncs
[root@master scripts]# chkconfig --add heartbeat[root@master scripts]# chkconfig heartbeat on[root@master scripts]# /etc/init.d/heartbeat start#输入以下信息,说明启动成功[root@master scripts]# ps -ef |grep heartbeatroot 7302 1 0 13:15 ? 00:00:05 heartbeat: master control processroot 7305 7302 0 13:15 ? 00:00:00 heartbeat: FIFO reader root 7306 7302 0 13:15 ? 00:00:01 heartbeat: write: bcast eth0 root 7307 7302 0 13:15 ? 00:00:00 heartbeat: read: bcast eth0 root 7308 7302 0 13:15 ? 00:00:01 heartbeat: write: bcast eth1 root 7309 7302 0 13:15 ? 00:00:00 heartbeat: read: bcast eth1 root 7310 7302 0 13:15 ? 00:00:00 heartbeat: write: ucast eth0 root 7311 7302 0 13:15 ? 00:00:00 heartbeat: read: ucast eth0 root 7312 7302 0 13:15 ? 00:00:00 heartbeat: write: ucast eth1 root 7313 7302 0 13:15 ? 00:00:00 heartbeat: read: ucast eth1 root 7314 7302 0 13:16 ? 00:00:01 heartbeat: write: ping 192.168.254.141root 7315 7302 0 13:16 ? 00:00:00 heartbeat: read: ping 192.168.254.141500 7335 7302 0 13:16 ? 00:00:00 /usr/lib64/heartbeat/ipfail500 7336 7302 0 13:16 ? 00:00:00 /usr/lib64/heartbeat/dopdroot 8311 7214 0 14:13 pts/0 00:00:00 grep heartbeat
――安装nfs
1)安装nfs
[root@master ~]# yum -y install nfs-utils rpcbind
2)配置nfs实例
[root@master ~]# vi /etc/exports/drbd/mynode1 192.168.254.0/24(rw,no_root_squash,no_all_squash,sync)
3)启动nfs [不需要设置开机启动]
[root@master ~]# exportfs -r[root@master ~]# service rpcbind restart[root@master ~]# service nfs restart
――客户端挂载
[root@Client ~]# mount -t nfs 192.168.254.200:/drbd/mynode1 /nfs/
――测试heartbeat故障转移
1)在master停止heartbeat
[root@master ~]# /etc/init.d/heartbeat stopStopping High-Availability services: 已终止
2)在slave上面查看日志是否切换成功
[root@slave ~]# tail -f /var/log/ha-log Jan 29 14:42:24 slave heartbeat: [7263]: info: Local status now set to: 'active'Jan 29 14:42:24 slave heartbeat: [7263]: info: Starting child client "/usr/lib64/heartbeat/ipfail" (500,500)Jan 29 14:42:24 slave heartbeat: [7263]: info: Starting child client "/usr/lib64/heartbeat/dopd" (500,500)Jan 29 14:42:24 slave heartbeat: [7294]: info: Starting "/usr/lib64/heartbeat/dopd" as uid 500 gid 500 (pid 7294)Jan 29 14:42:24 slave heartbeat: [7293]: info: Starting "/usr/lib64/heartbeat/ipfail" as uid 500 gid 500 (pid 7293)Jan 29 14:42:25 slave heartbeat: [7263]: info: remote resource transition completed.Jan 29 14:42:25 slave heartbeat: [7263]: info: remote resource transition completed.Jan 29 14:42:25 slave heartbeat: [7263]: info: Local Resource acquisition completed. (none)Jan 29 14:42:25 slave heartbeat: [7263]: info: Initial resource acquisition complete (T_RESOURCES(them))Jan 29 14:42:25 slave heartbeat: [7263]: info: Link master:eth0 up.Jan 29 14:42:30 slave ipfail: [7293]: info: Link Status update: Link master/eth0 now has status upJan 29 14:42:31 slave ipfail: [7293]: info: Ping node count is balanced.Jan 29 14:42:54 slave heartbeat: [7263]: info: Received shutdown notice from 'master'.Jan 29 14:42:54 slave heartbeat: [7263]: info: Resources being acquired from master.Jan 29 14:42:54 slave heartbeat: [7298]: info: acquire all HA resources (standby).Jan 29 14:42:54 slave heartbeat: [7299]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys slave] to acquire.ResourceManager[7324]: 2015/01/29_14:42:54 info: Acquiring resource group: master drbddisk::r0 Filesystem::/dev/drbd0::/drbd::ext4 rpcbind nfs IPaddr::192.168.254.200/24/eth1ResourceManager[7324]: 2015/01/29_14:42:54 info: Running /etc/ha.d/resource.d/drbddisk r0 startFilesystem[7393]: 2015/01/29_14:42:54 INFO: Resource is stopped#说明成功ResourceManager[7324]: 2015/01/29_14:42:54 info: Running /etc/ha.d/resource.d/Filesystem /dev/drbd0 /drbd ext4 startFilesystem[7473]: 2015/01/29_14:42:54 INFO: Running start for /dev/drbd0 on /drbdFilesystem[7465]: 2015/01/29_14:42:54 INFO: SuccessResourceManager[7324]: 2015/01/29_14:42:54 info: Running /etc/ha.d/resource.d/rpcbind startResourceManager[7324]: 2015/01/29_14:42:55 info: Running /etc/ha.d/resource.d/nfs startIPaddr[7716]: 2015/01/29_14:43:05 INFO: Resource is stoppedResourceManager[7324]: 2015/01/29_14:43:05 info: Running /etc/ha.d/resource.d/IPaddr 192.168.254.200/24/eth1 startIPaddr[7801]: 2015/01/29_14:43:05 INFO: Using calculated netmask for 192.168.254.200: 255.255.255.0#获取IPIPaddr[7801]: 2015/01/29_14:43:05 INFO: eval ifconfig eth1:0 192.168.254.200 netmask 255.255.255.0 broadcast 192.168.254.255IPaddr[7775]: 2015/01/29_14:43:05 INFO: SuccessJan 29 14:43:05 slave heartbeat: [7298]: info: all HA resource acquisition completed (standby).Jan 29 14:43:05 slave heartbeat: [7263]: info: Standby resource acquisition done [all].harc[7888]: 2015/01/29_14:43:05 info: Running /usr/etc/ha.d//rc.d/status statusmach_down[7905]: 2015/01/29_14:43:05 info: Taking over resource group drbddisk::r0ResourceManager[7932]: 2015/01/29_14:43:05 info: Acquiring resource group: master drbddisk::r0 Filesystem::/dev/drbd0::/drbd::ext4 rpcbind nfs IPaddr::192.168.254.200/24/eth1Filesystem[7974]: 2015/01/29_14:43:05 INFO: Running OKIPaddr[8085]: 2015/01/29_14:43:06 INFO: Running OKmach_down[7905]: 2015/01/29_14:43:06 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquiredmach_down[7905]: 2015/01/29_14:43:06 info: mach_down takeover complete for node master.
本文出自 “命运.” 博客,请务必保留此出处http://hypocritical.blog.51cto.com/3388028/1609597