请选择 进入手机版 | 继续访问电脑版

安装配置 keepalived

[复制链接]
查看1214 | 回复0 | 2018-12-27 15:37:18 | 显示全部楼层 |阅读模式
安装配置keepalived
192.168.3.33192.168.3.34上安装keepalived


  1.安装keepalived

# tar -zxvf keepalived-1.2.19.tar.gz

# cd keepalived-1.2.19

#./configure

#make

#makeinstall


  2.修改配置文件路径
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/

# mkdir /etc/keepalived

#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/                              
# cp /usr/local/sbin/keepalived /usr/sbin/

  3.设置为服务,开机启动
#vi /etc/rc.local
添加以下内容:
/etc/init.d/keepalived start
保存退出。


  4.修改配置文件

以下是192.168.3.33上的配置文件:

#vi/etc/keepalived/keepalived.conf
vrrp_instanceVI_1 {
    state MASTER
    interface bond0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
   virtual_ipaddress {
        192.168.3.99
    }
}

vrrp_instanceVI_2 {
    state BACKUP
    interface bond0
    virtual_router_id 52
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.3.199
    }
}


  5.启动服务
#service keepalived start


192.168.3.33192.168.3.34上安装keepalived的方法相同,只是配置文件不同:

以下是192.168.3.34上的配置文件:
#vi /etc/keepalived/keepalived.conf

vrrp_instanceVI_2 {
    state MASTER
    interface bond0
    virtual_router_id 52
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.3.199
    }
}

vrrp_instanceVI_1 {
    state BACKUP
    interface bond0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.3.99
    }
}

执行命令
#ip addr
即可看到主机ip 和虚拟ip

192.168.3.33:
QQ截图20181227153555.jpg

192.168.3.34:
QQ截图20181227153636.jpg


停止一台机的keepalived服务,这台机上的虚拟ip会转移到另一台机上;
启动刚刚停止的keepalived服务,这台机原先的虚拟ip会恢复。
这样的话,说明keepalived运行正常。





上一篇:keepalived安装 healthcheck child process died
下一篇:接口调用 并发低时haproxy的CPU占用率非常高
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1249

主题

2736

帖子

7万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
70188
QQ