使用haproxy+keepalived实现Mariadb负载均衡
controller2: 10.100.2.52 haproxy+keepalived
controller3: 10.100.2.53 haporxy+keepalived
vip:10.100.2.99
network1: 10.100.2.61 mariadb-galera-1
network2: 10.100.2.62 mariadb-galera-2
compute1: 10.100.2.71 mariadb-galera-3
controller2:
yum install -y haproxy keepalived
vim /etc/keepalived/keepalived.conf
global_defs {
router_id controller2
}
vrrp_script chk_haproxy {
script "/etc/keepalived/chk_haproxy.sh"
interval 1
weight 2
}
vrrp_instance VI_1 {
state SLAVE
interface ens161
virtual_router_id 201
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_haproxy
}
virtual_ipaddress {
10.100.2.99/24
}
track_interface {
ens161
}
}
controller3:
router_id controller3
state MASTER
priority 99
vim /etc/keepalived/chk_haproxy.sh
#!/bin/bah
chkha=`ps -C haproxy --no-header |wc -l`
if [ $chkha -eq 0 ];then
systemctl stop keepalived
fi
chmod +x /etc/keepalived/chk_haproxy.sh
vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
spread-checks 3
tune.bufsize 32768
tune.maxrewrite 1024
tune.ssl.default-dh-param 2048
defaults
log global
log 127.0.0.1 local3
mode http
option httplog
option dontlognull
retries 10
option redispatch
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen mariadb
bind *:3306
mode tcp
balance roundrobin
server network1 10.100.2.61:3306 weight 5
server network2 10.100.2.62:3306 weight 5
server compute1 10.100.2.71:3306 weight 5
listen stats
bind *:1080
mode http
option httplog
maxconn 10
stats enable
stats refresh 30s
stats uri /stats
stats realm MaCluster\ Haproxy
stats auth admin:admin
stats hide-version
stats admin if TRUE
systemct start haproxy keepalived.service
systemctl enable haproxy keepalived.service
kolla对接exteral Maraidb Galera Cluster
参考搭建galera Cluster 文档
```bash
1. Enabling External MariaDB support
vim /etc/kolla/globals.yml
enable_mariadb: "no"
vim multinode
[mariadb]
10.100.2.99
vim e/tc/kolla/globals.yml
database_address: "10.100.2.99"
2.使用预设数据库/用户 #
vim /etc/kolla/globals.yml
use_preconfigured_databases: "yes"
keystone_database_user: "keystone" keystone
glance_database_user: "glance" glance
nova_database_user: "nova" nova nova_cell0
nova_api_database_user: "nova" nova_api
neutron_database_user: "neutron" #neutron
cinder_database_user: "cinder" #cinder
manila_database_user: "manila" #manila
panko_database_user: "panko" # panko
trove_database_user: "trove" # trove
aodh_database_user: "aodh" # aodh
gnocchi_database_user: "gnocchi" # gnocchi
octavia_database_user: "octavia" # octavia
rally_database_user: "rally" #rally
palcement_database_user: "placement" # placement
barbican_database_user: "barbican" # barbican
ironic_database_user: "ironic" # ironic-api
ironic_inspector_database_user: "ironic" # ironic-inspector
heate_database_user: "heat" # heat
grafana_database_user: "grafana"
mysql -uroot -popenstack
# keystone
MariaDB [(none)]> CREATE DATABASE keystone;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \
IDENTIFIED BY 'openstack';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \
IDENTIFIED BY 'openstack';
sed -i -r -e 's/([a-z_]{0,}database_password:+)(.*)$/\1 openstack/gi' /etc/kolla/passwords.yml
参考文档:
https://docs.openstack.org/kolla-ansible/stein/reference/databases/external-mariadb-guide.html
https://www.cloudandheat.com/blog/tutorial-part-2-highly-available-mariadb-galera-cluster-with-floating-ip/
https://www.cnblogs.com/fawaikuangtu123/p/10915229.html