基于redhat linux虚拟服务器的web负载均衡集群(piranha+LVS)
基于redhat linux虚拟服务器的web负载均衡集群硬件环境
分发机
LB1:192.168.0.129
LB2:192.168.0.130
真实节点主机
NODE1:192.168.0.131
NODE2:192.168.0.132
试验在VMWARE下完成测试成功
初始化配置
在LB1上编辑hosts文件,并且设置 root ssh key 这样有利于节点之间相互访问
[*]# cat /etc/hosts
[*]
[*]# Do not remove the following line, or various programs
[*]
[*]# that require network functionality will fail.
[*]
[*]127.0.0.1 localhost.localdomain localhost
[*]
[*]::1 localhost6.localdomain6 localhost6
[*]
[*]192.168.0.129 lb1.test.com lb1
[*]
[*]192.168.0.130 lb2.test.com lb2
[*]
[*]192.168.0.131 node1.test.com node1
[*]
[*]192.168.0.132 node2.test.com node2
[*]# ssh-keygen
[*]
[*]Generating public/private rsa key pair.
[*]
[*]Enter file in which to save the key (/root/.ssh/id_rsa):
[*]
[*]/root/.ssh/id_rsa already exists.
[*]
[*]Overwrite (y/n)?
[*]
[*]#
将LB1的/root/.ssh和/etc/hosts复制到其他节点中
[*]For hostname in lb2 node1 node2 ; do scp –r /root/.ssh $hostname:/root ;done
[*]
[*]For hostname in lb2 node1 node2 ; do scp /etc/hosts $hostname:/etc/hosts ;done
在LB1上安装ipvasdm piranha httpd 软件包
[*]yum install -y ipvsadm piranha httpd
[*]
[*]Loaded plugins: fastestmirror
[*]
[*]Loading mirror speeds from cached hostfile
[*]
[*]Setting up Install Process
[*]
[*]Package ipvsadm-1.24-10.x86_64 already installed and latest version
[*]
[*]Package piranha-0.8.4-16.el5.x86_64 already installed and latest version
[*]
[*]Package httpd-2.2.3-43.el5.centos.x86_64 already installed and latest version
[*]
[*]Nothing to do
再LB2上安装ipvasdm piranha 包!
[*]yum install -y ipvsadm piranha
[*]
[*]Loaded plugins: fastestmirror
[*]
[*]Loading mirror speeds from cached hostfile
[*]
[*]Setting up Install Process
[*]
[*]Package ipvsadm-1.24-10.x86_64 already installed and latest version
[*]
[*]Package piranha-0.8.4-16.el5.x86_64 already installed and latest version
[*]
[*]Nothing to do
在node1 node2上安装httpd arptables_jf
[*]# yum install httpd arptables_jf
[*]
[*]Loaded plugins: fastestmirror
[*]
[*]Loading mirror speeds from cached hostfile
[*]
[*]Setting up Install Process
[*]
[*]Package httpd-2.2.3-43.el5.centos.x86_64 already installed and latest version
[*]
[*]Package arptables_jf-0.0.8-8.x86_64 already installed and latest version
[*]
[*]Nothing to do
#
登陆 LB1 配置piranha登陆设置密码
[*]# piranha-passwd
[*]
[*]New Password:
[*]
[*]Verify:
[*]
[*]Updating password for user piranha
启动piranha-gui服务
[*]# /etc/init.d/piranha-gui start
Starting piranha-gui: [确定]
#
浏览器中打开http://192.168.0.129:3636,输入用户名密码登陆!
http://blog.运维网.com/attachment/201202/220949774.jpg
http://blog.运维网.com/attachment/201202/221035374.jpg
设置primary server public ip 192.168.0.129 点击accept生效
http://blog.运维网.com/attachment/201202/221128480.jpg
选择REDUNDANCY 然后点击ENABLE,设置Redundant server public ip 为192.168.0.130,单击accept
http://blog.运维网.com/attachment/201202/221234583.jpg
选择VIRTUAL SERVERS 然后点击ADD
http://blog.运维网.com/attachment/201202/221314202.jpg
编辑VIRTUAL SERVER编辑,如图!
http://blog.运维网.com/attachment/201202/221500792.jpg
添加,编辑REAL SERVER 为两个真实节点,编辑完后别忘了,保持,并且active
http://blog.运维网.com/attachment/201202/221523480.jpg
选择MONITORING SCRIPTS , 将sending Program设为/bin/testlinks %h ,将
Expect 设置 ok 。点击ACCEPT保存。点击VIRTUAL SERVERS回到上级菜单
http://blog.运维网.com/attachment/201202/221539892.jpg
点击ACTIVETE激活!
http://blog.运维网.com/attachment/201202/221553629.jpg
最后回到CONTROL/MONITORING点击update information now 更新
配置文件保存在/etc/sysconfig/ha/lvs.cf
[*]# cat /etc/sysconfig/ha/lvs.cf
[*]
[*]serial_no = 58
[*]
[*]primary = 192.168.0.129
[*]
[*]service = lvs
[*]
[*]backup_active = 1
[*]
[*]backup = 192.168.0.130
[*]
[*]heartbeat = 1
[*]
[*]heartbeat_port = 539
[*]
[*]keepalive = 6
[*]
[*]deadtime = 18
[*]
[*]network = direct
[*]
[*]debug_level = NONE
[*]
[*]monitor_links = 0
[*]
[*]syncdaemon = 0
[*]
[*]virtual apache {
[*]
[*] active = 1
[*]
[*] address = 192.168.0.250 eth0:1
[*]
[*] vip_nmask = 255.255.255.255
[*]
[*] port = 80
[*]
[*] send = "GET / HTTP/1.0\r\n\r\n"
[*]
[*] expect = "ok"
[*]
[*] use_regex = 0
[*]
[*] send_program = "/bin/testlinks %h"
[*]
[*] load_monitor = none
[*]
[*] scheduler = wlc
[*]
[*] protocol = tcp
[*]
[*] timeout = 6
[*]
[*] reentry = 15
[*]
[*] quiesce_server = 0
[*]
[*] server node1 {
[*]
[*] address = 192.168.0.131
[*]
[*] active = 1
[*]
[*] weight = 1
[*]
[*] }
[*]
[*] server node2 {
[*]
[*] address = 192.168.0.132
[*]
[*] active = 1
[*]
[*] weight = 1
[*]
[*] }
[*]
[*]}
[*]
[*]#
将这个文件cp到LB2上!
[*]# scp/etc/sysconfig/ha/lvs.cf lb2:/etc/sysconfig/ha/lvs.cf
在LB1上编辑服务器测试程序/bin/testlink,并且加上执行权限!
[*]# cat /bin/testlink
[*]
[*]#!/bin/bash
[*]
[*]/usr/bin/links -dump 1 $1 >/dev/null 2>&1
[*]
[*]if [ 0 -eq $? ] ; then
[*]
[*]echo ok
[*]
[*]else
[*]
[*]echo fail
[*]
[*]fi
[*]
[*]#chmod a+x /bin/testlink
然后讲、bin/testlink文件复制一份到LB2上!
在node1上编辑arptables脚本,并且运行它
[*]# cat /arp_arptables.sh
[*]
[*]#!/bin/bash
[*]
[*]VIP=192.168.0.250
[*]
[*]RIP=192.168.0.131
[*]
[*]arptables -F
[*]
[*]arptables -A IN -d $VIP -j DROP
[*]
[*]arptables -A OUT -s $VIP -j mangle --mangle-ip-s $RIP
[*]
[*]/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
[*]
[*]/sbin/route add -host $VIP dev eth0:1
[*]
[*]#
放入测试页面,并且启动httpd
[*]# echo "node1" > /var/www/html/index.html
[*]
[*]# service httpd start
启动 httpd:
在node2上编辑arptables脚本,并且运行它
[*]# cat /arp_arptables.sh
[*]
[*]#!/bin/bash
[*]
[*]VIP=192.168.0.250
[*]
[*]RIP=192.168.0.132
[*]
[*]arptables -F
[*]
[*]arptables -A IN -d $VIP -j DROP
[*]
[*]arptables -A OUT -s $VIP -j mangle --mangle-ip-s $RIP
[*]
[*]/sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
[*]
[*]/sbin/route add -host $VIP dev eth0:1
[*]
[*]#
放入测试页面,并且启动httpd
[*]# echo "node2" > /var/www/html/index.html
[*]
[*]# service httpd start
启动 httpd:
LB1 LB2上启动PULSE服务,查看ipvsadm结果
[*]/etc/init.d/pulse start
[*]
[*]Ipvsadm-L –n
如果前面的配置正确,这里可以在lb1上看到正确的回显。
当我们将lib1的网线拔除后,分发服务将自动切换到lib2上。
当我们将node1的网线拔除后,分发器将把node1从分发列表中剔出。当我们将
node1的网线插回后,分发器又将把node1恢复到分发列表中去。
无论你如何测试,请使用额外的机器访问VIP,这也有利于测试分发器是否正确的保持
了session。
页:
[1]