HA高可用集群搭建

准备2台机器:
主:master:192.168.254.140
从:slave:192.168.254.141

vim /etc/hosts
主、从:
192.168.254.140 master
192.168.254.141 slave


1.主和从上安装:
wget www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
rpm -ivh epel-release-6-8_64.noarch.rpm
yum install -y libnet
yum install -y heartbeat

2.主上编辑HA的3个配置文件
cd /usr/share/doc/heartbeat-3.0.4/
cp authkeys ha.cf haresources /etc/ha.d/
cd /etc/ha.d/

vim authkeys


chmod 600 authkeys

vim haresources
这里的ip是vip:

 
主从不一样的就是下面这个配置文件:
vim ha.cf

debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility      local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 649
ucast eth0 192.168.254.141   #这里ip是对方ip,若是从就是140
auto_failback on
node  master
node  slave
ping 192.168.1.1
respawn hacluster /usr/lib64/heartbeat/ipfail

3.拷贝3个配置到从上
yum install openssh-clients    #scp的安装包
scp authkeys haresources ha.cf  slave:/etc/ha.d/    #三个配置都是从主上复制过来的
vim ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility      local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 649
ucast eth0 192.168.254.140   #这里ip对方ip,若是从就是140
auto_failback on
node  master
node  slave
ping 192.168.1.1
respawn hacluster /usr/lib64/heartbeat/ipfail
4.启动(先主后从)
/etc/init.d/heartbeat start

5.测试
主:
echo "11111111111111111master" > /usr/share/nginx/html/index.html
iptables -A INPUT -p icmp -j DROP
iptables -D INPUT -p icmp -j DROP
/etc/init.d/heartbeat stop
从:
echo "2222222222222slave" > /usr/share/nginx/html/index.html



猜你喜欢

转载自www.linuxidc.com/Linux/2017-03/141524.htm