pid-file=/run/mariadb/mariadb.pid
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_name=“mariadb_galera_cluster”
wsrep_cluster_address=“gcomm://controller01,controller02,controller03”
wsrep_node_name=“db01”
wsrep_node_address=“10.15.253.163”
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=4
innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=1024M
wsrep_sst_method=rsync
[embedded]
[mariadb]
[mariadb-10.3]
[wsrep\_sync\_wait]( ):默认值是0,如果需要保证读写一致性可以设置为1。但是需要注意的是,该设置会带来相应的延迟性
##### 1.5 将controller01的配置文件分别拷贝到其他两个主机
修改两台节点对应的地址和主机名:wsrep\_node\_name、wsrep\_node\_address,bind-address
scp -rp /etc/my.cnf.d/openstack.cnf controller02:/etc/my.cnf.d/openstack.cnf
scp -rp /etc/my.cnf.d/openstack.cnf controller03:/etc/my.cnf.d/openstack.cnf
以上的安装配置操作在所有控制节点执行完毕以后,就可以开始构建集群,可以在任一控制节点执行
#### 2. 构建集群
##### 2.1 停止全部控制节点的mariadb服务,以controller01节点为例
systemctl stop mariadb
##### 2.2 在controller01节点通过如下方式启动mariadb服务
[root@controller01 ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &
[1] 8255
[root@controller01 ~]# 2020-08-28 14:02:44 0 [Note] /usr/libexec/mysqld (mysqld 10.3.20-MariaDB) starting as process 8255 …
##### 2.3 其他控制节点加入mariadb集群
以controller02节点为例;启动后加入集群,controller02节点从controller01节点同步数据,也可同步查看mariadb日志/var/log/mariadb/mariadb.log
[root@controller02 ~]# systemctl start mariadb.service
##### 2.4 回到controller01节点重新配置mariadb
#重启controller01节点;并在启动前删除contrller01节点之前的数据
[root@controller01 ~]# pkill -9 mysqld
[root@controller01 ~]# rm -rf /var/lib/mysql/*
#注意以system unit方式启动mariadb服务时的权限
[root@controller01 ~]# chown mysql:mysql /var/run/mariadb/mariadb.pid
启动后查看节点所在服务状态,controller01节点从controller02节点同步数据
[root@controller01 ~]# systemctl start mariadb.service
[root@controller01 ~]# systemctl status mariadb.service
##### 2.5 查看集群状态
[root@controller01 ~]# mysql -uroot -p
MariaDB [(none)]> show status like “wsrep_cluster_size”;
±-------------------±------+
| Variable_name | Value |
±-------------------±------+
| wsrep_cluster_size | 3 |
±-------------------±------+
1 row in set (0.001 sec)
MariaDB [(none)]> SHOW status LIKE ‘wsrep_ready’;
±--------------±------+
| Variable_name | Value |
±--------------±------+
| wsrep_ready | ON |
±--------------±------+
1 row in set (0.001 sec)
##### 2.6 在controller01创建数据库,到另外两台节点上查看是否可以同步
[root@controller01 ~]# mysql -uroot -p
MariaDB [(none)]> create database cluster_test charset utf8mb4;
Query OK, 1 row affected (0.005 sec)
MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| cluster_test |
| information_schema |
| mysql |
| performance_schema |
±-------------------+
另外两台查看
[root@controller02 ~]# mysql -uroot -pZx***** -e ‘show databases’
±-------------------+
| Database |
±-------------------+
| cluster_test | √
| information_schema |
| mysql |
| performance_schema |
±-------------------+
[root@controller03 ~]# mysql -uroot -pZx***** -e ‘show databases’
±-------------------+
| Database |
±-------------------+
| cluster_test | √
| information_schema |
| mysql |
| performance_schema |
±-------------------+
#### 3. 设置心跳检测clustercheck
##### 3.1 下载clustercheck脚本
在全部控制节点下载修改此脚本
wget -P /extend/shell/ https://raw.githubusercontent.com/olafz/percona-clustercheck/master/clustercheck
注意账号/密码与脚本中的账号/密码对应,这里用的是脚本默认的账号/密码,否则需要修改clustercheck脚本
[root@controller01 ~]# vim /extend/shell/clustercheck
MYSQL_USERNAME=“clustercheck”
MYSQL_PASSWORD=“Zx*****”
MYSQL_HOST=“localhost”
MYSQL_PORT=“3306”
…
#添加执行权限并复制到/usr/bin/下
[root@controller01 ~]# chmod +x /extend/shell/clustercheck
[root@controller01 ~]# \cp /extend/shell/clustercheck /usr/bin/
##### 3.2 创建心跳检测用户
在任意一个控制节点的数据库中创建clustercheck\_user用户并赋权; 其他两台节点会自动同步
GRANT PROCESS ON . TO ‘clustercheck’@‘localhost’ IDENTIFIED BY ‘Zx*****’;
flush privileges;
##### 3.3 创建心跳检测文件
在全部控制节点新增心跳检测服务配置文件`/etc/xinetd.d/mysqlchk`,以controller01节点为例
[root@controller01 ~]# touch /etc/xinetd.d/galera-monitor
[root@controller01 ~]# cat >/etc/xinetd.d/galera-monitor <<EOF
default:on
description: galera-monitor
service galera-monitor
{
port = 9200
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
group = root
groups = yes
server = /usr/bin/clustercheck
type = UNLISTED
per_source = UNLIMITED
log_on_success =
log_on_failure = HOST
flags = REUSE
}
EOF
##### 3.4 启动心跳检测服务
在全部控制 节点修改/etc/services,变更tcp9200端口用途,以controller01节点为例
[root@controller01 ~]# vim /etc/services
…
#wap-wsp 9200/tcp # WAP connectionless session service
galera-monitor 9200/tcp # galera-monitor
**启动 xinetd 服务**
#全部控制节点都需要启动
systemctl daemon-reload
systemctl enable xinetd
systemctl start xinetd</