<?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>*.hosting &#187; Database</title>
	<atom:link href="http://blog.stardothosting.com/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stardothosting.com</link>
	<description>Star Dot Hosting : Technology, Security, Virtualization and Cloud Computing</description>
	<lastBuildDate>Mon, 30 Aug 2010 19:16:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MySQL Query Log &#8211; diagnosing and debugging mysql</title>
		<link>http://blog.stardothosting.com/2010/07/12/mysql-query-log-diagnosing-and-debugging-mysql/</link>
		<comments>http://blog.stardothosting.com/2010/07/12/mysql-query-log-diagnosing-and-debugging-mysql/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 18:13:53 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=373</guid>
		<description><![CDATA[The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The general query log is a general record of what mysqld is doing. The server writes information to this log when clients connect or disconnect, and it logs each SQL statement received from clients. The general query log can be very useful when you suspect an error in a client and want to know exactly what the client sent to mysqld.</p>
<p>mysqld writes statements to the query log in the order that it receives them, which might differ from the order in which they are executed. This logging order contrasts to the binary log, for which statements are written after they are executed but before any locks are released. (Also, the query log contains all statements, whereas the binary log does not contain statements that only select data.)</p>
<p>To enable the general query log, start mysqld with the &#8211;log[=file_name] or -l [file_name] option.</p>
<p>If no file_name value is given for &#8211;log or -l, the default name is host_name.log in the data directory.</p>
<p>Server restarts and log flushing do not cause a new general query log file to be generated (although flushing closes and reopens it). On Unix, you can rename the file and create a new one by using the following commands:</p>
<pre>
shell> mv host_name.log host_name-old.log
shell> mysqladmin flush-logs
shell> cp host_name-old.log backup-directory
shell> rm host_name-old.log
</pre>
<p>Before 5.0.17, you cannot rename a log file on Windows while the server has it open. You must stop the server and rename the file, and then restart the server to create a new log file. As of 5.0.17, this applies only to the error log. However, a stop and restart can be avoided by using FLUSH LOGS, which causes the server to rename the error log with an -old suffix and open a new error log. </p>
<p><a href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%26%238211%3B%20diagnosing%20and%20debugging%20mysql" title="Digg" rel="nofollow" target="_blank"><img src="http://blog.stardothosting.com/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a> <a href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%26%238211%3B%20diagnosing%20and%20debugging%20mysql" title="Twitter" rel="nofollow" target="_blank"><img src="http://blog.stardothosting.com/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a> <a href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%26%238211%3B%20diagnosing%20and%20debugging%20mysql" title="Reddit" rel="nofollow" target="_blank"><img src="http://blog.stardothosting.com/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a> <a href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fblog.stardothosting.com%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%26%238211%3B%20diagnosing%20and%20debugging%20mysql" title="Delicious" rel="nofollow" target="_blank"><img src="http://blog.stardothosting.com/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a> <a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.stardothosting.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.stardothosting.com/2010/07/12/mysql-query-log-diagnosing-and-debugging-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Replication : Replicating an existing database</title>
		<link>http://blog.stardothosting.com/2009/09/11/mysql-replication-replicating-an-existing-database/</link>
		<comments>http://blog.stardothosting.com/2009/09/11/mysql-replication-replicating-an-existing-database/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 00:00:32 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=189</guid>
		<description><![CDATA[I decided to make a revised post detailing the different steps required in order to implement a master / slave replication relationship within two or more MySQL servers.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F09%2F11%2Fmysql-replication-replicating-an-existing-database%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F09%2F11%2Fmysql-replication-replicating-an-existing-database%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>You may remember a <a href="http://blog.stardothosting.com/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/">previous post</a> about MySQL replication.</p>
<p>I decided to make a revised post detailing the different steps required in order to implement a master / slave replication relationship within two or more MySQL servers.</p>
<p>The steps required are slightly different and I think its important to outline the necessary steps in order to accomplish this task &#8212; it may actually save you some troubleshooting! <img src='http://blog.stardothosting.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><big><strong>
<ul>
Replication of Existing DBs</ul>
<p></strong></big></p>
<p>If you have existing data on your master that you want to synchronize on your slaves before starting the replication process, then you must stop processing statements on the master, obtain the current position, and then dump the data, before allowing the master to continue executing statements.</p>
<p>If you do not stop the execution of statements, the data dump and the master status information that you use will not match and you will end up with inconsistent or corrupted databases on the slaves.</p>
<ul>
<strong>PREPARATION OF MASTER SERVER</strong></ul>
<p>1. Select a master server. It can be either one.</p>
<p>2. Make sure all databases that you want to replicate to the slave already exist! The easist way is to just copy the database dirs inside your MySQL data directory intact over to your slave, and then recursively chown them to &#8220;mysql:mysql&#8221;. Remember, the binary structures are file-system dependant, so you can&#8217;t do this between MySQL servers on different OS&#8217;s. In this instance you will want to use mysqldump most likely.</p>
<p>3. Create /etc/my.cnf if you do not already have one:</p>
<pre>
[mysqld]
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]
server-id=1
log-bin=mysql-bin
binlog-do-db=bossdb     # input the database which should be replicated
binlog-ignore-db=mysql1 # input the database that should be ignored for replication
binlog-ignore-db=mysql2  # input the database that should be ignored for replication
</pre>
<p>4. Permit your slave server to replicate by issuing the following SQL command (substituting your slave&#8217;s IP and preferred password):</p>
<pre>
mysql> GRANT SUPER,REPLICATION CLIENT,REPLICATION SLAVE,RELOAD ON *.* TO 'replicate'@'192.168.1.1' IDENTIFIED BY 'somepass';
</pre>
<p>5. Flush all talbes and block write statements :</p>
<pre>
mysql> FLUSH TABLES WITH READ LOCK;
</pre>
<p>6. Use the <strong>SHOW MASTER STATUS</strong> statement to determine the current binary log file name and offset on the master:</p>
<pre>
mysql > SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| mysql-bin.003 | 73       | test         | manual,mysql     |
+---------------+----------+--------------+------------------+
</pre>
<p>Copy the file + position for use in Step 4 of the slave configuration.</p>
<p>7. Create data snapshot to import into slave with mysqldump :</p>
<pre>
shell> mysqldump -u root -p db_name --lock-all-tables >dbdump.sql
</pre>
<p>8. Unlock the tables of the database :</p>
<pre>
mysql> UNLOCK TABLES;
</pre>
<p>9. Transfer &#038; import the db into the slave</p>
<p>10. Shut down and restart MySQL daemon and verify that all is functional.</p>
<p><big><b><u>PREPARATION OF SLAVE</big></u></b></p>
<p>1. Create /etc/my.cnf if you do not already have one:</p>
<pre>
[mysqld]
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]
server-id=2 [MUST be different to master]
master-host=192.168.1.1
master-user=replicate
master-password=somepass
</pre>
<p>2. Shut down and restart MySQL on slave.</p>
<p>3. Log into mysql and stop slave :</p>
<pre>
mysql> stop slave;
</pre>
<p>4. Set the master configuration on the slave :</p>
<pre>
mysql> CHANGE MASTER TO
    ->     MASTER_HOST='master_host_name',
    ->     MASTER_USER='replication_user_name',
    ->     MASTER_PASSWORD='replication_password',
    ->     MASTER_LOG_FILE='recorded_log_file_name',
    ->     MASTER_LOG_POS=recorded_log_position;
</pre>
<p>3. Issue the following SQL command to check status:</p>
<pre>
mysql> show slave status\G;
</pre>
<p>Ensure that the following two fields are showing this :</p>
<pre>
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
</pre>
<p>If not, try to issue the following command :</p>
<pre>
mysql> start slave;
</pre>
<p>This will manually start the slave process. Note that only updated tables and entries after the slave process has started will be sent from the master to the slave &#8212; it is not a differential replication.</p>
<p><big><b><u>TESTING</b></u></big></p>
<p>Just update some data on the master, and query that record on the slave. The update should be instantaneous.</p>
<p>Test creating a table on the master MySQL server database :</p>
<pre>
mysql> use replicateddb;
Database changed

mysql> CREATE TABLE example4( id INT NOT NULL AUTO_INCREMENT,  PRIMARY KEY(id),  name VARCHAR(30),   age INT);
Query OK, 0 rows affected (0.04 sec)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.stardothosting.com/2009/09/11/mysql-replication-replicating-an-existing-database/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to repair damaged MySQL tables</title>
		<link>http://blog.stardothosting.com/2009/05/12/how-to-repair-damaged-mysql-tables/</link>
		<comments>http://blog.stardothosting.com/2009/05/12/how-to-repair-damaged-mysql-tables/#comments</comments>
		<pubDate>Tue, 12 May 2009 20:31:27 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=110</guid>
		<description><![CDATA[This tutorial gives step-by-step instructions for repairing damaged mysql tables.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F12%2Fhow-to-repair-damaged-mysql-tables%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F12%2Fhow-to-repair-damaged-mysql-tables%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Once in a while something will happen to a server and the <a href="http://www.mysql.com" target="_new">mysql database</a> will get corrupted.</p>
<p>A specific instance comes to mind on one of our <a href="http://www.cacti.net" target="_new">Cacti monitoring</a> servers.</p>
<p>The /var partition filled up due to too many messages being sent to the root user in /var/spool/. This caused MySQL to crash as well since the cacti poller couldnt write to the poller_output table in MySQL.</p>
<p>The result was all graphs being blank within cacti.</p>
<p>In any case, a thorough analysis of the <a href="http://www.stardothosting.com/linux-vps-hosting" target="_new">mysql database</a> was in order and I decided to post this quick tutorial for performing quick / lengthy table checks for offline and online <a href="http://paragonhost.wordpress.com/2006/11/08/howto-back-up-re-store-mysql-database-with-myphpadmin-gui-or-mysqldump-command-line-tool/" target="_new">MySQL databases</a>.</p>
<p><big><b><u>Stage 1: Checking your tables</b></u></big></p>
<p>Run:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk *.MYI</div></div>
<p></strong></p>
<p>or</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk -e *.MYI</div></div>
<p></strong></p>
<p>if you have more time. Use the -s (silent) option to suppress unnecessary information.</p>
<p>If the mysqld server is stopped, you should use the &#8211;update-state option to tell myisamchk to mark the table as “checked.”</p>
<p>You have to repair only those tables for which myisamchk announces an error. For such tables, proceed to Stage 2.</p>
<p>If you get unexpected errors when checking (such as out of memory errors), or if myisamchk crashes, go to Stage 3.</p>
<p><big><b><u>Stage 2: Easy safe repair</b></u></big></p>
<p>First, try :</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk -r -q tbl_name</div></div>
<p></strong><br />
(-r -q means “quick recovery mode”). </p>
<p>This attempts to repair the index file without touching the data file. If the data file contains everything that it should and the delete links point at the correct locations within the data file, this should work, and the table is fixed. Start repairing the next table. Otherwise, use the following procedure:</p>
<p>1. Make a backup of the data file before continuing.</p>
<p>2. Use</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk -r tbl_name</div></div>
<p></strong></p>
<p>(-r means “recovery mode”)</p>
<p>This removes incorrect rows and deleted rows from the data file and reconstructs the index file.</p>
<p>3. If the preceding step fails, use</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk --safe-recover tbl_name</div></div>
<p></strong></p>
<p>Safe recovery mode uses an old recovery method that handles a few cases that regular recovery mode does not (but is slower).</p>
<p>Note: If you want a repair operation to go much faster, you should set the values of the sort_buffer_size and key_buffer_size variables each to about 25% of your available memory when running myisamchk.</p>
<p>If you get unexpected errors when repairing (such as out of memory errors), or if myisamchk crashes, go to Stage 3.</p>
<p><big><b><u>Stage 3: Difficult repair</u></b></big></p>
<p>You should reach this stage only if the first 16KB block in the index file is destroyed or contains incorrect information, or if the index file is missing. In this case, it is necessary to create a new index file. Do so as follows:</p>
<p>1. Move the data file to a safe place.</p>
<p>2. Use the table description file to create new (empty) data and index files:</p>
<pre>   shell> mysql db_name
     mysql> SET AUTOCOMMIT=1;
     mysql> TRUNCATE TABLE tbl_name;
     mysql> quit</pre>
<p>3. Copy the old data file back onto the newly created data file. (Do not just move the old file back onto the new file. You want to retain a copy in case something goes wrong.)</p>
<p>Go back to Stage 2. : </p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk -r -q should work.</div></div>
<p></strong> (This should not be an endless loop.)</p>
<p>You can also use the REPAIR TABLE tbl_name USE_FRM SQL statement, which performs the whole procedure automatically. There is also no possibility of unwanted interaction between a utility and the server, because the server does all the work when you use REPAIR TABLE. See Section 12.5.2.6, “REPAIR TABLE Syntax”.</p>
<p><big><b><u>Stage 4: Very difficult repair</u></b></big></p>
<p>You should reach this stage only if the .frm description file has also crashed. That should never happen, because the description file is not changed after the table is created:</p>
<p>1. Restore the description file from a backup and go back to Stage 3. You can also restore the index file and go back to Stage 2. In the latter case, you should start with</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myisamchk -r</div></div>
<p></strong></p>
<p>2. If you do not have a backup but know exactly how the table was created, create a copy of the table in another database. Remove the new data file, and then move the .frm description and .MYI index files from the other database to your crashed database. This gives you new description and index files, but leaves the .MYD data file alone. Go back to Stage 2 and attempt to reconstruct the index file. </p>
<p>Thats it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stardothosting.com/2009/05/12/how-to-repair-damaged-mysql-tables/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to setup a slave DNS Nameserver with Bind</title>
		<link>http://blog.stardothosting.com/2009/05/05/how-to-setup-a-slave-dns-nameserver-with-bind/</link>
		<comments>http://blog.stardothosting.com/2009/05/05/how-to-setup-a-slave-dns-nameserver-with-bind/#comments</comments>
		<pubDate>Tue, 05 May 2009 20:00:09 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=98</guid>
		<description><![CDATA[This need for a DNS master/slave implementation where new zone files are transferred between the master nameserver and the slave became apparent as operations grew and geographic DNS redundancy became apparent.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F05%2Fhow-to-setup-a-slave-dns-nameserver-with-bind%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F05%2Fhow-to-setup-a-slave-dns-nameserver-with-bind%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>When implementing redundancy as far as <a href="http://en.wikipedia.org/wiki/BIND" target="_new">DNS</a> is concerned, automated is always better. In a <a href="http://www.stardothosting.com/linux-vps-hosting" target="_new">hosting environment</a>, new <a href="http://en.wikipedia.org/wiki/Zone_file" target="_new">zone files</a> are constantly being created.</p>
<p>This need for a DNS <a href="http://tldp.org/HOWTO/DNS-HOWTO.html" target="_new">master</a>/<a href="http://www.zytrax.com/books/dns/ch4/" target="_new">slave</a> implementation where new zone files are transferred between the master nameserver and the slave became apparent as operations grew and geographic DNS redundancy became apparent.</p>
<p>Obviously some <a href="http://www.powerdns.com/" target="_new">commercial dns products</a> provide this type of functionality out-of-the-box, but I will show you how to do this with a simple <A href="http://www.isc.org/products/BIND" target="_new">Bind DNS</a> distribution.</p>
<p>I wrote this tutorial to help you, hopefully, to create an automated DNS slave / zone file transfer environment. Obviously you can create as many slave servers as you feel necessary.</p>
<p><big><strong><u>MASTER Server</big></strong></u></p>
<p>1. Edit /etc/named.conf and add the following to the options section where xx.xx.xx.xx is the ip of your slave server.:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">allow-transfer { xx.xx.xx.xx; };</div></div>
<p></strong></p>
<p>2. Create a script with the following, where <strong>somedirectory</strong> is the directory on your SLAVE server to store the slave zones and where <strong>yy.yy.yy.yy</strong> is your MASTER server ip and <strong>somewwwdir</strong> is a directory browsable via http and finally <strong>someslavefile.conf</strong> is the output file to write you slave config:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
#<br />
for domain in `/bin/grep ^zone /etc/named.conf |/bin/grep &quot;type master&quot; |/bin/awk '{print $2}' |/bin/awk -F\&quot; '{print $2}'`<br />
<br />
do<br />
<br />
/usr/bin/printf &quot;zone \&quot;${domain}\&quot; { type slave; file \&quot;/var/named/slaves/somedirectory/${domain}.db\&quot;; masters { yy.yy.yy.yy; }; };\n&quot;<br />
<br />
done &gt; /var/www/html/somewwwdir/someslavefile.conf</div></div>
<p></strong></p>
<p>3. Test the script to ensure it is writing out the appropriate format.</p>
<p>4. Run the script as any user with permission to write to an http visible directory via cron.</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0 4 * * * /path/to/script &gt; /dev/null 2&gt;&amp;1</div></div>
<p></strong></p>
<p><big><strong><u>SLAVE SERVER</big></strong></u></p>
<p>1. Transfer the rndc.key file from your master server to the slave :</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">scp MASTERSERVER:/etc/rndc.key /etc/ns1rndc.key</div></div>
<p></strong></p>
<p>2. Edit ns1rndc.key and change the name of the key definition. </p>
<p>3. Edit named.conf and add the following to the options section:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">allow-transfer { zz.zz.zz.zz; };</div></div>
<p></strong></p>
<p>4. Append the following to the named.conf file:<br />
<strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">include &quot;/etc/ns1rndc.key&quot;;<br />
include &quot;/path/to/someslavefile.conf&quot;;</div></div>
<p></strong></p>
<p>5. Run the following commands</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">touch /path/to/someslavefile.conf<br />
mkdir /var/named/slaves/somedirectory/<br />
chown -R named:named /var/named/slaves/somedirectory/<br />
/etc/init.d/named restart</div></div>
<p></strong></p>
<p>6. Create a script:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
/usr/bin/wget http://yy.yy.yy.yy/somewwwdir/someslavefile.conf &nbsp;-O /var/named/slaves/someslavefile.conf<br />
/etc/init.d/named restart</div></div>
<p></strong></p>
<p>7. Add to root&#8217;s crontab </p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">0 4 * * * /path/to/script</div></div>
<p></strong></p>
<p>In the second slave script, you see that the transfer is done via wget. This can be replaced by many other more secure methods. If ssh based key authentication is employed, a simple scp or even rsync can be utilized to accomplish the actual zone transfer.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stardothosting.com/2009/05/05/how-to-setup-a-slave-dns-nameserver-with-bind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Replication : Setting up a Simple Master / Slave</title>
		<link>http://blog.stardothosting.com/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/</link>
		<comments>http://blog.stardothosting.com/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/#comments</comments>
		<pubDate>Mon, 04 May 2009 14:08:51 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=86</guid>
		<description><![CDATA[This simple how-to is intended to setup a simple master / slave mysql replication.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F04%2Fmysql-replication-setting-up-a-simple-master-slave%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.stardothosting.com%2F2009%2F05%2F04%2Fmysql-replication-setting-up-a-simple-master-slave%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>It is often necessary, when designing <A href="http://en.wikipedia.org/wiki/High_availability" target="_new">high availability environments</a> to implement a <a href="http://en.wikipedia.org/wiki/Replication_(computer_science)" target="_new">database replication</a> scenario with <a href="http://www.mysql.com/" target="_new">MySQL</a>. </p>
<p>This simple how-to is intended to setup a simple master / slave relationship.</p>
<p><big><u><strong>PREPARATION OF MASTER SERVER</strong></big></u></p>
<p>1. Select a master server. It can be either one.</p>
<p>2. Make sure all databases that you want to replicate to the slave already exist! The easist way is to just copy the database dirs inside your MySQL data directory intact over to your slave, and then recursively chown them to &#8220;mysql:mysql&#8221;. Remember, the binary structures are file-system dependant, so you can&#8217;t do this between MySQL servers on different OS&#8217;s. In this instance you will want to use mysqldump most likely.</p>
<p>3. Create /etc/my.cnf if you do not already have one:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[mysqld]<br />
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]<br />
server-id=1<br />
log-bin=mysql-bin<br />
binlog-do-db=bossdb &nbsp; &nbsp; # input the database which should be replicated<br />
binlog-ignore-db=mysql1 # input the database that should be ignored for replication<br />
binlog-ignore-db=mysql2 &nbsp;# input the database that should be ignored for replication</div></div>
<p></strong></p>
<p>4. Permit your slave server to replicate by issuing the following SQL command (substituting your slave&#8217;s IP and preferred password):<br />
<strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysql&gt; GRANT REPLICATION SLAVE ON *.* TO 'replicate'@'192.168.1.1' IDENTIFIED BY 'somepass';</div></div>
<p></strong></p>
<p>5. Shut down and restart MySQL daemon and verify that all is functional.</p>
<p><big><u><strong>PREPARATION OF SLAVE</strong></big></u></p>
<p>1. Create /etc/my.cnf if you do not already have one:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[mysqld]<br />
socket=/tmp/mysql.sock [enter YOUR path to mysql.sock here]<br />
server-id=2 [MUST be different to master]<br />
master-host=192.168.1.1<br />
master-user=replicate<br />
master-password=somepass</div></div>
<p></strong></p>
<p>2. Shut down and restart MySQL on slave.</p>
<p>3. Issue the following SQL command to check status:</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysql&gt; show slave status\G;</div></div>
<p></strong></p>
<p>Ensure that the following two fields are showing this :</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes</div></div>
<p></strong></p>
<p>If not, try to issue the following command :<br />
<strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysql&gt; start slave;</div></div>
<p></strong></p>
<p>This will manually start the slave process. Note that only updated tables and entries after the slave process has started will be sent from the master to the slave &#8212; it is not a differential replication.</p>
<p><big><strong><u>TESTING</big></u></strong></p>
<p>Just update some data on the master, and query that record on the slave. The update should be instantaneous.</p>
<p>Test creating a table on the master MySQL server database :</p>
<p><strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mysql&gt; use replicateddb;<br />
Database changed<br />
<br />
mysql&gt; CREATE TABLE example4( id INT NOT NULL AUTO_INCREMENT, &nbsp;PRIMARY KEY(id), &nbsp;name VARCHAR(30), &nbsp; age INT);<br />
Query OK, 0 rows affected (0.04 sec)</div></div>
<p></strong></p>
<p>And check the database on the slave to ensure that the recently created table on the master was replicated properly. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.stardothosting.com/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
