- 论坛徽章:
- 0
|
使用LVS+Keepalived 实现高性能高可用负载均衡实际操作说明
kkmangnn 网站:
http://hi.baidu.com/way2rhce
前言:
本文档用keepalived实现负载均衡和高可用性
一. 网站负载均衡拓朴图
.
IP信息列表:
主机名
IP
说明
dr1.example.com
192.168.0.6
LVS-DR-Master
dr2.example.com
192.168.0.7
LVS-DR-BACKUP
192.168.0.8
LVS-DR-VIP
web1.example.com
192.168.0.9
WEB1-Realserver
web2.example.com
192.168.0.10
WEB2-Realserver
192.168.0.1
GateWay
系统环境:CentOS 5.2 ,需要安装有gcc openssl-devel kernel-devel包
二. 安装LVS和Keepalvied软件包
1. 下载相关软件包
#mkdir /usr/local/src/lvs
#cd /usr/local/src/lvs
#wget
http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
#wget
http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
2. 安装LVS和Keepalived
#lsmod |grep ip_vs
#uname -r
2.6.18-92.el5
#ln -s /usr/src/kernels/2.6.18-92.el5-i686/ /usr/src/linux
#tar zxvf ipvsadm-1.24.tar.gz
#cd ipvsadm-1.24
#make && make install
#tar zxvf keepalived-1.1.15.tar.gz
#cd keepalived-1.1.15
#./configure && make && make install
把keepalived做成系统启动服务方便管理
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
#service keepalived start|stop
三. 配置web服务器的脚本.
#vi /usr/local/src/lvs/web.sh
#!/bin/bash
SNS_VIP=192.168.0.8
case "$1" in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP dev lo:0
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
sysctl -p >/dev/null 2>$1
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
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 "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
# chmod +x /usr/local/src/lvs/web.sh ##修改成可执行
#vi /etc/rc.local ##将该脚本写入开机文件
/usr/local/src/lvs/web.sh start
配置好一台web服务器之后,将配置文件拷贝到第二台服务器。
四.使用Keepalvied实现负载均衡和和高可用性
1.配置在主负载均衡服务器上配置keepalived.conf
#vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
# notification_email {
# acassen@firewall.loc
# failover@firewall.loc
# sysadmin@firewall.loc
# }
# notification_email_from Alexandre.Cassen@firewall.loc
# smtp_server 192.168.200.1
# smtp_connect_timeout 30
router_id LVS_DEVEL
}
#2009-08-24 by pricet
#VIP1
vrrp_instance VI_1 {
state MASTER ###在备用机dr2上配置成BACKUP
interface eth0
virtual_router_id 51
priority 100 ###在备用机dr1上配置成99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.8
}
}
virtual_server 192.168.0.8 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 192.168.0.9 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.0.10 80 {
weight 3
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
2. BACKUP服务器同上配置,先安装lvs再按装keepalived,仍后配置/etc/keepalived/keepalived.conf,只需将红色标示的部分改一下即可.
3. 启动keepalived,查看lvs服务是否正常
#watch ipvsadm –ln
[root@dr1 keepalived-1.1.15]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.0.8:http wrr persistent 50
-> 192.168.0.10:http Route 3 0 0
-> 192.168.0.9:http Route 1 0 0
#tail –f /var/log/message 监听日志,查看状态。
5.停Master服务器的keepalived服务,查看BAKCUP服务器是否能正常接管.
![]()
文件:
使用LVS+Keepalived 实现高性能高可用负载均衡实际操作说明.rar
大小:
53KB
下载:
下载
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/96411/showart_2038323.html |
|