搭建HAProxy + Keepalived高可用

安装

在四台虚拟机上,我们以如下方式搭建集群:

192.168.115.3 haproxy+keepalived
192.168.115.4haproxy+keepalived
192.168.115.5 nginx
192.168.115.6 nginx

在192.168.115.3 和192.168.115.4 上安装haproxy和keepalived(haproxy编译安装,keepalived yum安装)

安装过程省略

配置keepalived

主(192.168.115.3)

vim /etc/keepalived/keepalived.conf 

备(192.168.115.4)

vim /etc/keepalived/keepalived.conf

配置haproxy配置(2台机一致)

建立配置文件

mkdir /etc/haproxy

vim /etc/haproxy/haproxy.cfg

搭建HAProxy + Keepalived高可用_第1张图片

搭建HAProxy + Keepalived高可用_第2张图片

添加为系统服务

cp /root/haproxy-1.7.2/examples/haproxy.init /etc/init.d/haproxy

vim  /etc/init.d/haproxy

搭建HAProxy + Keepalived高可用_第3张图片

chmod +x /etc/init.d/haproxy

chkconfig --add /etc/init.d/haproxy

添加3和5运行级别下自启动

chkconfig haproxy --level 35 on

chkconfig --list 

搭建HAProxy + Keepalived高可用_第4张图片

配置syslog日志

vim /etc/rsyslog.d/haproxy.conf

搭建HAProxy + Keepalived高可用_第5张图片

启动服务

启动keepalived

systemctl start keepalived

启动haproxy( 也可以使用systemctl进行启停)

service haproxy  start

service haproxy  stop

service haproxy  restart  | reload

systemctl  daemon-reload
 搭建HAProxy + Keepalived高可用_第6张图片

在192.168.115.5 和192.168.115.6 上安装nginx(yum安装)

安装过程省略

配置nginx网页文档

启动服务

测试

客户端访问

搭建HAProxy + Keepalived高可用_第7张图片

 搭建HAProxy + Keepalived高可用_第8张图片

断掉主,测试备

 备

 客户端访问

搭建HAProxy + Keepalived高可用_第9张图片

搭建HAProxy + Keepalived高可用_第10张图片

你可能感兴趣的:(linux,服务器,运维)