<?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>Database &#8211; G1FEF</title>
	<atom:link href="https://g1fef.co.uk/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>https://g1fef.co.uk</link>
	<description></description>
	<lastBuildDate>Tue, 13 Aug 2019 09:32:46 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Setup MySQL / MariaDB master slave replication</title>
		<link>https://g1fef.co.uk/setup-mysql-mariadb-master-slave-replication/</link>
		
		<dc:creator><![CDATA[G1FEF]]></dc:creator>
		<pubDate>Sun, 02 Jul 2017 08:21:15 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[System admin]]></category>
		<guid isPermaLink="false">https://g1fef.co.uk/?p=176</guid>

					<description><![CDATA[mysql -u root -p &#60; dump.sql How to setup a single master with one or more readonly slaves First configure the master by editing the mysql configuration file, this could be /etc/my.cnf or on Centos 7 it is /etc/my.cnf.d/server.cnf Find the [server] section and add the following lines: bind-address = 12.34.56.78 # replace 12.34.56.78 with [&#8230;]]]></description>
										<content:encoded><![CDATA[<pre class="lang:default decode:true ">mysql -u root -p &lt; dump.sql</pre>
<h4>How to setup a single master with one or more readonly slaves</h4>
<p><span id="more-176"></span></p>
<p>First configure the master by editing the mysql configuration file, this could be /etc/my.cnf or on Centos 7 it is /etc/my.cnf.d/server.cnf</p>
<p>Find the [server] section and add the following lines:</p>
<pre class="text">bind-address = 12.34.56.78 # replace 12.34.56.78 with the IP of your server
log_bin
server_id = 1
log_basename = master1
datadir = /var/lib/mysql
binlog-ignore-db = mysql
</pre>
<p>The binlog-ignore-db line tells the master not to replicate the &#8216;mysql&#8217; database, you can add additional entries to not replicate other databases if you wish, e.g.</p>
<pre class="text">binlog-ignore-db = information_schema
binlog-ignore-db = performance_schema
</pre>
<p>Adding the following additional entries allows you to tweak the performance of your server:</p>
<pre class="text">max_allowed_packet=64M
max_heap_table_size = 64M
tmp_table_size = 128M
join_buffer_size = 128M
innodb_buffer_pool_size = 256M
innodb_doublewrite = OFF
innodb_additional_mem_pool_size = 128M
innodb_flush_log_at_timeout = 4
innodb_read_io_threads = 48
innodb_write_io_threads = 32
max_connections = 128
</pre>
<p>Following any changes to the config files you will need to restart MySQL (or MariaDB if you use that instead), so you would do one of the following:</p>
<pre class="text">systemctl restart mysqld
systemctl restart mariadb
</pre>
<p>Now login to your local MySQL server, e.g.</p>
<pre class="text">mysql -u root -p
</pre>
<p>Once logged into the MySQL CLI add a user that the slaves will use to replicate:</p>
<pre class="text">GRANT REPLICATION SLAVE ON *.* TO 'replication'@'1.2.3.4' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
</pre>
<p>Replace 1.2.3.4 with the IP of your slave server. You can run the above command multiple times, once for each slave server. Remember to change &#8216;password&#8217; to an actual password, a good choice would be 12 (or more) characters consisting of a random mix of upper/lowercase letters, numbers and punctuation characters.</p>
<p>Now we&#8217;re ready to take a backup of the master, for this you will need to open a second session on your master server. In the first session, still logged into the MySQL CLI issue the following commands:</p>
<pre class="text">FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
</pre>
<p>You should see something along these lines:</p>
<pre class="text">+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| master1-bin.000001 |   456    |              | mysql            |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
</pre>
<p>Leave this session in place whilst you move to the second session to backup the databases you want to replicate by using your preferred method, e.g.</p>
<pre class="text">mysqldump -u root -p --all-databases &gt; dump.sql
</pre>
<p>Now you can go back to the first window and release the lock:</p>
<pre class="text">UNLOCK TABLES;
QUIT;
</pre>
<p>Now copy this backup to your slave server(s). I use scp for this, e.g.</p>
<pre class="text">scp dump.sql username@12.34.56.78:.
</pre>
<p>Now login to the slave server and import the dumped databases:</p>
<p>mysql -u root -p &lt; dump.sql</p>
<p>Now configure MySQL (or mariadb) to be a slave by editing it&#8217;s configuration file, e.g. /etc/my.cnf.d/server.cnf and add the following to the [server] section:</p>
<pre class="text">server-id = 2
datadir = /var/lib/mysql
relay-log = /var/lib/mysql/mysql-relay-bin.log
log_bin = /var/lib/mysql/mysql-bin.log
</pre>
<p>As per the master server, following any changes to the config files you will need to restart MySQL (or MariaDB if you use that instead), so you would do one of the following:</p>
<pre class="text">systemctl restart mysqld
systemctl restart mariadb
</pre>
<p>The next step is to login to the MySQL CLI and tell it where to find the master along with the login details and the starting position in the log:</p>
<pre class="text">CHANGE MASTER TO MASTER_HOST='12.34.56.78',MASTER_USER='replication', MASTER_PASSWORD='password', MASTER_LOG_FILE='master1-bin.000001', MASTER_LOG_POS=456;
</pre>
<p>The last thing we need to do is start the slave process, and check it is running. Do this by issuing the following commands on the slave MySQL CLI:</p>
<pre class="text">START SLAVE;
SHOW SLAVE STATUS\G
</pre>
<p>You can repeat the slave part on each server you want to setup replication, just remember to give each slave a different server_id</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Setting up a Galera MariaDB Cluster</title>
		<link>https://g1fef.co.uk/setting-galera-mariadb-cluster/</link>
		
		<dc:creator><![CDATA[G1FEF]]></dc:creator>
		<pubDate>Sat, 27 May 2017 05:58:55 +0000</pubDate>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[System admin]]></category>
		<guid isPermaLink="false">https://g1fef.co.uk/?p=89</guid>

					<description><![CDATA[How to setup a Galera MariaDB Cluster Remove any existing packages: yum remove maria* Update: yum update Add the official repo for MariaDB by creating the file /etc/yum.repos.d/MariaDB.repo [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.1/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 Now install MariaDB: yum install -y MariaDB-server MariaDB-client MariaDB-compat galera socat jemalloc Setup MariaDB: systemctl start mariadb mysql_secure_installation [&#8230;]]]></description>
										<content:encoded><![CDATA[<h4>How to setup a Galera MariaDB Cluster</h4>
<p><span id="more-89"></span></p>
<p>Remove any existing packages:</p>
<pre class="SCREEN">
yum remove maria*
</pre>
<p>Update:</p>
<pre class="SCREEN">
yum update
</pre>
<p>Add the official repo for MariaDB by creating the file /etc/yum.repos.d/MariaDB.repo</p>
<pre class="SCREEN">
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
</pre>
<p>Now install MariaDB:</p>
<pre class="SCREEN">
yum install -y MariaDB-server MariaDB-client MariaDB-compat galera socat jemalloc
</pre>
<p>Setup MariaDB:</p>
<pre class="SCREEN">
systemctl start mariadb
mysql_secure_installation
systemctl stop mariadb
</pre>
<p>To generate the CA certificate:</p>
<pre class="SCREEN">
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca.pem
</pre>
<p>To generate the server certificate, remove passphrase, and sign it:</p>
<pre class="SCREEN">
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 -CA ca.pem -CAkey ca-key.pem -set_serial -1 -out server-cert.pem
</pre>
<p>(Optional) To generate the client certificate, remove passphrase, and sign it:</p>
<pre class="SCREEN">
openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem
openssl rsa -in client-key.pem -out client-key.pem
openssl x509 -req -in client-req.pem -days 3600 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
</pre>
<p>Edit the file: /etc/my.cnf.d/server.cnf</p>
<pre class="SCREEN">
[sst]
encrypt=4
ssl-ca=/etc/pki/ca.pem
ssl-cert=/etc/pki/server-cert.pem
ssl-key=/etc/pki/server-key.pem

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address='gcomm://a.a.a.a,b.b.b.b,c.c.c.c'
wsrep_cluster_name='cluster.name'
wsrep_node_address='10.0.0.11'
wsrep_node_name='node1'
wsrep_sst_method=rsync
wsrep_sst_receive_address='x.x.x.x'
wsrep_provider_options='socket.ssl_key=/etc/pki/server-key.pem;socket.ssl_cert=/etc/pki/server-cert.pem;socket.ssl_ca=/etc/pki/ca.pem;evs.inactive_timeout=PT45S;evs.install_timeout=PT45S;evs.keepalive_period=PT3S;evs.max_install_timeouts=8;evs.send_window=512;evs.suspect_timeout=PT30S;evs.user_send_window=256;'
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
</pre>
<p>In the file above the line &#8220;wsrep_sst_receive_address=&#8217;x.x.x.x'&#8221; is required if any of the nodes are behind a NAT router on private IP addresses, where x.x.x.x is the public IP address of the router. Without this SST donors will try to send snapshot data to the nodes private IP address which will invariably fail.</p>
<p>The &#8220;wsrep_provider_options&#8221; are tailored to for nodes that talk to each other over a WAN (i.e. the internet). If your nodes are all on the same LAN then you can leave this option out completely &#8211; it adjusts some timeout default values to better cope with varying connectivity quality across a WAN.</p>
<p>Start the primary node:</p>
<pre class="SCREEN">
galera_new_cluster
</pre>
<p>Start the other nodes:</p>
<pre class="SCREEN">
systemctl start mariadb
</pre>
<p>Login to any of the nodes and check status:</p>
<pre class="SCREEN">
show status like 'wsrep%';
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
