CentOS中安装keepalived

centos安装keepalived

一,yum安装
1,预先安装好epel-release源

yum list installed | grep epel-release

2,查找可用安装的keepalived源

yum search keepalived

3,命令进行安装:

yum install keepalived -y

4,启动keepalived服务:

systemctl start keepalived
yum安装默认配置文件路径为:etc/keepalived/keepalived.conf

二,下载安装包安装

安装keepalive(主备)

yum install -y openssl-devel
cd /usr/local/src/
wget http://www.keepalived.org/software/keepalived-2.0.19.tar.gz
tar -zvxf keepalived-2.0.19.tar.gz
cd keepalived-2.0.19
./configure --prefix=/usr/local/keepalived
#如果出现错误*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS. 
#执行:yum -y install libnl libnl-devel
make && make install

cp /usr/local/src/keepalived-2.0.19/keepalived/etc/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived/
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
echo "/etc/init.d/keepalived start" >> /etc/rc.local

chmod +x /etc/rc.d/init.d/keepalived
chkconfig keepalived on

#相关启动命令
service keepalived start
service keepalived restart
service keepalived stop
#主备打开ip_forward转发功能
echo "1" > /proc/sys/net/ipv4/ip_forward

查看下图此路径下的文件路径是否正确,如果不正确无法用命令启动,只能/usr/local/keepalived/sbin/keepalived去 启动keepalived
CentOS中安装keepalived_第1张图片

主的keepalive.conf配置 vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
    
global_defs {
   router_id LVS_Master
}
    
vrrp_instance VI_1 {
    state MASTER               #指定instance初始状态,实际根据优先级决定.backup节点不一样
    interface eth0             #虚拟IP所在网
    virtual_router_id 51       #VRID,相同VRID为一个组,决定多播MAC地址
    priority 100               #优先级,另一台改为90.backup节点不一样
    advert_int 1               #检查间隔
    authentication {
        auth_type PASS         #认证方式,可以是pass或ha
        auth_pass 1111         #认证密码
    }
    virtual_ipaddress {
        182.148.15.239         #VIP
    }
     # 三个指令,如果主机状态变成Master|Backup|Fault之后会去执行的通知脚本,脚本要自己写
    notify_master ""
    notify_backup ""
    notify_fault ""
}
备机上的keepalived.conf,唯一不同的就是state、priority以及router_id。
备用上的keepalived.conf配置
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
    
global_defs {
   router_id LVS_Backup
}
    
vrrp_instance VI_1 {
    state BACKUP          
    interface eth0         
    virtual_router_id 51   
    priority 90           
    advert_int 1          
    authentication {
        auth_type PASS     
        auth_pass 1111     
    }
    virtual_ipaddress {
        182.148.15.239     
    }
}
验证keepalived是否生效

1,主备keepalived都启动起来
2,主备配置文件中都添加上vip,目标网卡eth1
3.,查看master节点,此时vip挂在eth1上,查看backup节点,eth1上无vip
4,宕掉master节点keepalived,此时eth1上的vip消失。查看backup,vip挂在eth1上
5,启动master节点,vip又回到eth1上,backup的eth1上的vip消失
keepalived验证功能生效

你可能感兴趣的:(CentOS中安装keepalived)