LVS+KEEPALIVED 安装与配置实例

简介: --------------------------------------master---------------------------------------echo "1" > /proc/sys/net/ipv4/ip_forwardwget http://www.

--------------------------------------master---------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
tar -zxvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26
make&&make install

查看

ipvsadm -L -n

wget http://www.keepalived.org/software/keepalived-2.0.9.tar.gz
tar zxvf keepalived-2.0.9.tar.gz
cd keepalived-2.0.9
./configure --perfix=/ --mandir=/usr/local/share/man
make &&make install
cp keepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
cp keepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived
chkconfig --add keepalived
chkconfig --level 345 keepalived on

编辑

vi /etc/sysconfig/keepalived
global_defs {
notification_email {
finalsd@gmail.com
}
notification_email_from finaxx@gmail.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id haproxy-ha
}
vrrp_sync_group VG1 {
group {
VI1
}
}
vrrp_instance VI1 {
state BACKUP
smtp_alert
notify_fault "/root/script/notify_mail.sh fault"
notify_master "/root/script/notify_mail.sh master"
nopreempt
insterface eth1

track_interface {
eth 0
eth 1
}
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass abc123..
}
virtual_ipaddress {
192.168.1.1/24 dev eth1 scope global
}
}
virtual_server 192.168.1.1 80 {
delay_loop 3
lb_algo wlc #rr wrr
lb_kind DR
persistence_timeout 1200
protocol TCP
ha_suspend

real_server 192.168.1.11 80 {
weight 3
TCP_CHECK {
nb_get_retry 3
delay_before_retry 3
connect_timeout 3
connect_port 80
}
}
real_server 192.168.1.12 80 {
weight 3
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
}

service keepalived start

------------------------------------------backup-------------------------------------------------
和master一样,priority改为100,nopreempt删掉


---------------------------------------所有real server---------------------------------------------
vi /etc/init.d/realserver

!/bin/sh

VIP=192.168.1.1
. /etc/rc.d/init.d/functions

case "$1" in

禁用本地的ARP请求、绑定本地回环地址

start)
/sbin/ifconfig lo down
/sbin/ifconfig lo up
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
/sbin/sysctl -p >/dev/null 2>&1
/sbin/ifconfig lo:0 VIP netmask 255.255.255.255 up #在回环地址上绑定VIP,设定掩码,与Direct Server(自身)上的IP保持通信 /sbin/route add -hostVIP dev lo:0
echo "LVS-DR real server starts successfully.\n"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del VIP >/dev/null 2>&1 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 echo "LVS-DR real server stopped.\n" ;; status) isLoOn=`/sbin/ifconfig lo:0 | grep "VIP"isRoOn=/bin/netstat -rn | grep "VIP"` if [ "isLoON" == "" -a "isRoOn" == "" ]; then echo "LVS-DR real server has run yet." else echo "LVS-DR real server is running." fi exit 3 ;; *) echo "Usage:0 {start|stop|status}"
exit 1
esac
exit 0

chmod +x /etc/init.d/realserver
echo "/etc/init.d/realserver start" >> /etc/rc.d/rc.local
service realserver start


目录
相关文章
|
6月前
|
运维 算法 Linux
LVS详解(四)——LVS安装与配置命令
LVS详解(四)——LVS安装与配置命令
130 2
|
2月前
|
运维 负载均衡 网络协议
LVS+Keepalived 负载均衡
LVS+Keepalived 负载均衡
73 8
LVS+Keepalived 负载均衡
|
2月前
|
域名解析 运维 负载均衡
LVS+Keepalived 负载均衡(二)28-1
【8月更文挑战第28天】LVS+Keepalived 负载均衡 配置 LVS VIP
63 5
|
4月前
|
网络协议 应用服务中间件 Linux
LVS介绍与配置
LVS介绍与配置
199 8
|
4月前
|
负载均衡 网络协议 算法
使用IPVSADM配置LVS负载均衡
使用IPVSADM配置LVS负载均衡
|
6月前
|
运维 负载均衡 监控
keepalived+LVS实现高可用性集群
通过结合keepalived和LVS,你可以创建一个高可用性的负载均衡集群,确保服务器的稳定性和性能。这对于托管Web服务、应用服务器等关键服务的服务器集群非常有用。
119 1
|
6月前
|
负载均衡 监控 Linux
CentOS6.5高可用集群LVS+Keepalived(DR模式)
CentOS6.5高可用集群LVS+Keepalived(DR模式)
|
6月前
|
负载均衡 监控 调度
Keepalived+Lvs(dr)调度器主备配置小实验
Keepalived和LVS(Linux Virtual Server)是两个常用的开源软件,通常结合使用以提供高可用性和负载均衡的解决方案。 Keepalived是一种用于实现高可用性的软件,它可以监控服务器的健康状态,并在主服务器出现故障时自动切换到备份服务器。
213 2
|
负载均衡 应用服务中间件 Linux
企业实战(13)LVS负载均衡NAT(网络地址转换)模式实战详解(一)
企业实战(13)LVS负载均衡NAT(网络地址转换)模式实战详解(一)
171 0
|
负载均衡 应用服务中间件 Linux
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
Nginx系列教程(14) - LVS+KeepAlived+Nginx实现高性能负载均衡集群
1148 0