Linux 下 LVS+Keepalived 负载均衡安装
lvs是一个开源的软件,由毕业于国防科技大学的章文嵩博士于1998年5月创立(中国人的项目),可以实现LINUX平台下的简单负载均衡。
LVS是Linux Virtual Server的缩写,意思是Linux虚拟服务器。
负载均衡系统可以选用LVS方案,而为避免Director Server单点故障引起系统崩溃,我们可以选用LVS+Keepalived组合保证高可用性。
具体LVS作用是什么,这里就不详细说明。
直接执行命令(相应tar.gz文件自行下载)
#!/bin/sh pathDir=$(cd `dirname $0`; pwd) yum install -y libnl* popt* yum -y install openssl-devel cd ${pathDir} tar -zxvf ipvsadm-1.26.tar.gz make;make install cd ${pathDir} tar -zxvf keepalived-1.2.16.tar.gz cd keepalived-1.2.16 ./configure make;make install find / -name keepalived # 查看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 status #查看状态 #添加自启 chkconfig --add /etc/rc.d/init.d/keepalived chkconfig keepalived on #配置Web服务器的 #复制VIP.sh (修改虚拟IP地址)到/etc/rc.d/init.d #cd /etc/rc.d/init.d/ #chmod 755 /etc/rc.d/init.d/functions #chmod 755 /etc/rc.d/init.d/VIP.sh #bash /etc/rc.d/init.d/VIP.sh start
需要开机启动的VIP.sh,注意将SNS_VIP替换成自己的虚拟IP
#!/bin/bash # description: Config realserver lo and apply noarp SNS_VIP=192.168.2.219 /etc/rc.d/init.d/functions 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
Blog都是随笔,只当做笔记,不会有详细介绍,测试请慎重。。。