LVS-DR负载均衡-01 第一章 Web LVS 安装实施 2.1 软件测试环境部署 软件平台 Vmware workstation 系统平台 redhat AS 5.4 32bit Lvs 集群软件 ipvsadm v1.24 Keepalived Keepalived v1.1.20 Web服务 Apache 2.2 服务器资源分配规划 集群角色 Master负载均衡器 Backup负载均衡器 真实服务器 真实服务器 主机名 Lvs_01 Lvs_02 Rs01 Rs02 Ip地址 192.168.28.132 192.168.28.133 192.168.28.134 192.168.28.135 Vip 虚拟IP 192.168.28.111 客户端 192.168.2.130(物理机客户端) LVS 模式 DR模式 2.3准备实验环境 VMware Virtual Ethernet Adapter for VMnet8 配置IP 非DHCP,Vmnet1不做配置 物理地址: 00-50-56-C0-00-08 已启用 DHCP: 否 IPv4 地址: 192.168.28.244 IPv4 子网掩码: 255.255.255.0 IPv4 默认网关: IPv4 DNS 服务器: IPv4 WINS 服务器: 已启用 NetBIOS over Tcpip: 是 虚拟机网卡模式设置为NAT模式 2.4 Apache WEB 服务器配置 使用RS(Real Server)中系统自带apache服务 两台RS中分别编辑http.conf文件定义Documentroot 分别为: 01. /home/serv01/public_html 02. /home/serv02/public_html 编辑执行 echo “192.168.18.134”>/home/serv01/public_html/index.html echo “192.168.18.135”>/home/serv02/public_html/index.html 分别启动apache服务 #service httpd start 2.5 安装Ipvsadm 内核需求检查,要求linux内核版本在2.2.4以上 查看当前内核 [root@lvs_01 ~]# uname -r 2.6.18-164.el5 下载ipvsadm编译安装要求与内核相对应的ipvsadm软件,通过ftp方式传入VS中 执行以下命令 [root@lvs_01 ~]# cd /usr/src [root@lvs_01 ~]# tar zxvf ipvsadm-1.24.tar.gz [root@lvs_01 ~]# ln -s kernels/2.6.18-164.el5-i686/ linux [root@lvs_01 ~]# cd ipvsadm-1.24 [root@lvs_01 ~]# make all #编译 [root@lvs_01 ~]# make install #安装 [root@lvs_01 ipvsadm-1.24] # ipvsadm --version #查看版本 2.6 安装配置keepalived 下载tar包,在两台虚拟服务器中分别安装keepalived,安装步骤及其过程一致 [root@lvs_01 local]# cd /usr/src/ [root@lvs_01 local]#tar -xzvf keepalived-1.1.20.tar.gz [root@lvs_01 local]#cd keepalived-1.1.20 [root@lvs_01 local]#./configure —prifix= /etc/keepalived/ [root@lvs_01 local]#make && make [root@lvs_01 local]#cd /etc/keepalived [root@lvs_01 local]#cp etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ [root@lvs_01 local]#cp etc/sysconfig/keepalived /etc/sysconfig/ [root@lvs_01 local]#mkdir /etc/keepalived [root@lvs_01 local]#cp etc/keepalived/keepalived.conf /etc/keepalived [root@lvs_01 local]#chkconfig —add keepalived [root@lvs_01 local]#chkconfig –level 35 keepalived on [root@lvs_01 local]#cp sbin/keepalived /sbin 2.7 配置keepalived 编辑/etc/keepalived/keepalived.conf 配置文件 ! Configuration File for keepalived global_defs { notification_email { cnseek@gmail.com # failover@firewall.loc # sysadmin@firewall.loc } notification_email_from sns-lvs@gmail.com smtp_server 127.0.0.1 # smtp_connect_timeout 30 router_id LVS_DEVEL } # VIP1 vrrp_instance VI_1 { state MASTER #备份服务器上将MASTER改为BACKUP interface eth0 virtual_router_id 51 priority 100 #备份服务上将100改为99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.28.111 #(如果有多个VIP,继续换行填写.) } } virtual_server 192.168.28.132 80 { delay_loop 6 #(每隔6秒查询realserver状态) lb_algo rr # (lvs 算法) lb_kind DR # (Direct Route) persistence_timeout 60 # (同一IP的连接60秒内被分配到同一台realserver) protocol TCP #(用TCP协议检查realserver状态) real_server 192.168.28.134 80 { weight 3 #(权重) TCP_CHECK { connect_timeout 10 #(10秒无响应超时) nb_get_retry 3 delay_before_retry 3 connect_port 80 } } real_server 192.168.28.135 80 { weight 3 TCP_CHECK { connect_timeout 10 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
本文出自 “O Record” 博客,请务必保留此出处http://evils798.blog.51cto.com/8983296/1420849
原文地址:http://evils798.blog.51cto.com/8983296/1420849