9月242014
用Piranha来实现WEB的负载均衡
- yum -y install piranha ipvsadm
- piranha-passwd
- /etc/init.d/piranha-gui start
- vi /etc/sysconfig/ha/lvs.cf
- serial_no = 41
- #primary_private = 10.0.0.1
- service = lvs
- backup_active = 1
- backup = 192.168.0.112
- #backup_private = 10.0.0.2
- heartbeat = 1
- heartbeat_port = 539
- keepalive = 6
- deadtime = 18
- network = direct
- debug_level = NONE
- monitor_links = 1
- syncdaemon = 1
- virtual web_vip {
- active = 1
- address = 192.168.0.115 eth0:1
- vip_nmask = 255.255.255.255
- sorry_server = 127.0.0.1
- port = 80
- pmask = 255.255.255.255
- use_regex = 0
- load_monitor = none
- scheduler = rr
- protocol = tcp
- timeout = 6
- reentry = 15
- quiesce_server = 0
- server web01 {
- address = 192.168.0.113
- active = 1
- port = 80
- weight = 1
- }
- server web02 {
- address = 192.168.0.114
- active = 1
- port = 80
- weight = 1
- }
- }
- sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#' /etc/sysctl.conf
- sysctl -p
- /etc/init.d/pulse start
- #!/bin/bash
- VIP=192.168.0.115
- /etc/rc.d/init.d/functions
- case "$1" in
- start)
- echo "start LVS of REALServer"
- for ((i=0; i<`echo ${#VIP[*]}`; i++))
- do
- interface="lo:`echo ${VIP[$i]}|awk -F . '{print $4}'`"
- /sbin/ifconfig $interface ${VIP[$i]} broadcast ${VIP[$i]} netmask 255.255.255.255 up
- done
- echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
- echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
- echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
- echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
- ;;
- stop)
- /sbin/ifconfig lo:110 down
- echo "close LVS Directorserver"
- #echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
- #echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
- #echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
- #echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
- ;;
- *)
- echo "Usage: $0 {start|stop}"
- exit 1
- esac
- chmod 700 /root/scripts/lvs_sh
- /root/scripts/lvs.sh start
- [root@lb01 ~]# ipvsadm -Ln
- IP Virtual Server version 1.2.1 (size=4096)
- Prot LocalAddress:Port Scheduler Flags
- -> RemoteAddress:Port Forward Weight ActiveConn InActConn
- TCP 192.168.0.115:80 rr
- -> 192.168.0.114:80 Route 1 0 0
- -> 192.168.0.113:80 Route 1 2 0
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!