Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mariadb Galera Cluster deployment

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Unlike standard MySQL servers and MySQL clusters, MySQL / MariaDB Galera clusters have some small differences in startup mode. Galera needs to start a node in the cluster as a reference point before the remaining nodes can join the cluster. This process is called cluster booting. Booting is an initial step, with the bootstrap node as the master node and other nodes using the master node as a reference point to synchronize data.

Start the cluster

Install mariadb on three machines and initialize the configuration. Modify the content of / etc/my.cnf.d/server.cnf on the first node, and add the cluster configuration in the "galera" section:

Wsrep_on=ONwsrep_provider=/usr/lib64/galera/libgalera_smm.sowsrep_cluster_address='gcomm://' # configuration of the first boot node wsrep_cluster_name='mariadb_cluster'wsrep_node_address='192.168.0.56' # Native IP address wsrep_node_name='mariadb_node1' # Cluster node name wsrep_sst_method=rsync binlog_format=rowdefault_storage_engine=InnoDBinnodb_autoinc_lock_mode=2bind-address=0.0.0.0

Configure the [galera] section of the / etc/my.cnf.d/server.cnf file on the second and third nodes:

Wsrep_on=ONwsrep_provider=/usr/lib64/galera/libgalera_smm.sowsrep_cluster_address='gcomm://192.168.0.56192.168.0.58'wsrep_cluster_name='mariadb_cluster'wsrep_node_address='192.168.0.57'wsrep_node_name='mariadb_node2'wsrep_sst_method=rsync binlog_format=rowdefault_storage_engine=InnoDBinnodb_autoinc_lock_mode=2bind-address=0.0.0.0

Wsrep_on=ONwsrep_provider=/usr/lib64/galera/libgalera_smm.sowsrep_cluster_address='gcomm://192.168.0.56192.168.0.57'wsrep_cluster_name='mariadb_cluster'wsrep_node_address='192.168.0.58'wsrep_node_name='mariadb_node3'wsrep_sst_method=rsync binlog_format=rowdefault_storage_engine=InnoDBinnodb_autoinc_lock_mode=2bind-address=0.0.0.0

If you want to start Mariadb Galera Cluster, first select the node1 node as the initial node, node1 as the first startup node, and set gcomm to empty, otherwise you cannot start.

Wsrep_cluster_address='gcomm://'

Nide1 startup command (different startup methods for different versions):

$service mysql bootstrap # sysvinit$ service mysql start-wsrep-new-cluster # sysvinit$ galera_new_cluster # systemd $mysqld_safe-wsrep-new-cluster # command line

After node1 starts, start node2 and node3. After that, modify the node1 "wsrep_cluster_address" configuration to add other cluster nodes IP.

$systemctl start mariadb

Check to see if the system port exists. By default, the system will listen on port 3306 and 4567.

Log in to the database to see if the cluster node has joined:

MariaDB [(none)] > SHOW STATUS LIKE "wsrep_cluster_size"; +-+-+ | Variable_name | Value | +-+ | wsrep_cluster_size | 3 | +-+-+

You can view the synchronization status of nodes through wsrep_cluster_status and wsrep_local_state_comment.

MariaDB [(none)] > show status like "wsrep_cluster_status" +-- +-+ | Variable_name | Value | +-- +-+ | wsrep_cluster_status | Primary | +-- +-+ 1 row in set (0.00 sec) MariaDB [(none)] > show status like "wsrep_local_state_comment" +-- +-+ | Variable_name | Value | +-+-+ | wsrep_local_state_comment | Synced | +- -+-+ 1 row in set (0.00 sec)

Warning: when adding a new node to an existing cluster, do not boot this node (bootstrap). You cannot use two boot nodes in a cluster.

Failure recovery and restarting the cluster

When our mariadb Galera Cluster cluster needs to be restarted (unexpected downtime), it is very important to select a suitable master node as the boot startup node to ensure the integrity of the data in the future. If the boot sequence is incorrect, it may result in data loss or failure to start.

When Galera starts with a boot command on the node, that particular node reaches the primary state (check the value of wsrep_cluster_status). The rest of the nodes only need a normal startup command, and they will automatically find the existing master component (PC) in the cluster and join it to form a cluster. Data synchronization then occurs through an incremental state transfer (IST) or snapshot state transfer (SST) between the accelerator and the donor.

Therefore, basically, if you want to start a new cluster or if no other nodes in the cluster are in the PRIMARY state, you should only boot the cluster. Care should be taken when choosing the action to take, otherwise it may lead to splitting the cluster or losing data.

If the primary node in the cluster is working properly, we only need to start the other nodes normally. So the key point is that after all the cluster is down, we need to find the last node to exit the cluster, and the data is the most complete node. By starting this node, other nodes synchronize data with this node after startup to ensure that the data of the database cluster is not lost.

1. Find the last downtime node (the node with the highest number of seqno is the master node for the next boot, which should be started first):

# cat / maria-data/mysql/grastate.dat # GALERA saved stateversion: 2.1uuid: 8736f68d-0af7-11e7-aba5-9a9e6a4d342cseqno: 15safe_to_bootstrap: 0

Tip: if all nodes have a seqno value of-1, and we know which node has the highest priority, we can manually specify this node as the boot node, change the safe_to_bootstrap = 1 of the grastate.dat file, and then start this node.

2. If all nodes stop the database due to sudden downtime, we need to find the node with the most complete data synchronization as the startup node. You can use the following command on each node:

$mysqld-- wsrep-recover...2016-11-18 01:42:15 36311 [Note] InnoDB: Database was not shutdown normally2016-11-18 01:42:15 36311 [Note] InnoDB: Starting crash recovery....2016-11-18 01:42:16 36311 [Note] WSREP: Recovered position: 8bcf4a34Muzaedbmur14e5Mub3Mud3e36277729fuv114428.

In the prompt, the ID specified after Recovered position is the database node that we need to start first. Modify the node grastate.dat configuration file "safe_to_bootstrap: 1" to start the node.

Reference documentation:

Https://severalnines.com/blog/how-bootstrap-mysqlmariadb-galera-cluster

Http://galeracluster.com/documentation-webpages/restartingcluster.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report