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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
1.keepalived安装
yum  install  -y kernel-devel openssl-devel popt-devel
rpm -vih ipvsadm-1.25*
wget http: //www .keepalived.org /software/keepalived-1 .2.2. tar .gz
tar  zxf keepalived-1.2.2. tar .gz
cd  keepalived-1.2.2
. /configure  --prefix=/ --with-kernel- dir = /usr/src/kernels/2 .6.32-131.0.15.el6.i686
make  &&  make  install
chkconfig --add keepalived
chkconfig keepalived on
2.简单双机热备
环境
主服务器172.16.16.173 /24
备服务器172.16.16.174 /24
漂移IP172.16.16.172 /24
主服务器配置
cd  /etc/keepalived
cp  keepalived.conf keepalived.conf.bak
vim keepalived.conf
global_defs {
route_id HA_TEST_R1         #本服务器的名称
}
vrrp_instance VI_1 {         #定义vrrp热备实例
state MASTER             #热备状态MASTER表示主服务器
interface eth0             #承载VIP地址的物理接口
virtual_route_id 1         #虚拟服务器的ID每个热备组保持一致
priority 100                 #优先级数据值越大优先级越高
advert_int 1                 #通告间隔秒数心跳频率
authentication {          #认证信息每个热备组保持一致
auth_type PASS             #认证类型
auth_pass 123456         #密码字符
}
virtual_ipaddress {         #指定漂移地址可以有多个
172.16.16.172
}
}
service keepalived start
ip addr show eth0
备用服务器配置
vim keepalived.conf
global_defs {
route_id HA_TEST_R2         #本服务器的名称
}
vrrp_instance VI_1 {
state SLAVE                         #热备状态SLAVE表示备用服务器
priority 99                             #优先级数值应低于主服务器
……
}
3.lvs+keepalived
环境
主调度器172.16.16.173 /24  192.168.7.173 /24
备调度器172.16.16.174 /24  192.168.7.174 /24
web服务器池172.16.16.177-180 /24  192.168.7.177-180 /24
nfs共享192.168.7.250 /24
VIP:172.16.16.172
配置主调度器
vim keepalived.conf
global_defs {
route_id LVS_HA_R1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_route_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.16.16.172
}
}
#web服务器池配置
virtual_server 172.16.16.172 80 {       #VIP地址端口
delay_loop 15                                     #健康检查的时间间隔秒
lb_algo rr                                             #轮询调度算法
lb_kind DR                                         #直接路由集群模式
!persistence 60                                 #连接保持时间若起用则去掉叹号
protocol TCP                                     #应用服务采用TCP协议
real_server 172.16.16.177 80 {             #第一个web节点的IP 端口
weight 1                                             #节点的权重
TCP_CHECK {                                     #健康检查方式
connect_port 80                                 #检查的目标端口
connect_timeout 3                             #连接超时秒
nb_get_retry 3                                     #重试次数
delay_before_retry 4                             #重试间隔秒
}
}
real_server 172.16.16.178 80 {             #第二个web节点的IP 端口
……
}
real_server 172.16.16.179 80 {             #第三个……
……
}
……
配置从调度器类似于主
global_defs {
route_id LVS_HA_R2
}
vrrp_instance VI_1 {
state SLAVE
interface eth0
virtual_route_id 1
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
172.16.16.172
}
}
virtual_server 172.16.16.172 80 {
delay_loop 15
lb_algo rr
lb_kind DR
!persistence 60
protocol TCP
real_server 172.16.16.177 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 172.16.16.178 80 {
……
}
real_server 172.16.16.179 80 {
……
}
……
}