<?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>ukstokes.com &#187; Enterprise Linux</title>
	<atom:link href="http://ukstokes.com/blog/category/enterprise-linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://ukstokes.com/blog</link>
	<description>tech stuff from a tech bloke</description>
	<lastBuildDate>Tue, 01 Nov 2011 11:29:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A cunning problem with for loops</title>
		<link>http://ukstokes.com/blog/2011/03/18/a-cunning-problem-with-for-loops/</link>
		<comments>http://ukstokes.com/blog/2011/03/18/a-cunning-problem-with-for-loops/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 07:26:34 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Desktop Linux]]></category>
		<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Bash scripting]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=815</guid>
		<description><![CDATA[I came across a cunning little problem with for loops where the values being parsed contain spaces, and can offer a couple of solutions to it. I'll explain what I mean with some code. If you md5sum a bunch of files, you get this kind of output: I wanted to iterate through a list of [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a cunning little problem with for loops where the values being parsed contain spaces, and can offer a couple of solutions to it. I'll explain what I mean with some code.</p>
<p>If you md5sum a bunch of files, you get this kind of output:</p>
<pre class="brush: bash; title: ; notranslate">[ben@minitron ~]$ md5sum *.txt
d41d8cd98f00b204e9800998ecf8427e  myfile.txt
cdbd2b665e14f8803d6bddc80bff1402  omg.txt
6353f9b2e7c47f73b48eef4544968bcd  otherfile.txt</pre>
<p>I wanted to iterate through a list of files and their md5sums using a for loop, run a test and then take some action based on the result. But my script kept throwing unexpected output. I realised the for loop was parsing each word, rather than each line because of the spaces.</p>
<pre class="brush: bash; title: ; notranslate">[ben@minitron ~]$ for line in $(md5sum *.txt); do
echo $line; done
d41d8cd98f00b204e9800998ecf8427e
myfile.txt
cdbd2b665e14f8803d6bddc80bff1402
omg.txt
6353f9b2e7c47f73b48eef4544968bcd
otherfile.txt</pre>
<p>Sometimes putting spaces around variables can help bash to resolve values in the right way, but here it caused all line breaks to be removed:</p>
<pre class="brush: bash; title: ; notranslate">[ben@minitron ~]$ for line in &quot;$(md5sum *.txt)&quot;; do echo $line; done
d41d8cd98f00b204e9800998ecf8427e myfile.txt cdbd2b665e14f8803d6bddc80bff1402 omg.txt 6353f9b2e7c47f73b48eef4544968bcd otherfile.txt</pre>
<p>I needed to preserve the original line breaks in order for my script to make sense of which md5sum matched up to which file. There are a couple of ways to do this. One possible solution is to use <strong>tr </strong>to translate the spaces into a different character:</p>
<pre class="brush: bash; title: ; notranslate">[ben@minitron ~]$ for line in $(md5sum *.txt | tr &quot; &quot; :); do
echo $line; done
d41d8cd98f00b204e9800998ecf8427e::myfile.txt
cdbd2b665e14f8803d6bddc80bff1402::omg.txt
6353f9b2e7c47f73b48eef4544968bcd::otherfile.txt</pre>
<p>But for some reason md5sum uses 2 spaces for a field separator, if you wanted just one character between the md5sum and the filename, you could go a little more advanced:</p>
<pre class="brush: bash; title: ; notranslate">[ben@minitron ~]$ for file in *.txt; do
echo -n &quot;$file:&quot;;md5sum $file | cut -d &quot; &quot; -f1 ; done
myfile.txt:d41d8cd98f00b204e9800998ecf8427e
omg.txt:cdbd2b665e14f8803d6bddc80bff1402
otherfile.txt:6353f9b2e7c47f73b48eef4544968bcd</pre>
<p>This does give the output in the other way round but was good enough for me to make my script work.</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2011/03/18/a-cunning-problem-with-for-loops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitor AJP threads on multiple Tomcat servers</title>
		<link>http://ukstokes.com/blog/2011/02/04/monitor-ajp-threads-on-multiple-tomcat-servers/</link>
		<comments>http://ukstokes.com/blog/2011/02/04/monitor-ajp-threads-on-multiple-tomcat-servers/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 06:57:18 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=764</guid>
		<description><![CDATA[Here's a script to gather AJP thread usage from a farm of tomcat servers, in my case I needed to query 120 tomcat instances spread over 30 servers. It uses a freely avaiable JMX command line client to query the currentThreadsBusy of the JVM. There are perhaps more elegant solutions to do this, I needed [...]]]></description>
			<content:encoded><![CDATA[<p>Here's a script to gather AJP thread usage from a farm of tomcat servers, in my case I needed to query 120 tomcat instances spread over 30 servers. It uses a freely avaiable JMX command line client to query the currentThreadsBusy of the JVM. There are perhaps more elegant solutions to do this, I needed a quick solution.</p>
<p><strong>Notes<br />
</strong>One thing I have noticed with command line Java utilities, is they always output to stdErr. So if you want to grep or awk the output of the commands you have to redirect that to stdIn first, hence the "2&gt;&amp;1".</p>
<ul>
<li>Replace <strong>user:pass</strong> with the JMX username and password set in jmx.properties</li>
<li>Replace <strong>server</strong> with the first part of your server name</li>
<li>Replace the port numbers with the JMX ports your servers are using.</li>
<li>Finally you'll need to change the paths to the log file and the JMX client.</li>
<li>The variables "one","three", "five" and "seven" can be changed to anything you want. It makes sense to call them this in my environment.</li>
</ul>
<pre class="brush: bash; title: ; notranslate">#!/bin/bash
while true; do

 export now=$(date +%Y-%m-%d)
 export log=/path/to/ajp_all_tomcat_${now}.log
  if [ ! -f $log ]; then
   echo -n &quot;Start AJP thread count log
Time&quot; &gt; $log;
   for s in $(seq -w 1 30); do for i in 1 3 5 7; do echo -n &quot;,server${s}tc0${i}&quot; &gt;&gt; $log; done; done
   echo &gt;&gt; $log
  fi

 echo -n $(date +%H:%M:%S) &gt;&gt; $log
 for s in $(seq -w 1 30); do
  export one=$(/usr/bin/java -jar /path/to/cmdline-jmxclient-0.10.3.jar user:pass server${s}:7601 &quot;Catalina:type=ThreadPool,name=ajp-7501&quot; currentThreadsBusy 2&gt;&amp;1 | awk '{print $6}')
  export three=$(/usr/bin/java -jar /path/to/cmdline-jmxclient-0.10.3.jar user:pass server${s}:7603 &quot;Catalina:type=ThreadPool,name=ajp-7503&quot; currentThreadsBusy 2&gt;&amp;1 | awk '{print $6}')
  export five=$(/usr/bin/java -jar /path/to/cmdline-jmxclient-0.10.3.jar user:pass server${s}:7605 &quot;Catalina:type=ThreadPool,name=ajp-7505&quot; currentThreadsBusy 2&gt;&amp;1 | awk '{print $6}')
  export seven=$(/usr/bin/java -jar /path/to/cmdline-jmxclient-0.10.3.jar user:pass server${s}:7607 &quot;Catalina:type=ThreadPool,name=ajp-7507&quot; currentThreadsBusy 2&gt;&amp;1 | awk '{print $6}')
  echo -n &quot;,$one,$three,$five,$seven&quot; &gt;&gt; $log
 done
 echo &gt;&gt; $log

done
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2011/02/04/monitor-ajp-threads-on-multiple-tomcat-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic X forwarding</title>
		<link>http://ukstokes.com/blog/2010/11/10/automatic-x-forwarding/</link>
		<comments>http://ukstokes.com/blog/2010/11/10/automatic-x-forwarding/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 22:05:46 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Desktop Linux]]></category>
		<category><![CDATA[Enterprise Linux]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=733</guid>
		<description><![CDATA[At work I've found I often need to bring up X applications like jvisualvm, or HPSUM, while I administer Linux servers from my Windows 7 machine. This is how I automatically set the $DISPLAY variable on the bash session to point to my machine: Add the following to the end of your .bash_profile: Then on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ukstokes.com/blog/wp-content/uploads/2010/11/xorg.jpg"><img src="http://ukstokes.com/blog/wp-content/uploads/2010/11/xorg-150x150.jpg" alt="" title="xorg" width="80" height="80" class="alignleft size-thumbnail wp-image-743" /></a>At work I've found I often need to bring up X applications like jvisualvm, or HPSUM, while I administer Linux servers from my Windows 7 machine. This is how I automatically set the $DISPLAY variable on the bash session to point to my machine:</p>
<p>Add the following to the end of your .bash_profile:</p>
<pre class="brush: bash; title: ; notranslate">export DISPLAY=$(who am i | awk -F &quot;(&quot; {'print $2'} | awk -F &quot;.&quot; {'print $1'}):0.0</pre>
<p>Then on my Windows 7 laptop, I installed <a href="http://sourceforge.net/projects/xming/files/">xming</a> and configured xlaunch to start automatically when the computer is started (with the "no access control" box ticked). </p>
<p>Now I can just SSH to servers and launch X apps, and they appear on my desktop with no configuration required.</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2010/11/10/automatic-x-forwarding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading bugzilla from 3.0.x to 3.4.6</title>
		<link>http://ukstokes.com/blog/2010/05/11/upgrading-bugzilla-from-3-0-x-to-3-4-6/</link>
		<comments>http://ukstokes.com/blog/2010/05/11/upgrading-bugzilla-from-3-0-x-to-3-4-6/#comments</comments>
		<pubDate>Tue, 11 May 2010 21:23:16 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[Bugzilla]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=602</guid>
		<description><![CDATA[A few weeks ago I updated a 3 year old installation of Bugzilla to the most recent version, and made these notes along the way. The Bugzilla online documentation is pretty good and my plan was formed using their docs as a guide. Send advance warning to users Log on to site, edit params and [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I updated a 3 year old installation of Bugzilla to the most recent version, and made these notes along the way. The Bugzilla online documentation is pretty good and my plan was formed using their docs as a guide.</p>
<ul>
<li>Send advance warning to users</li>
<li>Log on to site, edit params and enter some text under 'shutdown site'</li>
<li>Backup db using this commmand</li>
</ul>
<pre class="brush: bash; title: ; notranslate">mysqldump --opt -u bugs -p bugs &gt; bugs_backup_$(date +%d%m%y).sql</pre>
<ul>
<li>Download and extract bugzilla 3.4.6</li>
</ul>
<pre class="brush: bash; title: ; notranslate">cd ~
wget http://ftp.mozilla.org/pub/mozilla.org/webtools/bugzilla-3.4.6.tar.gz
tar fvzx bugzilla-3.4.6.tar.gz
cd /var/www/html/
mv bugzilla bugzilla.old
cp -r ~/bugzilla-3.4.6 ./bugzilla
cp -r bugzilla.old/localconfig* bugzilla</pre>
<p>Later you will install the DBD::mysql perl module which requires mysql header files. So if you don't have mysql-devel, install it now. Also the Image::Magick perl module may fail to build from cpan (this is what happened to me), this can be installed by yum as an alternative.</p>
<pre class="brush: bash; title: ; notranslate">yum install mysql-devel ImageMagick-perl.i386
cd bugzilla
./checksetup.pl</pre>
<p>checksetup.pl will tell you to install missing perl modules using cpan, however this requires an internet connection. I used ntlmaps to proxy through our MS ISA server as my bugzilla server doesn't have Internet access. I got ntlmaps from another server on the network:</p>
<pre class="brush: bash; title: ; notranslate">scp -r root@bugtest:/root/ntlm* .
cd ntlmaps-0.9.9.0.1
nohup python main.py
export http_proxy=http://localhost:5865
export ftp_proxy=ftp://localhost:5865
cd /var/www/html/bugzilla</pre>
<p>Install optional updates:</p>
<pre class="brush: bash; title: ; notranslate"># failed  --&gt; /usr/bin/perl install-module.pl Image::Magick
# skipped --&gt; /usr/bin/perl install-module.pl Authen::Radius
/usr/bin/perl install-module.pl SOAP::Lite
/usr/bin/perl install-module.pl TheSchwartz
/usr/bin/perl install-module.pl Daemon::Generic
/usr/bin/perl install-module.pl SOAP::Lite</pre>
<p>Install compulsary updates:</p>
<pre class="brush: bash; title: ; notranslate">/usr/bin/perl install-module.pl DBD::mysql
/usr/bin/perl install-module.pl CGI
/usr/bin/perl install-module.pl Digest::SHA
/usr/bin/perl install-module.pl DateTime
/usr/bin/perl install-module.pl DateTime::TimeZone
/usr/bin/perl install-module.pl Template
/usr/bin/perl install-module.pl Email::MIME
/usr/bin/perl install-module.pl Email::MIME::Encodings</pre>
<p>I also needed these perl modules, even though they weren't listed by checksetup.pl:</p>
<pre class="brush: bash; title: ; notranslate">/usr/bin/perl install-module.pl DateTime::Locale
/usr/bin/perl install-module.pl List::MoreUtils</pre>
<p>Finished with ntlmaps now, it can be stopped</p>
<pre class="brush: bash; title: ; notranslate">kill $(ps x | grep main.py | grep -v grep | awk {'print $1'})
export http_proxy=
export ftp_proxy=</pre>
<p>Run checksetup again, this bit can take some time while the db is upgraded:</p>
<pre class="brush: bash; title: ; notranslate">./checksetup.pl</pre>
<ul>
<li>Fix any more problems, run again if required.</li>
<li>Once finished log into bugzilla, put maintenance page back up. This option has now moved to Administration</li>
<li>Run sanity check, fix any problems.</li>
<li>Change any css and templates that you lost in the upgrade.</li>
<li>Reopen the site for logons when you are ready.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2010/05/11/upgrading-bugzilla-from-3-0-x-to-3-4-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Managing multiple PuTTys</title>
		<link>http://ukstokes.com/blog/2009/09/09/managing-multiple-puttys/</link>
		<comments>http://ukstokes.com/blog/2009/09/09/managing-multiple-puttys/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:21:22 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Putty]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=407</guid>
		<description><![CDATA[I don't have any Linux cluster servers to look after but do manage 2 Linux server farms. They are similar to clusters in that they are both groups of RHEL servers that all have to have an identical config. The larger of these farms is 12 RHEL 5.3 servers, and to roll out changes to [...]]]></description>
			<content:encoded><![CDATA[<p>I don't have any Linux cluster servers to look after but do manage 2 Linux server farms. They are similar to clusters in that they are both groups of RHEL servers that all have to have an identical config. The larger of these farms is 12 RHEL 5.3 servers, and to roll out changes to them all, I wanted to be able to make the change once, and after it was verified, make the same change on the other 11 servers. I started off by writing this script on <em>server1</em>:</p>
<pre class="brush: bash; title: ; notranslate">#!/bin/sh

echo -n &quot;Enter command to run (on one line): &quot;
read STRING

for SERVER in server2 server3 server4 server5 server6 etc; do

echo -e &quot;\033[1;31m$SERVER says:\033[m&quot;
ssh $SERVER &quot;$STRING&quot;

done

echo -n &quot;Do you want to run the command locally? (y/n) :&quot;
read ANSWER

case &quot;$ANSWER&quot; in

y|Y) echo -e &quot;\033[1;31mlocalhost says:\033[m&quot;; $STRING ;;
N|n) exit 1 ;;
esac</pre>
<p>For this to work I had to create ssh keys on each server using:</p>
<pre class="brush: bash; title: ; notranslate">ssh-keygen -t dsa</pre>
<p>And then install the newly generated key (~/ssh/id_dsa.pub) into the authorized_keys file on<em> server1</em>. This works for running simple commands one at a time.</p>
<p>For other tasks its sometimes necessary to manage multiple ssh sessions at once, for example to monitor resources using <a href="http://htop.sourceforge.net/">htop</a> or tailing log files. On Linux you can use <a href="http://clusterssh.sourceforge.net/">ClusterSSH</a> (cssh) but this turned out to be a royal pain in the butt to get working on CentOS or RHEL. It worked OK in an Ubuntu VM but was a bit clunky and I felt there would be a better way of managing multiple PuTTy windows, since I am using a Windows 7 laptop for my day-to-day stuff.</p>
<p>There are quite a few goodies for this on the <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/links.html">Links page</a> on the Putty website and this is where I found <a href="http://www.millardsoftware.com/puttycs">Putty Command Sender</a>. Quite simply you type your command into the command sender, and much like clusterssh, it sends it to all the putty windows you have open.</p>
<p style="text-align: center;"><a href="http://ukstokes.com/blog/wp-content/uploads/2009/09/puttys.png"><img class="size-medium wp-image-518 aligncenter" title="puttys" src="http://ukstokes.com/blog/wp-content/uploads/2009/09/puttys-300x187.png" alt="puttys" width="300" height="187" /><em><br />
Putty Command Sender</em></a></p>
<p style="text-align: left;">It's not so great for editing files in Vi on 12 servers at once but it is possible - you can send cursor movements as well as lines of code or single commands. The only thing you have to watch out for in PuttyCS is that all Putty windows have updated before you start typing your next command, otherwise the last window to update may miss the first few characters of the next command.</p>
<p style="text-align: left;">Finally to launch my sessions in groups I'm using <a href="http://puttysm.sourceforge.net/">Putty Session Manager</a>. Other alternatives are available but I found this one to be the best. It's lightweight nature fits in with Putty nicely.</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2009/09/09/managing-multiple-puttys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install RHEL with Kickstart and no DHCP</title>
		<link>http://ukstokes.com/blog/2009/06/25/install-rhel-with-kickstart-and-no-dhcp/</link>
		<comments>http://ukstokes.com/blog/2009/06/25/install-rhel-with-kickstart-and-no-dhcp/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 12:44:52 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[kickstart]]></category>
		<category><![CDATA[RHEL]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=442</guid>
		<description><![CDATA[I've been installing 16 RHEL 5.3 servers on a DR site, owned by our sister company. There is no DHCP server on the subnet which has stopped us using HP Rapid Deployment Pack to roll out the servers, but it was still possible to use Kickstart, by specifying the IP information as a parameter when booting [...]]]></description>
			<content:encoded><![CDATA[<p>I've been installing 16 RHEL 5.3 servers on a DR site, owned by our sister company. There is no DHCP server on the subnet which has stopped us using HP Rapid Deployment Pack to roll out the servers, but it was still possible to use Kickstart, by specifying the IP information as a parameter when booting from the RHEL CD (disk 1). The syntax goes like this:</p>
<pre class="brush: plain; title: ; notranslate">boot: linux ks=http://server/kickstart.cfg ksdevice=eth0 ip=xx.xx.xx.xx netmask=xx.xx.xx.xx gateway=xx.xx.xx.xx dns=xx.xx.xx.xx</pre>
<p>DNS servers can be comma separated if you want to specify more than one.</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2009/06/25/install-rhel-with-kickstart-and-no-dhcp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set up a &#8216;honeypot&#8217; router using Netfilter (iptables)</title>
		<link>http://ukstokes.com/blog/2009/06/04/set-up-a-honeypot-router-using-netfilter-iptables/</link>
		<comments>http://ukstokes.com/blog/2009/06/04/set-up-a-honeypot-router-using-netfilter-iptables/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 21:06:33 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[netfilter]]></category>
		<category><![CDATA[routing]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=369</guid>
		<description><![CDATA[We're in the process of moving all servers from a legacy flat network to a new server VLAN. Each time a server is moved and is assigned a new IP address, there is a risk that some applications in the building might still try and connect to the server's old IP address rather than the [...]]]></description>
			<content:encoded><![CDATA[<p>We're in the process of moving all servers from a legacy flat network to a new server VLAN. Each time a server is moved and is assigned a new IP address, there is a risk that some applications in the building might still try and connect to the server's old IP address rather than the DNS name. To log any attempts to reach the old IP address I've set up a 'honeypot' router using iptables and CentOS (as a small VMware machine). Each time a server is moved, the old server IP is added to the CentOS machine and and 2 rules are added in the iptables firewall to drop and log the incoming IP connections. The failed connections would usually logged to the console and the 'messages' log file, but alternatively these could be sent to a remote syslog server by specifying:</p>
<pre class="brush: plain; title: ; notranslate">kern.*        @xx.xx.xx.xx</pre>
<p>in the syslog.conf. In our case we're logging to our Cacti server and using the Cacti syslog plugin (<a href="http://cactiusers.org/downloads/">from here</a>) to view our Linux server and network switch syslogs in a central location.</p>
<p><strong>iptables configuration</strong><br />
In a default installation of CentOS, iptables is already installed and running by default. There are only 2 changes to make; The first is to bind your additional IP address to your network card (usually eth0). This is done by creating a virtual device called eth0:1, by inserting this text into new file etc/sysconfig/network-scripts/<strong>ifcfg-eth0:1 <span style="font-weight: normal;">(10.10.2.17 is the destination address of the incoming traffic that I want to log):</span></strong></p>
<pre class="brush: plain; title: ; notranslate">IPADDR=10.10.2.17
NETMASK=255.255.0.0</pre>
<p>And then bringing up the virtual device using:</p>
<pre class="brush: plain; title: ; notranslate">ifconfig eth0:1 up</pre>
<p>In the iptables config file (etc/sysconfig/iptables) I added these lines in the RH-Firewall-1-INPUT chain:</p>
<pre class="brush: plain; title: ; notranslate">-A RH-Firewall-1-INPUT -d 10.10.2.17 -j LOG --log-level 4 --log-prefix &quot;OLD SRV1&quot;
-A RH-Firewall-1-INPUT -d 10.10.2.17 -j DROP</pre>
<p>Any traffic to 10.10.2.17 will now be logged in messages and the lines will be prefixed with "OLD SRV1".</p>
<p><em>Note about file paths:</em> I'm getting an odd error when posting Linux file paths in WordPress - putting a leading / in the path gives a 404 error. The paths I mentioned above should have a leading forwardslash "/".</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2009/06/04/set-up-a-honeypot-router-using-netfilter-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get system stats automatically on SSH login</title>
		<link>http://ukstokes.com/blog/2009/04/10/get-system-stats-automatically-on-ssh-login/</link>
		<comments>http://ukstokes.com/blog/2009/04/10/get-system-stats-automatically-on-ssh-login/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 22:22:46 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Bash scripting]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=126</guid>
		<description><![CDATA[I noticed in recent versions of Ubuntu you get some system stats in a banner message when you connect using SSH. I thought this was pretty useful so have implemented my own version on our Red Hat servers at work. This runs every 5 minutes as a cron job and updates the file /etc/motd (Message [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed in recent versions of Ubuntu you get some system stats in a banner message when you connect using SSH. I thought this was pretty useful so have implemented my own version on our Red Hat servers at work.</p>
<p>This runs every 5 minutes as a cron job and updates the file /etc/motd (Message Of The Day) which is shown when a user logs in. Our servers already have a 5 line banner message with information including the server name and purpose of the server, hence the first 5 lines being saved and readded into a new /etc/motd each time.</p>
<pre><code>
<pre class="brush: bash; title: ; notranslate">#!/bin/bash
cat /etc/motd | head -n 5 &gt; /tmp/file &amp;&amp; cat /tmp/file &gt; /etc/motd

CPUTIME=$(ps -eo pcpu | awk 'NR&gt;1' | awk '{tot=tot+$1} END {print tot}')
CPUCORES=$(cat /proc/cpuinfo | grep -c processor)

echo &quot;System summary (collected `date`)

 - CPU Usage (total average) = `echo $CPUTIME / $CPUCORES | bc`%
 - Memory free (real)        = `free -m | head -n 2 | tail -n 1 | awk {'print $4'}` Mb
 - Memory free (cache)       = `free -m | head -n 3 | tail -n 1 | awk {'print $3'}` Mb
 - Swap in use               = `free -m | tail -n 1 | awk {'print $3'}` Mb
&quot; &gt;&gt; /etc/motd</pre>
<p></code></pre>
<p>Now when we log in we get a summary like this:</p>
<p><img src="http://ukstokes.com/images/stats.png" alt="SSH Server Stats" /></p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2009/04/10/get-system-stats-automatically-on-ssh-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with Logical Volumes</title>
		<link>http://ukstokes.com/blog/2009/04/01/working-with-logical-volumes/</link>
		<comments>http://ukstokes.com/blog/2009/04/01/working-with-logical-volumes/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 21:20:48 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Logical Volumes]]></category>
		<category><![CDATA[LVM]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=221</guid>
		<description><![CDATA[I'm actually coming around to Linux LVM - once you get the hang of the concepts and the associated commands it can be a straightforward exercise to extend your existing volumes after adding new physical disks. This differs from software RAID, as you have the ability to lay an LVM filesystem over a single disk [...]]]></description>
			<content:encoded><![CDATA[<p>I'm actually coming around to Linux LVM - once you get the hang of the concepts and the associated commands it can be a straightforward exercise to extend your existing volumes after adding new physical disks. This differs from software RAID, as you have the ability to lay an LVM filesystem over a single disk and later take advantage of the LVM commands to resize your volumes if you so desire.</p>
<p>I recently was confronted with a VM that was out of space on /usr/local. The filesystem was already using LVM so I just added a new virtual disk and stretched the /usr/local volume over the new disk. The whole process is even easier in VMware as you can add the new disk while the machine is running and run through the whole process without a reboot, providing you don't have daemons or processes running in /usr/local that stop it from being unmounted. Here's how I did it:</p>
<pre class="brush: plain; title: ; notranslate">init 1
umount /usr/local</pre>
<p>Going to runlevel 1 may not always be necessary but was in my case.<strong> pvcreate </strong>enables the new physical disk for use with LVM. Then <strong>vgextend </strong>extends the volume group, and <strong>lvresze</strong> resizes the logical volume. In my case the new disk that was added became known to the system as /dev/sdc.</p>
<pre class="brush: plain; title: ; notranslate">pvcreate /dev/sdc
vgextend VolGroup00 /dev/sdc
lvresize /dev/VolGroup/lvol0 -L 12.7G</pre>
<p>Then use <strong>resize2fs </strong>to extend the file system into the free space. You are required to fun a filesystem check first.</p>
<pre class="brush: plain; title: ; notranslate">e2fsck -f /dev/VolGroup/lvol0
resize2fs /dev/VolGroup00/lvol0 12700M
mount -a
init 3</pre>
<p>In my example the previous size was 7.7Gb, I added a 5Gb disk and extended to 12.7Gb.</p>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2009/04/01/working-with-logical-volumes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resize swap partitions on Red Hat Linux</title>
		<link>http://ukstokes.com/blog/2008/08/12/resize-swap-partitions-on-red-hat-linux/</link>
		<comments>http://ukstokes.com/blog/2008/08/12/resize-swap-partitions-on-red-hat-linux/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 20:58:49 +0000</pubDate>
		<dc:creator>ben</dc:creator>
				<category><![CDATA[Enterprise Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Red Hat]]></category>

		<guid isPermaLink="false">http://ukstokes.com/blog/?p=99</guid>
		<description><![CDATA[First of all a little disclaimer - although I've done this a few times and never had any problems, one should never consider resizing partitions a completely foolproof exercise. Things can go wrong. With regards to swap though, don't worry if your swap partition is destroyed as this will not harm your system - most [...]]]></description>
			<content:encoded><![CDATA[<p>First of all a little disclaimer - although I've done this a few times and never had any problems, one should never consider resizing partitions a completely foolproof exercise. Things can go wrong. With regards to swap though, don't worry if your swap partition is destroyed as this will not harm your system - most healthy systems will not ever need swap and unlike Windows, Linux only starts using swap when it needs it and can quite easily survive without it. You can trash it and format it as many times as you like <span style="text-decoration: underline;">as long as it's not in use</span>. And of course take backups of any important data first!</p>
<p><strong>Resize swap partition in Red Hat Linux</strong></p>
<ul>
<li>Is your swap on a logical volume (LVM)? If so then skip below to the LVM section. If not then read on:</li>
<li>Download gparted (<a href="http://gparted.sourceforge.net/" target="_self">Gnome Partition Manager</a>), burn the iso and then boot into it.</li>
<li>Gparted will identify the filesystems on each partition so your target will be clearly labelled as swap.</li>
<li>Reize your partitions as required. Try to minimise the overall number of resize and move operations as this can take several hours to complete.</li>
</ul>
<p>When you reboot swap not be enabled - if you check using <strong>top</strong> (or <strong>htop</strong>) or <strong>free -m</strong>, you will see 0 mb of swap available. The reason for this is the UUID of the partition changed when it was resized by GParted, and this confuses the system when it tries to mount the volumes in /etc/fstab. The solution is to relabel your swap partition, by reformatting it as swap and specifying the correct label.</p>
<pre class="brush: plain; title: ; notranslate">fdisk -l | grep swap</pre>
<p>Note down the device name of your swap partition. e.g:</p>
<pre class="brush: plain; title: ; notranslate">/dev/cciss/c0d0p3 1926 3837 15358140 82 Linux swap</pre>
<p>Make a note of the label for the swap partition from fstab:</p>
<pre class="brush: plain; title: ; notranslate">cat /etc/fstab | grep swap</pre>
<p>e.g.</p>
<pre class="brush: plain; title: ; notranslate">LABEL=SW-cciss/c0d0p3 swap</pre>
<p>Now format your partition as swap, specifiying the label exactly as shown in the fstab.</p>
<pre class="brush: plain; title: ; notranslate">mkswap /dev/cciss/c0d0p3 -L SW-cciss/c0d0p3</pre>
<p>You can then enable the swap space straight away by using <strong>swapon </strong><em>devicename</em>, or just reboot and check with<strong> free -m</strong> again, and all should be ok.</p>
<p><strong>Resizing swap on LVM</strong><br />
If your swap partition is on a logical volume it can be resized without rebooting your system. However you will need free space to extend into, if you do not have free space you will need to shrink another volume or add another physical disk into your volume group (see <a href="http://ukstokes.com/blog/2009/04/01/working-with-logical-volumes/">this post</a> which explains how to do this).</p>
<pre class="brush: plain; title: ; notranslate">cat /etc/fstab | grep swap
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0</pre>
<p><strong>lvdisplay </strong>will show you the size of your logical volume:</p>
<pre class="brush: plain; highlight: [10]; title: ; notranslate">lvdisplay /dev/VolGroup00/LogVol01

--- Logical volume ---
LV Name                /dev/VolGroup00/LogVol01
VG Name                VolGroup00
LV UUID                RVIFz3-B8kp-z9KV-JYtG-N997-JOQ6-ETaJaJ
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                512.00 MB
Current LE             24
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:1</pre>
<p>To resize an LVM you need to unmount it, or in this case <strong>swapoff</strong>.</p>
<pre class="brush: plain; title: ; notranslate">swapoff /dev/VolGroup00/LogVol01</pre>
<p>Resizing the volume to 768Mb (assuming you have the space to extend into)</p>
<pre class="brush: plain; title: ; notranslate">lvresize /dev/VolGroup00/LogVol01 -L 768M
Extending logical volume LogVol01 to 768.00 MB
Logical volume LogVol01 successfully resized

swapon /dev/VolGroup00/LogVol01
free -m
total       used       free     shared    buffers     cached
Mem:           375        343         32          0         48        120
-/+ buffers/cache:        174        201
Swap:          767          0        767</pre>
]]></content:encoded>
			<wfw:commentRss>http://ukstokes.com/blog/2008/08/12/resize-swap-partitions-on-red-hat-linux/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

