{"id":7369,"date":"2018-05-03T10:07:12","date_gmt":"2018-05-03T02:07:12","guid":{"rendered":"http:\/\/rmohan.com\/?p=7369"},"modified":"2018-05-03T21:19:26","modified_gmt":"2018-05-03T13:19:26","slug":"centos-7-4-mariadb-galera-cluster","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7369","title":{"rendered":"CentOS 7.4  MariaDB Galera Cluster"},"content":{"rendered":"<div id=\"li_all\">\n<div id=\"li_1\"><\/div>\n<\/div>\n<div id=\"content\">\n<p>Mariadb galera cluster installation:<br \/>\nOperating system:\u00a0<a title=\"CentOS\" href=\"https:\/\/www.linuxidc.com\/topicnews.aspx?tid=14\" target=\"_blank\" rel=\"noopener\">CentOS<\/a>\u00a07.4 version<br \/>\nCluster number: 3 nodes<br \/>\nHost information: 192.168.153.142 node1 selinux=disabled firewalld Shutdown<br \/>\n192.168.153.143 node2 selinux=disabled firewalld Shut down<br \/>\n192.168.153.144 node3 selinux=disabled firewalld Shut down<\/p>\n<p>Build steps<\/p>\n<p>1. Hosts resolve each other: all three nodes must execute<br \/>\nvim \/etc\/hosts<br \/>\n192.168.153.142 node1<br \/>\n192.168.153.143 node2<br \/>\n192.168.153.144 node3<\/p>\n<p>2. Install the software package<\/p>\n<p>The first method: (yum install -y MariaDB-server MariaDB-client galera)<br \/>\nConfigure yum installation source and configure mariadb galera installation source<br \/>\nyum source configuration hang iso<br \/>\nSet up mariadb yum source and install (all nodes are required)<br \/>\nModify yum source file<\/p>\n<p>vi \/etc\/yum.repos.d\/mariadb.repo<\/p>\n<p>[mariadb]<br \/>\nname = MariaDB<br \/>\nbaseurl = http:\/\/yum.mariadb.org\/10.3.5\/centos74-amd64<br \/>\ngpgkey=https:\/\/yum.mariadb.org\/RPM-GPG-KEY-MariaDB<br \/>\ngpgcheck=1<br \/>\nenabled=0<br \/>\nWhen installing galera software, it needs to resolve its dependencies: boost-program-options.x86_64 (direct yum source installation)<\/p>\n<p>The second method: (rpm package installation) all three nodes need to be installed<br \/>\nto download the rpm package from the web: galera-25.3.23-1.rhel7.el7.centos.x86_64.rpm<br \/>\nMariaDB-10.3.5-centos74-x86_64-client .rpm<br \/>\nMariaDB-10.3.5-centos74-x86_64-compat.rpm<br \/>\nMariaDB-10.3.5-centos74-x86_64-common.rpm<br \/>\nMariaDB-10.3.5-centos74-x86_64-server.rpm<br \/>\nrpm -ivh MariaDB-10.3.5- Centos74-x86_64-compat.rpm &#8211;nodeps<br \/>\nrpm -ivh MariaDB-10.3.5-centos74-x86_64-common.rpm<br \/>\nrpm -ivh MariaDB-10.3.5-centos74-x86_64-client.rpm<br \/>\nyum install -y boost-program- Options.x86_64 (resolve to install galera dependencies)<br \/>\nrpm -ivh galera-25.3.23-1.rhel7.el7.centos.x86_64.rpm<br \/>\nrpm -ivh MariaDB-10.3.5-centos74-x86_64-server.rpm<\/p>\n<p>3.mariadb initialization (the three nodes need to be executed) After the<br \/>\ninstallation is complete, it will prompt the need to initialize mariadb (set the password)<br \/>\nsystemctl start mariadb<br \/>\nmysql_secure_installation (set the mysql password as prompted)<br \/>\nsystemctl stop mariadb<\/p>\n<p>4. Configure the galera<br \/>\nmaster node configuration file server.cnf<br \/>\nvim \/etc\/my.cnf.d\/server.cnf<br \/>\n[galera]<br \/>\nwsrep_on=ON<br \/>\nwsrep_provider=\/usr\/lib64\/galera\/libgalera_smm.so<br \/>\nwsrep_cluster_address=&#8221;gcomm:\/\/192.168 .153.142,192.168.153.143,192.168.153.144 &#8221;<br \/>\nwsrep_node_name = node1<br \/>\nwsrep_node_address = 192.168.153.142<br \/>\nbinlog_format = Row<br \/>\ndefault_storage_engine = the InnoDB<br \/>\ninnodb_autoinc_lock_mode = 2<br \/>\nwsrep_slave_threads. 1 =<br \/>\nthe innodb_flush_log_at_trx_commit = 0<br \/>\ninnodb_buffer_pool_size = 120M<br \/>\nwsrep_sst_method = the rsync<br \/>\nwsrep_causal_reads the ON =<br \/>\ncopy of this file mariadb- 2, mariadb-3, and attention should wsrep_node_name wsrep_node_address into the corresponding node hostname and ip.<\/p>\n<p>5. Start the cluster service:<br \/>\nStart the MariaDB Galera Cluster service:<br \/>\n[root@node1 ~]# \/bin\/galera_new_cluster The<br \/>\nremaining two nodes are started by:<br \/>\n[root@node1 ~]# systemctl start mariadb<br \/>\nCheck the cluster status: (The cluster service uses 4567. And 3306 ports))<br \/>\n[root@node1 ~]# netstat -tulpn | grep -e 4567 -e 3306<br \/>\ntcp 0 0 0.0.0.0:4567 0.0.0.0: LISTEN 3557\/mysqld<br \/>\ntcp6 0 0 :::3306 ::: LISTEN 3557\/mysqld<\/p>\n<p>6. Verify the cluster status:<br \/>\nExecute on node1:<br \/>\n[root@node1 ~]# mysql -uroot -p ##Enter the database to<br \/>\nsee if galera plug-in is enabled to<br \/>\nconnect to mariadb and check if galera plug-in<br \/>\nMariaDB\u00a0is enabled\u00a0[(none)]&gt; show status like &#8220;wsrep_ready&#8221;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212; +&#8212;&#8212;-+<br \/>\n| wsrep_ready | ON |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<br \/>\n1 row in set (0.004 sec)<br \/>\npresent cluster machine Number<br \/>\nMariaDB [(none)]&gt; show status like &#8220;wsrep_cluster_size&#8221;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br \/>\n| wsrep_cluster_size | 3 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;+&#8212;&#8212;-+<br \/>\n1 row in set (0.001 sec)<br \/>\ncheck the cluster status<br \/>\nMariaDB [(none)]&gt; show status like &#8220;wsrep%&#8221;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| wsrep_apply_oooe | 0.000000 |<br \/>\n| wsrep_apply_oool | 0.000000 |<br \/>\n| wsrep_apply_window | 1.000000 |<br \/>\n| wsrep_causal_reads | 14 |<br \/>\n| wsrep_cert_deps_distance | 1.200000 |<br \/>\n| wsrep_cert_index_size | 3 |<br \/>\n| wsrep_cert_interval | 0.000000 |<br \/>\n| wsrep_cluster_conf_id | 22 |<br \/>\n| wsrep_cluster_size | 3 | ## cluster members<br \/>\n| wsrep_cluster_state_uuid | b8ecf355-233a-11e8-825e-bb38179b0eb4 | ##UUID cluster unique tag<br \/>\n| wsrep_cluster_status | Primary | ##primary server<br \/>\n| wsrep_commit_oooe | 0.000000 |<br \/>\n| Wsrep_commit_oool | 0.000000 |<br \/>\n| wsrep_commit_window | 1.000000 |<br \/>\n| wsrep_connected | ON | ## currently connected in<br \/>\n| wsrep_desync_count | 0 |<br \/>\n| wsrep_evs_delayed | |<br \/>\n| wsrep_evs_evict_list | |<br \/>\n| wsrep_evs_repl_latency | 0\/0\/0\/0\/0 |<br \/>\n| wsrep_evs_state | the OPERATIONAL |<br \/>\n| wsrep_flow_control_paused | 0.000000 |<br \/>\n| wsrep_flow_control_paused_ns | 0 |<br \/>\n| wsrep_flow_control_recv | 0 |<br \/>\n| wsrep_flow_control_sent | 0 |<br \/>\n| wsrep_gcomm_uuid | 0eba3aff-2341-11e8-b45a-f277db2349d5 |<br \/>\n| wsrep_incoming_addresses | 192.168.153.142:3306,192.168.153.143:3306, 192.168.153.144:3306 | ## database in connection<br \/>\n| wsrep_last_committed | 9 | ##sql commit record<br \/>\n| wsrep_local_bf_aborts | 0 | ## is interrupted locally by the executing transaction process<br \/>\n| Wsrep_local_cached_downto | 5 |<br \/>\n| wsrep_local_cert_failures | 0 | ## local failed transaction<br \/>\n| wsrep_local_commits | 4 | sql ## local execution<br \/>\n| wsrep_local_index | 0 |<br \/>\n| wsrep_local_recv_queue | 0 |<br \/>\n| wsrep_local_recv_queue_avg | .057143 |<br \/>\n| wsrep_local_recv_queue_max | 2 |<br \/>\n| wsrep_local_recv_queue_min | 0 |<br \/>\n| wsrep_local_replays | 0 |<br \/>\n| wsrep_local_send_queue | 0 | local queue ## emitted<br \/>\n| wsrep_local_send_queue_avg | 0.000000 | ## queues averaging interval<br \/>\n| wsrep_local_send_queue_max |. 1 |<br \/>\n| wsrep_local_send_queue_min | 0 |<br \/>\n| wsrep_local_state |. 4 |<br \/>\n| wsrep_local_state_comment | Synced |<br \/>\n| wsrep_local_state_uuid | b8ecf355-233a-11e8-825e-bb38179b0eb4 | ##Cluster ID<br \/>\n| wsrep_protocol_version | 8 |<br \/>\n| wsrep_provider_name | Galera |<br \/>\n| wsrep_provider_vendor | Codership Oy &lt;info@codership.com&gt; |<br \/>\n| wsrep_provider_version | 25.3.23(r3789) |<br \/>\n| wsrep_ready | ON | ## Plug-In<br \/>\nWsrep_received | 35 | ##Data Copy Recipients<br \/>\n| wsrep_received_bytes | 5050 |<br \/>\n| wsrep_repl_data_bytes | 1022 |<br \/>\n| wsrep_repl_keys | 14 |<br \/>\n| wsrep_repl_keys_bytes | 232 |<br \/>\n| wsrep_repl_other_bytes | 0 |<br \/>\n| wsrep_replicated |. 5 | ## as the number of copy emitted<br \/>\n| wsrep_replicated_bytes | 1600 | sent replication data word ## The number of sections<br \/>\n| wsrep_thread_count | 2 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;+<br \/>\n58 rows in set (0.003 sec)<br \/>\nView connected hosts<br \/>\nMariaDB [(none)]&gt; show status like &#8220;wsrep_incoming_addresses&#8221;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| wsrep_incoming_addresses | 192.168.153.142:3306,192.168.153.143:3306,192.168.153.144:3306 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n1 row in set (0.002 sec)<\/p>\n<p>7. Test whether the cluster mariad data is synchronized<br \/>\nMariaDB [(none)] create database lizk;<br \/>\nQuery OK, 1 row affected (0.010 sec)<\/p>\n<p>MariaDB [(none)]&gt; show databases;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Database |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;+<br \/>\n| china |<br \/>\n| hello |<br \/>\n| hi |<br \/>\n| information_schema |<br \/>\n| lizk |<br \/>\n| mysql |<br \/>\n| performance_schema |<br \/>\n| test |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8211;+<br \/>\n8 rows in set (0.001 sec)<br \/>\nYou can see that the lizk library is synchronized on the other two nodes.<\/p>\n<p>8. Simulated Brain Fissure After Treatment<br \/>\nThe following simulations show that in the case of packet loss in network jitter, the two nodes are disconnected and cause brain split.\u00a0It was performed on 192.168.153.143 192.168.153.144 and two nodes:<br \/>\niptables -A the INPUT -p TCP -j 4567 &#8211;sport the DROP<br \/>\niptables -A the INPUT -p TCP -j 4567 &#8211;dport the DROP<br \/>\nmore commands to disable the whole wsrep replication communication port 4567<br \/>\nto see node on 192.168.153.142:<br \/>\nMariaDB [(none)]&gt; Show Status like &#8220;WS%&#8221;;<br \/>\n+ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; &#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- &#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8211; + &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n| wsrep_apply_oooe | 0.000000 |<br \/>\n| wsrep_apply_oool | 0.000000 |<br \/>\n| wsrep_apply_window | 1.000000 |<br \/>\n| wsrep_causal_reads | 16 |<br \/>\n| wsrep_cert_deps_distance | 1.125000 |<br \/>\n| wsrep_cert_index_size | 3 |<br \/>\n| Wsrep_cert_interval | 0.000000 |<br \/>\n| wsrep_cluster_conf_id | 18446744073709551615 |<br \/>\n| wsrep_cluster_size | 1 |<br \/>\n| wsrep_cluster_state_uuid | b8ecf355-233a-11e8-825e-bb38179b0eb4 |<br \/>\n| wsrep_cluster_status | non-Primary |<br \/>\nnow split brain situation has occurred, and the cluster can not execute any commands.<br \/>\nIn order to solve this problem, you can execute<br \/>\nset global wsrep_provider_options=&#8221;pc.bootstrap=true&#8221;;<br \/>\nThis command is used to forcibly recover nodes that have split brain.<br \/>\nVerify:<br \/>\nMariaDB [(none)]&gt; = wsrep_provider_options Global SET &#8220;to true pc.bootstrap =&#8221;;<br \/>\nQuery the OK, 0 rows affected (0.015 sec)<\/p>\n<p>MariaDB [(none)]&gt; select @@wsrep_node_name;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| @@wsrep_node_name |<br \/>\n+&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8211;+<br \/>\n| node1 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n1 row in set (0.478 sec)<br \/>\nFinally we will node 192.168.153.143 and 192.168 .153.144 Recover, just clean up the iptables table (because my test environment, the production environment needs to delete the above rules can be):<br \/>\n[root@node3 mysql]# iptables-F<br \/>\nafter the restoration to verify:<br \/>\nMariaDB [(none ]]&gt; show status like &#8220;wsrep_cluster_size&#8221;;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;-+<br \/>\n| Variable_name | Value |<br \/>\n+&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+<br \/>\n| wsrep_cluster_size | 3 |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- -+&#8212;&#8212;-+<br \/>\n1 row in set (0.001 sec)<\/p>\n<p>9. Because of the fault, it is necessary to check the two nodes of the cluster and check whether the data can be synchronized after restarting the service.<br \/>\nTo stop the operations of mariadb on 192.168.153.143 and 192.168.153.144:<br \/>\n[root@node2 mysql]# systemctl stop mariadb is<br \/>\nat 192.168. Insert data on node 153.142:<br \/>\nMariaDB [test]&gt; select * from test1;<br \/>\n+&#8212;&#8212;+<br \/>\n| id |<br \/>\n+&#8212;&#8212;+<br \/>\n| 2 |<br \/>\n| 2 |<br \/>\n| 1 |<br \/>\n| 3 |<br \/>\n+&#8211; &#8212;-+<br \/>\n4 rows in set (0.007 sec)<br \/>\nNow restart the other two nodes in the cluster and see the data consistency, as with the master node.<\/p>\n<p>10. Abnormal processing: When the room suddenly loses power, all galera hosts are shut down abnormally, and the galera cluster service cannot start properly when the phone is switched on.\u00a0How to deal with?<br \/>\nStep 1: Open the mariadb service of the master host of the galera cluster.<br \/>\nStep 2: Start the mariadb service on the member host of the galera cluster.<br \/>\nException handling: The mysql service of the master host and member host of the galera cluster cannot be started. What should I do?<br \/>\nSolution one: Step 1. Delete the \/var\/lib\/mysql\/grastate.dat status file of<br \/>\n\/\u00a0garlera master host\u00a0\/bin\/galera_new_cluster to start the service.\u00a0Start normally.\u00a0Log in and check the wsrep status.<br \/>\nStep 2: Remove the \/var\/lib\/mysql\/grastate.dat status file from the galera member host<br \/>\nsystemctl restart mariadb Restart the service.\u00a0Start normally.\u00a0Log in and check the wsrep status.<br \/>\nSolution two: Step 1, modify the \/var\/lib\/mysql\/grastate.dat status file in the main host of the garlera group to<br \/>\nstart the service\u00a0with 0 as 1\u00a0\/bin\/galera_new_cluster.\u00a0Start normally.\u00a0Log in and check the wsrep status.<br \/>\nStep 2: Modify the 0 in the \/var\/lib\/mysql\/grastate.dat state file in the galera member host to 1<br \/>\nsystemctl restart mariadb to restart the service.\u00a0Start normally.\u00a0Log in and check the wsrep status.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"\n<p>Mariadb galera cluster installation: Operating system: CentOS 7.4 version Cluster number: 3 nodes Host information: 192.168.153.142 node1 selinux=disabled firewalld Shutdown 192.168.153.143 node2 selinux=disabled firewalld Shut down 192.168.153.144 node3 selinux=disabled firewalld Shut down<\/p>\n<p>Build steps<\/p>\n<p>1. Hosts resolve each other: all three nodes must execute vim \/etc\/hosts 192.168.153.142 node1 192.168.153.143 node2 192.168.153.144 node3<\/p>\n<p>2. Install [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7369"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7369"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7369\/revisions"}],"predecessor-version":[{"id":7371,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7369\/revisions\/7371"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}