码迷,mamicode.com
首页 > 其他好文 > 详细

heartbeat

时间:2017-01-09 00:45:09      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:heartbeat

用heartbeat配置nginx的的双机热设备!

主(lnmp):192.168.1.123

从(slave):192.168.1.121

下面这部分操作在主从上都要操作:

1:设置主机名,主机名若设置好,则不用设置:

/etc/sysconfig/network

2:关闭防火墙和selinux

iptables -F
service iptables save

setenforce 0

3:配置hosts:

cat /etc/hosts
192.168.1.121   slave
192.168.1.123   lnmp

4:安装epel源

yum install -y epel-release

5:安装heartbeat

yum install -y heartbeat

需要安装依赖包:

yum install -y libnet

在主机上操作:

1:拷贝配置文件样例:

cd /usr/local/heartbeat-3.0.4/
cp authkeys ha.cf haresources /etc/ha.d

2.修改authkeys文件,

技术分享

修改其文件权限:

chmod 600 authkeys

3:修改haresoures文件,加入下面一行

主机名    流动ip的网段及网卡      资源,也就是要用heartbeat的服务  
lnmp     192.168.1.110/24/eth0:0  nginx

4:编辑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.1.121
auto_failback on
node lnmp
node slave
ping 192.168.1.1
respawn hacluster /usr/lib/heartbeat/ipfail

在从机上操作

1.把主机上的三个配置文件拷贝到从上

scp ha.cf haresources authkeys 192.168.1.121:/etc/ha.d

需要修改ha.cf文件中的一个配置就是ucast那一行,改为对方的ip!

ucast eth0 192.168.1.123

配置完成。

注意启动顺序:先主后从。

在主上启动

service heartbeat start

在从上启动:

service heartbeat start

测试:主上的nginx服务已经启动,但是从上的你滚下服务并未启动。

[root@lnmp ~]# ps aux |grep nginx
root     16383  0.0  0.0   5508   616 ?        Ss   22:37   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   16384  0.0  0.1   6688  2016 ?        S    22:37   0:00 nginx: worker process                                          
nobody   16385  0.0  0.1   6688  1932 ?        S    22:37   0:00 nginx: worker process                                          
root     16753  0.0  0.0   4356   724 pts/0    S+   23:02   0:00 grep --color=auto nginx
[root@lnmp ~]# 


[root@slave ~]# ps aux |grep nginx
root      4465  0.0  0.0   4356   720 pts/1    S+   23:05   0:00 grep --color=auto nginx
[root@slave ~]#

在主上查看ip,多出一个虚拟的网卡eth0:0

[root@lnmp ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:52:83:DD  
          inet addr:192.168.1.123  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe52:83dd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:44438 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27726 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:6134385 (5.8 MiB)  TX bytes:5486765 (5.2 MiB)
          Interrupt:19 Base address:0x2000 

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:52:83:DD  
          inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:19 Base address:0x2000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:3351 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3351 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:751595 (733.9 KiB)  TX bytes:751595 (733.9 KiB)


然后在主上禁止ping,结果是主上的nginx关闭,但是从上的ngixn启动!

[root@lnmp ~]# iptables -I INPUT -p icmp -j DROP
[root@lnmp ~]# ps aux |grep nginx
root     16994  0.0  0.0   4356   744 pts/0    S+   23:06   0:00 grep --color=auto nginx

这时从上的nginx是启动的!

[root@slave ~]# ps aux |grep nginx
root      4749  0.0  0.0   5532   644 ?        Ss   23:08   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody    4750  0.0  0.2   6784  2124 ?        S    23:08   0:00 nginx: worker process                                          
nobody    4751  0.0  0.1   6784  2036 ?        S    23:08   0:00 nginx: worker process                                          
root      4755  0.0  0.0   4356   724 pts/1    S+   23:09   0:00 grep --color=auto nginx
[root@slave ~]#



接着上面的测试,清除主上的iptables规则,可以发现n主上ginx服务器又启动了,从上自动关闭了!

[root@lnmp ~]# iptables -F
[root@lnmp ~]# ps aux |grep nginx
root     17041  0.0  0.0   4356   724 pts/0    S+   23:08   0:00 grep --color=auto nginx
[root@lnmp ~]# ps aux |grep nginx
root     17332  0.0  0.0   5508   620 ?        Ss   23:08   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody   17333  0.0  0.1   6688  2016 ?        S    23:08   0:00 nginx: worker process                                          
nobody   17334  0.0  0.1   6688  1932 ?        S    23:08   0:00 nginx: worker process                                          
root     17343  0.0  0.0   4356   724 pts/0    S+   23:08   0:00 grep --color=auto nginx
[root@lnmp ~]# 

中间需要等待一段时间,nginx服务才会启动!

从上的nginx服务已经关闭!

[root@slave ~]# ps aux |grep nginx
root      4929  0.0  0.0   4356   724 pts/1    S+   23:12   0:00 grep --color=auto nginx
[root@slave ~]#


本文出自 “自定义” 博客,谢绝转载!

heartbeat

标签:heartbeat

原文地址:http://zidingyi.blog.51cto.com/10735263/1890260

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!