Friday, March 25, 2022

Steps to configure Galera cluster in MariaDB


 Clustering adds high availability to your database by distributing changes to different servers. In the event that one of the instances fails, others are quickly available to continue serving.

Clusters come in two general configurations, active-passive and active-active. In active-passive clusters, all writes are done on a single active server and then copied to one or more passive servers that are poised to take over only in the event of an active server failure. Some active-passive clusters also allow SELECT operations on passive nodes. In an active-active cluster, every node is read-write and a change made to one is replicated to all.

We will configure an active-active MariaDB Galera cluster.

What we need?

  • 3x Ubuntu 16.04 Servers in the same network, so that all nodes can access each other using private IPs

Let’s Start

We will start step by step to setup the cluster.

Step 01: Adding MariaDB Repository to the servers and Install it

MariaDB is not available by default from apt-get . So we need to add manually MariaDB repository. Although, you can also install from source.

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.1/ubuntu xenial main'sudo apt-get update# Install MariaDB
sudo apt-get install mariadb-server

Althogh, rsync comes with MariaDB server installations, but make sure it is installed by:

sudo apt-get install rsync

Step 02: Configuring nodes

Each node should have exact configuration to be in cluster. So we will make changes in first node and copy it to rest 2 nodes.

By default, MariaDB is configured to check the /etc/mysql/conf.d directory to get additional configuration settings for from ending in .cnf. We will write our configurations in s/etc/mysql/conf.d/galera_cluster.cnf.

[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration wsrep_on=ON wsrep_provider=/usr/lib/galera/libgalera_smm.so # Galera Cluster Configuration
wsrep_cluster_name="<name-of-cluster>" wsrep_cluster_address="gcomm://<first-pvt-ip>,<second-pvt-ip>,<third-pvt-ip>"
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="<this-node-ip>"
wsrep_node_name="<this-node-name>"

Change the variables in <> according to needs and use private IPs in the configuration.

Step 03: Starting cluster

To bring up the first node, we’ll need to use a galera commands. Without using the galera_new_cluster script that allows systemd to pass the the --wsrep-new-cluster parameter, a normal systemctl start mysql would fail because there are no nodes running for the first node to connect with.

sudo galera_new_cluster

Now for rest of the two nodes, start them by:

sudo systemctl start mysql

Hurray! Your MariaDB Cluster is setup completed successfully. You can test the cluster by this:

$ mysql -u root -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+
$

Now you can read/write in any nodes and it will be replicated to other nodes.

Thursday, March 3, 2016

ORA-15040: diskgroup is incomplete

ORA-15040: diskgroup is incomplete


I received this error while I was trying to bring up cluster on the second in my 2-node cluster.
When I tried to start cluster, ora.asm resource was found in intermediate state.
[root@host02 ~]# crsctl start cluster
CRS-5702: Resource 'ora.evmd' is already running on 'host02'
CRS-2800: Cannot start resource 'ora.asm' as it is already in the INTERMEDIATE state on server 'host02'
CRS-4000: Command Start failed, or completed with errors.
– Since asm was not up, OCR could not be read and hence cluster could not come up
[root@host02 ~]# crsctl stat res -t -init
--------------------------------------------------------------------------------
NAME           TARGET  STATE        SERVER                   STATE_DETAILS       
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.asm
      1        ONLINE  INTERMEDIATE host02                   OCR not started
– The alert log showed that DATA diskgroup could not be mounted.
2013-09-04 13:55:38.896
[/u01/app/11.2.0/grid/bin/oraagent.bin(28674)]CRS-5019:All OCR locations are on ASM disk groups [DATA], and none of these disk groups are mounted. Details are at “(:CLSN00100:)” in “/u01/app/11.2.0/grid/log/host02/agent/ohasd/oraagent_grid/oraagent_grid.log”.
– I tried to mount DATA diskgroup using SQL but I got ORA-15040 which indicated that disk “0” could not be read
SQL> alter diskgroup data mount;
alter diskgroup data mount
*
ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15040: diskgroup is incomplete
ORA-15042: ASM disk "0" is missing from group number "1" 
– When I listed ASM disks on second node, ASMDISK01 was not listed
[root@host02 bin]# oracleasm listdisks
ASMDISK010
ASMDISK011
ASMDISK012
ASMDISK013
ASMDISK014
ASMDISK02
ASMDISK03
ASMDISK04
ASMDISK05
ASMDISK06
ASMDISK07
ASMDISK08
ASMDISK09
– I issued oracleasm scandisks which led to discovery of ASMDISK01
[root@host02 bin]# oracleasm scandisks
Reloading disk partitions: done
Cleaning any stale ASM disks...
Scanning system for ASM disks...
Instantiating disk "ASMDISK01"
– Now when I issued oracleasm listdisks, ASMDISK01 was also listed.
[root@host02 bin]# oracleasm listdisks
ASMDISK01
ASMDISK010
ASMDISK011
ASMDISK012
ASMDISK013
ASMDISK014
ASMDISK02
ASMDISK03
ASMDISK04
ASMDISK05
ASMDISK06
ASMDISK07
ASMDISK08
ASMDISK09
— Now I could mount DATA diskgroup successfully
SQL> alter diskgroup data mount;

Diskgroup altered.
Reference:http://oracleinaction.com/ora-15040/