安装
在四台虚拟机上,我们以如下方式搭建集群:
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
添加为系统服务
cp /root/haproxy-1.7.2/examples/haproxy.init /etc/init.d/haproxy
vim /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
chkconfig --add /etc/init.d/haproxy
添加3和5运行级别下自启动
chkconfig haproxy --level 35 on
chkconfig --list
配置syslog日志
vim /etc/rsyslog.d/haproxy.conf
启动服务
启动keepalived
systemctl start keepalived
启动haproxy( 也可以使用systemctl进行启停)
service haproxy start
service haproxy stop
service haproxy restart | reload
systemctl daemon-reload
在192.168.115.5 和192.168.115.6 上安装nginx(yum安装)
安装过程省略
配置nginx网页文档
启动服务
测试
客户端访问
断掉主,测试备
主
备
客户端访问