当前位置:正能量 » 代码编程 » Linux » openwrt部署keepalived

openwrt部署keepalived

OpenWRT VRRP协议配置: OpenWRT上需要安装keepalived,安装命令:

opkg update & opkg install keepalived

然后,修改配置文件 /etc/keepalived/keepalived.conf,内容如下(没有就自行新建):

global_defs {
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
  interface br-lan #指定连接ROS的接口,默认为LAN接口的桥接
  state BACKUP #默认状态是BACKUP,也可以指定为MASTER
  virtual_router_id 51 #和ROS保持一致即可
  priority 110 # 本机优先级为110,主路由,ROS优先级为100
  advert_int 1

  virtual_ipaddress {
    192.168.88.8 # 虚拟网关地址,和ROS保持一致
  }
}

划重点

OpenWrt安装后,启动时候会自动执行配置命令,故:每次配置完毕后,一旦重启OpenWrt,配置文件会丢失。解决办法是注释掉以下配置,代码位置:/etc/init.d/keepalived

reload_service() {
        #process_config   这行代码是需要注释的
        #SIGHUP is used by keepalived to do init.d reload
        procd_send_signal keepalived
}

start_service() {
        procd_open_instance
        procd_set_param command /usr/sbin/keepalived
        procd_append_param command -n # don't daemonize, procd will handle that for us
        procd_append_param command -f "$KEEPALIVED_CONF"

        #process_config    这行代码也是需要注释的

        # set auto respawn behavior
        procd_set_param respawn
        procd_close_instance
}

启动 /usr/sbin/keepalived -n -f /etc/keepalived/keepalived.conf(可略,参见下面的附录) 查看服务情况 ps -ef | grep keepalived查看服务状态service keepalived status重载配置文件 service keepalived reload启动服务 service keepalived start停止服务 service keepalived stop

附录:

由于keepalived启动时候指定了配置文件,故在/etc/init.d/keepalived文件的首几行可以修改指定配置文件

 #KEEPALIVED_CONF=/tmp/keepalived.conf   这行注释掉,或者改成如下:
KEEPALIVED_CONF=/etc/keepalived/keepalived.conf

这样,Openwrt重启后,配置文件就不会丢失且会自动按配置文件/etc/keepalived/keepalived.conf来启动keepalived

未经允许不得转载:正能量 » openwrt部署keepalived

相关文章

评论 (0)

5 + 6 =