openstack ubuntu20.04 安装和使用lsyncd 主从同步控制节点备份。
apt install lsyncd
vim /etc/lsyncd/lsyncd.conf.lua
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
maxProcesses = 1
}
sync {
default.rsyncssh,
source = "/var/lib/rabbitmq",
host = "root@11.1.0.29",
targetdir = "/var/lib/rabbitmq",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/chrony",
host = "root@11.1.0.29",
targetdir = "/etc/chrony",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/mysql",
host = "root@11.1.0.29",
targetdir = "/etc/mysql",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc",
host = "root@11.1.0.29",
targetdir = "/etc",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
_extra = {
"--include=memcached.conf",
"--exclude=*"
}
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/default",
host = "root@11.1.0.29",
targetdir = "/etc/default",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
_extra = {
"--include=etcd",
"--exclude=*"
}
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/etcd",
host = "root@11.1.0.29",
targetdir = "/var/lib/etcd",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}sync {
default.rsyncssh,
source = "/etc/keystone",
host = "root@11.1.0.29",
targetdir = "/etc/keystone",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/keystone",
host = "root@11.1.0.29",
targetdir = "/var/lib/keystone",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/apache2",
host = "root@11.1.0.29",
targetdir = "/etc/apache2",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/root",
host = "root@11.1.0.29",
targetdir = "/root",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/glance",
host = "root@11.1.0.29",
targetdir = "/etc/glance",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/glance",
host = "root@11.1.0.29",
targetdir = "/var/lib/glance",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/placement",
host = "root@11.1.0.29",
targetdir = "/etc/placement",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/placement",
host = "root@11.1.0.29",
targetdir = "/var/lib/placement",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/nova",
host = "root@11.1.0.29",
targetdir = "/etc/nova",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/nova",
host = "root@11.1.0.29",
targetdir = "/var/lib/nova",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lock/nova",
host = "root@11.1.0.29",
targetdir = "/var/lock/nova",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/libvirt",
host = "root@11.1.0.29",
targetdir = "/etc/libvirt",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/neutron",
host = "root@11.1.0.29",
targetdir = "/etc/neutron",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/neutron",
host = "root@11.1.0.29",
targetdir = "/var/lib/neutron",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/openvswitch",
host = "root@11.1.0.29",
targetdir = "/var/lib/openvswitch",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/cinder",
host = "root@11.1.0.29",
targetdir = "/etc/cinder",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/cinder",
host = "root@11.1.0.29",
targetdir = "/var/lib/cinder",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/etc/ceph",
host = "root@11.1.0.29",
targetdir = "/etc/ceph",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/var/lib/mysql",
host = "root@11.1.0.29",
targetdir = "/var/lib/mysql",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
sync {
default.rsyncssh,
source = "/run/netns",
host = "root@11.1.0.29",
targetdir = "/run/netns",
delay = 0,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
},
ssh = {
port = 22
}
}
mkdir /var/log/lsyncd
touch /var/log/lsyncd/lsyncd.{log,status}
systemctl start lsyncd
systemctl enable lsyncd
systemctl status lsyncd
用于需要设置同一个ip服务才能正常,所以需要通过arp绑定方式指定访问主机:
arp -s 11.0.0.2 76:5a:9b:df:d2:74
controller01 (11.0.0.2) at 76:5a:9b:df:d2:74 [ether] on vlan11 #代表是动态ARP没有绑定
controller01 (11.0.0.2) at 76:5a:9b:df:d2:74 [ether] PERM on vlan11 #代表静态arp绑定了
批量执行静态绑定脚本(前提事所有服务器都安装了 net-tools)
#/bin/bash
host_name_ip=$1
hostlistnum=`cat /etc/hosts | grep 11.0 | wc -l`
for i in $(seq 1 $hostlistnum)
do
host_name_2=`cat /etc/hosts | grep 11.0 | head -n $i | tail -1 | awk -F" " '{print $2}'`
ssh root@$host_name_2 "arp -s $host_name_ip 76:5a:9b:df:d2:74"
done
host_name_ip=$1
hostlistnum=`cat /etc/hosts | grep 11.0 | wc -l`
for i in $(seq 1 $hostlistnum)
do
host_name_2=`cat /etc/hosts | grep 11.0 | head -n $i | tail -1 | awk -F" " '{print $2}'`
ssh root@$host_name_2 "arp -s $host_name_ip 76:5a:9b:df:d2:74"
done
然后在没插网线的网卡上使用ifconfig设置一个ip
ifconfig [网络接口名称] 11.0.0.2 netmask 255.255.255.0
ifconfig [网络接口名称] 11.0.0.2 netmask 255.255.255.0
重启备用控制节点服务器。
重启后查看ip netns 是否同步了路由节点。
root@controller01:~# ip netns
fip-9e4a10d2-0375-4ee6-a06d-6f0f88bd4725 (id: 7)
qrouter-24c8bbad-2dc6-4e39-b4fc-dd29656106df (id: 4)
qrouter-d3bd72eb-f08e-4bcc-a31e-4448a04dff5f (id: 3)
snat-d3bd72eb-f08e-4bcc-a31e-4448a04dff5f (id: 5)
snat-24c8bbad-2dc6-4e39-b4fc-dd29656106df (id: 6)
qdhcp-cebc1513-f24d-45ee-8c9e-bcde9ca49a77 (id: 2)
qdhcp-2cb56042-b2ca-4e49-9e6a-c1fe2c388042 (id: 1)
qdhcp-9e4a10d2-0375-4ee6-a06d-6f0f88bd4725 (id: 0)
fip-9e4a10d2-0375-4ee6-a06d-6f0f88bd4725 (id: 7)
qrouter-24c8bbad-2dc6-4e39-b4fc-dd29656106df (id: 4)
qrouter-d3bd72eb-f08e-4bcc-a31e-4448a04dff5f (id: 3)
snat-d3bd72eb-f08e-4bcc-a31e-4448a04dff5f (id: 5)
snat-24c8bbad-2dc6-4e39-b4fc-dd29656106df (id: 6)
qdhcp-cebc1513-f24d-45ee-8c9e-bcde9ca49a77 (id: 2)
qdhcp-2cb56042-b2ca-4e49-9e6a-c1fe2c388042 (id: 1)
qdhcp-9e4a10d2-0375-4ee6-a06d-6f0f88bd4725 (id: 0)
同步后 netplan apply 重置网卡,防止计算节点访问到错误的控制节点,导致虚拟机无法访问宿主机。
控制节点挂掉后,立马在控制节点网卡里面加入 11.0.0.2 ip,并重启所有服务。
systemctl restart chrony mariadb python3-pymysql rabbitmq-server
systemctl restart memcached python3-memcache etcd keystone glance glance-api placement-api nova-api nova-conductor nova-novncproxy nova-scheduler openstack-dashboard cinder-api cinder-scheduler cinder-volume tgt ceph
systemctl restart neutron-server neutron-plugin-ml2 openvswitch-switch neutron-openvswitch-agent neutron-l3-agent neutron-dhcp-agent neutron-metadata-agent
systemctl restart chrony mariadb python3-pymysql rabbitmq-server
systemctl restart memcached python3-memcache etcd keystone glance glance-api placement-api nova-api nova-conductor nova-novncproxy nova-scheduler openstack-dashboard cinder-api cinder-scheduler cinder-volume tgt ceph
systemctl restart neutron-server neutron-plugin-ml2 openvswitch-switch neutron-openvswitch-agent neutron-l3-agent neutron-dhcp-agent neutron-metadata-agent
并在虚拟机内部测试SNAT通不通。