本帖最后由 straw 于 2019-7-1 11:59 编辑
更新于2019-07-01
配置文件修改了一个bug
一个HASS同时连多个MQTT服务器的方法——MQTT桥接
https://bbs.hassbian.com/thread-7520-1-1.html
(出处: 『瀚思彼岸』» 智能家居第一站)
这个帖子里有人问主备问题,
我是这么实现的
说习惯了,virtual ip,也就是第2个ip
通过ip addr 看出来是这样的
5: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 8c:21:0a:d9:e5:11 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.204/24 brd 192.168.1.255 scope global br-lan
valid_lft forever preferred_lft forever
inet 192.168.1.205/24 scope global secondary br-lan
valid_lft forever preferred_lft forever
这是keepalived的简单配置(在linux服务器上)
在第一台openwrt上是这样的:
config global_defs
config ipaddress
option name "ipaddress2"
option address "192.168.1.205/24"
option device "br-lan"
config vrrp_instance
option name "VI_1"
option state "MASTER"
option interface "br-lan"
option auth_type "PASS"
option auth_pass "passwordxxx"
list virtual_ipaddress "ipaddress2"
option virtual_router_id "128"
option priority "128"
option advert_int "5"
在第2台openwrt上是这样配置的:/etc/config/keepalived
config global_defs
config ipaddress
option name "ipaddress2"
option address "192.168.1.205/24"
option device "br-lan"
config vrrp_instance
option name "VI_1"
option state "BACKUP"
option interface "br-lan"
option auth_type "PASS"
option auth_pass "passwordxxxx"
list virtual_ipaddress "ipaddress2"
option virtual_router_id "128"
option priority "128"
option advert_int "5"
然后再enable keepalived为开机程序
/etc/init.d/keepalived enable
/etc/init.d/mosquitto enable
以上是keepalived的配置,当keepalived检测到vip不通时会自动在backup node上增加192.168.1.205。这样你的mqtt就不会中断了
---------------------------------
2台mqtt broker,
第一台broker原来的配置。
第二台mosquitto broker增加如下配置:
connection name
address firstnodeip:1883
topic # both "" ""
try_private true
notifications true
cleansession true
然后在2台broker上配置vip,用keepalived来控制vip
隐藏没有内容
|