<?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>That Chris Brown's Blog &#187; centos</title>
	<atom:link href="http://www.thatchrisbrown.com/tag/centos/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thatchrisbrown.com</link>
	<description>Another Chris Brown &#38; another blog</description>
	<lastBuildDate>Sat, 03 Apr 2010 13:05:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making squid work under selinux with non-default settings</title>
		<link>http://www.thatchrisbrown.com/2010/making-squid-work-under-selinux-with-non-default-settings/</link>
		<comments>http://www.thatchrisbrown.com/2010/making-squid-work-under-selinux-with-non-default-settings/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 13:05:09 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[selinux]]></category>
		<category><![CDATA[squid]]></category>

		<guid isPermaLink="false">http://www.thatchrisbrown.com/?p=143</guid>
		<description><![CDATA[I've been wrestling with squid today, and although I have inky stains on my body and soul, I've made some headway.  I've been trying to be a good sysadmin and not just disable selinux, or set it to permissive and forget it, at the first sign of trouble.  Thing is, I wanted a non-default squid configuration, and selinux got in the way.  I had two problems that I had to solve - non standard listen ports, and non-standard cache location.  This is how I fixed those [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2010%2Fmaking-squid-work-under-selinux-with-non-default-settings%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2010%2Fmaking-squid-work-under-selinux-with-non-default-settings%2F&amp;source=thatchrisbrown&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve been wrestling with squid today, and although I have inky stains on my body and soul, I&#8217;ve made some headway.  I&#8217;ve been trying to be a good sysadmin and not just disable selinux, or set it to permissive and forget it, at the first sign of trouble.  Thing is, I wanted a non-default squid configuration, and selinux got in the way.  I had two problems that I had to solve &#8211; non standard listen ports, and non-standard cache location.<br />
<span id="more-143"></span></p>
<p>I installed squid with the usual <code><strong>yum install squid</strong></code> command on my CentOS 5.4 server.  I want to be able to use a single squid instance to support both configured browsers (on the basis that it&#8217;s better if browsers know they are being proxied) and transparent (sometimes called &#8220;intercept&#8221;) proxying for applications with their own http access libraries, and guest machines on my network that may not want to configure my proxy settings, or don&#8217;t respect autoconfigure via DHCP.  So, after using webmin to set up a few basics, I jumped into the <code>/etc/squid/squid.conf</code> file and set up the following:<br />
<code># Listen on internal address for VLAN 2<br />
http_port 10.254.225.65:3128<br />
http_port 10.254.225.65:3129 transparent</p>
<p># Listen on internal address for VLAN 3<br />
http_port 10.254.225.129:3128<br />
http_port 10.254.225.129:3129 transparent</code></p>
<p>I then used Webmin to create a new logical volume on my RAID array, a nice healthy 64GB.  Big for a cache, but I want to try and cache installers and downloaded updates, so I want plenty of space.  I created the logical volume, mounted it on /webcache and jumped back into squid config in Webmin and added a cache location /webcache of 5000MB, 16 1st-level folders and 256 2nd-level folders.</p>
<p>Squid failed to start.  OK, I thought, I&#8217;ll initialise the cache with squid -z.  That ran fine as root.  Squid still wouldn&#8217;t start.  A check of the log files showed that squid was complaining &#8220;<em>cache_dir /webcache: (13) Permission denied</em>&#8220;.  Of course, I hadn&#8217;t set permissions on /webcache, so a quick <code><strong>chown -R squid:squid /webcache</strong></code> and I thought I was done.  I was not &#8211; squid still wouldn&#8217;t start.</p>
<p>I realised selinux might be the culprit and checked this by running <code><strong>setenforce Permissive</strong></code> and lo and behold, squid started.  A review of <code>/var/log/audit/audit.log</code> suggested that there were two problems &#8211; the non-standard port 3129 and the non-standard cache location.</p>
<p>The port issue was relatively easy to fix.  <code><strong>semanage port -l | grep "cache"</strong></code> to list any selinux information about ports that cache processes are allowed to use suggested the following:<br />
<code>http_cache_port_t              tcp      3128, 8080, 8118, 11211, 10001-10010<br />
http_cache_port_t              udp      3130, 11211</code></p>
<p>So, I needed to add port 3129 to the list.  A quick Google found a note about adding non-standard Apache ports, and from that is was easy to work out that the magic line would be <code><strong>semanage port -a -t http_cache_port_t -p tcp 3129</strong></code> which adds port 3129 to the list of allowed ports for http caches.  I didn&#8217;t expect this to get squid running, but at least the next failure gave me a smaller set of audit log entries to work on!</p>
<p>Next, I needed to fix the file contexts for /webcache.  This was a little more complex, being a novice to selinux.  I discovered that I could view existing context with <code><strong>ls -Z</strong></code> so at least I could assess my efforts.  I also found that it&#8217;s possible to change the file context with <strong>chcon</strong>, but this may not survive reboots, a <strong>restorecon</strong> (restore contexts) command or a &#8220;relabel&#8221; of the filesystem.  I needed a way to make sure that selinux knew that /webcache was meant to be used for squid, so I disn&#8217;t have to keep telling it.</p>
<p>After some poking around, and trying a few things out to no avail, I found that I needed to use a command <code><strong>grep -hi "squid" /etc/selinux/targeted/contexts/files/file_contexts*</strong></code> which showed me where the selinux policy knew about allowable locations for squid to keep files, as follows:<br />
<code>/etc/squid(/.*)?        system_u:object_r:squid_conf_t:s0<br />
/var/log/squid(/.*)?    system_u:object_r:squid_log_t:s0<br />
/var/squidGuard(/.*)?   system_u:object_r:squid_cache_t:s0<br />
/var/spool/squid(/.*)?  system_u:object_r:squid_cache_t:s0<br />
/usr/share/squid(/.*)?  system_u:object_r:squid_conf_t:s0<br />
/var/cache/squid(/.*)?  system_u:object_r:squid_cache_t:s0<br />
/var/log/squidGuard(/.*)?       system_u:object_r:squid_log_t:s0<br />
/usr/sbin/squid --      system_u:object_r:squid_exec_t:s0<br />
/var/run/squid\.pid     --      system_u:object_r:squid_var_run_t:s0<br />
/usr/lib/squid/cachemgr\.cgi    --      system_u:object_r:httpd_squid_script_exec_t:s0<br />
/usr/lib64/squid/cachemgr\.cgi  --      system_u:object_r:httpd_squid_script_exec_t:s0</code></p>
<p>So, it seems all I needed to do was to add to that list, and all would be good.  There was a small wrinkle to this too though.  <code><strong>semanage fcontext -a -t squid_cache_t /webcache</strong></code> would seem to do the necessary magic, but in fact semanage fcontext doesn&#8217;t work like a regular filesystem tool, so there&#8217;s no recursion.  It didn&#8217;t seem &#8220;clean&#8221; to then iterate through each sub-folder (all 4096 of them!) and set the context.</p>
<p>The answer was actually simple.  Delete the cache folders with <code><strong>rm -rf /webcache/0*</strong></code> and <code><strong>rm -rf /webcache/swap*</strong></code> and then set the required context on /webcache in the policy with <code><strong>semanage fcontext -a -t squid_cache_t /webcache</strong></code> and finally make this the current context with <code><strong>restorecon -R /webcache</strong></code>.  Then, with context set in the parent folder, running <code><strong>squid -z</strong></code> meant that the 4096 cache directories were also created with the right context.</p>
<p>I re-enabled Enforcing mode, squid started and my selinux policy is aware of my non-standard configuration, so hopefully future updates won&#8217;t break it.  My small concern is that future updates to the selinux policy may overwrite my changes &#8211; I don&#8217;t know how selinux works well enough to know if my policy changes will survive or be overwritten.  At least I&#8217;ve got my own handy guide to how to make it work again if I need it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thatchrisbrown.com/2010/making-squid-work-under-selinux-with-non-default-settings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USB CentOS to the rescue!</title>
		<link>http://www.thatchrisbrown.com/2009/usb-centos-to-the-rescue/</link>
		<comments>http://www.thatchrisbrown.com/2009/usb-centos-to-the-rescue/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 22:44:07 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[recovery]]></category>

		<guid isPermaLink="false">http://www.thatchrisbrown.com/?p=115</guid>
		<description><![CDATA[I stupidly broke a host and managed to recover it with CentOS Live CD running from a USB stick, which was refreshingly easy to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2009%2Fusb-centos-to-the-rescue%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2009%2Fusb-centos-to-the-rescue%2F&amp;source=thatchrisbrown&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>OK, OK &#8211; I was stupid.</p>
<p>As part of my ongoing move from Xen to KVM for VM hosting, I fireed up a server that had been sitting about too long switched off under the desk, thinkig that it would make an ideal machine to try KVM out on.  A <strong>yum groupremove Virtualization</strong> seemed to produce no issues, so I was looking good to go with a bit fo repo cleanup and then an update before upgrading from CentOS 5.2 to 5.3 with yum.  Then I did something stupid.</p>
<p>I renamed the logical volume that / is mounted from, becuase I thought the name wasn&#8217;t descriptive enough.  Then I rebooted the box.  Oh yes.</p>
<p>Cue a kernel panic when grub couldn&#8217;t find the root partition.  Oh Chris, how SMRT!  The physical box doesn&#8217;t have a CD/DVD drive (it&#8217;s meant to be a headless box) but luckily it does have USB ports, and I had a spare screen and keyboard about, and I happeend to have a 4GB USB thumb drive in my laptop bag.  A quick Google search turned up Pendrivelinux.com and a handy <a href="http://www.pendrivelinux.com/usb-centos-5-live-install-via-windows/" target="_blank">guide</a> to getting CentOS 5 working on USB.  I already had a CentOS 5.2 Live CD image on my hard drive, so a quick upload of the thumb drive contents, a quick download of the <a href="https://fedorahosted.org/liveusb-creator/" target="_blank">Fedora LiveUSB Creator</a> and I was in business!</p>
<p>It was a pretty simple recovery.  I had to unmount and remount the LVs becuase CentOS Live CD mounted them read-only, but that was easy enough &#8211; the device mapper nodes were all there and sensibly named too, so it was pretty intuitive.  The I just had to edit the LV names in /boot/grub/grub.conf, /etc/fstab and /etc/mtab.  For good measure I removed the duplicate entry in /etc/blkid/blkid.tab too.</p>
<p>Reboot, pull out the USB drive at the BIOS screen and a few moment later, there was my host back in the land of the serving. Phew!</p>
<p>A lucky escape this time, but it shows the risk of unintended consequences.  The sooner I get KVM sorted out, and all the real work done in VM guests in LVs, the better, because at least then I&#8217;ll be able to make a snapshot before I try anything like a sysadmin task!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thatchrisbrown.com/2009/usb-centos-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In theory &#8211; migrating from Xen to KVM under CentOS 5.3</title>
		<link>http://www.thatchrisbrown.com/2009/in-theory-migrating-from-xen-to-kvm-under-centos-5-3/</link>
		<comments>http://www.thatchrisbrown.com/2009/in-theory-migrating-from-xen-to-kvm-under-centos-5-3/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 14:56:59 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[virtualisation]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[virtualization]]></category>
		<category><![CDATA[xen]]></category>

		<guid isPermaLink="false">http://www.thatchrisbrown.com/?p=107</guid>
		<description><![CDATA[I'm advance planning my migration of live services from Xen VMs to KVM VMs on the same physical box, with as little downtime as [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2009%2Fin-theory-migrating-from-xen-to-kvm-under-centos-5-3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thatchrisbrown.com%2F2009%2Fin-theory-migrating-from-xen-to-kvm-under-centos-5-3%2F&amp;source=thatchrisbrown&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I have a CentOS 5.3 (actually a CentOS 5.2 build upgraded in yum, but that&#8217;s not terribly important) x86_64 machine that is in fact a Xen hypervisor kernel with said CentOS 5.3 running as the dom0 (service VM), and currently four guest VMs also running CentOS 5.2 x86_64, upgraded to CentOS 5.3 with yum.  This was a kind of interesting project in itself, in that I used the Gitco repos in order to get Xen 3.3.1 on the CentOS build, and I had to do some hackery of the Xen and stock CentOS networking scripts to make things work.  The box doesn&#8217;t use Xen network scripts and xenbr0, because they broke pretty badly with bonded dual NICs.  It has a fairly standard Ethernet bond setup going, then a patched RH network script so bridges don&#8217;t init before the bond, a standard Linux bridge br0, which all my Xen vifs attach to, and a virbr0 which doesn&#8217;t have any physical NICs attached, but does have an IP address and dhcpd running against it, so I have a place to quickly fire up new VM guests without having to assign network addresses.</p>
<p>This complexity lead to a few problems, partly during installation, when I ended up temporarily having to go wiht a non-Xen kernel in order to update bits and ipeces and set up repos so I could go back to a Xen kernel, and when yum wanted to update to kernel-xen-2.6.18-128.1.10.el5 and like a trusting fool I let it, and promptly had no running VMs on the next reboot.  Hacking grub back to 2.6.18-128.1.6.el5xen seemed to sort it, and it never got changed from there.</p>
<p>Actually, to tell the trust, I also have another machine built a similar way, <em>sans</em> CentOS 5.3 upgrade.  This one was meant to potentially be a home to a windows machine, or most likely a Linux MCE installation running in  a non-PV guest.  That one didn&#8217;t get installed yet, and has been sitting under my desk for many a month, waiting for cabling.  Oops.</p>
<p>My guest DomUs are living in Xen virtual disks which are inside LVM logical volumes as far as the dom0 is concerned.  If I&#8217;d been smarter, I might have set up three LVs for each domU &#8211; one for /boot, one swap and one for /, so that I cold more easily manage them from not only the guest domU, but also the dom0 if the domU was offline for any reason.</p>
<p>The increased exposure KVM is getting in RHEL 5.4 is making me wonder if all this Xen tinkering is worth it.  My machine only runs Linux guests, and then only really for a bit of process separation security.  Given that the dom0 has to do a bit of service work for guest domUs anyway, and it seems that this involves a bit of context switching overhead, I don&#8217;t see that doing the hypervisor function in the kernel is going to be a problem for me, especially on that currently unused box, which is going to be a home all-in-one media, file/print, NATting, caching and bandwidth arbitrating machine.  As I was going to just accept doing all the networking for that (including the firewall/NAT/bandwidth and some VPN stuff) in the dom0 instead of making the Xen networking even more complicated with dual virtual NICs and a virtual firewall box, I guess just making all that work in plain old Linux and then loading up a kernel module when I want a media centre guest VM (yes, I know I could just be less lazy and make all the bits of Linux MCE work under CentOS natively, but starting a VM and installing an OS-up image for LMCE seems like a good thing) installing makes a bit of sense.</p>
<p>The currently unused machine isn&#8217;t so bad &#8211; as it currently has no VMs and didn&#8217;t get the 5.2/5.3/Gitco hybrid horror treatment, I could just strip Gitco repo, group uninstall Virtualisation (sorry Virtuali<strong>z</strong>ation), and boot it as a regular Linux kernel, do the networkingy bits (and make better use of my rather rubbish 1.5Mb/s of patchy ADSL) and then worry about that media server when the time is right.  The dual-NIC networkign will be far easier &#8211; one outside one inside, attach a separate bridge to each and I could then attach VMs to the &#8220;public&#8221; or &#8220;private&#8221; bridges and the host OS will iptables them like any other hosts.  Great!</p>
<p>It&#8217;s that first server that is going to be &#8216;interesting&#8217;.  Fedora&#8217;s virt-v2v is a ways off yet, so I&#8217;ve got to think of smart ways of moving painlessly from Xen to KVM without losing services for long.  The current outline plan goes something like:</p>
<ol>
<li>Install a plain old Linux kernel into each VM guest</li>
<li>Install a plain old Linux kernel into the current dom0</li>
<li>Make new LVM logical volumes for guest VMs &#8211; <em>possibly three each for /boot, swap and /</em></li>
<li>Modify guest VM grub config to default the plain old Linux kernel</li>
<li>Shutdown guest VMs</li>
<li>Reboot dom0 as a plain old Linux kernel, albeit with KVM support loaded</li>
<li>Make any networking changes required</li>
<li>Create new KVM virtual machine images in the logival volumes</li>
<li>Stop the new KVM guests</li>
<li>Mount guests Xen virtual &#8216;disks&#8217; (actually just some partitions I think, not full bootable disk images) on loopback in the dom0</li>
<li>dd the contents of the Xen partitions into the new LVM logical volumes, overwriting the guest images created at step 7</li>
<li>Start the KVM guests</li>
<li>Panic when it goes wrong (had to be step 13, didn&#8217;t it?)</li>
</ol>
<p>I&#8217;m hoping that the fact I already do the networking outside of Xen, and just use standard Linux bridging on and the libvirt virbr0, will mean a slightly easier migration &#8211; all I have to do is get my instances booting off a standard kernel instead of a Xenified one, and inside a different virtual disk format.</p>
<p>I&#8217;ll still need my standard-breaking networking patch to enable bonds before bridges though.  Hopefully RH fix that one in RHEL 5.4 so CentOS picks it up in the next release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thatchrisbrown.com/2009/in-theory-migrating-from-xen-to-kvm-under-centos-5-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
