HA:高可用集群,主要用于故障切换
两台服务器IP分别为192.168.10.105(master)和192.168.10.109(slave)
1.准备:
a.修改两台服务器的主机名
hostname master
bash
hostname slave
bash
b.在两台服务器上编辑主机映射文件
vim /etc/hosts
192.168.10.105 master
192.168.10.109 slave
c.关闭防火墙
2.主从上都安装扩展源:
wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
[root@master ~]# rpm -ivh epel-release-6-8_32.noarch.rpm
[root@master ~]# yum -y install heartbeat* libnet nginx
主服务器配置:
[root@master ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@master heartbeat-3.0.4]# ls
apphbd.cf AUTHORS COPYING ha.cf README
authkeys ChangeLog COPYING.LGPL haresources
[root@master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
用来验证的
[root@master ha.d]# vim authkeys
修改如下:将对应的注释去掉
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
赋予权限:
[root@master ha.d]# chmod 600 authkeys
[root@master ha.d]# vim haresources
修改如下:
将
node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2
修改如下:
master 192.168.10.119/24/eth0:0 nginx //这里的IP为VIP地址,俗称心跳线
[root@master 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 694
ucast eth0 192.168.10.109 //为对方的IP地址
auto_failback on
node master
node slave
ping 192.168.10.1
respawn hacluster /usr/lib64/heartbeat/ipfail
远程拷贝到从服务器上
scp authkeys haresources ha.cf slave:/etc/ha.d/
到从服务器上修改ha.cf配置文件
[root@slave ha.d]#vim ha.cf
修改IP
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth0 192.168.10 .105 //为对方的IP地址
auto_failback on
node master
node slave
ping 192.168.10.1
respawn hacluster /usr/lib64/heartbeat/ipfail
启动服务:注意先主后从
[root@master ha.d]# service heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
[root@master ha.d]# ps aux | grep nginx
root 4377 0.0 0.1 15628 1500 ? Ss 21:27 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 4379 0.0 0.1 15784 1960 ? S 21:27 0:00 nginx: worker process
root 4383 0.0 0.0 5980 748 pts/1 S+ 21:27 0:00 grep nginx
主上查看网卡
[root@master ha.d]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:FB:25:BF
inet addr:192.168.10.105 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefb:25bf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:58150 errors:0 dropped:0 overruns:0 frame:0
TX packets:30513 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:83167906 (79.3 MiB) TX bytes:2206168 (2.1 MiB)
Interrupt:19 Base address:0x2024
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:FB:25:BF
inet addr:192.168.10.119 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2024
但是在从服务器上是不会出现eth0:0的信息
测试一、加入测试网页
主服务器
[root@master ha.d]# echo "111111master" > /usr/share/nginx/html/index.html
从服务器:
[root@slave ~]# echo "222222slave" > /usr/share/nginx/html/index.html
打开网页输入192.168.10.119即可访问到111111master
测试二:
主上故意禁ping
[root@master ha.d]# iptables -I INPUT -p icmp -j DROP
[root@master ha.d]#service heartbeat stop
从服务器开启服务
[root@slave ~]# service heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
查看出现eth0:0
[root@slave ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:D1:A8:16
inet addr:192.168.10.109 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed1:a816/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38654 errors:0 dropped:0 overruns:0 frame:0
TX packets:20997 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54817472 (52.2 MiB) TX bytes:1569020 (1.4 MiB)
Interrupt:19 Base address:0x2024
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D1:A8:16
inet addr:192.168.10.119 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2024
注意:这是在主服务器上查看网卡时是没有eth0:0的信息了
刷新网页192.168.10.119即可发现网页信息变成222222slave
在主服务器上删除刚才配置的防火墙规则
[root@master ha.d]# iptables -D INPUT -p icmp -j DROP
启动主服务
[root@master ha.d]# service heartbeat start
可以先查看下网卡信息是否出现eth0:0
然后再在网页中刷新,会出现主服务器上配置的网页111111master
也可以查看日志信息
[root@master ha.d]# vim /var/log/ha-log
当主服务器开启后再日志中会出现以下信息表示主服务开启
ResourceManager(default)[5146]: 2016/08/29_21:48:11 info: Running /etc/init.d/nginx start
Aug 29 21:48:21 master heartbeat: [4921]: info: Local Resource acquisition completed. (none)
Aug 29 21:48:21 master heartbeat: [4921]: info: local resource transition completed.
在从服务器上查看日志信息
ug 29 21:45:00 slave heartbeat: [3493]: info: slave Heartbeat shutdown complete.
两台服务器IP分别为192.168.10.105(master)和192.168.10.109(slave)
1.准备:
a.修改两台服务器的主机名
hostname master
bash
hostname slave
bash
b.在两台服务器上编辑主机映射文件
vim /etc/hosts
192.168.10.105 master
192.168.10.109 slave
c.关闭防火墙
2.主从上都安装扩展源:
wget www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
[root@master ~]# rpm -ivh epel-release-6-8_32.noarch.rpm
[root@master ~]# yum -y install heartbeat* libnet nginx
主服务器配置:
[root@master ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@master heartbeat-3.0.4]# ls
apphbd.cf AUTHORS COPYING ha.cf README
authkeys ChangeLog COPYING.LGPL haresources
[root@master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
用来验证的
[root@master ha.d]# vim authkeys
修改如下:将对应的注释去掉
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
赋予权限:
[root@master ha.d]# chmod 600 authkeys
[root@master ha.d]# vim haresources
修改如下:
将
node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2
修改如下:
master 192.168.10.119/24/eth0:0 nginx //这里的IP为VIP地址,俗称心跳线
[root@master 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 694
ucast eth0 192.168.10.109 //为对方的IP地址
auto_failback on
node master
node slave
ping 192.168.10.1
respawn hacluster /usr/lib64/heartbeat/ipfail
远程拷贝到从服务器上
scp authkeys haresources ha.cf slave:/etc/ha.d/
到从服务器上修改ha.cf配置文件
[root@slave ha.d]#vim ha.cf
修改IP
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
ucast eth0 192.168.10 .105 //为对方的IP地址
auto_failback on
node master
node slave
ping 192.168.10.1
respawn hacluster /usr/lib64/heartbeat/ipfail
启动服务:注意先主后从
[root@master ha.d]# service heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
[root@master ha.d]# ps aux | grep nginx
root 4377 0.0 0.1 15628 1500 ? Ss 21:27 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 4379 0.0 0.1 15784 1960 ? S 21:27 0:00 nginx: worker process
root 4383 0.0 0.0 5980 748 pts/1 S+ 21:27 0:00 grep nginx
主上查看网卡
[root@master ha.d]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:FB:25:BF
inet addr:192.168.10.105 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefb:25bf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:58150 errors:0 dropped:0 overruns:0 frame:0
TX packets:30513 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:83167906 (79.3 MiB) TX bytes:2206168 (2.1 MiB)
Interrupt:19 Base address:0x2024
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:FB:25:BF
inet addr:192.168.10.119 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2024
但是在从服务器上是不会出现eth0:0的信息
测试一、加入测试网页
主服务器
[root@master ha.d]# echo "111111master" > /usr/share/nginx/html/index.html
从服务器:
[root@slave ~]# echo "222222slave" > /usr/share/nginx/html/index.html
打开网页输入192.168.10.119即可访问到111111master
测试二:
主上故意禁ping
[root@master ha.d]# iptables -I INPUT -p icmp -j DROP
[root@master ha.d]#service heartbeat stop
从服务器开启服务
[root@slave ~]# service heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
查看出现eth0:0
[root@slave ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:D1:A8:16
inet addr:192.168.10.109 Bcast:192.168.10.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed1:a816/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38654 errors:0 dropped:0 overruns:0 frame:0
TX packets:20997 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:54817472 (52.2 MiB) TX bytes:1569020 (1.4 MiB)
Interrupt:19 Base address:0x2024
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D1:A8:16
inet addr:192.168.10.119 Bcast:192.168.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2024
注意:这是在主服务器上查看网卡时是没有eth0:0的信息了
刷新网页192.168.10.119即可发现网页信息变成222222slave
在主服务器上删除刚才配置的防火墙规则
[root@master ha.d]# iptables -D INPUT -p icmp -j DROP
启动主服务
[root@master ha.d]# service heartbeat start
可以先查看下网卡信息是否出现eth0:0
然后再在网页中刷新,会出现主服务器上配置的网页111111master
也可以查看日志信息
[root@master ha.d]# vim /var/log/ha-log
当主服务器开启后再日志中会出现以下信息表示主服务开启
ResourceManager(default)[5146]: 2016/08/29_21:48:11 info: Running /etc/init.d/nginx start
Aug 29 21:48:21 master heartbeat: [4921]: info: Local Resource acquisition completed. (none)
Aug 29 21:48:21 master heartbeat: [4921]: info: local resource transition completed.
在从服务器上查看日志信息
ug 29 21:45:00 slave heartbeat: [3493]: info: slave Heartbeat shutdown complete.
编辑回复