Centos7安装配置Keepalived

1.上传或下载 keepalived(keepalived-2.0.20.tar.gz) 到 /usr/local/src

wget https://www.keepalived.org/software/keepalived-2.0.20.tar.gz

2.解压

tar -zxvf keepalived-2.0.20.tar.gz

3.编译

# 执行配置,指定路径
./configure --prefix=/usr/local/keepalived
# 编译
make && make install

4.修改配置文件
节点1

! Configuration File for keepalived

global_defs {  
   router_id NodeA   
}

vrrp_instance VI_1 {
    state MASTER            #角色是MASTER
    interface eno1          #当前使用的网卡
    virtual_router_id 51    #让master 和backup在同一个虚拟路由里,id 号必须相同
    priority 100            #优先级
    advert_int 1            #心跳间隔时间
    authentication {
        auth_type PASS      #认证
        auth_pass 1111      #密码
    }
    virtual_ipaddress {
        10.13.100.200       #虚拟ip
    }
}

节点2

! Configuration File for keepalived

global_defs {  
   router_id NodeB   
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno1
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.13.100.200
    }
}

5.安装系统服务

# 拷贝源码中的keepalived-2.0.20/keepalived/etc/init.d/keepalived 到 /etc/init.d/
cp /usr/local/src/keepalived-2.0.20/keepalived/etc/init.d/keepalived /etc/init.d/
 
# 拷贝编译后的keepalived/etc/sysconfig/keepalived 到 /etc/sysconfig/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
 
# 创建文件夹
mkdir /etc/keepalived
 
# 把配置文件移到文件夹中
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
 
# 把执行文件移动到/usr/sbin/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

6.启动服务

 #安装系统自动启动
systemctl enable keepalived
#启动
systemctl start keepalived
#失败
systemctl stop keepalived

#查看keepalived进程是否启动
ps aux | grep keepalived

#查看虚拟IP状态
ip a

你可能感兴趣的:(Centos7安装配置Keepalived)