Seele

Seele

Create a MariaDB cluster using Galera

Creating a MariaDB Cluster with Galera#

OS-RELEASE

PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

1. Installing MariaDB#

apt install mariadb-server-10.6

Installing Galera#

apt install galera-4

Corresponding Version

Pay attention to version issues, it's really frustrating.

2. Configuring MariaDB#

2.1 Configuring Remote Access for MariaDB#

Configuring the Default Password#

mysql_secure_installation

Allowing Remote Login as root User#

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

2.2 Configuring MariaDB as a Cluster#

nano /etc/mysql/conf.d/galera.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
wsrep_provider=/usr/lib/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="test_cluster"
wsrep_cluster_address='gcomm://'

# Galera Synchronization Configuration
wsrep_sst_method=rsync

# Galera Node Configuration
wsrep_node_address="10.147.19.2"
wsrep_node_name="db1"
wsrep_sst_auth=username:password # Cluster synchronization username and password

As the first node to start, wsrep_cluster_address='gcomm://', when starting subsequent nodes, fill in the address of the first node, such as wsrep_cluster_address='gcomm://10.147.19.2,10.147.19.3'

2.3 Restarting MariaDB#

systemctl stop mariadb

Use the following command to start the first node

galera_new_cluster

Use the following command to start the remaining nodes

systemctl restart mariadb

Insufficient performance or slow network connection will cause the cluster to start slowly.

3. Verifying the Cluster#

mysql -u root -p
SHOW STATUS LIKE 'wsrep_cluster_size';

If the cluster is functioning properly, it will display the number of cluster nodes.
If it is 0, it means the cluster failed to start.
If it is 1, it means the cluster started successfully, but there is only one node.
If it is 2, it means the cluster started successfully with two nodes.

I tested it on my local laptop and everything is fine, but the server performance is really not enough, and the cluster failed to start, so I had to give up.

Local Verification

Below are some files used during the verification process, for reference only.

docker-compose.yml

services:
  vaultwarden1:
    image: ekm43wj2.mirror.aliyuncs.com/vaultwarden/server:latest
    environment:
      WEBSOCKET_ENABLED: 'true'
      SIGNUPS_ALLOWED: 'true'
      ADMIN_TOKEN: 'admin_token_here'
      DATABASE_URL: 'mysql://root:[email protected]/vaultwarden'
    ports:
      - 8100:80
    volumes:
      - ./vw_data1:/data
    restart: always

  vaultwarden2:
    image: ekm43wj2.mirror.aliyuncs.com/vaultwarden/server:latest
    environment:
      WEBSOCKET_ENABLED: 'true'
      SIGNUPS_ALLOWED: 'true'
      ADMIN_TOKEN: 'another_admin_token_here'
      DATABASE_URL: 'mysql://root:[email protected]/vaultwarden'
    ports:
      - 8101:80
    volumes:
      - ./vw_data2:/data
    restart: always
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.