Linux技术区

Linux服务篇之 keepalived第一篇

2017-09-09  本文已影响341人  数据革命

Linux服务篇之 keepalived第一篇

keepalived简介

Keepalived服务的三个重要功能

管理LVS负载均衡软件

LVS集群健康检查功能

系统网络服务的高可用

Keepalived搭建

[root@localhost ~]# yum install kepalived -y
[root@localhost ~]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {                 <<<<邮箱地址           
   notification_email {
     acassen@firewall.loc
     failover@firewall.loc
     sysadmin@firewall.loc
   }
   notification_email_from Alexandre.Cassen@firewall.loc        <<<<指定邮件发送人
   smtp_server 192.168.200.1                <<<<指定发送邮件的服务器
   smtp_connect_timeout 30                  <<<<超时时间
   router_id LVS_DEVEL                       <<<<路由标识(必须是唯一)
}

vrrp_instance VI_1 {                   <<<<实例,每个实例就相当于他的一个业务,可以有多个实例
    state MASTER                       <<<<角色状态,一共有两种状态(MASTER和BACKUP)必须为大写字符
    interface eth0                     <<<<网络接口,也就是网卡接口 
    virtual_router_id 51               <<<<虚拟标识必须是唯一的
    priority 100                       <<<<优先级数字越大优先级越高
    advert_int 1                       <<<<同步通知时间间隔,默认为1秒
    authentication {                   <<<<权限认证配置,密码不得大于8位
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {                <<<<虚拟IP地址
        192.168.200.16
        192.168.200.17
        192.168.200.18
    }
}
! Configuration File for keepalived

global_defs {
   notification_email {           <<<<添加了邮箱
     601037481-qq.com         


   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1              <<<本地连接服务器
   smtp_connect_timeout 30            
   router_id hostname1             <<<<修改了标识
   vrrp_mcast_group4 224.20.20.18             <<<多播地址
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.16.250.88                      <<<<添加了虚拟IP
    }
}
[root@localhost ~]# service keepalived  start
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:b5:96:a2 brd ff:ff:ff:ff:ff:ff
    inet 172.16.253.48/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:feb5:96a2/64 scope link 
       valid_lft forever preferred_lft forever
! Configuration File for keepalived

global_defs {
   notification_email {
     601037481-@qq.com


   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id hostname2           <<<<标识必须修改
   vrrp_mcast_group4 224.20.20.18
}

vrrp_instance VI_1 {
    state BACKUP                    <<<<状态修改为BACKUP,记住必须为大写
    interface eth0
    virtual_router_id 55
    priority 80                      <<<<优先级不能大于MASTER,必须修改
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       172.16.250.88
    }
}
[root@localhost ~]# service keepalived start
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# service keepalived stop
Stopping keepalived:                                       [  OK  ]
[root@localhost ~]# ip a  l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:b5:96:a2 brd ff:ff:ff:ff:ff:ff
    inet 172.16.253.48/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:feb5:96a2/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip a  l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever

keepalived双主配置

[root@localhost ~]# vim /etc/keepalived/keepalived.conf 
global_defs {
   notification_email {
     601037481-qq.com


   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id hostname1
   vrrp_mcast_group4 224.20.20.18
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 55
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.16.250.88
    }
}
vrrp_instance VI_2 {               <<<<修改成第二个实例
    state BACKUP                   <<<<修改为BACKUP
    interface eth0
    virtual_router_id 56            <<<<标识必须唯一
    priority 99                        <<<<由于是备用优先级不能超过MASTER
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.16.250.87             <<<<设定第二个虚拟IP
    }
global_defs {
   notification_email {
     601037481-@qq.com


   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id hostname2
   vrrp_mcast_group4 224.20.20.18
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 55
    priority 99
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
       172.16.250.88
    }
}
vrrp_instance VI_2 {    <<<<修改成第二个实例
    state MASTER         <<<<修改为MASTER
    interface eth0
    virtual_router_id 56           <<<<标识必须唯一
    priority 100                     <<<<由于是备用优先级不能超过MASTER
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
    172.16.250.87              <<<<设定第二个虚拟IP

[root@localhost ~]# service keepalived  start
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:b5:96:a2 brd ff:ff:ff:ff:ff:ff
    inet 172.16.253.48/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:feb5:96a2/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.87/32 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# service keepalived  stop
Stopping keepalived:                                       [  OK  ]
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.87/32 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:d7:b2:e1 brd ff:ff:ff:ff:ff:ff
    inet 172.16.252.110/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.87/32 scope global eth0
    inet6 fe80::20c:29ff:fed7:b2e1/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:0c:29:b5:96:a2 brd ff:ff:ff:ff:ff:ff
    inet 172.16.253.48/16 brd 172.16.255.255 scope global eth0
    inet 172.16.250.88/32 scope global eth0
    inet6 fe80::20c:29ff:feb5:96a2/64 scope link 
       valid_lft forever preferred_lft forever
上一篇下一篇

猜你喜欢

热点阅读