How To Create a Galera Cluster with MariaDB 10.2 on Aliyun ECS (CentOS Linux release 7.2.1511 (Core))
Aliyun ECS of Node (47.75.71.94、47.75.74.157、47.75.73.200)
1) Check the SELINUX.(the default of ECS is the disable SELINUX )
>>getenforce
Disabled
>>(if the results is enforcing or permissive,you need to change it to Disabled.)
>>sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
2) Disable Firewall or open required ports(each node)
You can disable the firewall for now and enable it later and open the required ports or You can open the required ports.
i)if you decieded to total disable firewall for now , use below statement
>> systemctl stop firewalld.service
>> systemctl disable firewalld.service
ii)if you have decieded to keep the firewall enabled,then you have to run below commands to open required ports.
>> firewall-cmd --zone=public --add-port=3306/tcp --permanent
>> firewall-cmd --zone=public --add-port=4567/tcp --permanent
>> firewall-cmd --zone=public --add-port=4568/tcp --permanent
>> firewall-cmd --zone=public --add-port=4444/tcp --permanent
3) Install MariaDB 10.2 on Each Node
first of all you need to install MariaDB 10.2 on each of the node.
i)Check the Linux Version:
>> cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
ii)Create or Edit mariadb.repo (each node):
>>Create mariadb.repo file in /etc/yum.repos.d/
>> cat >>/etc/yum.repos.d/mariadb.repo <<EOF
>> [mariadb]
>> name = MariaDB
>> baseurl = http://yum.mariadb.org/10.2/centos7-amd64
>> gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
>> gpgcheck=1
>> EOF
iii)Install MariaDB server and MariaDB client (each node)
>> sudo yum install -y MariaDB-server MariaDB-client
iv)Start MariaDB service (each node)
>> sudo systemctl start mariadb.service
v) Run Secure Installation(each node)
run the secure installation by using below statment to configure root password and other features.
>> sudo mysql_secure_installation
vi)Login to mariadb by using root.(each node)
>> mysql -uroot -p
>> password:cntsp
vii)Stop mariadb service
>> sudo systemctl stop mariadb.service
4) Make changes to /etc/my.cnf.d/server.cnf file (each one).
>> cat >/etc/my.cnf.d/server.cnf <<EOF
>> [galera]
>> #Mandatory settings
>> wsrep_on=ON
>> wsrep_cluster_address=gcomm://mariadb-a1,mariadb-a2,mariadb-a3
>> wsrep_node_address=This Node IP
>> wsrep_node_incoming_address=This Node IP
>> # wsrep_sst_donor =
>> binlog_format=row
>> default_storage_engine=InnoDB
>> innodb_autoinc_lock_mode=2
>> innodb_buffer_pool_size=122M
>> wsrep_provider=/usr/lib64/galera/libgalera_smm.so
>> wsrep_cluster_name="YourClusterName"
>> wsrep_slave_threads=1
>> wsrep_certify_nonPK=1
>> wsrep_max_ws_rows=0
>> wsrep_max_ws_size=2147483647
>> wsrep_debug=0
>> wsrep_convert_LOCK_to_trx=0
>> wsrep_retry_autocommit=1
>> wsrep_auto_increment_control=1
>> wsrep_drupal_282555_workaround=0
>> wsrep_causal_reads=0
>> wsrep_notify_cmd=
>> #
>> # 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
>> # this is only for embedded server
>> [embedded]
>> # This group is only read by MariaDB servers, not by MySQL.
>> # If you use the same .cnf file for MySQL and MariaDB,
>> # you can put MariaDB-only options here
>> [mariadb]
>>EOF
5)Start Service on first node:
To start the mariadb service on first Node, you will be using below command.DON’T USE SYSTEMCTL start mriadb.service or service mysql start
>> sudo /usr/bin/galera_new_cluster
service should start successfully.Once the mariadb service is started on first node,you can check the cluster information by connecting to mariadb.
>> mysql -uroot -p
>> password:cntsp
>> MariaDB>> show status like 'wsrep_cluster_size%';
>> you should see the output as shown below.
>> -------------------------
>> Variable_name Value
>> -------------------------
>> wsrep_cluster_size 1
>> -------------------------
6)Join 2nd and 3third node
You are all set to join other nodes to Galera Cluster. Connect to second node and then start MariaDB service by using below statment.
>> sudo systemctl start mariadb.service
if the command line has some error,
like:Job for mariadb.service failed because a fatal signal was delivered to the control process. See “systemctl status mariadb.service” and “journalctl -xe” for details.
journalctl -xe
WSREP: Failed to prepare for incremental state transfer: Local state UUID (00000000-0000-0000-0000-000000000000) does not match group state UUID (a25a4592-2c4
repeat the commands on all the nodes.Once the mariadb service is started on all the Nodes, you can check Galera cluster size again to make sure all the nodes are part of cluster by running below statment.
mysql -uroot -p -e “SHOW STATUS LIKE ‘wsrep_cluster_size’”