Implementation of mariadb galera cluster based on docker

Keywords: MariaDB Docker MySQL Database

Environment configuration:

Node name IP address
node01 192.168.10.207
node02 192.168.10.167

Basic environment configuration:

  1. Remove firewalld
yum remove firewalld -y
  1. Turn off selinux
sudo vim  /etc/selinux/config

Modify the following:
SELINUX=disabled

  1. Install iptables services and Bash completion
yum install -y iptables-services bash-completion
systemctl enable iptables
systemctl start iptables
iptables -F
service iptables save
systemctl restart iptables
  1. Add hosts hostname resolution
cat /etc/hosts
192.168.10.207	node01
192.168.10.167 node02
  1. Add iptables rule group required by mariadb
iptables -A INPUT -p tcp -m multiport --dport 3306,4567,4444 -j ACCEPT

Deploy galera cluster

1. Download the latest docker image of mariadb 10.3.10

docker pull mariadb:10.3.10

2. Create the directory required by the database to save the mariadb configuration file and mariadb data

mkdir -p /opt/mariadb/conf
mkdir -p /opt/mariadb/data

node1 node operation:
1. Run mariadb for the first time at node01 node for running purpose. Copy the configuration file of mariadb to the host, and generate the database file in the directory / opt/mariadb/data
docker run -d
–name mariadb-node01
-v /opt/mariadb/data:/var/lib/mysql
-e MYSQL_ROOT_PASSWORD=123456
mariadb:10.3.10
2. Copy the mariadb container configuration file to the directory / opt/mariadb/conf

docker cp mariadb-node01:/etc/mysql /opt/mariadb/conf

3. Enter the container and enter the mysql database command line mysql database gives remote login permission

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

4. Exit the container and delete it (to delete the parent of the container is to generate the data files required by the database in the directory / opt/mariadb/data)

docker sotp mariadb-node01 && docker rm mariadb-node01

5. Modify the configuration of [galera] in my.cnf configuration file under the directory / opt/mariadb/conf

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.10.207:4567,192.168.10.167:4567
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=192.168.10.207
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0

6. Start the mariadb container at node01 node for the second time. To start the first database of the cluster, you need to add the wsrep new cluster parameter

docker run -d \
--name mariadb-node01 \
-p 3306:3306 \
-p 4567:4567 \
-p 4444:4444 \
-v /opt/mariadb/conf:/etc/mysql \
-v /opt/mariadb/data/:/var/lib/mysql \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes  \
-e TIMEZONE=Asia/Shanghai \
mariadb:10.3.10 --wsrep-new-cluster

node02 node operation
1. Run mariadb for the first time in node02 node for running purpose. Copy the configuration file of mariadb to the host, and generate the database file in the directory / opt/mariadb/data

docker run -d \
--name mariadb-node02 \
-v /opt/mariadb/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mariadb:10.3.10

2. Copy the mariadb container configuration file to the directory / opt/mariadb/conf

docker cp mariadb-node02:/etc/mysql /opt/mariadb/conf

3. Enter the container and enter the mysql database command behavior mysql database gives remote login permission

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

4. Exit the container and delete it (to delete the parent of the container is to generate the data files required by the database in the directory / opt/mariadb/data)

docker sotp mariadb-node02 && docker rm mariadb-node02

5. Modify the configuration of [galera] in my.cnf configuration file under the directory / opt/mariadb/conf

[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.1010.207:4567,192.168.10.167:4567
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=192.168.10.167
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0

6. Start the mariadb container at node01 node for the second time. To start the first database of the cluster, you need to add the wsrep new cluster parameter

docker run -d \
--name mariadb-node02 \
-p 3306:3306 \
-p 4567:4567 \
-p 4444:4444 \
-v /opt/mariadb/conf:/etc/mysql \
-v /opt/mariadb/data/:/var/lib/mysql \
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes  \
-e TIMEZONE=Asia/Shanghai \
mariadb:10.3.10 --wsrep-new-cluster

Verify that the galera cluster is working properly

show status like '%wsrep%';

link

Published 44 original articles, praised 0, visited 909
Private letter follow

Posted by versatilewt on Wed, 22 Jan 2020 01:00:27 -0800