环境: 虚拟机:VMware Workstation
操作系统:CentOS 5.5
一、keepalived+lvs-DR模式配置高可用负载均衡 拓扑如下:
二、服务器ip配置信息 1. ip_lb 主机(master) :
2.ip_lb_2 主机 (backup)
3.web1 主机
4.web2 主机
三、在master和backup分别查看是否有ipvsadm软件 1. 检查ipvsadm是否安装成功.可以直接输入 [root@localhost ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
2. 检查模版是否加入内核
[root@localhost ~]# lsmod |grep ip_vs
ip_vs 78081 0
四、分别在web1和web2上面安装apache服务. # 安装apache服务不说明了. 开放的端口是:8099 五、在master主机(192.168.96.2)和backup主机(192.168.96.22)上安装keepalived 1. keepalived-1.2.1.tar.gz # 解压这个文件并且安装 (tar -zxvf keepalived-1.2.1.tar.gz) 2. ./configure --prefix=/home/keepalived/ --with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686 3.make 4.make install 5.配置文件的路径 cp /home/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ cp /home/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /home/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp /home/keepalived/sbin/keepalived /sbin/ 6.配置keepalived.conf文件.( ip_lb 主机<master> ) vim /etc/keepalived/keepalived.conf
7、配置keepalived.conf文件.(ip_lb_2 主机 <backup> ) vim /etc/keepalived/keepalived.conf
8. 分别在主备上启动keepalived [root@ip_lb home]# /etc/init.d/keepalived start Starting keepalived: [ OK ] [root@ip_lb home]# tail -f /var/log/message # PS:这里说的LVS.并不是用ipvsadm软件配置.而是直接用keepalived的virtual_server配置项控制的. # 安装ipvsadm只是可以看到负载状况.其实只需要keepalived也可以实现负载均衡集群. 六、在web1和web2主机上配置LVS-DR的相关配置. 1. vim /etc/init.d/lvsDR_node (web1主机)
2. 把这个文件复制到web2主机上. 3. 在web1和web2上分别启动这个脚本: /etc/init.d/lvsDR_node start 七、web1和web2主机上开启httpd服务. /etc/init.d/httpd start # ================= TEST ======================================= 八、测试是否可以负载均衡. 编写测试脚本:
结果: 九、测试断开一个web服务或加入一个web服务 现在关闭 web2主机(192.168.96.4) 的web 服务.. 查看日志可以看到: 现在再把 web2主机(192.168.96.4)的web 服务加入进来: 查看日志可以看到: 十、 测试HA 现在模拟主(master)的keepalived主机死掉. 备机的日志文件: 可以看到备机的keepalived已经开始工作.... 整个部署就完成了. 官方参考中文文档:http://www.keepalived.org/pdf/sery-lvs-cluster.pdf (责任编辑:IT) |