mouse 发表于 2018-12-28 11:42:26

haproxy+keepalived群集

  本次案列需要搭建两台web服务器,两台haproxy群集调度工具用于调度使web服务器。然后需要在haproxy上部署keepalived实现haproxy双机热备。
haproxy用于调度web服务器,keepalived用于实现haproxy的高可用性,两者协调可以使得web群集同时具备这两种性能。
http://i2.运维网.com/images/blog/201805/04/42f5ac62633b85b0b4154e972caed6fa.png
1、首先准备两台nginx服务器,开启nginx服务。在本地配置地址分别使用192.168.1.10和192.168.1.20,并配置虚拟地址lo:0-192.168.1.111用以作为群集标记。
http://i2.运维网.com/images/blog/201805/04/dfb4d99798d46934c2b67d6a6c44114f.png
http://i2.运维网.com/images/blog/201805/04/c4e9d4ddf89d8465c56b51b81a632b5a.png
http://i2.运维网.com/images/blog/201805/04/c22ae8401d27352321d3e806a585e266.png
http://i2.运维网.com/images/blog/201805/04/279f6cc65a59144ebcfbcf9d1fcf2fdf.png
另一台nginx服务器配置相同。
2、【搭建haproxy部分】为haproxy配置地址两个地址,一个为192.168.1.30和192.168.1.111(群集地址);另一个为192.168.1.40和192.168.1.111
http://i2.运维网.com/images/blog/201805/04/fb0fe7a8d0966c267b66ef4308e20a0f.png
http://i2.运维网.com/images/blog/201805/04/242ce813b57d4b5333c9275c160a1ff8.png
http://i2.运维网.com/images/blog/201805/04/cb7a4fe4ef7865e33883258ddc960d04.png
http://i2.运维网.com/images/blog/201805/04/7ea1c72b4a24bf1b13940843c5e0d930.png
3、使用yum安装pcre-devel和bzip2-devel。
http://i2.运维网.com/images/blog/201805/04/860fd77050ff0e62b72bebad07e0362f.png
4、安装haproxy。
http://i2.运维网.com/images/blog/201805/04/bbf97dc0bd5c1af3cf7bcecddec8321c.png
5、建立haproxy配置文件和服务控制文件
http://i2.运维网.com/images/blog/201805/04/147ffa7313fed71e219ffd8d04d65d12.png
6、编辑haproxy配置文件。vim /etc/haproxy/haproxy.cfg
http://i2.运维网.com/images/blog/201805/04/c3b9e52fa9e6aa1a5d5b3c1abb7f8a0c.png
http://i2.运维网.com/images/blog/201805/04/da751f3ebae1a535b5700d2645a6bc59.png
7、优化haproxy执行路径,并给与服务控制文件可执行权限。
http://i2.运维网.com/images/blog/201805/04/534181ba62fd1d0f194b65a52f06af23.png
8、启动haproxy服务
http://i2.运维网.com/images/blog/201805/04/72e521cec649d8df19cdfb41fd4f9161.png
9、【安装配置keepalived部分】安装keepalived
http://i2.运维网.com/images/blog/201805/04/813d6cc0035febd29a75ee970a6a50bc.png
10、添加keepalived系统服务
http://i2.运维网.com/images/blog/201805/04/2b868f60b7946fdb9b0eff0da584d6e9.png
11、编辑keepalived配置文件,vim /etc/keepalived/keepalived.conf。(两台keepalived的配置不同,需注意)
http://i2.运维网.com/images/blog/201805/04/7d56e1ade6c46b82c1b32077c1b2b6d6.png
http://i2.运维网.com/images/blog/201805/04/2ead69235408ec8a068034994588a339.png
12、启动keepalived服务
http://i2.运维网.com/images/blog/201805/04/c218123c5c01c4583a8e7cab6bc305dd.png
13、在设备上登陆keepalived的virtual_server的ip地址-192.168.1.111
http://i2.运维网.com/images/blog/201805/04/d207b9cb78e25b7d3f176ce915ccad37.png
http://i2.运维网.com/images/blog/201805/04/668076f73acdd50517f6cd0cfcef310e.png
14、可以通过ip addr show dev eth0查看keepalived漂移地址。
http://i2.运维网.com/images/blog/201805/04/600a235744bfb1d1cfa516ec027febfd.png
http://i2.运维网.com/images/blog/201805/04/572eaffed52581023c1c2b0d36905b4f.png
15、测试。关闭目前的keepalived活跃服务器haproxy1的网卡,可以看到地址会漂移到备份的haproxy2上。
http://i2.运维网.com/images/blog/201805/04/3b3067b6b52d843ec8cf3dbb58f49ca5.png
16、再次登陆该地址192.168.1.111,依然可以访问。
http://i2.运维网.com/images/blog/201805/04/dc3895aca064f4715400ba963cc18746.png



页: [1]
查看完整版本: haproxy+keepalived群集