{"id":6744,"date":"2017-06-03T17:29:42","date_gmt":"2017-06-03T09:29:42","guid":{"rendered":"http:\/\/rmohan.com\/?p=6744"},"modified":"2017-06-03T17:30:18","modified_gmt":"2017-06-03T09:30:18","slug":"6744","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6744","title":{"rendered":"MariaDB Galera Cluster deployment"},"content":{"rendered":"<p><strong>MariaDB Galera Cluster deployment (how quickly deploy MariaDB cluster)<\/strong><\/p>\n<p>MariaDB is a branch of Mysql, has been widely used in open source projects, such as hot openstack, therefore, in order to ensure high availability of services, while increasing the load capacity of the system, clustered deployment is essential. <\/p>\n<p>MariaDB Galera Cluster Introduction<\/p>\n<p>MariaDB MariaDB cluster is synchronous multi-master cluster. It only supports XtraDB \/ InnoDB storage engine (although experimental support for MyISAM &#8211; see wsrep_replicate_myisam system variable).<\/p>\n<p>The main function:<\/p>\n<p>Replication<br \/>\nTrue multi-master, that is, all nodes can read and write the database at the same time<br \/>\nAutomatic control node members, the failed node is automatically cleared<br \/>\nThe new node joins the data is automatically copied<br \/>\nTrue parallel copy, row-level<br \/>\nUsers can directly connect to the cluster, use exactly the same experience with MySQL<br \/>\nAdvantage:<\/p>\n<p>Because it is multi-master, Slavelag so there is no (delayed)<br \/>\nThere is no case of lost transactions<br \/>\nBut also has the ability to read and write extended<br \/>\nSmaller client latencies<br \/>\nData synchronization between nodes, and the Master \/ Slave mode is asynchronous, the binlog on different slave may be different<br \/>\ntechnology:<\/p>\n<p>Galera Cluster replication based Galeralibrary achieve, in order to allow MySQL and Galera library communications, developed specifically for MySQL wsrep API.<\/p>\n<p>Galera Cluster Synchronization Plug-assurance data, maintaining data consistency, can rely on certified copy, it works in the following figure:<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2017\/06\/gallery.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2017\/06\/gallery.png\" alt=\"\" width=\"1598\" height=\"876\" class=\"aligncenter size-full wp-image-6745\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery.png 1598w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery-300x164.png 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery-768x421.png 768w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery-1024x561.png 1024w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery-150x82.png 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery-400x219.png 400w\" sizes=\"(max-width: 1598px) 100vw, 1598px\" \/><\/a><\/p>\n<p>When the client sends a commit command, before the transaction is committed, all changes to the database are collected write-set up, and sends the contents of write-set record to other nodes.<\/p>\n<p>write-set will be certification testing at each node, the node test results determine whether to apply the write-set change data.<\/p>\n<p>If the authentication test fails, the node will discard the write-set; if the certification test is successful, the transaction commits. <\/p>\n<p>1. Installation Environment Preparation<\/p>\n<p>Install MariaDB cluster requires at least 3 servers (if only two words requires special configuration, please refer to the official documentation)<\/p>\n<p>Here, I list the configuration of the test machine:<\/p>\n<p>Operating system version: CentOS 7<\/p>\n<p>node4: 192.168.1.16 Node5: 192.168.1.17 Node6: 192.168.1.18<\/p>\n<p>The first line as an example, node4 for the hostname, 192.168.1.16 for the ip, the three machines to modify \/ etc \/ hosts file, my file as follows:<br \/>\n192.168.1.16 Node4<br \/>\n192.168.1.17 Node5<br \/>\n192.168.1.18 Node6<\/p>\n<p>In order to ensure mutual communication between nodes, need to disable the firewall settings (if you need a firewall, refer to the official website to increase the firewall settings)<\/p>\n<p>Execute commands three nodes are:<br \/>\nsystemctl STOP firewalld<\/p>\n<p>Then the \/ etc \/ sysconfig \/ selinux selinux is set to disabled, so that the initialization is complete environment. <\/p>\n<p>2. Install the Cluster Galera MariaDB<br \/>\n[Node4 the root @ ~] # yum the install -Y-MariaDB MariaDB MariaDB Galera-Server-Common-Galera Galera the rsync<\/p>\n<p>[root@node5 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync<\/p>\n<p>[root@node6 ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync<\/p>\n<p>3. MariaDB Galera Cluster<\/p>\n<p>Initialize the database service, only one node<\/p>\n<p>[root@node4 mariadb]# systemctl start mariadb<br \/>\n[root@node4 mariadb]# mysql_secure_installation<\/p>\n<p>NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB<br \/>\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!<\/p>\n<p>In order to log into MariaDB to secure it, we&#8217;ll need the current<br \/>\npassword for the root user.  If you&#8217;ve just installed MariaDB, and<br \/>\nyou haven&#8217;t set the root password yet, the password will be blank,<br \/>\nso you should just press enter here.<\/p>\n<p>Enter current password for root (enter for none):<br \/>\nOK, successfully used password, moving on&#8230;<\/p>\n<p>Setting the root password ensures that nobody can log into the MariaDB<br \/>\nroot user without the proper authorisation.<\/p>\n<p>Set root password? [Y\/n]<br \/>\nNew password:<br \/>\nRe-enter new password:<br \/>\nPassword updated successfully!<br \/>\nReloading privilege tables..<br \/>\n &#8230; Success!<\/p>\n<p>By default, a MariaDB installation has an anonymous user, allowing anyone<br \/>\nto log into MariaDB without having to have a user account created for<br \/>\nthem.  This is intended only for testing, and to make the installation<br \/>\ngo a bit smoother.  You should remove them before moving into a<br \/>\nproduction environment.<\/p>\n<p>Remove anonymous users? [Y\/n] n<br \/>\n &#8230; skipping.<\/p>\n<p>Normally, root should only be allowed to connect from &#8216;localhost&#8217;.  This<br \/>\nensures that someone cannot guess at the root password from the network.<\/p>\n<p>Disallow root login remotely? [Y\/n] y<br \/>\n &#8230; Success!<\/p>\n<p>By default, MariaDB comes with a database named &#8216;test&#8217; that anyone can<br \/>\naccess.  This is also intended only for testing, and should be removed<br \/>\nbefore moving into a production environment.<\/p>\n<p>Remove test database and access to it? [Y\/n] n<br \/>\n &#8230; skipping.<\/p>\n<p>Reloading the privilege tables will ensure that all changes made so far<br \/>\nwill take effect immediately.<\/p>\n<p>Reload privilege tables now? [Y\/n] y<br \/>\n &#8230; Success!<\/p>\n<p>Cleaning up&#8230;<\/p>\n<p>All done!  If you&#8217;ve completed all of the above steps, your MariaDB<br \/>\ninstallation should now be secure.<\/p>\n<p>Thanks for using MariaDB!<\/p>\n<p> <a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2017\/06\/gallery1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2017\/06\/gallery1.png\" alt=\"\" width=\"533\" height=\"751\" class=\"aligncenter size-full wp-image-6746\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery1.png 533w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery1-213x300.png 213w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery1-106x150.png 106w, https:\/\/mohan.sg\/wp-content\/uploads\/2017\/06\/gallery1-400x564.png 400w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/a><\/p>\n<p> \/etc\/my.cnf.d\/galera.cnf<br \/>\n[root@node4 mariadb]# systemctl stop mariadb<br \/>\n[root@node4 ~]# vim \/etc\/my.cnf.d\/galera.cnf<\/p>\n<p>[mysqld]<br \/>\n&#8230;&#8230;<br \/>\nwsrep_provider = \/usr\/lib64\/galera\/libgalera_smm.so<br \/>\nwsrep_cluster_address = &#8220;gcomm:\/\/node4,node5,node6&#8243;<br \/>\nwsrep_node_name = node4<br \/>\nwsrep_node_address=192.168.1.16<br \/>\n#wsrep_provider_options=&#8221;socket.ssl_key=\/etc\/pki\/galera\/galera.key; socket.ssl_cert=\/etc\/pki\/galera\/galera.crt;&#8221;<\/p>\n<p>Tip: If you do not have a way ssl certification, please put wsrep_provider_options commented.<\/p>\n<p>Copy this file to node5, node6, attention should wsrep_node_name and wsrep_node_address into the corresponding node hostname and ip. <\/p>\n<p>4. Start MariaDB Galera Cluster Service<br \/>\n[root @ node4 ~] # \/ usr \/ libexec \/ mysqld &#8211;wsrep-new-cluster &#8211;user = root &#038;<\/p>\n<p>?????<br \/>\n[root@node4 ~]# tail -f \/var\/log\/mariadb\/mariadb.log<\/p>\n<p>150701 19:54:17 [Note] WSREP: wsrep_load(): loading provider library &#8216;none&#8217;<br \/>\n150701 19:54:17 [Note] \/usr\/libexec\/mysqld: ready for connections.<br \/>\nVersion: &#8216;5.5.40-MariaDB-wsrep&#8217;  socket: &#8216;\/var\/lib\/mysql\/mysql.sock&#8217;  port: 3306  MariaDB Server, wsrep_25.11.r4026<\/p>\n<p>Ready for connections appear to prove that we started successfully, continue to start another node:<br \/>\n[root @ Node5 ~] # systemctl Start MariaDB<br \/>\n[root @ Node6 ~] # systemctl Start MariaDB<\/p>\n<p>You can view \/var\/log\/mariadb\/mariadb.log, the log can see the nodes are added to the cluster.<\/p>\n<p>Warning ?: &#8211; wsrep-new-cluster This cluster initialization parameters can only be used, and can only be used in a node. <\/p>\n<p>5. Check the cluster status<\/p>\n<p>We can focus on a few key parameters:<\/p>\n<p>wsrep_connected = on the link is on<\/p>\n<p>wsrep_local_index = 1 the cluster index value<\/p>\n<p>wsrep_cluster_size = the number of nodes in the cluster 3<\/p>\n<p>wsrep_incoming_addresses = 192.168.1.17:3306,192.168.1.16:3306,192.168.1.18:3306 access nodes in the cluster address <\/p>\n<p>6. verification data synchronization<\/p>\n<p>Our new database on node4 galera_test, then a query on node5 and node6, if you can check galera_test library, a data synchronization is successful, the cluster is operating normally.<\/p>\n<p>[root@node4 ~]# mysql  -uroot  -p root  -e  &#8220;create database galera_test&#8221;<\/p>\n<p>[root@node5 ~]# mysql  -uroot  -p root  -e  &#8220;show databases&#8221;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Database          |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| information_schema |<br \/>\n| galera_test        |<br \/>\n| mysql              |<br \/>\n| performance_schema |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\n<p>[root@node6 ~]# mysql  -uroot  -p root  -e  &#8220;show databases&#8221;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| Database          |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n| information_schema |<br \/>\n| galera_test        |<br \/>\n| mysql              |<br \/>\n| performance_schema |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\n<p>At this point, our MariaDB Galera Cluster has been successfully deployed.<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;Dividing line&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MariaDB Galera Cluster deployment (how quickly deploy MariaDB cluster)<\/p>\n<p>MariaDB is a branch of Mysql, has been widely used in open source projects, such as hot openstack, therefore, in order to ensure high availability of services, while increasing the load capacity of the system, clustered deployment is essential. <\/p>\n<p>MariaDB Galera Cluster Introduction<\/p>\n<p>MariaDB MariaDB [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6744"}],"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=6744"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6744\/revisions"}],"predecessor-version":[{"id":6748,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6744\/revisions\/6748"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}