<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Control WebPanel Wiki &#187; MySQL Cluster</title>
	<atom:link href="https://wiki.centos-webpanel.com/tag/mysql-cluster/feed" rel="self" type="application/rss+xml" />
	<link>https://wiki.centos-webpanel.com</link>
	<description>CentOS WebPanel Wiki</description>
	<lastBuildDate>Wed, 12 Feb 2025 20:38:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>MySQL Cluster (MariaDB Galera)</title>
		<link>https://wiki.centos-webpanel.com/mysql-cluster-mariadb-galera</link>
		<comments>https://wiki.centos-webpanel.com/mysql-cluster-mariadb-galera#comments</comments>
		<pubDate>Wed, 08 Jul 2015 18:04:11 +0000</pubDate>
		<dc:creator><![CDATA[publisher]]></dc:creator>
				<category><![CDATA[Clusters]]></category>
		<category><![CDATA[MySQL Cluster]]></category>

		<guid isPermaLink="false">http://wiki.centos-webpanel.com/?p=355</guid>
		<description><![CDATA[How to setup MySQL Cluster (master/master) with MariaDB Galera Cluster We will use two Servers for MySQL Cluster cluster1 with IP 10.90.90.101 cluster2 with IP 10.90.90.102 ..this can be public or private IP's depending on your needs. Make sure that SeLinux is disabled and IP's are whitelisted in the firewall. Create a mariadb repository: nano [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><strong>How to setup MySQL Cluster (master/master) with MariaDB Galera Cluster</strong></p>
<p><strong>We will use two Servers for MySQL Cluster</strong><br />
cluster1 with IP 10.90.90.101<br />
cluster2 with IP 10.90.90.102<br />
..this can be public or private IP's depending on your needs.</p>
<p>Make sure that SeLinux is disabled and IP's are whitelisted in the firewall.</p>
<p><strong>Create a mariadb repository:</strong> nano /etc/yum.repos.d/mariadb.repo</p>
<p>CentOS 6 64bit</p>
<pre>[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1</pre>
<p>CentOS 6 32bit</p>
<pre>[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-x86
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1</pre>
<p><strong>Installation on all cluster servers</strong></p>
<pre>yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/socat-1.7.2.3-1.el6.x86_64.rpm
yum -y install MariaDB-server MariaDB-client rsync galera
service mysql start
/usr/bin/mysql_secure_installation</pre>
<p>You can enter a DATABASE-PASSWORD and accepted all defaults (if you don't know what to do).</p>
<p>Now we need to add MariaDB Galera Cluster user</p>
<pre>mysql -u root -p</pre>
<p>** For password just hit enter</p>
<pre>mysql> DELETE FROM mysql.user WHERE user='';
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'DATABASE-PASSWORD';
mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY 'DATABASE-PASSWORD';
mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%';
mysql> FLUSH PRIVILEGES;
mysql> quit</pre>
<p>You can replace "%" with hostname or IP address from which that users can access the database.<br />
"%" means that you can access databases from any server so this is decreasing your security level.</p>
<p><strong>Now lets configure MariaDB Galera Cluster</strong></p>
<pre>service mysql stop</pre>
<p>Under <strong>[galera]</strong> in file <strong>/etc/my.cnf.d/server.cnf</strong> add cluster configuration.<br />
<em>DON'T FORGET TO EDIT</em> <strong>wsrep_node_address</strong> and <strong>wsrep_node_name</strong> for each server.</p>
<pre>
wsrep_on=ON
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.90.90.101,10.90.90.102"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='10.90.90.101'
wsrep_node_name='cluster1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
</pre>
<p><strong>Now let's start our clusters</strong><br />
On cluster1 ONLY run MySQL with additonal option "<strong>--wsrep-new-cluster</strong>"</p>
<pre>/etc/init.d/mysql start --wsrep-new-cluster</pre>
<p>On every other cluster server like cluster2 in our example you need to start mysql as usual</p>
<pre>service mysql start</pre>
<p>And that is it, you cluster should be working now <img src="https://wiki.centos-webpanel.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /></p>
<p><strong>Test which MySQL servers are running in cluster</strong><br />
You should see IP address of each server in cluster and number of servers in cluster</p>
<pre>mysql -u root -p -e "show status like 'wsrep%'"</pre>
<pre>| wsrep_local_state_comment | Synced                                 |
| wsrep_incoming_addresses  | 10.90.90.101:3306,10.90.90.102:3306    |
| wsrep_cluster_size        | 3                                      |
| wsrep_connected           | ON                                     |
| wsrep_ready               | ON                                     |</pre>
<p><strong>Final improvements</strong><br />
Avoid password requests from command line for MySQL root user:<br />
Create file /root/.my.cnf and add in it</p>
<pre>[client]
host=MYSQL-IP
port=3306
password="DATABASE-PASSWORD"  
user=root</pre>
<p>Secure this file to be readable for root user only</p>
<pre>chmod 400 /root/.my.cnf</pre>
<p><strong>Avoid DNS</strong><br />
To avoid DNS communication between cluster servers we need to define cluster servers in <strong>/etc/hosts</strong> file on each server.<br />
We can do that by adding IP's and server name for each cluster at end of /etc/hosts file.</p>
<pre>10.90.90.101 cluster1
10.90.90.102 cluster2
</pre>
<p>You can also change configuration for server by using example from this files /usr/share/mysql/:</p>
<pre>
my-huge.cnf (1-2GB RAM)        
my-innodb-heavy-4G.cnf (4GB RAM,InnoDB only,ACID,heavy queries)
my-large.cnf (512MB RAM)        
my-medium.cnf (128MB RAM)    
my-small.cnf (<=64MB RAM)
</pre>
<p>Don't forget that cluster works with innodb tables, you can check the database table type with this command.</p>
<pre>mysql -e "SHOW TABLE STATUS FROM \`DATABASE-NAME\`;"|awk {'print $2'}|sort|uniq -c</pre>
<p>*** Replace DATABASE-NAME with the name of your database.</p>
<p><strong>For assistance you can contact our support</strong><br />
<a href="http://centos-webpanel.com/contact" title="Contact CentOS support" target="_blank">http://centos-webpanel.com/contact</a></p>
]]></content:encoded>
			<wfw:commentRss>https://wiki.centos-webpanel.com/mysql-cluster-mariadb-galera/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
