We will need to install required softwares as regular:
- Disable SELinux:
- Add MariaDB repo to /etc/yum.repos.d/mariadb.repo using MariaDB Repository Configuration tool. For CentOS 6 64-bit:
[bash]# MariaDB 10.0 CentOS repository list – created 2015-03-16 12:01 UTC
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
- Add Epel repository:
[bash]rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm[/bash]
- Install socat:
[bash]yum install socat[/bash]
- Install MariaDB Glera:
[bash]yum install MariaDB-Galera-server MariaDB-client galera which rsync[/bash]
- Start MySQL and Secure MariaDB after installation:
Setting up MariaDB Galera Cluster
There is an assumption that the IP and node name of the cluster’s nodes are as follows
- Cluster node 1: hostname c1 and IP address 192.168.0.1
- Cluster node 2: hostname c2 and IP address 192.168.0.2
- Cluster node 3: hostname c3 and IP address 192.168.0.3
- Create a new MariaDB Galera Cluster user. In this case, we can choose to create a new user which is allowed to connect from any host (%) or just some pre-defined host. Of course the later option is more secure. However to be simple, I use % as the host so that the user can be connected from anywhere. The IP restriction will be done via network firewall, not inside the MariaDB configuration. Steps:
[bash][[email protected] ~]# mysql -u root -p
MariaDB [(none)]> GRANT USAGE ON *.* to [email protected]’%’ IDENTIFIED BY ‘STT_PASSWORD’;
MariaDB [(none)]> GRANT ALL PRIVILEGES on *.* to [email protected]’%’;
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> quit;
- Stop MariaDB in ALL nodes:
[bash]service mysql stop[/bash]
- Create MariaDB cluster config, just need to edit /etc/my.cnf.d/server.cnf and add the following configuration under [mariadb-10.0]:
- Apply the configure in the master node for all 2nd and 3rd nodes. Remember that we need to change wsrep_node_address and wsrep_node_name to match information on these nodes.
- Start the first node:
[bash]/etc/init.d/mysql start –wsrep-new-cluster[/bash]
Remember that in case you restart the mysql server in this first node, if other nodes are currently up and running, do not use –wsrep-new-cluster again or it will create a new cluster and other running nodes cannot connect to this (until you restart all other nodes). This parameter is only be used when the node to start is the FIRST / ONLY node in the cluster.
- Start 2nd and 3rd nodes:
[bash]service mysql start[/bash]
- Test the cluster configuration on each node:
[bash]mysql -uroot -p -e "show status like ‘wsrep%’"[/bash]
- Well, we can then verify the cluster by adding database, data to any node and test the data in the remaining nodes.
- Always remember to have rsync and which installed in each of your node. I did have a problem of starting slave nodes just because of the lack of which so it generated the error relates to wsrep_sst_rsync.
- In Debian/Ubuntu, we might face stupid error due to the incompatible dependencies. E.g.
[bash][email protected]:~# apt-get install -y rsync galera mariadb-galera-server
The following packages have unmet dependencies:
mariadb-galera-server : Depends: mariadb-galera-server-10.0 (= 10.0.17+maria-1~wheezy) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.[/bash]
. In this case, just install the exact version of mariadb galera such as
[bash]apt-get install -y rsync mariadb-galera-server-10.0[/bash]
- Ports to be opened in both IN and OUT traffic: 3306,4444,4567,4568
- Be careful when playing with auto-increment value since this kind of value will not increased by 1, but by the number of node. This feature helps concurrent writes on any node so just aware of it :-). Reference: https://blog.mariadb.org/auto-increments-in-galera/
- If you are on CentOS 7 and selinux is on, remember to turn selinux to permissive for mysqld
[bash]semanage permissive -a mysqld_t[/bash]
. Otherwise, you will not be able to start galera cluster since other node cannot connect to mysqld service in this server.
- If you use MariaDB from 10.1, MariaDB-Galera-server is not available. The galera is included in the MariaDB-server itself, so you just need to install MariaDB-server package.