所需软件包:heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-libs-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm heartbeat-devel-3.0.4-2.el6.x86_64.rpm
所需环境:若有其它集群,要先关闭相关进程
【server1/server2】
rpm -ivh heartbeat-3.0.4-2.el6.x86_64.rpm heartbeat-devel-3.0.4-2.el6.x86_64.rpm heartbeat-libs-3.0.4-2.el6.x86_64.rpm ldirectord-3.9.5-3.1.x86_64.rpm
需要先解决依赖性如下图:
可以直接yum install
如果是纯净的虚拟机还需要安装以下服务
【server1/server2】
yum install -y mysql-server yum install -y iscsi-initiator-utils
【server3】
yum install -y scsi-target-utils
添加一个硬盘 /dev/vdb
vim /etc/tgt/targets.conf
<target iqn.2016-07.com.example:server.target1>
backing-store /dev/vdb
initiator-address 172.25.45.1
initiator-address 172.25.45.2
</target>
/etc/init.d/tgtd start
【server1/server2】
iscsiadm -t st -m discovery -p 172.25.45.3 iscsiadm -m node -l
增加一个分区/dev/sda1,并格式化。
【server1】
cd /usr/share/doc/heartbeat-3.0.4/ cp haresources ha.cf authkeys /etc/ha.d/ cd /etc/ha.d/
vim ha.cf
将48行、56行、61行、71行、76行、91行、211行、212行、220行、253行、259行的注释取消
将71行的initdead的值改为60
将211行node后改为server1.example.com
将212行node后改为server2.example.com
将220行ping的IP改为172.25.45.250
将253行的目录改为/usr/lib64/heartbeat/ipfail
vim haresources
在最后添上以下内容:
server1.example.com IPaddr::172.25.45.100/24/eth0 mysqld
vim authkeys
将23行、24行的注释取消
chmod 600 authkeys scp ha.cf haresources authkeys 172.25.45.2:/etc/ha.d/
/etc/init.d/heartbeat start tail -f /var/log/message
【server2】
/etc/init.d/heartbeat start
【server1】
ip addr show
关闭server1的heartbeat的服务,vip切到server2上,但把server1的heartbeat服务打开,vip会切回server1上
2.
【server1】
vim haresources
修改最后一行的内容为以下:
server1.example.com IPaddr::172.25.45.100/24/eth0 Filesystem::/dev/sda1::/var/lib/mysql::ext4 mysqld
scp haresources 172.25.45.2:/etc/ha.d/
/etc/init.d/mysqld stop
mount /dev/sda1 /mnt cd /var/lib/mysql/ cp -rp * /mnt/ chown mysql.mysql /mnt/ umount /mnt /etc/init.d/heartbeat stop /etc/init.d/heartbeat start tail -f /var/log/message
/etc/init.d/heartbeat start ##在server2上
ip addr show
/etc/init.d/heartbeat stop
ip addr show ##在server2上
将server1上的heartbeat服务再次打开,则server2上的vip和挂载都会切回server1
##drbd##
为server1和server2都添加一个4G的虚拟硬盘
【server1/server2】
/etc/init.d/heartbeat stop /etc/init.d/iscsi stop
fdisk -l
所需软件包:drbd-8.4.3.tar.gz
tar zxf drbd-8.4.3.tar.gz cd drbd-8.4.3 ./configure --enable-spec --with-km
yum install -y gcc flex rpm-build ##解决依赖性
rpmbuild -bb drbd.spec ##报错
cd cp drbd-8.4.3.tar.gz rpmbuild/SOURCES/ cd - rpmbuild -bb drbd.spec
rpmbuild -bb drbd-km.spec ##解决依赖性: yum install -y kernel-devel
cd /root/rpmbuild/RPMS/x86_64 ls
rpm -ivh *
scp * 172.25.45.2:
【server2】
rpm -ivh drbd-*
【server1】
cd /etc/drbd.d/ vim example.res
添加以下内容:
resource sqldata {
meta-disk internal;
device /dev/drbd1;
syncer {
verify-alg sha1;
}
on server1.example.com {
disk /dev/vdb;
address 172.25.45.1:7789;
}
on server2.example.com {
disk /dev/vdb;
address 172.25.45.2:7789;
}
}
scp example.res 172.25.45.2:/etc/drbd.d/
【server1/server2】
drbdadm create-md sqldata /etc/init.d/drbd start
【server1】
cat /proc/drbd
drbdadm primary sqldata --force cat /proc/drbd
watch cat /proc/drbd
mkfs.ext4 /dev/drbd1 mount /dev/drbd1 /mnt
cd /var/lib/mysql/ cp -rp * /mnt/ chown mysql.mysql /mnt umount /mnt
drbdadm secondary sqldata cat /proc/drbd
【server2】
drbdadm primary sqldata cat /proc/drbd
mount /dev/drbd1 /mnt cd /mnt ls
cd umount /mnt
drbdadm secondary sqldata
【server1】
vim /etc/ha.d/haresources
修改内容为以下:
server1.example.com IPaddr::172.25.45.100/24/eth0 drbddisk::sqldata Filesystem::/dev/drbd1::/var/lib/mysql::ext4 mysqld
scp /etc/ha.d/haresources 172.25.45.2:/etc/ha.d/
cat /proc/drbd ##此时ro:Secondary/Secondary
/etc/init.d/heartbeat start tail -f /var/log/messages
【server2】
/etc/init.d/heartbeat start
【server1】
cat /proc/drbd
/etc/init.d/heartbeat stop
【server2】
cat /proc/drbd