MariaDB is a relational database management system (RDBMS) and MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB. It is available on Linux only, and only supports the XtraDB/InnoDB storage engines. This article explains how to setup MariaDB Galera Cluster 10.0 with 3 nodes running on CentOS 7 x86_64 resulting in a HA (high-availability) database cluster.
Cluster node 1 has hostname db1 and IP address 1.1.1.1 Cluster node 2 has hostname db2 and IP address 1.1.1.2 Cluster node 3 has hostname db3 and IP address 1.1.1.3
Step 1: Add MariaDB Repositories
# vi /etc/yum.repos.d/mariadb.repo[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Step 2: Set SELinux in permissive mode
# setenforce 0
Step 3: Install MariaDB Galera Cluster 10.0 software
# yum install MariaDB-Galera-server MariaDB-client rsync galera socat
Step 4: Setup MariaDB security
# systemctl start mysql
# mysql_secure_installationStep 5: Create MariaDB Galera Cluster users
# mysql -u root -p
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpass';
mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY 'dbpass';
mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%';
mysql> FLUSH PRIVILEGES;
mysql> quit
# systemctl stop mysql
Step 6: Create the MariaDB Galera Cluster config
# vi /etc/my.cnf.d/server.cnf
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://1.1.1.1,1.1.1.2,1.1.1.3"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='1.1.1.1'
wsrep_node_name='db1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
IMPORTANT NOTE: when executing this command on db2 and db3 do not forget to adjust the wsrep_node_address and wsrep_node_name variables.Step 7: Initialize the first cluster node
Start MariaDB with the special ‘‐‐wsrep-new-cluster’ option ,Do it on node db1 only so the primary node of the cluster is initialized:
# /etc/init.d/mysql start --wsrep-new-cluster
Check status by run the following command on node db1 only:
# mysql -u root -p -e"show status like 'wsrep%'"
Some important information in the output are the following lines:
wsrep_local_state_comment | Synced <-- cluster="" is="" nbsp="" span="" synced="">-->
wsrep_incoming_addresses | 1.1.1.1:3306 <-- a="" db1="" is="" nbsp="" node="" provider="" span="">-->
wsrep_cluster_size | 1 <-- 1="" cluster="" consists="" nbsp="" node="" of="" span="">-->
wsrep_ready | ON <-- :="" good="" span="">-->
Step 8: Add the other cluster nodes
Check and confirm nodes db2 and db3 have the correct configuration in /etc/my.cnf.d/server.cnf under the [mariadb-10.0] as described in step 6.With the correct configuration in place, all that is required to make db2 and db3 a member of the cluster is to start them like you would start any regular service. On db2 issue the following command: # systemctl start mysql
Step 9: Check firewall and SElinux
Firewall ports:MySQL: 3306/tcp
MySQL IST: 4568/tcp
MySQL SST: 4444/tcp
Galera: 4567/tcp
seaudit for /var/log/audit/audit.log
require {
type sysctl_net_t;
type kerberos_port_t;
type mysqld_t;
class process setpgid;
class tcp_socket name_bind;
class netlink_tcpdiag_socket create;
class dir search;
class file read;
class file open;
class unix_stream_socket connectto;
class file getattr;
}
#============= mysqld_t ==============
#!!!! This avc is allowed in the current policy
allow mysqld_t kerberos_port_t:tcp_socket name_bind;
#!!!! This avc is allowed in the current policy
allow mysqld_t self:netlink_tcpdiag_socket create;
#!!!! This avc is allowed in the current policy
allow mysqld_t self:process setpgid;
#!!!! This avc is allowed in the current policy
allow mysqld_t sysctl_net_t:dir search;
allow mysqld_t sysctl_net_t:file read;
allow mysqld_t sysctl_net_t:file open;
#!!!! This avc can be allowed using the boolean 'daemons_enable_cluster_mode'
allow mysqld_t self:unix_stream_socket connectto;
allow mysqld_t sysctl_net_t:file getattr;
Комментариев нет:
Отправить комментарий