MariaDB10.4 Galera Cluster 集群安装

岳时铭
2023-12-01

一。安装环境:centos7、MariaDB 10.4 stable、3节点IP:192.168.56.122、192.168.56.123、192.168.56.124

二。集群安装

官网最新正式版地址:https://downloads.mariadb.org/mariadb/repositories/#mirror=shanghai-university&distro=CentOS&distro_release=centos7-amd64--centos7&version=10.4

官网安装教程:https://mariadb.com/kb/en/library/yum/

从MariaDB 10.1版本开始,Galera Cluster支持已包含在标准MariaDB Server软件包中。

在MariaDB 10.4及更高版本中,您还需要安装该galera-4软件包以获取Galera 4 wsrep提供程序库。

2.1 节点间配置通信,可参考:linux VM间配置ssh免密互信

vim /etc/hosts
192.168.56.122 centos122
192.168.56.123 centos123
192.168.56.124 centos124

2.2 每个节点下执行(配置yum源):

vim /etc/yum.repos.d/MariaDB.repo
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64 
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB 
gpgcheck=1

保存配置:Esc后输入“:wq”;刷新:yum clean all;yum makecache

注意:baseurl和gpgkey不是官网给的地址(国外镜像很慢),改成了国内镜像地址。或者改成:

baseurl = https://ipv4.mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64
gpgkey=https://ipv4.mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

2.3 每个节点下安装MariaDB:

yum install MariaDB-server MariaDB-client galera-4 -y

三。集群启动

3.1 每个节点下修改server配置:

[root@centos122 ~]# vim /etc/my.cnf.d/server.cnf
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.56.122,192.168.56.123,192.168.56.124" #整个集群的IP地址
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
wsrep_provider_options="gcache.size=1G"
wsrep_cluster_name=MariaDB-Galera-Cluster #集群名称
wsrep_node_name=centos122 #hostname,对应前面网路配置/etc/hosts
wsrep_node_address=192.168.56.122 #机器IP地址
wsrep_sst_method=rsync #同步方式

除wsrep_node_name、wsrep_node_address每个节点不同,其它配置相同。

注意:wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so中的目录是galera-4(MariaDB 10.4之前是galera),否则报错

[ERROR] wsrep_load(): dlopen(): /usr/lib64/galera/libgalera_smm.so: cannot open shared object file: No... directory
[ERROR] WSREP: Failed to create a new provider '/usr/lib64/galera/libgalera_smm.so' with optio...ep library

3.2 启动集群:

去第一个122节点启动集群(底层调用的是mysqld --wsrep-new-cluster命令):

galera_new_cluster

然后去其它2节点启动mariadb(底层调用的是/bin/systemctl start mariadb.service命令,会自动加入集群中):

service mariadb start

查看日志:

systemctl status mariadb.service
Jul 10 10:40:52 centos122 mysqld[2085381]: 0: 1e2b23d4-a22c-11e9-9bc6-23944a901828, centos123
Jul 10 10:40:52 centos122 mysqld[2085381]: 1: 55ae61f3-a22c-11e9-ba18-4b92bba70395, centos124
Jul 10 10:40:52 centos122 mysqld[2085381]: 2: c123f182-a22b-11e9-ba00-7f7033924971, centos122
Jul 10 10:40:52 centos122 mysqld[2085381]: =================================================
Jul 10 10:40:52 centos122 mysqld[2085381]: 2019-07-10 10:40:52 3 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
Jul 10 10:40:52 centos122 mysqld[2085381]: 2019-07-10 10:40:52 0 [Note] WSREP: 0.0 (centos123): State transfer to 1.0 (centos124) complete.
Jul 10 10:40:52 centos122 mysqld[2085381]: 2019-07-10 10:40:52 0 [Note] WSREP: Member 0.0 (centos123) synced with group.
Jul 10 10:40:54 centos122 mysqld[2085381]: 2019-07-10 10:40:54 0 [Note] WSREP: (c123f182, 'tcp://0.0.0.0:4567') turning message relay requesting off
Jul 10 10:40:59 centos122 mysqld[2085381]: 2019-07-10 10:40:59 0 [Note] WSREP: 1.0 (centos124): State transfer from 0.0 (centos123) complete.
Jul 10 10:40:59 centos122 mysqld[2085381]: 2019-07-10 10:40:59 0 [Note] WSREP: Member 1.0 (centos124) synced with group.

可看到123、124节点加入到122创建的mysql集群的日志信息。

查看mysql进程状态:

[root@centos122 galera-4]# ps aux | grep mysql
mysql    2085381  0.4  0.1 3540764 106680 ?      Ssl  17:27   0:05 /usr/sbin/mysqld --wsrep-new-cluster --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1

四。集群常用命令

登录数据库,查看集群成员数(SHOW STATUS LIKE"wsrep_cluster_size"):

[root@centos122 galera-4]# mysql
MariaDB [(none)]> show status like 'wsrep_cluster%';
+----------------------------+--------------------------------------+
| Variable_name              | Value                                |
+----------------------------+--------------------------------------+
| wsrep_cluster_weight       | 3                                    |
| wsrep_cluster_capabilities |                                      |
| wsrep_cluster_conf_id      | 18446744073709551615                 |
| wsrep_cluster_size         | 3                                    |
| wsrep_cluster_state_uuid   | c1434da2-a22b-11e9-97bd-2fcc5b042cda |
| wsrep_cluster_status       | Primary                              |
+----------------------------+--------------------------------------+

补充:

关闭防火墙

[root@node1 ~]# systemctl stop firewalld 
[root@node1 ~]# systemctl disable firewalld

关闭SELINUX

[root@node1 ~]# vi /etc/selinux/config 
修改成如下: 
SELINUX=disabled

卸载MariaDB:

[root@centos122 galera-4]# ps aux | grep mysql
mysql    2085381  0.3  0.1 3540764 106944 ?      Ssl  17:27   0:07 /usr/sbin/mysqld --wsrep-new-cluster --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1
root     2206822  0.0  0.0 112712   984 pts/1    S+   17:59   0:00 grep --color=auto mysql
[root@centos122 galera-4]# kill -9 2085381
yum -y remove Maria*
rm -rf /var/lib/mysql/*
rm -rf /etc/my.cnf.d/
rm -rf /etc/my.cnf

 

 类似资料: