<?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; Linux</title>
	<atom:link href="http://www.stardothosting.com/blog/category/linux/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>Fri, 03 Feb 2012 21:43:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Massive Amazon Route53 API Bind Zone Import Script</title>
		<link>http://www.stardothosting.com/blog/2012/02/03/massive-amazon-route53-api-bind-zone-import-script/</link>
		<comments>http://www.stardothosting.com/blog/2012/02/03/massive-amazon-route53-api-bind-zone-import-script/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 16:39:31 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Amazon API]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[route53]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>
		<category><![CDATA[systems automation]]></category>

		<guid isPermaLink="false">http://www.stardothosting.com/blog/?p=491</guid>
		<description><![CDATA[Hello there, Occasionally some of our managed services work has us dealing directly with other cloud providers such as Amazon. One of our clients set a requirement to migrate over 5,000 domain&#8217;s to Amazon&#8217;s Route53 DNS service. There was little doubt that this could be automated, but since we have never done this massive of [...]]]></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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello there,</p>
<p>Occasionally some of our managed services work has us dealing directly with other cloud providers such as Amazon. One of our clients set a requirement to migrate over 5,000 domain&#8217;s to Amazon&#8217;s Route53 DNS service. </p>
<p>There was little doubt that this could be automated, but since we have never done this massive of a deployment through Amazon&#8217;s API directly, we thought it might be interesting to post the process as well as the script through which we managed the import process.</p>
<p>Essentially the script utilizes a master domain name list file as its basis for looping through the import. The master list refers to the bind zone files and imports them into Amazon&#8217;s Route53 via the Cli53 tool package.</p>
<p>One final note, the script outputs all completed domain imports into a CSV file with the following format :</p>
<pre>
domain.com,ns1.nameserver.com,ns2.nameserver.com,ns3.nameserver.com,ns4.nameserver.com
</pre>
<p>This is because when facilitating the actual nameserver change request, all the nameservers assigned to domains when imported to Route53 are randomly generated, so the script has to keep track of these nameserver/domain associations.</p>
<p>The script isn&#8217;t perfect and could benefit from some optimizations and more error checking (it does a lot of error checking already, however), but here it is in its entirety. We hope you will have some use for it!</p>
<pre>
#!/bin/sh
# Import all zone files into amazon
# Star Dot Hosting 2012
# www.stardothosting.com

currentmonth=`date "+%Y-%m-%d"`

#sanitize input and verify input was given
command=`echo "$1" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`

if [ -z "$1" ];
then
        echo "AWS ZONE IMPORT"
        echo "---------------"
        echo ""
        echo "Usage : ./importzone.sh file.txt"
        echo ""
        exit 0
fi

echo "zone import log : $currentmonth" > /var/log/importzone.log 2>&#038;1
echo " " >> /var/log/importzone.log 2>&#038;1

for obj0 in $(cat $1);
do
        echo "checking if $obj0 was already migrated ..."
        ls -la /usr/local/zones/$1-zones/complete | grep -w $obj0 >> /dev/null 2>&#038;1
        if [ "$?" -eq 1 ]
        then
        echo "importing $obj0 ..."

        #check if zone file has NS records
        cat /usr/local/zones/$1-zones/$obj0.txt | grep NS >> /dev/null 2>&#038;1
        if [ "$?" -eq 0 ]
        then
                echo "Nameserver exists, continuing..."
        else
                echo "Adding nameserver to record..."
                echo "$obj0. 43201 IN NS ns1.nameserver.com." >> /usr/local/zones/$1-zones/$obj0.txt
        fi

        #check if zone exists
        /usr/local/zones/cli53/bin/cli53 info $obj0 >> /var/log/importzone.log 2>&#038;1
        if [ "$?" -eq 0 ]
        then
                # grab NAMESERVERS
                nameservers=`/usr/local/zones/cli53/bin/cli53 rrlist $obj0 | grep "NS" | awk -F "NS\t" '{printf "%s\n", $2}' | sed 's/.$/g' | sed ':a;N;$!ba;s/\n/,/g'`
   # import zone file
                /usr/local/zones/cli53/bin/cli53 import $obj0 -r -f /usr/local/zones/$1-zones/$obj0.txt
                if [ "$?" -eq 0 ]
                then
                        #move to complete folder
                        mv /usr/local/zones/$1-zones/$obj0.txt /usr/local/zones/$1-zones/complete
                else
                        echo "There was an error in importing the zone file!" >> /var/log/importzone.log
                        exit 1
                fi
        else
                #create on route53
                /usr/local/zones/cli53/bin/cli53 create $obj0 >> /var/log/importzone.log 2>&#038;1
                # grab NAMESERVERS
                nameservers=`/usr/local/zones/cli53/bin/cli53 rrlist $obj0 | grep "NS" | awk -F "NS\t" '{printf "%s\n", $2}' | sed 's/.$/g' | sed ':a;N;$!ba;s/\n/,/g'`
                # import zone file
                /usr/local/zones/cli53/bin/cli53 import $obj0 -r -f /usr/local/zones/$1-zones/$obj0.txt
                if [ "$?" -eq 0 ]
                then
                        #move to complete folder
                        mv /usr/local/zones/$1-zones/$obj0.txt /usr/local/zones/$1-zones/complete
                else
                        echo "There was an error in importing the zone file!" >> /var/log/importzone.log
                        exit 1
                fi
        fi

        # output domain + nameservers in a CSV with format : domain.com,ns1,ns2,ns3,ns4
        echo "$obj0,$nameservers" >> nameserver_registrar_request.txt 2&#038;>1
        else
                echo "Domain already migrated .. !"
        fi
done
</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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" 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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" 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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" 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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;linkname=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2012%2F02%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F03%2Fmassive-amazon-route53-api-bind-zone-import-script%2F&amp;title=Massive%20Amazon%20Route53%20API%20Bind%20Zone%20Import%20Script" 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/03/massive-amazon-route53-api-bind-zone-import-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centralized remote backup script with SSH key authentication</title>
		<link>http://www.stardothosting.com/blog/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/</link>
		<comments>http://www.stardothosting.com/blog/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 20:26:39 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[centralized]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=427</guid>
		<description><![CDATA[Greetings, It has been a while since we posted any useful tidbits for you , so we have decided to share one of our quick &#038; dirty centralized backup scripts. The script relies on ssh key based authentication, described here on this blog. It essentially parses a configuration file where each variable is separated by [...]]]></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%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Greetings,</p>
<p>It has been a while since we posted any useful tidbits for you , so we have decided to share one of our quick &#038; dirty centralized backup scripts.</p>
<p>The script relies on ssh key based authentication, described <a href="http://blog.stardothosting.com/2009/12/07/script-to-distribute-ssh-keys-across-many-servers/">here</a> on this blog. It essentially parses a configuration file where each variable is separated by a comma and colon, as in the example config here :</p>
<pre>
hostname1,192.168.1.1,etc:var:root
hostname2,192.168.1.2,etc:var:root:usr
</pre>
<p>Note the intended backup directories in the 3rd variable, separated by colon&#8217;s. Simply populate the <b>backup-hosts.txt</b> config file (located in the same folder as the script) with all the hosts you want to be backed up. </p>
<p>The script then ssh&#8217;s to the intended host, and sends a tar -czf stream (securely) over ssh, to be output into the destination of your choice. Ideally you should centralize this script on a box that has direct access to alot of disk space.</p>
<p>Find the script here :</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
# Centralized Linux Backup Script<br />
# By Star Dot Hosting , www.stardothosting.com<br />
# Uses SSH Key based authentication and remote ssh commands to tar.gz folders to iSCSI storage<br />
<br />
<br />
todaysdate=`date &quot;+%Y-%m-%d %H:%M:%S&quot;`<br />
backupdest=&quot;/backups/linux-backups&quot;<br />
<br />
echo &quot;Centralized Linux Backup: &quot; $todaysdate &gt; /var/log/linux-backup.log<br />
echo -e &quot;----------------------------------------------&quot; &gt;&gt; /var/log/linux-backup.log<br />
echo -e &gt;&gt; /var/log/linux-backup.log<br />
<br />
<br />
for obj0 in $(cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $2}');<br />
do<br />
&nbsp; &nbsp; &nbsp; &nbsp; backupname=`cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | grep $obj0 | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $1}'`<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; for obj1 in $(cat /usr/local/bin/backup-hosts.txt | grep -v &quot;\#&quot; | grep $obj0 | awk -F &quot;,&quot; '{printf &quot;%s\n&quot;, $3'} | awk '{gsub(&quot;:&quot;,&quot;\n&quot;);printf&quot;%s&quot;, $<br />
0}');<br />
&nbsp; &nbsp; &nbsp; &nbsp; do<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;backing up $obj0 with $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ssh -l root $obj0 &quot;(cd /$obj1/ &amp;&amp; tar -czf - . -C /$obj1)&quot; &gt;&gt; $backupdest/$backupname.$obj1.tar.gz 2&gt;&amp;1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if [ &quot;$?&quot; -eq 1 ]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;There were some errors while backing up $obj0 / $backupname within the $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #exit 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo -e &quot;Backup completed on $obj0 / $backupname while backing up $obj1 directory&quot; &gt;&gt; /var/log/linux-backup.log<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi<br />
&nbsp; &nbsp; &nbsp; &nbsp; done<br />
done<br />
<br />
echo &quot;Backup Script Completed.&quot; &gt;&gt; /var/log/linux-backup.log<br />
cat /var/log/linux-backup.log | mail -s &quot;Centralized Backup Complete&quot; topsoperations@topscms.com</div></div>
<p>You could modify this script to keep different daily backups , pruned to keep only X number of days of backups (i.e. only 7 days worth). There is alot you can do here.</p>
<p>If you have a handful of linux or bsd servers that you would like to backup in a centralized location, without having an individual script to maintain on each server, then perhaps you could use or modify this script to suit your needs.</p>
<p>I 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%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" 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%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" 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%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" 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%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;linkname=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2011%2F02%2F09%2Fcentralized-remote-backup-script-with-ssh-key-authentication%2F&amp;title=Centralized%20remote%20backup%20script%20with%20SSH%20key%20authentication" 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/2011/02/09/centralized-remote-backup-script-with-ssh-key-authentication/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Migrate from Linux to Xen with Rsync</title>
		<link>http://www.stardothosting.com/blog/2010/11/11/migrate-from-linux-to-xen-with-rsync/</link>
		<comments>http://www.stardothosting.com/blog/2010/11/11/migrate-from-linux-to-xen-with-rsync/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 17:30:06 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Xen]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[systems administration]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=410</guid>
		<description><![CDATA[I decided to write this little guide to provide the relatively simple steps needed to migrate your linux system to a Xen (HVM) virtual instance. It is assumed that on your source and destination boxes, that you only have one root &#8220;/&#8221; partition. If you partitioned out your file system differently, you will have to [...]]]></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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I decided to write this little guide to provide the relatively simple steps needed to migrate your linux system to a Xen (HVM) virtual instance.</p>
<p>It is assumed that on your source and destination boxes, that you only have one root &#8220;/&#8221; partition. If you partitioned out your file system differently, you will have to accommodate that based on these instructions.</p>
<p>The following steps walk you through the process of migrating linux to Xen from start to finish :</p>
<p><big><b>1. Install the exact same version of linux on your destination server</b></big><br />
This isn&#8217;t really 100% necessary, obviously. You could always boot into Finnix, partition your disk and install Grub. If you are uncomfortable doing that, install the distribution from start to finish. The file system will be overwritten anyways.</p>
<p><big><b>2. Boot into finnix on the destination system</b></big><br />
If you have never used  <a href="http://www.finnix.org/" target="_new">Finnix</a>, it is a &#8220;self contained, bootable linux distribution&#8221;. I like it alot actually and have used it for similar purposes, rescue operations and the like.</p>
<p><big><b>3. Setup networking on both destination and source systems</b></big><br />
If both systems are on the same network, you could assign local IP addresses to ensure the process of synchronisation is speedy and unobstructed.</p>
<p>Ensure you configure networking either way and that you set a root password and start ssh :</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">passwd<br />
/etc/init.d/ssh start</div></div>
<p><big><b>4. Mount the partition that you want to copy to on the destination server</b></big><br />
Remember, so far everything you are doing has been on the destination server. Mount the destination partition within finnix :</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">mount /dev/xvdb</div></div>
<p><big><b>5. On the source server, rsync all the files of the source partition to the destination partition</big></b><br />
When logged into the source server, simply issue the following rsync command and direct it to the destination server&#8217;s partition you just mounted :</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">rsync -aHSKDvz -e ssh / root@12.34.56.78:/mnt/xvdb/</div></div>
<p>The rsync process will complete and the partition on the destination server should be ready to boot into. Remember to change the networking configuration if you dont want any IP conflicts to happen.</p>
<p>I 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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;linkname=Migrate%20from%20Linux%20to%20Xen%20with%20Rsync" 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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;linkname=Migrate%20from%20Linux%20to%20Xen%20with%20Rsync" 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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;linkname=Migrate%20from%20Linux%20to%20Xen%20with%20Rsync" 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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;linkname=Migrate%20from%20Linux%20to%20Xen%20with%20Rsync" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F11%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F11%2Fmigrate-from-linux-to-xen-with-rsync%2F&amp;title=Migrate%20from%20Linux%20to%20Xen%20with%20Rsync" 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/11/11/migrate-from-linux-to-xen-with-rsync/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Xen template</title>
		<link>http://www.stardothosting.com/blog/2010/08/03/creating-a-xen-template/</link>
		<comments>http://www.stardothosting.com/blog/2010/08/03/creating-a-xen-template/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 20:33:47 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[systems administration]]></category>
		<category><![CDATA[xen]]></category>
		<category><![CDATA[xen template]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=387</guid>
		<description><![CDATA[One way to increase the efficiencies of Xen based systems is to utilize templates. VMware talks about this in their whitepaper for ESX2 best practices. With Xen, you have to create your own. Here is a straight forward guide for how to do it. 1. Bootstrap a DomU named -tpl (e.g. centos4-tpl). I recommend using [...]]]></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%2F08%2F03%2Fcreating-a-xen-template%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F08%2F03%2Fcreating-a-xen-template%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>One way to increase the efficiencies of Xen based systems is to utilize templates. VMware talks about this in their whitepaper for ESX2 best practices.</p>
<p>With Xen, you have to create your own. Here is a straight forward guide for how to do it.</p>
<p><big><b><u>1. Bootstrap a DomU named <distname>-tpl (e.g. centos4-tpl).</big></b></u></p>
<p>I recommend using a file-backed VBD, but partition or LVM volume will work fine as well. Here is an example /etc/xen/centos4-tpl</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">kernel = &quot;/boot/vmlinuz-2.6.12.6-xenU&quot;<br />
memory = 256<br />
name = &quot;centos4-tpl&quot; <br />
disk = [ &nbsp;'file:/opt/xen/domains/centos4-tpl/diskimage,sdb1,w','file:/opt/xen/domains/centos4-tpl/swapimage,sdb2,w' &nbsp;]<br />
root = &quot;/dev/sdb1 ro&quot;<br />
dhcp=&quot;dhcp</div></div>
<p>This is just a normal system (DomU) install &#8211; see Centos-4 on Xen for an example. Un-customize files</p>
<p><big><b><u>2.Inside the VM, edit the following files</big></u></b></p>
<p><b>/etc/hosts</b><br />
remove any address lines other than localhost</p>
<p><b>/etc/sysconfig/network</b><br />
use a generic hostname which will be unique to each deployment</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">NETWORKING=yes<br />
HOSTNAME=centos4-tpl-changeme.example.com</div></div>
<p><b>/etc/sysconfig/network-scripts/ifcfg-eth0</b><br />
should look 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">DEVICE=eth0<br />
ONBOOT=yes<br />
BOOTPROTO=dhcp</div></div>
<p>also important &#8211; remove any line starting with HWADDR, e.g.:</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">HWADDR=00:10:5A:XX:YY:ZZ</div></div>
<p>Other configuration files to consider tweaking include /etc/dhclient.conf &#038; /etc/hosts</p>
<p><big><b><u>3. Files to remove:</b></big></u></p>
<p>- SSH Host key files (auto-created at boot time)</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">rm -f /etc/ssh/*host*</div></div>
<p><big><b><u>4. Shutdown the template VM</big></b></u></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">xm shutdown centos4-tpl</div></div>
<p>You might normally link your VMs into /etc/xen/auto. I recommend against this as the template VM can be left shutdown until/unless you want to update it, saving valuable RAM and CPU cycles.</p>
<p>Clone the virtual disk Now we can deploy from the template by cloning the data into a clean diskimage (or partition or LVM volume). Create the diskimage using an appropriate size (must be larger than the template). Oh -the nice thing here is that there is flexibility. For instance, you can have a file-based diskimage and clone the data onto LVM volumes. As long as you can mount the (virtual) disks, you can clone templatized systems.</p>
<p>Here we use /mnt/disk to mount the new system disk, and /mnt/image to mount the template disk.</p>
<p>First, mount the template disk.</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">mount -o loop /opt/xen/domains/centos4-tpl/diskimage /mnt/image</div></div>
<p>Next, create and mount the new system (DomU) disk space &#038; swap space.</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">mkdir -p /opt/xen/domains/cloned<br />
cd /opt/xen/domains/cloned<br />
dd if=/dev/zero of=diskimage bs=1024k count=2048<br />
dd if=/dev/zero of=swapimage bs=1024k count=256<br />
mkfs.ext3 diskimage<br />
mkswap swapimage<br />
mkdir -p /mnt/disk<br />
mount -o loop /opt/xen/domains/cloned/diskimage /mnt/disk</div></div>
<p>Create the exclude file in /tmp/XenCloneExclude</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">proc/*<br />
users/*<br />
tmp/*<br />
lost+found/<br />
etc/mtab</div></div>
<p>Copy the data across</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">rsync -av -SHWD --exclude-from=&quot;/tmp/XenCloneExclude&quot; /mnt/image/ /mnt/disk</div></div>
<p>Chroot into the newly copied template and fixup certain files</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">chroot /mnt/disk /bin/bash</div></div>
<p>Fix the hostname, etc in the files we &#8220;un-customized&#8221; in the template.</p>
<p>Exit, unmount both the template image and volume</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">umount /mnt/disk<br />
umount /mnt/image</div></div>
<p>Setup your Xen config and be on your way!</p>
<p>cd /etc/xen<br />
cp centos4-tpl cloned<br />
(edit cloned to change name and paths to disk and swap)<br />
xm create -c cloned</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F08%2F03%2Fcreating-a-xen-template%2F&amp;linkname=Creating%20a%20Xen%20template" 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%2F08%2F03%2Fcreating-a-xen-template%2F&amp;linkname=Creating%20a%20Xen%20template" 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%2F08%2F03%2Fcreating-a-xen-template%2F&amp;linkname=Creating%20a%20Xen%20template" 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%2F08%2F03%2Fcreating-a-xen-template%2F&amp;linkname=Creating%20a%20Xen%20template" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F08%2F03%2Fcreating-a-xen-template%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F08%2F03%2Fcreating-a-xen-template%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F08%2F03%2Fcreating-a-xen-template%2F&amp;title=Creating%20a%20Xen%20template" id="wpa2a_8"><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/08/03/creating-a-xen-template/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Deploy Debian Load Balancers with bash scripting</title>
		<link>http://www.stardothosting.com/blog/2010/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/</link>
		<comments>http://www.stardothosting.com/blog/2010/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 19:58:46 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[load balancers]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems automation]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=361</guid>
		<description><![CDATA[In yet another post in our automation series, we will share a bash script that automates the deployment of debian based load balancers (specifically with LVS / Linux Virtual Server project). Even though the environments and systems you deploy may start to get more complicated such as with load balancers, there will always be a [...]]]></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%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In yet another post in our automation series, we will share a bash script that automates the deployment of debian based load balancers (specifically with LVS / <a href="http://www.linuxvirtualserver.org/" target="_new">Linux Virtual Server project</a>).</p>
<p>Even though the environments and systems you deploy may start to get more complicated such as with load balancers, there will always be a baseline level with which these systems can be brought to before further configuration and customization needs to be done. </p>
<p>There are many things that can be automated with this process, as you will see in the script below. In most round-robin load balancing scenarios, there wouldn&#8217;t be much more that needs to be done as far as configuration beyond what this script can do.</p>
<p>Obviously you will likely need to modify the script to suit your needs and requirements for the organization and standards therein.</p>
<p>Hopefully this will help you roll out many debian load balancers! May the load be split evenly between all your systems <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #666666; font-style: italic;"># Debian LVS deployer script</span><br />
<span style="color: #666666; font-style: italic;"># Version 1.0</span><br />
<br />
<span style="color: #007800;">PROGNAME</span>=<span style="color: #ff0000;">&quot;$0&quot;</span><br />
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># working directory for deployer process.</span><br />
<span style="color: #007800;">WORKDIR</span>=<span style="color: #ff0000;">&quot;/root&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># tasks left (this is updated every step to accommodate recovery during</span><br />
<span style="color: #666666; font-style: italic;"># the deployer &nbsp;process)</span><br />
<span style="color: #007800;">TASKS</span>=<span style="color: #ff0000;">&quot;./deploy-lvs.tasks&quot;</span><br />
<br />
init_tasks<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># This function will write a new tasks file.</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># it's called from the main body of the script if a tasks file does not exist.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">&lt;&lt;</span>EOS <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
nopasswd_ssh<br />
add_pkgs<br />
get_lvs<br />
configure_lvs<br />
set_hostname<br />
EOS<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
installer_splash<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] &nbsp;LVS deployer script starting...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; &nbsp;Version: <span style="color: #007800;">$VERSION</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
nopasswd_ssh<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># disable passwd auth on SSH</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Disabling password authentication for SSH... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^PasswordAuthentication yes/PasswordAuthentication no/g'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config<br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/^#PermitRootLogin yes/PermitRootLogin without-password/g'</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ssh<span style="color: #000000; font-weight: bold;">/</span>sshd_config<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ssh</span> restart<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
add_pkgs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">PKGS</span>=<span style="color: #ff0000;">&quot;libssl0.9.7 exim4 iproute ethtool tcpdump snmpd pciutils less python&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Installing packages: <span style="color: #007800;">$PKGS</span>... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #007800;">$PKGS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
get_lvs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Downloading &nbsp;packages... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># download the latest version of the &nbsp;Client firewall package.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">--no-check-certificate</span> http:<span style="color: #000000; font-weight: bold;">//</span>your.domain.com<span style="color: #000000; font-weight: bold;">/</span>lvs.tgz <span style="color: #660033;">-O</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># unpack firewall scripts</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--no-same-owner</span> <span style="color: #660033;">--no-same-permissions</span> <span style="color: #660033;">--directory</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-zxvf</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>firewall.tgz <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
configure_lvs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># time to configure the &nbsp;FW</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">KAD</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>keepalived<span style="color: #000000; font-weight: bold;">/</span>keepalived.conf<br />
&nbsp; &nbsp; <span style="color: #007800;">FW</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>firewall<br />
&nbsp; &nbsp; <span style="color: #007800;">COMMIT</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>lvs-commit.sh<br />
&nbsp; &nbsp; <span style="color: #007800;">HOSTS</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hosts<br />
&nbsp; &nbsp; <span style="color: #007800;">INTERFACES</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>interfaces<br />
&nbsp; &nbsp; <span style="color: #007800;">NRPE</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>nrpe_local.cfg<br />
&nbsp; &nbsp; <span style="color: #007800;">EXIM</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>exim4<span style="color: #000000; font-weight: bold;">/</span>update-exim4.conf.conf<br />
&nbsp; &nbsp; <span style="color: #007800;">CONFIGURE_LVS</span>=<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>network<span style="color: #000000; font-weight: bold;">/</span>configure-lvs.pl<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Configuring LVS...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #007800;">$CONFIGURE_LVS</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Configuring LVS script failed!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Moving files into place...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${KAD}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${FW}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${COMMIT}</span><span style="color: #660033;">-template</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #800000;">${CONFIGURE_LVS}</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${HOSTS}</span>.new <span style="color: #800000;">${HOSTS}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${INTERFACES}</span>.new <span style="color: #800000;">${INTERFACES}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${NRPE}</span>.new <span style="color: #800000;">${NRPE}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${EXIM}</span>.new <span style="color: #800000;">${EXIM}</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #800000;">${FW}</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #800000;">${COMMIT}</span><br />
&nbsp; &nbsp; update-rc.d keepalived defaults <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; update-exim4.conf <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># for compatibility</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Generating RSA Keys&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa <span style="color: #660033;">-P</span> <span style="color: #ff0000;">''</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">1</span><br />
<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
clean_up_and_reboot<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove:</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># -- temp task file</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$TASKS</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove self from .bashrc</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc.orig <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc.orig <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>.bashrc<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># delete self</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$0</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and reboot.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Please reboot system.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">#reboot -n</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
debug_quit<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># hard exit the script in appropriately referenced files </span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># so that no reboot happens.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;debug_quit seen in tasks file, exiting.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
set_hostname<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Setting LVS hostname... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>mailname<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
usage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Usage: <span style="color: #007800;">$PROGNAME</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">###############################</span><br />
<span style="color: #666666; font-style: italic;">### MAIN SCRIPT STARTS HERE ###</span><br />
<span style="color: #666666; font-style: italic;">###############################</span><br />
<br />
<span style="color: #666666; font-style: italic;"># installer_splash</span><br />
installer_splash<br />
<br />
<span style="color: #666666; font-style: italic;"># fix working dir.</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$WORKDIR</span><br />
<br />
<span style="color: #666666; font-style: italic;"># does our installer file exist? if not, initalize it.</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TASKS</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] No task file found, installation will start from beginning.&quot;</span><br />
&nbsp; &nbsp; init_tasks<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Cannot create tasks file. Installation will not continue.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">else</span> <br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Tasks file located - starting where you left off.&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #666666; font-style: italic;"># start popping off tasks from the task list and running them.</span><br />
<span style="color: #666666; font-style: italic;"># pop first step off of the list</span><br />
<span style="color: #007800;">STEP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$STEP</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># execute the function.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>###################################&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Running step: <span style="color: #007800;">$STEP</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;###################################<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">$STEP</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># command failed.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] ERROR: Step <span style="color: #007800;">$STEP</span> failed!&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot; &nbsp; &nbsp;Installation will now abort - you can pick it up after fixing the problem&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># throw up a newline just so things don't look so crowded</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># remove function from function list.</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-pi</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/<span style="color: #007800;">$STEP</span><span style="color: #000099; font-weight: bold;">\n</span>?//&quot;</span> <span style="color: #007800;">$TASKS</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #007800;">STEP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-n</span> <span style="color: #000000;">1</span> <span style="color: #007800;">$TASKS</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #000000; font-weight: bold;">done</span><br />
<br />
<span style="color: #666666; font-style: italic;"># clean_up_and_reboot</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[+] Installation finished - cleaning up.&quot;</span><br />
clean_up_and_reboot<br />
<br />
<span style="color: #666666; font-style: italic;"># script is done now - termination should happen with clean_up_and_reboot.</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[!] Should not be here!&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span></div></div>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" 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%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" 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%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" 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%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F06%2F14%2Fautomatically-deploy-debian-load-balancers-with-bash-scripting%2F&amp;title=Automatically%20Deploy%20Debian%20Load%20Balancers%20with%20bash%20scripting" id="wpa2a_10"><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/06/14/automatically-deploy-debian-load-balancers-with-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Deploy Debian Firewalls with bash scripting</title>
		<link>http://www.stardothosting.com/blog/2010/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/</link>
		<comments>http://www.stardothosting.com/blog/2010/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 19:47:25 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[firewalls]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=342</guid>
		<description><![CDATA[Automation is as necessary as any other aspect of systems administration in any critical or production environment where growth and scalability are moving at a significant pace. Growth in any organization is obviously a good thing. In the systems administrator&#8217;s perspective, however, growth can mean more time spent deploying systems and less time spent focusing [...]]]></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%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Automation is as necessary as any other aspect of systems administration in any critical or production environment where growth and scalability are moving at a significant pace.</p>
<p>Growth in any organization is obviously a good thing. In the systems administrator&#8217;s perspective, however, growth can mean more time spent deploying systems and less time spent focusing on other duties.</p>
<p>Automating the server deployment process is the natural next step when your organization has grown to a point where time efficiency becomes more relevant and noticeable to your business owners.</p>
<p>This is the first in a series of posts here where we will explain and share shell scripts that automate the deployment process of several key debian linux based systems. These scripts automate the patching, configuration and implementation of said systems.</p>
<p>They will certainly have to be modified to fit your organization&#8217;s needs and standards obviously, but hopefully it will give you a starting point to base your automation / roll-out policies.</p>
<p>Making your life easier and more automated is always a good thing! <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
<p><small><b></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/bin/sh<br />
# Debian FW deployer script<br />
# Version 1.0<br />
<br />
PROGNAME=&quot;$0&quot;<br />
VERSION=&quot;1.0&quot;<br />
<br />
# working directory for deployer process.<br />
WORKDIR=&quot;/root&quot;<br />
<br />
# tasks left (this is updated every step to accommodate recovery during<br />
# the deployer &nbsp;process)<br />
TASKS=&quot;./deploy-fw.tasks&quot;<br />
<br />
init_tasks() {<br />
&nbsp; &nbsp; # This function will write a new tasks file.<br />
&nbsp; &nbsp; # it's called from the main body of the script if a tasks file does not exist.<br />
&nbsp; &nbsp; cat &gt; $TASKS&lt;&lt;EOS || return 1<br />
nopasswd_ssh<br />
add_pkgs<br />
get__fw<br />
configure_fw<br />
set_hostname<br />
EOS<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
installer_splash() {<br />
&nbsp; &nbsp; echo &quot;[+] Firewall deployer script starting...&quot;<br />
&nbsp; &nbsp; echo &quot; &nbsp; &nbsp;Version: $VERSION&quot;<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
nopasswd_ssh() {<br />
&nbsp; &nbsp; # disable passwd auth on SSH<br />
&nbsp; &nbsp; echo &quot;[+] Disabling password authentication for SSH... &quot;<br />
&nbsp; &nbsp; perl -pi -e 's/^PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config<br />
&nbsp; &nbsp; perl -pi -e 's/^#PermitRootLogin yes/PermitRootLogin without-password/g' /etc/ssh/sshd_config<br />
&nbsp; &nbsp; /etc/init.d/ssh restart<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
add_pkgs() {<br />
&nbsp; &nbsp; PKGS=&quot;libssl0.9.7 exim4 iproute ethtool tcpdump snmpd pciutils less python&quot;<br />
&nbsp; &nbsp; echo &quot;[+] Installing packages: $PKGS... &quot;<br />
&nbsp; &nbsp; apt-get -y install $PKGS || return 1<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
get__fw() {<br />
&nbsp; &nbsp; echo &quot;[+] Downloading &nbsp;packages... &quot;<br />
&nbsp; &nbsp; # download the latest version of the &nbsp;Client firewall package.<br />
&nbsp; &nbsp; wget --no-check-certificate http://www.yoursite.com/fw.tgz -O /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; # get the latest firewall.trusted file<br />
&nbsp; &nbsp; wget --no-check-certificate http://www.yoursite.com/firewall.trusted -O /tmp/firewall.trusted || return 1<br />
&nbsp; &nbsp; # unpack firewall scripts<br />
&nbsp; &nbsp; tar --no-same-owner --no-same-permissions --directory / -zxvf /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; mv /tmp/firewall.trusted /etc/network/firewall.trusted || return 1<br />
&nbsp; &nbsp; chmod +x /etc/network/firewall.trusted || return 1<br />
&nbsp; &nbsp; rm /tmp/firewall.tgz || return 1<br />
&nbsp; &nbsp; echo &quot;done.&quot;<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
configure_fw() {<br />
&nbsp; &nbsp; # time to configure the &nbsp;FW<br />
&nbsp; &nbsp; &nbsp; &nbsp; KAD=/etc/keepalived/keepalived.conf<br />
&nbsp; &nbsp; FW=/etc/network/firewall<br />
&nbsp; &nbsp; RELOAD=/etc/network/reload.sh<br />
&nbsp; &nbsp; HOSTS=/etc/hosts<br />
&nbsp; &nbsp; INTERFACES=/etc/network/interfaces<br />
&nbsp; &nbsp; NRPE=/etc/nagios/nrpe_local.cfg<br />
&nbsp; &nbsp; EXIM=/etc/exim4/update-exim4.conf.conf<br />
&nbsp; &nbsp; CONFIGURE_FW=/etc/network/configure-fw.pl<br />
&nbsp; &nbsp; echo &quot;[+] Configuring Firewall...&quot;<br />
&nbsp; &nbsp; perl $CONFIGURE_FW<br />
&nbsp; &nbsp; if [ $? -ne 0 ]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Configuring firewall script failed!&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 1<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; echo &quot;[+] Moving files into place...&quot;<br />
&nbsp; &nbsp; rm ${KAD}-template || return 1<br />
&nbsp; &nbsp; rm ${FW}-template || return 1<br />
&nbsp; &nbsp; rm ${RELOAD}-template || return 1<br />
&nbsp; &nbsp; rm ${CONFIGURE_FW}<br />
&nbsp; &nbsp; mv ${HOSTS}.new ${HOSTS} || return 1<br />
&nbsp; &nbsp; mv ${INTERFACES}.new ${INTERFACES} || return 1<br />
&nbsp; &nbsp; mv ${NRPE}.new ${NRPE} || return 1<br />
&nbsp; &nbsp; mv ${EXIM}.new ${EXIM} || return 1<br />
&nbsp; &nbsp; chmod 700 ${FW}<br />
&nbsp; &nbsp; chmod 700 ${RELOAD}<br />
&nbsp; &nbsp; update-rc.d keepalived defaults || return 1<br />
&nbsp; &nbsp; update-exim4.conf || return 1<br />
&nbsp; &nbsp; # for compatibility<br />
&nbsp; &nbsp; echo &quot;[+] Generating RSA Keys&quot;<br />
&nbsp; &nbsp; ssh-keygen -t rsa -f ~/.ssh/id_rsa -P '' || return 1<br />
<br />
&nbsp; &nbsp; return 0<br />
}<br />
clean_up_and_reboot() {<br />
&nbsp; &nbsp; # remove:<br />
&nbsp; &nbsp; # -- temp task file<br />
&nbsp; &nbsp; rm $TASKS<br />
&nbsp; &nbsp; # remove self from .bashrc<br />
&nbsp; &nbsp; if [ -f /root/.bashrc.orig ]; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; mv /root/.bashrc.orig /root/.bashrc<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; if [ -z /root/.bashrc ]<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; rm /root/.bashrc<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; # delete self<br />
&nbsp; &nbsp; rm $0<br />
&nbsp; &nbsp; # and reboot.<br />
&nbsp; &nbsp; echo &quot;[+] Please reboot system.&quot;<br />
&nbsp; &nbsp; #reboot -n<br />
&nbsp; &nbsp; exit 0<br />
}<br />
<br />
debug_quit() {<br />
&nbsp; &nbsp; # hard exit the script in appropriately referenced files <br />
&nbsp; &nbsp; # so that no reboot happens.<br />
&nbsp; &nbsp; echo &quot;debug_quit seen in tasks file, exiting.&quot;<br />
&nbsp; &nbsp; exit 0<br />
}<br />
<br />
set_hostname() {<br />
&nbsp; &nbsp; echo &quot;[+] Setting FW hostname... &quot;<br />
&nbsp; &nbsp; echo `hostname` &gt; /etc/hostname<br />
&nbsp; &nbsp; echo `hostname` &gt; /etc/mailname<br />
&nbsp; &nbsp; echo &quot;done.&quot;<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
usage() {<br />
&nbsp; &nbsp; echo &quot;[+] Usage: $PROGNAME&quot;<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; return 0<br />
}<br />
<br />
###############################<br />
### MAIN SCRIPT STARTS HERE ###<br />
###############################<br />
<br />
# installer_splash<br />
installer_splash<br />
<br />
# fix working dir.<br />
cd $WORKDIR<br />
<br />
# does our installer file exist? if not, initalize it.<br />
if [ ! -f $TASKS ]<br />
then<br />
&nbsp; &nbsp; echo &quot;[+] No task file found, installation will start from beginning.&quot;<br />
&nbsp; &nbsp; init_tasks<br />
&nbsp; &nbsp; if (($? != 0))<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Cannot create tasks file. Installation will not continue.&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit 1<br />
&nbsp; &nbsp; fi<br />
else <br />
&nbsp; &nbsp; echo &quot;[+] Tasks file located - starting where you left off.&quot;<br />
fi<br />
<br />
# start popping off tasks from the task list and running them.<br />
# pop first step off of the list<br />
STEP=`head -n 1 $TASKS`<br />
while [ ! -z $STEP ]<br />
do<br />
&nbsp; &nbsp; # execute the function.<br />
&nbsp; &nbsp; echo -e &quot;\n\n###################################&quot;<br />
&nbsp; &nbsp; echo &quot;[+] Running step: $STEP&quot;<br />
&nbsp; &nbsp; echo -e &quot;###################################\n\n&quot;<br />
&nbsp; &nbsp; $STEP<br />
&nbsp; &nbsp; if (($? != 0))<br />
&nbsp; &nbsp; then<br />
&nbsp; &nbsp; &nbsp; &nbsp; # command failed.<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot;[!] ERROR: Step $STEP failed!&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo &quot; &nbsp; &nbsp;Installation will now abort - you can pick it up after fixing the problem&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; echo<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit 1<br />
&nbsp; &nbsp; fi<br />
&nbsp; &nbsp; # throw up a newline just so things don't look so crowded<br />
&nbsp; &nbsp; echo<br />
&nbsp; &nbsp; # remove function from function list.<br />
&nbsp; &nbsp; perl -pi -e &quot;s/$STEP\n?//&quot; $TASKS || exit 1<br />
&nbsp; &nbsp; STEP=`head -n 1 $TASKS`<br />
done<br />
<br />
# clean_up_and_reboot<br />
echo &quot;[+] Installation finished - cleaning up.&quot;<br />
clean_up_and_reboot<br />
<br />
# script is done now - termination should happen with clean_up_and_reboot.<br />
echo &quot;[!] Should not be here!&quot;<br />
exit 1</div></div>
<p></small></b></p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" 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%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" 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%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" 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%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;linkname=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F06%2F02%2Fautomatically-deploy-debian-firewalls-with-bash-scripting%2F&amp;title=Automatically%20Deploy%20Debian%20Firewalls%20with%20bash%20scripting" id="wpa2a_12"><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/06/02/automatically-deploy-debian-firewalls-with-bash-scripting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrate your custom IPTables script with Linux</title>
		<link>http://www.stardothosting.com/blog/2010/05/11/integrate-your-custom-iptables-script-with-linux/</link>
		<comments>http://www.stardothosting.com/blog/2010/05/11/integrate-your-custom-iptables-script-with-linux/#comments</comments>
		<pubDate>Tue, 11 May 2010 20:25:15 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[systems administration]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=330</guid>
		<description><![CDATA[A custom iptables script is sometimes necessary to work around the limitations of the Red Hat Enterprise Linux firewall configuration tool.]]></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%2F05%2F11%2Fintegrate-your-custom-iptables-script-with-linux%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F05%2F11%2Fintegrate-your-custom-iptables-script-with-linux%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>How do I integrate my custom iptables script with Red Hat Enterprise Linux?</p>
<p>A custom iptables script is sometimes necessary to work around the limitations of the Red Hat Enterprise Linux firewall configuration tool. The procedure is as follows:</p>
<p>1. Make sure that the default iptables initialization script is not running:</p>
<pre>service iptables stop</pre>
<p>2. Execute the custom iptables script:</p>
<pre>sh [custom iptables script]</pre>
<p>3. Save the newly created iptables rules:</p>
<pre>service iptables save</pre>
<p>4. Restart the iptables service:</p>
<pre>service iptables restart</pre>
<p>5. Verify that the custom iptables ruleset have taken effect:</p>
<pre>service iptables status</pre>
<p>6. Enable automatic start up of the iptables service on boot up:</p>
<pre>chkconfig iptables on</pre>
<p>The custom iptables script should now be integrated into the operating system. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2010/05/11/integrate-your-custom-iptables-script-with-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Patch Scanning / Information Gathering Script for RedHat / CentOS</title>
		<link>http://www.stardothosting.com/blog/2010/04/30/patch-scanning-information-gathering-script-for-redhat-centos/</link>
		<comments>http://www.stardothosting.com/blog/2010/04/30/patch-scanning-information-gathering-script-for-redhat-centos/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 16:17:27 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[imformation gathering]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=319</guid>
		<description><![CDATA[With all the patch management solutions, local repositories and other options, it is rarely necessary to manually scan all servers on your network to build a &#8220;report&#8221; of the patch levels in your environment. Sometimes it is, however. For instance, if you are brought into an environment that has not been properly managed and require [...]]]></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%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>With all the patch management solutions, local repositories and other options, it is rarely necessary to manually scan all servers on your network to build a &#8220;report&#8221; of the patch levels in your environment.</p>
<p>Sometimes it is, however. For instance, if you are brought into an environment that has not been properly managed and require some quick audits to evaluate how much actual work needs to be done bringing all the patch levels up to standard, then there are ways to produce these reports with simple bash scripting.</p>
<p>I have developed such a script for similar situations &#8212; quick reporting is sometimes necessary even when you are evaluating a large commercial patch management solution. It can even be implemented to coincide such solutions, for independent reporting perhaps.</p>
<p>This script would work well either by distributing it to each server and running the script via <a href="http://blog.stardothosting.com/2009/06/02/ssh-key-based-authentication/" target="_new">ssh key based authentication</a> for centralized reporting. Alternatively, you could modify this script to perform each command via SSH over the network to gather information that way. It is probably more ideal to centrally distribute the script to each server so only one ssh command is executed per server.</p>
<p>Find the script below &#8212; note that it only works with RedHat / CentOS systems. Obviously if you are paying for Red Hat enterprise support you already are using satellite; If you are using CentOS then this script may be useful for you.</p>
<p>Enjoy!</p>
<pre>
#!/bin/sh

# Basic Information Gathering
# Star Dot Hosting
# http://www.stardothosting.com

HOSTNAME=`hostname`
UNAME=`uname -a | awk '{print $3}'`

# Begin Package Scanning

# SSH

SSHON="0"
SSHRUN="NULL"
SSHRPM="NULL"
SSHMATCH="NULL"

if [ -f /usr/sbin/sshd ]
then
        SSHON="1"
	SSHMATCH="0"
        SSHRUN=`ssh -V 2>&#038;1 | awk 'BEGIN { FS = "_" } ; { print $2 }' | awk '{print $1}' | cut -b 0-5`
	TESTRPM=`rpm -qa openssh`
	if [ "$TESTRPM" <> 0  ]
	then
	        SSHRPM=`rpm -qa openssh | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$SSHRUN" == "$SSHRPM" ]
        then
                SSHMATCH="1"
        fi

fi

# Apache

HTTPDON="0"
HTTPDRUN="NULL"
HTTPDRPM="NULL"
HTTPDMATCH="NULL"

if [ -f /usr/sbin/httpd ]
then
        HTTPDON="1"
	HTTPDMATCH="0"
        HTTPDRUN=`httpd -v | grep version | awk 'BEGIN {FS="/"};{print$2}'`
	TESTRPM=`rpm -qa httpd`
	if [ "$TESTRPM" <> 0  ]
	then
        	HTTPDRPM=`rpm -qa httpd | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$HTTPDRUN" == "$HTTPDRPM" ]
        then
                HTTPDMATCH="1"
        fi
fi

# MySQL

MYSQLON="0"
MYSQLRUN="NULL"
MYSQLRPM="NULL"
MYSQLMATCH="NULL"

if [ -f /usr/bin/mysql ]
then
        MYSQLON="1"
	MYSQLMATCH="0"
        MYSQLRUN=`mysql -V | awk '{print $5}' | cut -b 0-6`
	TESTRPM=`rpm -qa mysql`
	if [ "$TESTRPM" <> 0  ]
	then
        	MYSQLRPM=`rpm -qa mysql | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$MYSQLRUN" == "$MYSQLRPM" ]
        then
                MYSQLMATCH="1"
        fi
fi

# PHP

PHPON="0"
PHPRUN="NULL"
PHPRPM="NULL"
PHPMATCH="NULL"

if [ -f /usr/bin/php ]
then
        PHPON="1"
	PHPMATCH="0"
        PHPRUN=`php -v | grep built | awk '{print $2 }'`
	TESTRPM=`rpm -qa php`
	if [ "$TESTRPM" <> 0  ]
	then
        	PHPRPM=`rpm -qa php | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PHPRUN" == "$PHPRPM" ]
        then
                PHPMATCH="1"
        fi
fi

# Exim
# Needs to be tested on RH box

EXIMON="0"
EXIMRUN="NULL"
EXIMRPM="NULL"
EXIMMATCH="NULL"

if [ -f /usr/sbin/exim ]
then
        EXIMON="1"
	EXIMMATCH="0"
        EXIMRUN=`exim -bV | grep version | awk '{print $3}'`
	TESTRPM=`rpm -qa exim`
	if [ "$TESTRPM" <> 0  ]
	then
        	EXIMRPM=`rpm -qa exim | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$EXIMRUN" == "$EXIMRPM" ]
        then
                EXIMMATCH="1"
        fi
fi

# OpenSSL

OSSLON="0"
OSSLRUN="NULL"
OSSLRPM="NULL"
OSSLMATCH="NULL"

if [ -f /usr/bin/openssl ]
then
        OSSLON="1"
	OSSLMATCH="0"
        OSSLRUN=`openssl version | awk '{print $2}'`
	TESTRPM=`rpm -qa openssl`
	if [ "$TESTRPM" <> 0  ]
	then
        	OSSLRPM=`rpm -qa openssl | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$OSSLRUN" == "$OSSLRPM" ]
        then
                OSSLMATCH="1"
        fi
fi

# PERL

PERLON="0"
PERLRUN="NULL"
PERLRPM="NULL"
PERLMATCH="NULL"

if [ -f /usr/bin/perl ]
then
        PERLON="1"
	PERLMATCH="0"
        PERLRUN=`perl -v | grep built | awk '{print $4}' | awk 'BEGIN { FS = "v" } ; { print $2 }'`
	TESTRPM=`rpm -qa perl`
	if [ "$TESTRPM" <> 0  ]
	then
        	PERLRPM=`rpm -qa perl | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PERLRUN" == "$PERLRPM" ]
        then
                PERLMATCH="1"
        fi
fi

# PYTHON

PYON="0"
PYRUN="NULL"
PYRPM="NULL"
PYMATCH="NULL"

if [ -f /usr/bin/python ]
then
        PYON="1"
	PYMATCH="0"
        PYRUN=`python -V 2>&#038;1 | awk '{print $2}'`
	TESTRPM=`rpm -qa python`
	if [ "$TESTRPM" <> 0  ]
	then
        	PYRPM=`rpm -qa python | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$PYRUN" == "$PYRPM" ]
        then
                PYMATCH="1"
        fi
fi

# GPG

GPGON="0"
GPGRUN="NULL"
GPGRPM="NULL"
GPGMATCH="NULL"

if [ -f /usr/bin/gpg ]
then
        GPGON="1"
	GPGMATCH="0"
        GPGRUN=`gpg --version | grep gpg | awk '{print $3}'`
	TESTRPM=`rpm -qa gnupg`
	if [ "$TESTRPM" <> 0  ]
	then
        	GPGRPM=`rpm -qa gnupg | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$GPGRUN" == "$GPGRPM" ]
        then
                GPGMATCH="1"
        fi
fi

# RPM

RPMON="0"
RPMRUN="NULL"
RPMRPM="NULL"
RPMMATCH="NULL"

if [ -f /bin/rpm ]
then
        RPMON="1"
	RPMMATCH="0"
        RPMRUN=`rpm --version | awk '{print $3}'`
	TESTRPM=`rpm -qa rpm`
	if [ "$TESTRPM" <> 0  ]
	then
        	RPMRPM=`rpm -qa rpm | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$RPMRUN" == "$RPMRPM" ]
        then
                RPMMATCH="1"
        fi
fi

# SENDMAIL

SENDON="0"
SENDRUN="NULL"
SENDRPM="NULL"
SENDMATCH="NULL"

if [ -f /usr/sbin/sendmail ]
then
        SENDON="1"
        SENDMATCH="0"
        SENDRUN=`echo 'quit' | nc localhost 25 | grep Sendmail | awk '{print $5}' | awk 'BEGIN { FS = "/" } ; { print $1 }'`
	TESTRPM=`rpm -qa sendmail`
	if [ "$TESTRPM" <> 0  ]
	then
	        SENDRPM=`rpm -qa sendmail | awk 'BEGIN { FS = "-" } ; { print $2 }'`
	fi
        if [ "$SENDRUN" == "$SENDRPM" ]
        then
                SENDMATCH="1"
        fi
fi

### Non running packages

# bind-libs

BINDLIB="NULL"
TESTRPM=`rpm -qa bind-libs`
if [ "$TESTRPM" <> 0  ]
then
	BINDLIB=`rpm -qa bind-libs | awk 'BEGIN { FS = "-" } ; { print $3 }'`
fi

# bind-utils

BINDUTIL="NULL"
TESTRPM=`rpm -qa bind-utils`
if [ "$TESTRPM" <> 0  ]
then
	BINDUTIL=`rpm -qa bind-utils | awk 'BEGIN { FS = "-" } ; { print $3 }'`
fi

# coreutils

COREUTIL="NULL"
TESTRPM=`rpm -qa coreutils`
if [ "$TESTRPM" <> 0  ]
then
	COREUTIL=`rpm -qa coreutils | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# chkconfig

CHKCONFIG="NULL"
TESTRPM=`rpm -qa chkconfig`
if [ "$TESTRPM" <> 0  ]
then
	CHKCONFIG=`rpm -qa chkconfig | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# initscripts

INITSCR="NULL"
TESTRPM=`rpm -qa initscripts`
if [ "$TESTRPM" <> 0  ]
then
	INITSCR=`rpm -qa initscripts | awk 'BEGIN { FS = "-" } ; { print $2 }'`
fi

# redhat-release

RHRELEASE="NULL"
TESTRPM=`rpm -qa redhat-release`
if [ "$TESTRPM" <> 0  ]
then
	RHRELEASE=`rpm -qa redhat-release | awk 'BEGIN { FS = "-" } ; { print $3"-"$4 }'`
fi

echo $HOSTNAME,$UNAME,$SSHMATCH,$HTTPDMATCH,$MYSQLMATCH,$PHPMATCH,$EXIMMATCH,$OSSLMATCH,$PYMATCH,$PERLMATCH,$GPGMATCH,
$RPMMATCH,$SENDMATCH,$BINDLIB,$BINDUTIL,$COREUTIL,$CHKCONFIG,$INITSCR,$RHRELEASE,$SSHON,$SSHRUN,$SSHRPM,$HTTPDON,$HTTPDRUN,
$HTTPDRPM,$MYSQLON,$MYSQLRUN,$MYSQLRPM,$PHPON,$PHPRUN,$PHPRPM,$EXIMON,$EXIMRUN,$EXIMRPM,$OSSLON,$OSSLRUN,$OSSLRPM,$PERLON,
$PERLRUN,$PERLRPM,$PYON,$PYRUN,$PYRPM,$GPGON,$GPGRUN,$GPGRPM,$RPMON,$RPMRUN,$RPMRPM,$SENDON,$SENDRUN,$SENDRPM
</pre>
<p>Note that you can modify the echo output to produce whatever output you need in order to present it in a nice human readable report.</p>
<p><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" 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%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" 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%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" 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%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;linkname=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" 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><!--[if IE]><iframe frameborder="0" allowTransparency="true" class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><![endif]--><!--[if !IE]><!--><iframe class="addtoany_special_service google_plusone" src="https://plusone.google.com/u/0/_/%2B1/fastbutton?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2010%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;size=medium&amp;count=false" scrolling="no" style="border:none;overflow:hidden;width:32px;height:20px"></iframe><!--<![endif]--><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%2F04%2F30%2Fpatch-scanning-information-gathering-script-for-redhat-centos%2F&amp;title=Patch%20Scanning%20%2F%20Information%20Gathering%20Script%20for%20RedHat%20%2F%20CentOS" id="wpa2a_14"><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/04/30/patch-scanning-information-gathering-script-for-redhat-centos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script to distribute SSH Keys across many servers</title>
		<link>http://www.stardothosting.com/blog/2009/12/07/script-to-distribute-ssh-keys-across-many-servers/</link>
		<comments>http://www.stardothosting.com/blog/2009/12/07/script-to-distribute-ssh-keys-across-many-servers/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 16:29:15 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh key distribution]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=249</guid>
		<description><![CDATA[The idea behind this script is to have a centralized, highly secure and restricted key repository server. Each server in your environment would run this script to "pull" the updated key list from the central server. The script would run as a cron job and can run as often as you like. Ideally every 5-10 minutes would allow for quick key updates / distribution.]]></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%2F12%2F07%2Fscript-to-distribute-ssh-keys-across-many-servers%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2009%2F12%2F07%2Fscript-to-distribute-ssh-keys-across-many-servers%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello once again!</p>
<p>You may remember an <a href="http://blog.stardothosting.com/2009/06/02/ssh-key-based-authentication/" target="_new">earlier post</a> that detailed how to implement SSH Key based authentication.</p>
<p>We believe it is important, when administering many (sometimes hundreds or thousands) of servers, to implement a strategy that can allow systems administrators to seamlessly run scripts, system checks or critical maintenance across all the servers.</p>
<p>SSH Key authentication allows for this potential. It is a very powerful strategy and should be maintained and implemented with security and efficiency as a top priority.</p>
<p>Distributing keys for all authorized systems administrators is something that would allow for the maintenance of this authentication system much easier &#8212; when an admin leaves or is dismissed, you need to be able to remove his or her&#8217;s keys from the &#8220;pool&#8221; quickly.</p>
<p>The idea behind this script is to have a centralized, highly secure and restricted key repository server. Each server in your environment would run this script to &#8220;pull&#8221; the updated key list from the central server. The script would run as a cron job and can run as often as you like. Ideally every 5-10 minutes would allow for quick key updates / distribution.</p>
<p>Here is the perl script :</p>
<pre>
#!/usr/bin/perl
#
# A script to sync ssh keys on UNIX servers automatically.  This
# will not overwrite user installed ssh keys
#

use strict;
use IPC::Open3;
use File::Copy;

use POSIX ":sys_wait_h";

# This is overkill but FreeBSD may install wget in
# /usr/local/bin in some cases.
$ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin";

####################################################

use constant URL => 'https://keys.yoursite.com/ssh-keys.txt';
use constant WGET => 'wget --no-check-certificate -q -O - ';
use constant KEYS_FILE => '/root/.ssh/authorized_keys';
use constant RESTRICTED => 'https://keys.yoursite.com/restricted.txt';

####################################################

my ($url, $wget, $keys_file, $restricted, %restrict);

for (my $i=0;$i<scalar @ARGV;$i++) {
        my $arg = $ARGV[$i];
        $arg =~ s/^-//;
        if ($arg eq 'k') {
                $keys_file = $ARGV[++$i];
        } elsif ($arg eq 'u') {
                $url = $ARGV[++$i];
        } elsif ($arg eq 'h') {
                usage();
        } elsif ($arg eq 'r') {
                $restricted++;
        } else {
                print STDERR "Unknown argument: $ARGV[$i]!\n";
        }
}

$wget = $wget ? $wget : WGET;
$url = $url ? $url : URL;
$keys_file = $keys_file ? $keys_file : KEYS_FILE;

$wget = "$wget $url";

####################################################

# reading fds
my $rdr;

# Buffer for Company keys
my $company_keys;

# Buffer for user installed keys
my $user_keys;
my $pid;

if ($restricted) {
        $pid = open3(\*WTR, \*RTR, \*ERR, "@{[WGET]} @{[RESTRICTED]}");

        while (<RTR>) {
                chomp;
                $restrict{$_}++;
        }
}

$pid = open3(\*WTR, \*RTR, \*ERR, "$wget");

while (<RTR>) {
        next if $restrict{$1};
        $company_keys .= $_;
}

$user_keys = read_key_file();

# Sanity check
my @rows = split('\n', $company_keys);

if (scalar @rows < 1) {
        print "Less than 1 company keys found, not installing keys..\n";
        exit(1);
}

open(TMP, ">$keys_file.$$.tmp") or die "Could not open tmp keys file: $!\n";
print TMP $company_keys;
print TMP $user_keys;
close(TMP);

# Sanity check

my (undef,undef,undef,undef,undef,undef,undef,$size,undef,undef,undef,undef,undef) = stat("$keys_file.$$.tmp");

if ($size < 100) {
        print "Keys file less than 100bytes, not writing";
        exit(1);
}

move("$keys_file.$$.tmp", $keys_file);

sub read_key_file {
        my $user_buf;

        open(KEY_FILE, "< $keys_file") or die "Could not open ssh key file; $!\n";

        while (<KEY_FILE>) {
                next if $_ =~ /company$/;
                $user_buf .= $_;
        }

        close(KEY_FILE);
        return($user_buf);
}

sub sig_chld {
        my $pid = waitpid(-1, WNOHANG);
}

sub usage {
        print STDERR <<"EOS";

        Usage: $0 -[kuh]

                -k <file>       Keys file to write to (default: @{[KEYS_FILE]})
                -u <url>        URL to download keys from (default: @{[URL]})
                -h              This screen

EOS
        exit(1);
}

1;

__END__
</pre>
<p>Note that it downloads the <b>public</b> keys via http with <b>wget</b>. This can be easily modified to utilize https, if necessary, or perhaps even another protocol to make the transfer. HTTP Was chosen because the public keys are harmless and http is the easiest method. HTTPS would be desirable, however.</p>
<p>We hope this script helps you along the way towards making your life easier! <img src='http://www.stardothosting.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2009/12/07/script-to-distribute-ssh-keys-across-many-servers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setup Up Exim with ClamAV and Spamassassin</title>
		<link>http://www.stardothosting.com/blog/2009/12/02/setup-exim-with-clamav-and-spamassassin/</link>
		<comments>http://www.stardothosting.com/blog/2009/12/02/setup-exim-with-clamav-and-spamassassin/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 16:49:49 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[clamav]]></category>
		<category><![CDATA[exim]]></category>
		<category><![CDATA[mail administration]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[spamassassin]]></category>

		<guid isPermaLink="false">http://blog.stardothosting.com/?p=237</guid>
		<description><![CDATA[I decided to post this article on implementing a simple single mail server with anti-spam and anti-virus capabilities.

This guide hopefully will help you on your way to configuring a basic mail system on Linux (specifically Debian).]]></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%2F12%2F02%2Fsetup-exim-with-clamav-and-spamassassin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.stardothosting.com%2Fblog%2F2009%2F12%2F02%2Fsetup-exim-with-clamav-and-spamassassin%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I decided to post this article on implementing a simple single mail server with anti-spam and anti-virus capabilities.</p>
<p>This guide hopefully will help you on your way to configuring a basic mail system on Linux (specifically Debian).</p>
<p><big><b><u>Installing and configuring Exim 4 on Debian</b></u></big></p>
<p><b>1. First, install all the necessary Debian packages are on the system as the root user. (The exim4 package will REPLACE the exim package.)</b></p>
<p><b>NOTE:</b> If you are using the stable branch, it is suggested to use the debian volatile packages (along with the security packages) so that your system is using the most up-to-date critical packages (like ClamAV) for security purposes. For production servers, you may not want to run a mixed stable/testing/unstable system (though I know some of you do!). To use these packages, see http://volatile.debian.net/ for more information. For those of you who are impatient and don&#8217;t want to find the correct mirror, here&#8217;s is what I added to my /etc/apt/sources.list file:</p>
<pre>deb http://volatile.debian.net/debian-volatile sarge/volatile main contrib</pre>
<p>I used aptitude to install these packages, but you could also use the old apt-get method:</p>
<pre>
apt-get install clamav-daemon \
clamav-freshclam exim4-daemon-heavy exim4 \
courier-base courier-authdaemon courier-imap \
courier-pop spamassassin wget spamc sa-exim
</pre>
<p>When going through the exim4 config, be sure to select the multiple file configuration layout. If you didn&#8217;t (or weren&#8217;t prompted for it), simply set dc_use_split_config to true in the /etc/exim4/update-exim.conf.conf file. (Thanks Mike!)</p>
<p><b>2. Create your Maildir directory</b></p>
<pre>
maildirmake ~/Maildir/
</pre>
<p><b>3. Now we want to make exim4 use Maildir format mailboxes. Modify the file /etc/exim4/update-exim4.conf.conf so that it contains:</b></p>
<pre>
dc_localdelivery='maildir_home'
</pre>
<p><b>4. We need to Edit /etc/default/spamassassin to enable spamd.</b></p>
<p><b>5. Each user can set up their own filters by creating a .forward file in their home directory. If the first line of this file reads  </b></p>
<pre>
# Exim filter then Exim4 will treat it as a filter.
</pre>
<p>Here is an example of an Exim filter that checks the headers that SpamAssassin adds and puts the mail in the appropriate Maildir folder:</p>
<pre>
      # Exim filter
      if $h_X-Spam-Status: CONTAINS "Yes"
           or
        $h_X-Spam-Flag: CONTAINS "Yes"
      then
        save $home/Maildir/.Spam/
        finish
      endif
</pre>
<p>Exim&#8217;s Interface To Mail Filtering (PDF format) &#8211; Local copy</p>
<p><b>6. Many system administrators like to set up the Maildir directories and .forward filter file in the /etc/skel directory so that when they make a new user on the system, everything is automatically copied over. I suggest that you do this as well as it makes things easier.</b></p>
<p><b>7. Before going live with the mail server, we will want to test it!</b></p>
<p><big><b><u>Testing the implementation</b></u></big></p>
<p><b>1. Generate the new configuration:</b></p>
<pre>
update-exim4.conf
</pre>
<p>If you made it through this, then your config files don&#8217;t have any syntax errors.</p>
<pre>
exim4 -bV
</pre>
<p>If that works, then there are no config issues</p>
<p><b>2. Next, start exim by issuing:</b></p>
<pre>
/etc/init.d/exim4 start
</pre>
<p>Above assumes that you are running exim4 as a daemon, and not through inetd</p>
<p><b>3. Now, check a local address:</b></p>
<pre>
            exim4 -bt local_user@example.com
</pre>
<p><b>4. Check sending an email:</b></p>
<pre>
            exim4 -v mailbox_you_can_check@dom.ain
               From: user@your.domain
               To: mailbox_you_can_check@dom.ain
               Subject: Testing exim

               Testing exim
               .
</pre>
<p>You should now see some messages to let you know that the email was sent or information about what went wrong.</p>
<p><b>5. To test with full debug output using a specific config file, use something like:</b></p>
<pre>
            exim4 -C /etc/exim/exim_example.conf -d -bt user@example.com
</pre>
<p><b>6. To test the config coming from a specified ip address, use:</b></p>
<pre>
            exim4 -bh 192.168.1.10

            HELO example.com
               MAIL FROM: <user@example.com>
               RCPT TO: <local_user@example.com>
               DATA
               Subject: something
               your message here
               .
               QUIT
</pre>
<p><b>8. Add the following to your /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs file:</b></p>
<pre>
      # This tells what virus scanner to use
      av_scanner = clamd:/var/run/clamav/clamd.ctl
</pre>
<p><b>9. Edit /etc/exim4/conf.d/acl/40_exim4-config_check_data to inlude the following before the &#8220;# accept otherwise&#8221; line:</b></p>
<pre>
      # Reject messages that have serious MIME errors.
         # This calls the demime condition again, but it
         # will return cached results.
         deny message = Serious MIME defect detected ($demime_reason)
         demime = *
         condition = ${if >{$demime_errorlevel}{2}{1}{0}}

         # Reject file extensions used by worms.
         # Note that the extension list may be incomplete.
         deny message = This domain has a policy of not accepting certain types of attachments \
                        in mail as they may contain a virus.  This mail has a file with a .$found_extension \
                        attachment and is not accepted.  If you have a legitimate need to send \
                        this particular attachment, send it in a compressed archive, and it will \
                        then be forwarded to the recipient.
         demime = exe:com:vbs:bat:pif:scr

         # Reject messages containing malware.
         deny message = This message contains a virus ($malware_name) and has been rejected
         malware = *
</pre>
<p><b>10. Then, you need to enable ClamAV.</b></p>
<p>a) Firstly, you will want to be sure that it is running against messages. In /etc/exim4/sa-exim.conf, search for SAEximRunCond:</p>
<pre>SAEximRunCond: ${if and {{def:sender_host_address} {!eq {$sender_host_address}{127.0.0.1}} {!eq {$h_X-SA-Do-Not-Run:}{Yes}} } {1}{0}}</pre>
<p>That is simply skipping the scan on anything from the local machine or if the X-SA-Do-Not-Run header in the message is set to Yes. If you just want exim to run ClamAV on all messages, use this:</p>
<pre>SAEximRunCond: 1</pre>
<p>b) Before restarting ClamAV, we need to be sure that all of the access rights are in place so that the scans actually happen. The best way to handle this is to add the clamav user to the Debian-exim group. Either manually edit /etc/group, or simple run:</p>
<pre>adduser clamav Debian-exim</pre>
<p>c) Be sure that /etc/clamav/clamd.conf contains a line that reads:</p>
<pre>AllowSupplementaryGroups</pre>
<p>d) Set the file permissions for the /var/run/clamav directory to allow for the correct user to use it:</p>
<pre>
            chown Debian-exim.Debian-exim /var/run/clamav
            chmod g+w /var/run/clamav
</pre>
<p>e)  A restart of ClamAV is necessary for the changes to take effect:</p>
<pre>/etc/init.d/clamav-daemon restart</pre>
<p><b>11. You should now be able to get your mail via IMAP with a mail client like Mozilla. </b></p>
<p>Check your headers (View Source) and see that SpamAssassin has added its headers. SMTP-end virus scanning should also be taking place. Check your /var/log/clamav/clamav.log to monitor this.</p>
<p><big><b><u>Multiple Domain Alias Files</big></b></u></p>
<p>The steps below are used to enable support for having multiple virtual domains each with its own alias file.</p>
<p><b>1. Exim will need to have the alias files for each domain.</b></p>
<p>a) Create the /etc/exim4/virtual directory.<br />
b) For each virtual domain, create a file that contains the aliases to be used named as the domain.</p>
<p>For example, if I example.com was one of my domains, I&#8217;d do the following:</p>
<p>a) Create the /etc/exim4/virtual/example.com file.<br />
b) If my system users were sys1, sys2, and sys3, and their email addresses were to be joe, john, jason, I&#8217;d put the following into the domain alias file:</p>
<pre>
                  joe:    sys1@localhost
                  john:   sys2@localhost
                  jason:  sys3@localhost
</pre>
<p>If john was also to get all mail addressed to info@example.com, you would add this entry:</p>
<pre>info:   sys2@localhost</pre>
<p>If you wanted all mail to user1@example.com to go to another email account outside of this domain, you would enter:</p>
<pre>user1:  a.user@some.domain</pre>
<p>If you wanted all mail directed at any address other than what is defined in the alias file to go to joe, you&#8217;d enter:</p>
<pre>*:      sys1@localhost</pre>
<p>In the above examples, the &#8220;@localhost&#8221; suffix to the user names forces the delivery to a system user. I found that if you do not include this in the alias files and your machine&#8217;s host name is within one of the domains handled by exim, every system user would need an entry in the machine&#8217;s domain in order to be delivered corectly. </p>
<p>For instance, if your host name was mail.example1.com and example1.com was handled by this server this would be needed. This would allow delivery to all the system user names at example1.com. </p>
<p>The reason is simple, and I will try to illustrate it for you here:</p>
<p>a) exim receives a message delivered to joe.blow@example3.com<br />
b) The alias file for this domain has joe.blow: jblow in it.<br />
c) This would translate to jblow@domain-of-the-system<br />
d) The process would be repeated using jblow@domain-of-the-system<br />
e) If there was no entry in the domain-of-the-system alias file for jblow, the message would be undeliverable (or non-routable)</p>
<p>You could even have special redirects like the following:</p>
<pre>
script: "| /path/to/some/script"
prev:   :fail: $local_part left!
kill:   :blackhole:
</pre>
<p><b>2. Edit /etc/exim4/conf.d/main/01_exim4-config_listmacrosdefs by replacing the current local_domains line with:</b></p>
<pre>domainlist local_domains = @:localhost:dsearch;/etc/exim4/virtual</pre>
<p><b>3. Create /etc/exim4/conf.d/router/350_exim4-config_vdom_aliases with the following content:</b></p>
<pre>
            vdom_aliases:
            driver = redirect
            allow_defer
            allow_fail
            domains = dsearch;/etc/exim4/virtual
            data = ${expand:${lookup{$local_part}lsearch*@{/etc/exim4/virtual/$domain}}}
            retry_use_local_part
            pipe_transport   = address_pipe
            file_transport   = address_file
</pre>
<p><b>4. Now, regenerate your exim4 config:</b></p>
<pre>update-exim4.conf</pre>
<p><b>5. If there were no errors, restart exim4:</b></p>
<pre>/etc/init.d/exim4 restart</pre>
<p><big><b><u>Domain Dependent Maximum Message Size</b></big></u></p>
<p>The next step for my server is to give each domain a configurable message size limit. Then, when the server get&#8217;s a message that is larger than the target domain&#8217;s size limit, I want to send a message back to the original sender telling them why the message was not delivered. However, I also want to have that message customized for each domain. That way, the domain owners can provide detailed instructions on how to send large messages to their domain if it is necessary. Of course, there will also need to be some kind of default size limit and message for domains that do not need the customization.</p>
<p><b>1. Create /etc/exim4/domain-size-limits to contain the list of domains and their maximum message size limits. You can also add a wildcard at the end entry if you want to set a default limit. The file may look something like the following:</b></p>
<pre>
      example.com: 20M
      example1.com: 5M
      *: 15M
</pre>
<p>This provides you a quick way to edit the values. The values will also take effect as soon as the file is saved &#8211; no need to restart exim!</p>
<p><b>2. OK, now we know what domains we want to customize the size for. Now it&#8217;s time to create a message to send for those domains. Create /etc/exim4/domain-size-limit-messages with content similar to:</b></p>
<pre>
      exmaple.com: The largest acceptable message size for Example.com is\
                   ${expand:${lookup{$domain}lsearch*@{/etc/exim4/domain-size-limits}}}.\
                   Your message was $message_size. If you feel that $local_part@$domain\
                   should really get your message, then visit http://www.example.com/files/\
                   where you can upload any large files. If you select $local_part@$domain\
                   from the "notify" list, they will receive a message with a link directly\
                   to your file.
      *:           The largest acceptable message size for $domain is\
                   ${expand:${lookup{$domain}lsearch*@{/etc/exim4/domain-size-limits}}}.\
                   Your message size was $message_size. Please revise your message so it\
                   does not exceed this maximum file size and resend. If this is not\
                   possible, contact the recipient in another way.
</pre>
<p>As you see, we have one domain that has a custom message sent out, and have defined a default message for all other domains. These messages can be edited at any time and do not need an exim restart to take effect.</p>
<p><b>3. Now for the fun part! We need a way to catch the messages that are too large for the domain! First, create /etc/exim4/conf.d/router/325_exim4-config_large_messages with the following:</b></p>
<pre>
      large_messages:
          driver = accept
          domains = dsearch;/etc/exim4/virtual
          condition = ${if >{$message_size}{${expand:${lookup{$domain}lsearch*@{/etc/exim4/domain-size-limits}}}} {yes}{no}}
          transport = bounce_large_messages
          no_verify
</pre>
<p>This router dynamically checks which domains are available and what their limits are set to.</p>
<p><b>4. Now create /etc/exim4/conf.d/transport/40_exim4-config_bounce_large_messages with the following content:</b></p>
<pre>
      # This bounces a message to people who send files too large for that domain
      bounce_large_messages:
        driver = autoreply
        from = $local_part@$domain
        to = $sender_address
        subject = Re: ${escape:$h_subject:}
        text = ${expand:${lookup{$domain}lsearch*@{/etc/exim4/domain-size-limit-messages}}}
</pre>
<p>This transport then sends the original sender a message using the text looked up from the domain-size-limit-messages file for that domain. The From: field is filled in with the intended recipient of the message &#8211; appearing to be a reply.</p>
<p>This was actually very simple to put together once I realized what I needed to do. The above is based on what I found in the Exim FAQ</p>
<p><big><b><u>Configuration Tips</big></b></u></p>
<p>Maybe this is something I should have said in the beginning, but at the time or writing this document, I had never set up an exim4 server, and the only exim3 server I had was used with the default debconf install. Therefore, if you see something on this page that could be done in a more elegant, more efficient or just plain better way, please send me a note.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stardothosting.com/blog/2009/12/02/setup-exim-with-clamav-and-spamassassin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

