OpenStack Mariadb数据库HA
192.168.17.111 demo.open-stack.cn
192.168.17.132 controller1 controller1.open-stack.cn
192.168.17.151 controller2 controller2.open-stack.cn
192.168.17.138 controller3 controller3.open-stack.cn
1、配置YUM源
[root@controller1 yum.repos.d]# vim Mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
enabled = 1
gpgcheck = 0
[root@controller1 ~]# scp /etc/yum.repos.d/mariadb.repo controller2:/etc/yum.repos.d/mariadb.repo 100% 103 0.1KB/s 00:00
[root@controller1 ~]# scp /etc/yum.repos.d/mariadb.repo controller3:/etc/yum.repos.d
2、安装mariadb
# yum install mariadb-server mariadb-client galera xinetd rsync -y
# systemctl start mariadb
# systemctl status mariadb
# mysql_secure_installation
3、配置mariadb
[root@controller1 ~]# vim /etc/my.cnf.d/server.cnf
# Galera Cluster Configuration
[galera]
# Mysql Configuration
binlog_format = ROW
max_connections = 10000
bind-address = 192.168.17.132
# Galera Cluster Configuration
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name = "OpenStack"
wsrep_cluster_address = "gcomm://192.168.17.132,192.168.17.151,192.168.17.138"
wsrep_node_name = controller1
wsrep_node_address = 192.168.17.132
wsrep_sst_method = rsync
wsrep_on = ON
wsrep_slave_threads = 1
# InnoDB Configuration
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_flush_log_at_trx_commit = 0
innodb_buffer_pool_size = 122M
将文件复制到controller2和controller3,文中IP和节点名修改成对应节点的
# vim /usr/lib/systemd/system/mariadb.service
LimitNOFILE=10000
LimitNPROC=10000
[root@server1 ~]# systemctl stop mariadb
Warning: mariadb.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@server1 ~]# systemctl daemon-reload
[root@server1 ~]# systemctl stop mariadb
先将三个节点Mariadb停止
启动主节点
[root@server1 ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &
再启动其它节点
[root@server2 ~]# systemctl start mariadb.service
[root@controller1 ~]# mysql -uroot -p
MariaDB [(none)]> show status like 'wsrep%';
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3
| wsrep_cluster_status | Primary
| wsrep_incoming_addresses | 192.168.17.132:3306,192.168.17.138:3306,192.168.17.151:3306
| wsrep_local_state_comment | Synced
| wsrep_provider_name | Galera
| wsrep_ready | ON
在Controller1创建一个数据库测试
MariaDB [(none)]> create database galera;
Query OK, 1 row affected (0.02 sec)
在controller2上验证
[root@controller2 ~]# mysql -uroot -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| galera |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
在controller3上验证
[root@controller3 ~]# mysql -uroot -p
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| galera |
| information_schema |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)