Centos7安装配置Keepalived

背景介绍

keepalived是一个类似于layer3, 4 &7交换机制的软件,也就是我们平时说的第3层、第4层和第7层交换。Keepalived是自动完成,不需人工干涉。

Keepalived软件主要是通过VRRP协议实现高可用功能的。VRRP是Virtual Router
RedundancyProtocol(虚拟路由器冗余协议)的缩写,VRRP出现的目的就是为了解决静态路由单点故障问题的,它能够保证当个别节点宕机时,整个网络可以不间断地运行。

Keepalived使用虚拟IP实现双机热备解决方案。

keepalived安装
Centos7使用源码安装keepalived。
安装
(1)上传或下载 keepalived(keepalived-1.4.0.tar.gz) 到 /usr/local/src
(2)# cd /usr/local/src
(3)# tar -zxvf keepalived-1.4.0.tar.gz
(4)# cd keepalived-1.4.0
(5)# ./configure --prefix=/usr/local/keepalived
(6)# make && make install

 修改 Keepalived 配置文件keepalived.conf
keepalived.conf位于( /usr/local/keepalived/etc/keepalived/keepalived.conf)
主设备keepalived.conf如下:

! Configuration File for keepalived
global_defs {
   notification_email {
      root@localhost
   }
   notification_email_from root@localhost
   smtp_server root
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
 #  vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_instance VI_1 {
    state MASTER
    interface enp0s3 #此处为自己的ip名
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.163.20.180
    }
}

从设备keepalived.conf如下:

! Configuration File for keepalived
global_defs {
   notification_email {
    root@localhost
   }
   notification_email_from root@localhost
   smtp_server localhost
   smtp_connect_timeout 30
 router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
#   vrrp_strict
vrrp_garp_interval 0
   vrrp_gna_interval 0
}
vrrp_instance VI_1 {
    state BACKUP
    interface enp0s3
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.163.20.180
     }
}

将 keepalived 安装成 Linux 系统服务

因为没有使用 keepalived 的默认路径安装(默认是/usr/local) ,安装完成之后,需要做一些工作复制默认配置文件到默认路径

# mkdir /etc/keepalived  
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/  
复制 keepalived 服务脚本到默认的地址
# cp /usr/local/src/keepalived/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/  
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/  

设置 keepalived 服务开机启动

# chkconfig keepalived on  
启动keepalived 服务
# service keepalived start  

查看keepalived进程

# ps aux | grep keepalived

这里写图片描述

查看虚拟IP状态

# ip a

Centos7安装配置Keepalived_第1张图片

注意:如果安装成功后虚拟IP ping不通则需要修改keepalived.conf,将vrrp_strict注释掉即可。

无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。

你可能感兴趣的:(网络,centos7)