• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup MariaDB Galera Cluster 10.0 on CentOS/RedHat & Fedora

Written by Rahul, Updated on July 22, 2014

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.

mariadb-banner

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 )

Note: Step 1/2/3 has to be done on all cluster nodes and remaining steps are node specific.

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.

[[email protected] ~]# 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.

[[email protected] ~]# /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.

[[email protected] ~]# 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.

[[email protected] ~]# /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.

[[email protected] ~]# 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.

[[email protected] ~]# /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.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

4 Comments

  1. Avatar Tung Reply
    January 1, 2015 at 4:06 am

    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 ?

    • Avatar kaiz Reply
      July 23, 2015 at 10:20 am

      Just replace
      wsrep_sst_method=rsync
      with
      wsrep_sst_method=xtrabackup

  2. Avatar Jason Reply
    December 19, 2014 at 11:46 pm

    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)

    • Avatar ChienChih Reply
      December 22, 2015 at 2:06 am

      Try open 4568 port for each node, 4568 For Incremental State Transfer

      reference: http://galeracluster.com/documentation-webpages/firewallsettings.html

Leave a Reply Cancel reply

Popular Posts

  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
  • How to Install .NET Core on Debian 10 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy