haproxy keepalived_Linux基础架构学习-Apache用于企业级容错-D13-Keepalived

KEEPALIVED

Keepalived是一个基于Linux的路由器,支持虚拟路由器冗余协议(VRRP)。 它通常与HAProxy结合使用以提供冗余,因为HAProxy本身不提供任何冗余。 图6-6显示了HAProxy和Keepalived的典型配置。

bcce03f03fae5b162715b666012140c0.png

其中一个HAProxy服务器是Keepalived主服务器; 另一个是Keepalived奴隶。 清单6-21显示了主/从配置。

清单6-21。 Keepalived主/从配置

安装Keepalived。

# yum install keepalived -y

/etc/keepalived/keepalived.conf has the following contents on the master:

global_defs { notification_email { admin@example.com } notification_email_from keepalived@example.com smtp_server 10.1.1.100 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script check_haproxy { script "/sbin/service haproxy status" interval 2 fall 2 rise 2}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.1.1.30 } track_script { check_haproxy }}

/etc/keepalived/Keepalived.conf has the following contents on the backup server:

global_defs { notification_email { admin@example.com } notification_email_from keepalived@example.com smtp_server 10.1.1.100 smtp_connect_timeout 30 router_id LVS_DEVEL}vrrp_script check_haproxy { script "/sbin/service haproxy status" interval 2 fall 2 rise 2}vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.1.1.30 } track_script { check_haproxy }}

Additional documentation is available at

  • http://www.keepalived.org/
  • http://datatracker.ietf.org/wg/vrrp/documents/

Keepalived in Action

清单6-22显示了Keepalived的运行情况。 有两个HAProxy服务器; 一个被称为haproxy并且是主人。 主站的IP地址为172.16.127.210。 另一台服务器名为haproxy1,IP地址为172.16.127.213; 它也是备份服务器。 他们都安装并配置了HAProxy。 虚拟IP地址值为172.16.127.214。 当主服务器在线时,它拥有虚拟IP地址。 当我们停止主服务器上的haproxy服务时,备份服务器将接管虚拟IP地址。

清单6-22。 Keepalived in Action

确认haproxy在运行。

# service haproxy statushaproxy (pid 2435) is running...

检查keepalive master机器的ip地址。地址是172.16.127.210。虚拟浮动IP地址是172.16.127.214。

# ip addr show | egrep '^s+inets+' inet 127.0.0.1/8 scope host lo inet 172.16.127.210/24 brd 172.16.127.255 scope global eth0 inet 172.16.127.214/32 scope global eth0

On the backup host, ensure the service haproxy is running.

在备份机器上,确保haproxy正在运行。

# service haproxy statushaproxy (pid 2341) is running...

Check the IP address of the backup Keepalived host. We only see a single IP for the interface: 172.16.127.213.

检查keepalive备份机器的ip地址配置,我们只是看到一个单独的只:172.16.127.213。

# ip addr show | egrep '^s+inets+' inet 127.0.0.1/8 scope host lo inet 172.16.127.213/24 brd 172.16.127.255 scope global eth1

在master上面,我们停掉haproxy。

# service haproxy stop

当我们在master上面检查日志/var/log/messages的时候,我们能看到vip已经被删除了。

Nov 19 13:48:07 haproxy Keepalived_vrrp[2471]: VRRP_Script(check_haproxy) failedNov 19 13:48:07 haproxy Keepalived_vrrp[2471]: VRRP_Instance(VI_1) Entering FAULT STATENov 19 13:48:07 haproxy Keepalived_vrrp[2471]: VRRP_Instance(VI_1) removing protocol VIPs.Nov 19 13:48:07 haproxy Keepalived_vrrp[2471]: VRRP_Instance(VI_1) Now in FAULT stateNov 19 13:48:07 haproxy Keepalived_healthcheckers[2470]: Netlink reflector reports IP 172.16.127.214 removed

On the backup, we check /var/log/messages and determine whether it is picking up the virtual IP address of 172.16.127.214.

在备份机器,我们检查/var/log/messages文件,并且是否拿起vip地址172.16.127.214做出决定。

Nov 19 13:48:07 haproxy Keepalived_vrrp[2366]: VRRP_Instance(VI_1) Transition to MASTER STATENov 19 13:48:08 haproxy Keepalived_vrrp[2366]: VRRP_Instance(VI_1) Entering MASTER STATENov 19 13:48:08 haproxy Keepalived_vrrp[2366]: VRRP_Instance(VI_1) setting protocol VIPs.Nov 19 13:48:08 haproxy Keepalived_vrrp[2366]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 172.16.127.214Nov 19 13:48:08 haproxy Keepalived_healthcheckers[2365]: Netlink reflector reports IP 172.16.127.214 added

On the backup host, when we check the IP address, we notice the floating IP address of 172.16.127.214 now belongs to the backup.

在备份机器上,我们检查ip地址,我们注意到浮动ip地址172.16.127.214已经属于备份机器了。

# ip addr show | egrep '^s+inets+' inet 127.0.0.1/8 scope host lo inet 172.16.127.213/24 brd 172.16.127.255 scope global eth1 inet 172.16.127.214/32 scope global eth1

获得帮助

Apache已经存在很多年了,很容易找到它的文档。 这里列出了一些获得额外帮助的方法:

Apache文档(https://httpd.apache.org/docs/current/)

关于Apache的书籍(http://www.amazon.com/Apache-Books/lm/2P2M3GSM1NKR8)

Apache邮件列表(https://httpd.apache.org/lists.html)

IRC(irc.freenode.net上的#httpd频道)

结论

在本章中,我简要介绍了ASF,并解释了HTTP协议。 之后我们研究了如何安装Apache并对其进行配置,以及如何增强Apache性能。 最后,我们检查了HAProxy和Keepalived。 使用这些工具,您可以构建容错的企业基础结构。 负载平衡,代理,故障转移,缓存和服务功能可帮助您构建冗余基础架构,从而延长正常运行时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值