原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://renzhenxing.blog.51cto.com/728846/1251228
1
|
yum install openssl-devel kernel-devel
|
1
|
yum install ipvsadm
|
1
|
yum install keepalived
|
1
2
|
chkconfig ipvsadm on
chkconfig keepalived on
|
1
|
vim /etc/keepalived/keepalived.confg
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
! Configuration File
for
keepalived
global_defs {
notification_email {
57674891
@qq.com # 联系人
}
notification_email_from
57674891
@qq.com
smtp_server smtp.qq.com
smtp_connect_timeout
30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER #从上直接改为BACKUP 即可。
interface
eth0
virtual_router_id
51
priority
100
# 主上是
100
从一定要设置比主小,
90
advert_int
1
authentication {
auth_type PASS #密码验证类型
auth_pass
1111
#主从之间的验证密码,主从
2
端一定要一致
}
virtual_ipaddress {
#
192.168
.
200.16
#
192.168
.
200.17
#
192.168
.
200.18
#
10.0
.
0.100
192.168
.
80.148
# 虚拟ip (vip)地址后面,下面可以继续叠加。
}
}
#--------------------------------------
virtual_server
192.168
.
80.148
80
{ # 虚拟IP
delay_loop
6
#(每隔
10
秒查询realserver状态)
lb_algo rr #(lvs 算法) 更改算法在此处更改
lb_kind DR #(Direct Route)
persistence_timeout
5
#(同一IP的连接
60
秒内被分配到同一台realserver)
protocol TCP #(用TCP协议检查realserver状态)
real_server
192.168
.
80.146
80
{ # web端地址
weight
1
#(权重)
TCP_CHECK {
connect_timeout
10
#(
10
秒无响应超时)
nb_get_retry
3
delay_before_retry
3
connect_port
80
#端口
}
}
real_server
192.168
.
80.147
80
{
weight
1
TCP_CHECK {
connect_timeout
10
nb_get_retry
3
delay_before_retry
3
connect_port
80
}
}
}
|
1
|
scp root@
192.168
.
80.144
:/etc/keepalived/keepalived.conf
|
1
|
vim /etc/keepalived/keepalived.conf
|
1
2
3
4
5
6
|
vrrp_instance VI_1 {
state BACKUP #直接改为BACKUP 即可。
interface
eth0
virtual_router_id
51
priority
90
#主上是
100
从一定要设置比主小,
90
advert_int
1
|
1
|
service keepalived start
|
1
|
vim /root/realserver.sh
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#!/bin/bash
# description: Config realserver
#Written by : http:
//kerry.blog.51cto.com
#此脚本转自以上作者,尊重他人劳动成果。特此保留版权信息
SNS_VIP=
192.168
.
80.148
# VIP 地址
/etc/rc.d/init.d/functions #如果提示权限不够 执行:chmod
777
/etc/rc.d/init.d/functions
case
"$1"
in
start)
/sbin/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)
/sbin/ifconfig lo:
0
down
/sbin/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
|
1
|
chmod a+x realserver.sh
|
1
|
echo /root/realserver.sh &>>/etc/rc.local
|
1
|
/root/realserver.sh &
|
1
|
ifconfig
|