第一步.安装.网上很多源码安装的步骤.咱们这里以最快的方式 .
[Shell] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
|
#安装 yum install -y keepalived #备份 cd /etc/keepalived cp keepalived.conf keepalived.conf.back #创建配置文件 echo "! Configuration File for keepalived #主机配置 global_defs { #id,主从不同 router_id LVS_DEVEL } vrrp_instance VI_1 { #主机设置为MASTER state MASTER #网卡1 interface eth0 #主从id要一样 virtual_router_id 51 #主机权重高于从机 priority 80 #广播时间,1秒 advert_int 1 #配置主从要一样 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #虚拟的ip,多个ip换行写即可 192.168.1.237 } } ">. /keepalived .conf #启动... keepalived -d -f /etc/keepalived/keepalived .conf |
以上是主机配置并启动
第二步,从机配置并启动
[Shell] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
|
#安装 yum install -y keepalived #备份 cd /etc/keepalived cp keepalived.conf keepalived.conf.back #创建配置文件 echo "! Configuration File for keepalived #主机配置 global_defs { #id,主从不同 router_id LVS_DEVEL2 } vrrp_instance VI_1 { #从机设置为BACKUP state BACKUP #网卡1 interface eth0 #主从id要一样 virtual_router_id 51 #主机权重高于从机 priority 20 #广播时间,1秒 advert_int 1 #配置主从要一样 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { #虚拟的ip,多个ip换行写即可 主从一致 192.168.1.237 } } ">. /keepalived .conf #启动... keepalived -d -f /etc/keepalived/keepalived .conf |
然后启动一个web服务访问一下192.168.1.237吧. 然后断开其中一台机器刷新再看一下 (注意2台机器的防火墙要关闭)