MariaDB Galera Cluster 10.0.12 Stable has been released and available for production use. MariaDB is a relational database management system (RDBMS). Generally we use single node of database server for small application but think about application which have thousands of users keep online at a time, In that situation we need a structure which will capable to handle this load and provides high availability. So we need to add multiple database servers interconnected with each other and keep synchronized, so in case any server goes down other servers can take place of them and provide services to users.
This article will help you to set up MariaDB Galera Cluster 10.0.12 with 3 nodes running with CentOS 6.5. Cluster server details are as following.
- Cluster DB1: 192.168.1.10 ( HostName:
db1.tecadmin.net ) - Cluster DB2: 192.168.1.20 ( HostName:
db2.tecadmin.net ) - Cluster DB3: 192.168.1.30 ( HostName:
db3.tecadmin.net )
Step 1: Add MariaDB Repositories
Create a mariadb repository /etc/yum.repos.d/mariadb.repo using following content in your system. Below repository will work on CentOS 6.x systems, For other system use repository generation tool and add to your system.
For CentOS 6 – 64bit
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
For CentOS 6 – 32bit
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos6-x86 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Step 2: Install MariaDB and Galera
Before installing MariaDB Galera cluster packages, remove any existing MySQL or MariaDB packages installed on system. After that use following command to install on all nodes.
# yum install MariaDB-Galera-server MariaDB-client galera
Step 3: Initial MariaDB Configuration
After successfully installing packages in above steps do the some initial MariaDB configurations. Use following command and follow the instructions on all nodes of cluster. If will prompt to set root account password also.
# service mysql start # mysql_secure_installation
After that create a user in MariaDB on all nodes, which can access database from your network in cluster.
# mysql -u root -p MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'cluster'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> exit
and stop MariaDB service before starting cluster configuration
# service mysql stop
Step 4: Setup MariaDB Galera Cluster on DB1
Lets start setup MariaDB Galera cluster from DB1 server. Edit MariaDB server configuration file and add following values under [mariadb] section.
[root@db1 ~]# vim /etc/my.cnf.d/server.cnf
query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.1.10,192.168.1.20,192.168.1.30" wsrep_cluster_name='cluster1' wsrep_node_address='192.168.1.10' wsrep_node_name='db1' wsrep_sst_method=rsync wsrep_sst_auth=cluster:password
Start cluster using following command.
[root@db1 ~]# /etc/init.d/mysql bootstrap Bootstrapping the clusterStarting MySQL.... SUCCESS!
If you get any problem during startup check MariaDB error log file /var/lib/mysql/<hostname>.err
Step 5: Add DB2 in MariaDB Cluster
After successfully starting cluster on DB1. Start configuration on DB2. Edit MariaDB server configuration file and add following values under [mariadb] section. All the settings are similar to DB1 except wsrep_node_address, wsrep_cluster_address and wsrep_node_name.
[root@db2 ~]# vim /etc/my.cnf.d/server.cnf
query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.1.10,192.168.1.20,192.168.1.30" wsrep_cluster_name='cluster1' wsrep_node_address='192.168.1.20' wsrep_node_name='db2' wsrep_sst_method=rsync wsrep_sst_auth=cluster:password
Start cluster using following command.
[root@db2 ~]# /etc/init.d/mysql start Starting MySQL..... SUCCESS!
Step 6: Add DB3 in MariaDB Cluster
This server is optional, If you want only two server in cluster, you can ignore this step, but you need to remove third server ip from DB1/DB2 configuration files. To add this server make changes same as DB2.
[root@db3 ~]# vim /etc/my.cnf.d/server.cnf
query_cache_size=0 binlog_format=ROW default_storage_engine=innodb innodb_autoinc_lock_mode=2 wsrep_provider=/usr/lib/galera/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.1.10,192.168.1.20,192.168.1.30" wsrep_cluster_name='cluster1' wsrep_node_address='192.168.1.30' wsrep_node_name='db2' wsrep_sst_method=rsync wsrep_sst_auth=cluster:password
Start cluster using following command.
[root@db3 ~]# /etc/init.d/mysql start Starting MySQL..... SUCCESS!
Step 7: Test MariaDB Galera Cluster Setup
At this stage your cluster setup has been completed and running properly. Now you can test the cluster setup by creating database and tables at any server in cluster, it will replicate immediately to all servers in cluster.
4 Comments
Thank you for tutorial.
It work fine for me, but when i stop one node so cluster is failed.
“use mydb;
ERROR 1047 (08S01): WSREP has not yet prepared node for application use”
“wsrep_local_state_comment | Initialized”
“wsrep_ready | OFF”
“wsrep_provider_version | 3.5(rXXXX)”
Can you help me fix this issue ?
Just replace
wsrep_sst_method=rsync
with
wsrep_sst_method=xtrabackup
Doesn’t work:
141219 16:42:05 [Note] WSREP: Flow-control interval: [23, 23]
141219 16:42:05 [Note] WSREP: Shifting OPEN -> PRIMARY (TO: 0)
141219 16:42:05 [Note] WSREP: State transfer required:
Group state: be5342f3-87d7-11e4-a243-8ad982947899:0
Local state: 00000000-0000-0000-0000-000000000000:-1
141219 16:42:05 [Note] WSREP: New cluster view: global state: be5342f3-87d7-11e4-a243-8ad982947899:0, view# 6: Primary, number of nodes: 2, my index: 0, protocol version 3
141219 16:42:05 [Warning] WSREP: Gap in state sequence. Need state transfer.
141219 16:42:05 [Note] WSREP: Running: ‘wsrep_sst_rsync –role ‘joiner’ –address ‘192.168.102.214’ –auth ‘cluster:password’ –datadir ‘/var/lib/mysql/’ –defaults-file ‘/etc/my.cnf’ –parent ‘2273’ ” ‘
141219 16:42:05 [Note] WSREP: Prepared SST request: rsync|192.168.102.214:4444/rsync_sst
141219 16:42:05 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
141219 16:42:05 [Note] WSREP: REPL Protocols: 5 (3, 1)
141219 16:42:05 [Note] WSREP: Service thread queue flushed.
141219 16:42:05 [Note] WSREP: Assign initial position for certification: 0, protocol version: 3
141219 16:42:05 [Note] WSREP: Service thread queue flushed.
141219 16:42:05 [Warning] WSREP: Failed to prepare for incremental state transfer: Local state UUID (00000000-0000-0000-0000-000000000000) does not match group state UUID (be5342f3-87d7-11e4-a243-8ad982947899): 1 (Operation not permitted)
at galera/src/replicator_str.cpp:prepare_for_IST():447. IST will be unavailable.
141219 16:42:05 [Note] WSREP: Member 0.0 (db2) requested state transfer from ‘*any*’. Selected 1.0 (db1)(SYNCED) as donor.
141219 16:42:05 [Note] WSREP: Shifting PRIMARY -> JOINER (TO: 0)
141219 16:42:05 [Note] WSREP: Requesting state transfer: success, donor: 1
141219 16:42:06 [Warning] WSREP: 1.0 (db1): State transfer to 0.0 (db2) failed: -255 (Unknown error 255)
141219 16:42:06 [ERROR] WSREP: gcs/src/gcs_group.c:gcs_group_handle_join_msg():723: Will never receive state. Need to abort.
141219 16:42:06 [Note] WSREP: gcomm: terminating thread
141219 16:42:06 [Note] WSREP: gcomm: joining thread
141219 16:42:06 [Note] WSREP: gcomm: closing backend
141219 16:42:07 [Note] WSREP: view(view_id(NON_PRIM,a33917bf-87d8-11e4-a106-8e47fa459564,6) memb {
a33917bf-87d8-11e4-a106-8e47fa459564,0
} joined {
} left {
} partitioned {
be52bf94-87d7-11e4-a39e-4e3be445bc84,0
})
141219 16:42:07 [Note] WSREP: view((empty))
141219 16:42:07 [Note] WSREP: gcomm: closed
141219 16:42:07 [Note] WSREP: /usr/sbin/mysqld: Terminated.
141219 16:42:07 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
WSREP_SST: [ERROR] Parent mysqld process (PID:2273) terminated unexpectedly. (20141219 16:42:07.987)
WSREP_SST: [INFO] Joiner cleanup. (20141219 16:42:07.988)
WSREP_SST: [INFO] Joiner cleanup done. (20141219 16:42:08.493)
Try open 4568 port for each node, 4568 For Incremental State Transfer
reference: http://galeracluster.com/documentation-webpages/firewallsettings.html