keepalived:一个master(主的)和多个dackup(备用的),同一时刻只有一个vip(在master),当master宕机后,会在backup中选举出来一个master。 vrrp协议:虚拟路由冗余协议,实现路由器的高可用 对外出口只有一个路由器
yum install openssl-devel -y
yum install libnl libnl-devel -y
yum insstall libnetlink-devel-*
./configure --with-init=SYSV --prefix=/usr/local/keepalived
SYSV启动脚本
prefix=/usr/local 安装路径
yum install gcc -y
27 yum install ipvsadm -y
28 chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived ---->启动脚本
29 ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
30 ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
31 ln -s /usr/local/keepalived/etc/keepalived/ /etc/
32 ln -s /usr/local/keepalived/sbin/keepalived /sbin
作连接可以方便启动
vim /etc/keepalived/keepalived.conf
1 Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 root@localhost
6 }
7 notification_email_from keepalived@localhost
8 smtp_server 127.0.0.1
9 smtp_connect_timeout 30
10 router_id LVS_DEVEL
11 vrrp_skip_check_adv_addr
12 #vrrp_strict
13 vrrp_garp_interval 0
14 vrrp_gna_interval 0
15 }
16
17 vrrp_instance VI_1 {
18 state MASTER 备用改为BAKEUP
19 interface eth1
20 virtual_router_id 53 冗余节点
21 priority 100 权重 备用权重小于100
22 advert_int 1
23 authentication {
24 auth_type PASS
25 auth_pass 1111
26 }
27 virtual_ipaddress {
28 172.25.2.100
29 }
30 }
32 virtual_server 172.25.2.100 80 {
33 delay_loop 3
34 lb_algo rr
35 lb_kind DR
36 #persistence_timeout 50 保持连接(保持50s连接)
37 protocol TCP
38
39 real_server 172.25.2.2 80 {
40 TCP_CHECK {
41 weight 1
42 connect_timeout 3
43 retry 3
44 delay_before_retry 3
45 }
46 }
47 real_server 172.25.2.3 80 {
48 TCP_CHECK {
49 weight 1
50 connect_timeout 3
51 retry 3
52 delay_before_retry 3
53 }
54 }
56 }
那台主机时master那台主机连接vip
yum install mailx -y 发送邮件时需要接受或者发送的软件