<?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>JoshPrewitt.com</title>
	<atom:link href="http://joshprewitt.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://joshprewitt.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 13 Aug 2012 20:39:59 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Using Sed to add a new line in Mac Terminal</title>
		<link>http://joshprewitt.com/2012/08/13/using-sed-to-add-a-new-line-in-mac-terminal/</link>
		<comments>http://joshprewitt.com/2012/08/13/using-sed-to-add-a-new-line-in-mac-terminal/#comments</comments>
		<pubDate>Mon, 13 Aug 2012 20:39:59 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Non-Website Related]]></category>
		<category><![CDATA[Tech Stuff]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=139</guid>
		<description><![CDATA[This was driving me crazy until I hunted down the correct syntax. The following will replace a semicolon with a new line in Terminal for Mac sed -e &#8216;s/;/\&#8217;$'\n/g&#8217; /tmp/blah]]></description>
			<content:encoded><![CDATA[<p>This was driving me crazy until I hunted down the correct syntax. The following will replace a semicolon with a new line in Terminal for Mac</p>
<p>sed -e &#8216;s/;/\&#8217;$'\n/g&#8217; /tmp/blah</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2012/08/13/using-sed-to-add-a-new-line-in-mac-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>dsh (Dancer&#8217;s Shell / Distributed Shell) and you</title>
		<link>http://joshprewitt.com/2011/12/11/dsh-dancers-shell-distributed-shell-and-you/</link>
		<comments>http://joshprewitt.com/2011/12/11/dsh-dancers-shell-distributed-shell-and-you/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 19:20:56 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Non-Website Related]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=137</guid>
		<description><![CDATA[dsh is an awesome tool for administering pools of servers where you would just want to run the same few commands on each one. I run Mac OSX locally, so I&#8217;ll write the article from that perspective: Install DSH on &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/12/11/dsh-dancers-shell-distributed-shell-and-you/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>dsh is an awesome tool for administering pools of servers where you would just want to run the same few commands on each one. I run Mac OSX locally, so I&#8217;ll write the article from that perspective:</p>
<h2>Install DSH on a Mac</h2>
<p>First and foremost, you need to install dsh. The downloads page for the project is a nightmare (<a href="http://www.netfort.gr.jp/~dancer/software/downloads/list.cgi">http://www.netfort.gr.jp/~dancer/software/downloads/list.cgi</a>), but you basically want the latest version of libdshconfig and dsh. At the time of this writing, that would be 0.20.13 and 0.25.9 respectively.</p>
<p>I just dropped them into /tmp for the time being:</p>
<pre>cd /tmp
wget http://www.netfort.gr.jp/~dancer/software/downloads/libdshconfig-0.20.13.tar.gz
wget http://www.netfort.gr.jp/~dancer/software/downloads/dsh-0.25.9.tar.gz</pre>
<p>Then go through the normal install from source process, starting with libdshconfig</p>
<pre>cd /tmp
tar -zxvf libdshconfig-0.20.13.tar.gz
cd libdshconfig-0.20.13
./configure
make
sudo make install</pre>
<pre>cd /tmp
tar -zxvf dsh-0.25.9.tar.gz
 cd dsh-0.25.9
 ./configure
 make
 sudo make install</pre>
<p>now you should be able to run dsh and have it return an error that no machine was specified:</p>
<pre>josh.prewitt$ dsh
dsh: no machine specified</pre>
<h2>Configuring DSH</h2>
<p>You will want to setup RSA keys for your user on each of the machines that you want to log in to remotely so that you are not prompted for a password. (This is outside the scope of this article, there are about a gazillion different articles online that will teach that). Once the keys are in place, you will want to create group files. You will need to mkdir -p ~/.dsh/group and then create a text file in the group directory that lists the machines you want to connect to. Here is an example:</p>
<pre>josh.prewitt$ pwd
/Users/josh.prewitt/.dsh/group</pre>
<pre>josh.prewitt$ cat web 
josh@server1.mywebsite.com
josh@server2.mywebsite.com
josh@server3.mywebsite.com</pre>
<p>This sets the user and the host that you want in the &#8220;web&#8221; group.</p>
<p>Next up is a very important configuration change. dsh wants to use rsh by default instead of ssh. You will need to edit /usr/local/etc/dsh.conf as an Administrator to change that. Just change the line:</p>
<pre>remoteshell =rsh</pre>
<p>to read:</p>
<pre>remoteshell =ssh</pre>
<p>Save the file, and you are ready to go.</p>
<h2>Actually using DSH</h2>
<p>Ok, now for the magic. Assuming you have a group named &#8216;web&#8217;, you could run:</p>
<pre>dsh -c -g web -M 'uname -a'</pre>
<p>This will return the results of uname -a for each server. The -c flag does it concurrently instead of going to each machine one at a time. The -M flag tells it to list the machine name by the response.</p>
<h2>Other stuff</h2>
<p>I prefer to always see the machine name, so instead of always specifying -M, I created a new file at ~/,dsh/dsh.conf and included the line &#8220;showmachinenames=1&#8243;. You can set other options here too. For example, say you use a non standard ssh port. You could specify on the command line with -o:</p>
<pre>dsh -c -g web -o "-p 2222" 'uname -a'</pre>
<p>OR, you can set dsh to always use a different port by adding the line &#8220;remoteshellopt=-p 2222&#8243; to your configuration file.</p>
<p>Other sources if my article didn&#8217;t make sense:</p>
<p>Check out Racker Hacker&#8217;s post: <a href="http://rackerhacker.com/2010/01/20/crash-course-in-dsh/">http://rackerhacker.com/2010/01/20/crash-course-in-dsh/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/12/11/dsh-dancers-shell-distributed-shell-and-you/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bash One Liner that uses multiple variables</title>
		<link>http://joshprewitt.com/2011/11/17/bash-one-liner-that-uses-multiple-variables/</link>
		<comments>http://joshprewitt.com/2011/11/17/bash-one-liner-that-uses-multiple-variables/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 06:26:21 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Non-Website Related]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=133</guid>
		<description><![CDATA[I&#8217;m not sure if this particular post will come in handy to a lot of people, but my bash scripting is still pretty weak and I think the best way to commit this to memory will be to write a &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/11/17/bash-one-liner-that-uses-multiple-variables/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure if this particular post will come in handy to a lot of people, but my bash scripting is still pretty weak and I think the best way to commit this to memory will be to write a short post on it.</p>
<p>I find myself doing one line &#8220;for&#8221; statements from the command line all the time to make quick loops. Maybe I need to loop through a list of servers and delete them all, maybe I need to ping a group of servers and see if they all reply, maybe I need to build a lot of servers of different flavors at once, etc.</p>
<p>Whatever the reason, I have occasionally come across the need for multiple variables in my loop. For example, let&#8217;s say that I have a list of data like this:</p>
<pre>| 11111 | Orange         | ACTIVE | 50.57.169.1   | 10.183.199.1 |
| 11112 | Apple        | ACTIVE | 50.57.169.2    | 10.183.199.2 |
| 11113 | Banana       | ACTIVE | 50.57.158.3   | 10.183.199.3 |
| 11114 | Cherry         | ACTIVE | 50.57.159.4    | 10.183.194.4  |
| 11115 | Pineapple    | ACTIVE | 50.57.159.5   | 10.183.192.5 |
| 11116 | Melon         | ACTIVE | 50.57.149.6   | 10.183.194.6 |
| 11117 | Peach       | ACTIVE | 50.57.162.7    | 10.183.195.7 |
| 11118 | Coconut      | ACTIVE | 50.57.162.8    | 10.183.195.8 |</pre>
<p>That format may look familiar if you use the Python Command Line tool for Rackspace Cloud Servers (http://pypi.python.org/pypi/python-cloudservers/1.2)</p>
<p>Now let&#8217;s say that I want to create an image of the 8 servers listed above. I would usually put the above table in a tmp file, and just call out the Server ID. Something like:</p>
<pre>$ for x in `awk '{print $2}' /tmp/servers`; do myservers image-create $x Image-of-$x; done</pre>
<p>This gets the job done, but it is pretty ugly. I end up with image names like &#8220;Image-of-11114&#8243;, which can be more difficult to read than &#8220;Image-of-Cherry&#8221;</p>
<p>Using something like the following, I can allow multiple variables in my for loop:</p>
<pre>$ cat /tmp/servers | while read x; do var1=`echo $x | awk '{print $2}'`; var2=`echo $x | awk '{print $4}'`; myservers image-create $var1 Image-of-$var2; done</pre>
<p>The whole idea is to read the full line into a variable (x) and then loops through the line assigning a specific variable to whichever fields I need.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/11/17/bash-one-liner-that-uses-multiple-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading to PHP 5.3 on Centos 5.5</title>
		<link>http://joshprewitt.com/2011/10/07/upgrading-to-php-5-3-on-centos-5-5/</link>
		<comments>http://joshprewitt.com/2011/10/07/upgrading-to-php-5-3-on-centos-5-5/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 05:04:56 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=130</guid>
		<description><![CDATA[The latest version of wordpress requires that you be running at least version 5.3 of php. This poses a problem for a lot of people who are still running 5.1 or 5.2 since that was the latest version available in &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/10/07/upgrading-to-php-5-3-on-centos-5-5/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>The latest version of wordpress requires that you be running at least version 5.3 of php. This poses a problem for a lot of people who are still running 5.1 or 5.2 since that was the latest version available in the CentOS or Epel repositories for a long time.</p>
<p>Fortunately, php 5.3 is now available in the CentOS Base repo, so upgrading shouldn&#8217;t be too much of a nightmare. Here is what I did:</p>
<p>First and foremost, hopefully you are using a Cloud Hosting provider like Rackspace that will allow you to take a quick image of the server before you go messing with it. I strongly encourage you to have a recent backup of the server available, just in case. Once you have your image, move on:</p>
<p>First, you want to know what modules you currently have installed. The easiest way to do that would be to query rpm:</p>
<pre>rpm -qa | grep -i php &gt; ~/php52</pre>
<p>This will query all packages for php and output to a file in your home directory named php52. For example, on one of my old servers, that list looked like this:</p>
<pre>php-pecl-memcache-2.2.3-1.el5_2
php-5.2.10-1.el5.centos
php-devel-5.2.10-1.el5.centos
php-pear-1.4.9-6.el5
php-common-5.2.10-1.el5.centos
php-cli-5.2.10-1.el5.centos
php-mysql-5.2.10-1.el5.centos
php-xml-5.2.10-1.el5.centos
php-mcrypt-5.2.9-2.el5.centos.3
php-mhash-5.1.6-15.el5.centos.1
php-pdo-5.2.10-1.el5.centos
php-gd-5.2.10-1.el5.centos
php-mbstring-5.2.10-1.el5.centos</pre>
<p>Now, you will want to make a copy of that list, and modify the names to be php53.</p>
<pre>cp ~/php52 ~/php53</pre>
<p>Using a text editor, open up php53 and remove from the major version to the end of the line, then replace &#8216;php&#8217; with &#8216;php53&#8242;. For example, the above list became this:</p>
<pre>php53-pecl-memcache
php53
php53-devel
php53-pear
php53-common
php53-cli
php53-mysql
php53-xml
php53-mcrypt
php53-mhash
php53-pdo
php53-gd
php53-mbstring</pre>
<p>Now you have your list of what was installed (php52) and what you want installed (php53). Remove the old version of php:</p>
<pre>yum remove `cat ~/php52`</pre>
<p>(Note that those are backticks before cat and after php52. The backtick is the weird looking character next to the number 1 on your keyboard.)</p>
<p>Now that all of those packages are removed, install the php53 ones.</p>
<pre>yum install `cat ~/php53`</pre>
<p>Expect some of the packages to fail. Some modules are now built into php53 common (mhash for one, I believe) and others simply don&#8217;t have a php53 package available yet (pear). Make note of the ones that yum complained were not available.</p>
<p>Any packages that were listed as not available will need to be examined one at a time to determine if you can use the old version, if it is deprecated, etc.</p>
<p>Once you are done, just restart apache and you should be good to go.</p>
<p>The one gotcha I ran into is that on some old custom sites I wrote sloppy code and used shorthand to open php code blocks (I used &lt;? instead of &lt;?php ) In the php.ini that comes with php53 from Centos, they have disabled this shorthand tag. To resolve this, just open up php.ini in a text editor and find the line for short_open_tag and turn it on. You can also use sed to make the change:</p>
<pre>sed -i s/'short_open_tag = Off'/'short_open_tag = On'/ /etc/php.ini</pre>
<p>That should be it! The nice part about doing it this way is that if you screw something up, you can just yum install `cat ~/php52` to return all of your old packages.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/10/07/upgrading-to-php-5-3-on-centos-5-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up MemCache to handle PHP Sessions for a Web Cluster</title>
		<link>http://joshprewitt.com/2011/07/03/setting-up-memcache-to-handle-php-sessions-for-a-web-cluster/</link>
		<comments>http://joshprewitt.com/2011/07/03/setting-up-memcache-to-handle-php-sessions-for-a-web-cluster/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 21:13:32 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=122</guid>
		<description><![CDATA[A really common issue when people start to look towards scaling horizontally (adding on additional web/app servers) is session persistence. Rackspace Cloud Load Balancers as a Service offers session persistence for HTTP (Port 80) traffic. This is done by the &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/07/03/setting-up-memcache-to-handle-php-sessions-for-a-web-cluster/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>A really common issue when people start to look towards scaling  horizontally (adding on additional web/app servers) is session  persistence.</p>
<p>Rackspace Cloud Load Balancers as a Service offers session  persistence for HTTP (Port 80) traffic. This is done by the LB injecting  a cookie into the response that specifies a node. The next time the  user requests a page, they send the cookie and the load balancer reads  it then directs traffic to the correct node.</p>
<p>This Session Persistence does NOT work on HTTPS (Port 443) because  the LB is not able to terminate SSL. This means that the LB has no way  to read the cookie being sent by the browser to achieve persistent  sessions (and for that matter, no way to inject the cookie either).</p>
<p>Even if you are just load balancing port 80 traffic, what happens if  you want to change or modify some code on a node? If you pull it out of  rotation, it will go into a draining state where existing sessions can  still connect; Not exactly a fast solution.</p>
<p>The solution to Load Balancing HTTPS or simply to load balancing  without having to worry about session persistence at the LB is to store  your sessions somewhere else. But where? You can store them in a  Database if you want, but more than likely your database is busy enough  as it is. A better solution would be to store the sessions on a separate  memcache server.</p>
<p>For the uninitiated, memcache was originally created by livejournal.  What it does is fairly simple: Gives you control over a certain amount  of memory on the server so that you can store anything you want in  there. This allows you to retrieve it much faster than if you had to  read from disk. You can store DB query results, pages, or practically  anything. We are going to store sessions.</p>
<p>This is assuming a brand new install of CentOS 5.5 from Rackspace Cloud Servers. First, let&#8217;s setup the memcache server.</p>
<h2>MemCache Server</h2>
<p>You will need the EPEL repo, so run this to install it:</p>
<pre>rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm</pre>
<p>Now that the EPEL repo is available, you can use yum to install it  (while we are doing this, might as well install vim and tcpdump so we  can watch it working)</p>
<pre>yum install memcached tcpdump vim-enhanced</pre>
<p>Next up, we need to setup the very simply config file that memcache  uses. It will be at /etc/sysconfig/memcached. Here is mine:</p>
<pre>PORT="11211"
 USER="memcached"
 MAXCONN="1024"
 CACHESIZE="1500"
 OPTIONS="-l 10.3.3.3"</pre>
<p>The variables are pretty straight forward: Port (default for memcache  is 11211) User, Maximum Connections, Cache Size (How much memory in MB  you are allowing memcache access to), Options (I specified -l for listen  and told it to listen on the private IP address only. This would be the  IP of the Memcache server, NOT the web server(s))</p>
<p>Next up, start the daemon and make it start on boot.</p>
<pre>/etc/init.d/memcached start &amp;&amp; chkconfig memcached on</pre>
<p>Next up, secure the memcache server. We don&#8217;t want to allow just  anyone on the private network access to memcache. A rule set like this  should do. Note that 10.1.1.1 and 10.2.2.2 would represent my Web Server  Private IPs. If you don&#8217;t know the difference between -A and -I read up  on it <a title="Troubleshooting iptables on Rackspace Cloud Servers" href="http://joshprewitt.com/2010/09/03/troubleshooting-iptables-on-rackspace-cloud-servers/">Here</a></p>
<pre>iptables -I INPUT -p tcp --dport 11211 -s 10.1.1.1 -j ACCEPT
 iptables -I INPUT -p tcp --dport 11211 -s 10.2.2.2 -j ACCEPT
 iptables -A INPUT -p tcp --dport 11211 -j DROP</pre>
<p>That&#8217;s it for the memcache server. Now all you have to do is setup the web server to write the sessions to the correct place.</p>
<h2>The Web Server</h2>
<p>Again, this is assuming a stock Centos 5.5 server from Rackspace, so we have to install what we need.</p>
<pre>yum install httpd php php-pecl-memcache vim-enhanced</pre>
<p>Now you can test that php has the memcache module loaded in.</p>
<pre>php -m</pre>
<p>Look for memcache; it should be there.</p>
<p>Start apache and make it start on boot</p>
<pre>/etc/init.d/httpd start &amp;&amp; chkconfig httpd on</pre>
<p>Open up iptables on the websevrer:</p>
<pre>iptables -I INPUT -p tcp --dport 80 -j ACCEPT
</pre>
<p>Now we need to edit the php configuration file to tell it that we want to save sessions to memcache, and where our memcache server is. This file will be at /etc/php.ini.</p>
<p>Look for these 2 lines:</p>
<pre>session.save_handler = files
session.save_path = "/var/lib/php/session"</pre>
<p>You will change these to (where 10.3.3.3 is your memcache servers IP address:</p>
<pre>session.save_handler = memcache
session.save_path = "tcp://10.3.3.3:11211"</pre>
<p>This simply tells php to write sessions to memcache and gives the address and port of the memcache server.</p>
<p>Now restart apache so that this will take effect:</p>
<pre>/etc/init.d/httpd restart</pre>
<p>All that is left to do now is test it. I created a file named sessiontest.php in /var/www/html that contains:</p>
<pre>&lt;?php
session_start();
$_SESSION['test']="This is my Session!";
?&gt;</pre>
<p>Start up a tcpdump on the memcaceh server listening for 11211:</p>
<pre>tcpdump -i eth1 port 11211</pre>
<p>Then access your test page at http://YourIpAddress/sessiontest.php. You will see that there is activity on the memcache server when the page is activated. If you really want to see the test in action, start up a 2nd web server with the exact same configuration, but change the script to:</p>
<pre>&lt;?php
session_start();
echo $_SESSION['test'];
?&gt;</pre>
<p>You will see it echo out the session that was created on the 1st web server.</p>
<p>That about covers it, Leave a message if you have any questions!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/07/03/setting-up-memcache-to-handle-php-sessions-for-a-web-cluster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a Rackspace Cloud Server from Cloud Files Manually</title>
		<link>http://joshprewitt.com/2011/03/31/building-a-rackspace-cloud-server-from-cloud-files-manually/</link>
		<comments>http://joshprewitt.com/2011/03/31/building-a-rackspace-cloud-server-from-cloud-files-manually/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 05:42:01 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Non-Website Related]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=112</guid>
		<description><![CDATA[This article will cover how to manually take image files in Cloud Files and build them to a new Cloud Server. This will ONLY work for Linux. I don&#8217;t have a clue how to make this work on Windows :-p &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/03/31/building-a-rackspace-cloud-server-from-cloud-files-manually/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This article will cover how to manually take image files in Cloud Files and build them to a new Cloud Server. This will ONLY work for Linux. I don&#8217;t have a clue how to make this work on Windows :-p</p>
<p>There can be several reasons why you would want to do this. Maybe you want to manually move from a US datacenter to a UK datacenter. Maybe you have an account and your boss/co-worker/friend has an account and you want to share images. Whatever the reason, these are the steps to make it work.</p>
<p>Credit where credit is due: The idea for this was originally published at <a href="http://failverse.com/manually-creating-a-cloud-server-from-a-cloud-files-image/" target="_blank">http://failverse.com/manually-creating-a-cloud-server-from-a-cloud-files-image/</a> (Thanks Jordan and Dewey). My article will just cover doing it using curl instead of wget, and some of the potential pitfalls not covered in their article.</p>
<p>So here goes! First things first, you will need to start up a new stock server in the receiving account that is the EXACT same image as the server that the image was built from. For example, if the image in Cloud Files was originally taken from a server running CentOS 5.5, you will build a stock image that is running CentOS 5.5 in the receiving account. Login to the new server you built.</p>
<p>Make a backup of the new server&#8217;s /etc directory. You will need this later:</p>
<pre>cp -a /etc /etc.bak</pre>
<p>If necessary, install curl (Some distros of linux come with it, others don&#8217;t).</p>
<p>Authenticate to the Cloud Files Account where the image is stored:</p>
<pre>curl -D - -H "X-Auth-User: YourUserName" -H "X-Auth-Key: YourAPIKey" https://auth.api.rackspacecloud.com/v1.0</pre>
<p>After you run that, it will spit out a list of names and values, like this:</p>
<pre>HTTP/1.1 204 No Content
Date: Wed, 30 Mar 2011 04:15:28 GMT
Server: Apache/2.2.3 (Mosso Engineering)
X-Storage-Url: https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-1234567890
X-Storage-Token: 63ea9670-c80f-402d-9657-1234567890
X-CDN-Management-Url: https://cdn1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-68b8ee123456
X-Auth-Token: 63ea9670-c80f-402d-9657-c59bdb123456
X-Server-Management-Url: https://servers.api.rackspacecloud.com/v1.0/123456
Content-Length: 0
Connection: close
Content-Type: application/octet-stream</pre>
<p>We care about X-Storage-URL (That is where the image files are stored) and X-Storage-Token (This is your authentication token that lets you actually download stuff). Now let&#8217;s see a list of all of the image files in the account. Replace your Storage Token and your URL below. Don&#8217;t forget the /cloudservers at the end of the URL.</p>
<pre>curl -H "X-Storage-Token: 63ea9670-c80f-402d-9657-1234567890" https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-1234567890/cloudservers
SpotImage_20110307_202634_cloudserver657824.tar.gz.0
SpotImage_20110307_202634_cloudserver657824.yml
TestCopy1_20100910_193142_cloudserver330148.tar.gz.0
TestCopy1_20100910_193142_cloudserver330148.yml
delweb1ssl_20110326_054323_cloudserver710521.tar.gz.0
delweb1ssl_20110326_054323_cloudserver710521.tar.gz.1
delweb1ssl_20110326_054323_cloudserver710521.yml</pre>
<p>As you can see above, there are several files associated with each image. All of the data is stored in the .tar.gz files. The .yml file is a configuration file that for this article we don&#8217;t care about. You will see that some of the images have more than one .tar.gz file. This happens when the image is larger than 5GB and it gets chunked into multiple objects in Cloud Files. We will assume that we are working with a chunked image because that will make it just a little bit harder.</p>
<p>Let&#8217;s grab the delweb1ssl image. Grab the first chunk like this:</p>
<pre>cd /
curl -H "X-Storage-Token: 63ea9670-c80f-402d-9657-1234567890"  https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-1234567890/cloudservers/delweb1ssl_20110326_054323_cloudserver710521.tar.gz.0 &gt; dlimage.tar.gz.0</pre>
<p>This can be up to 5GB, so it may take a little while. Next up, download the 2nd chunk (and then third, fourth, etc)</p>
<pre>curl -H "X-Storage-Token: 63ea9670-c80f-402d-9657-1234567890"   https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-1234567890/cloudservers/delweb1ssl_20110326_054323_cloudserver710521.tar.gz.1  &gt; dlimage.tar.gz.1</pre>
<p>Note that we are just changing what file we are getting and what we are calling it locally. Do this for as many .tar.gz files as there are in the account.</p>
<p>Now that we have all of the images downloaded, cat them together to make one big image</p>
<pre>cat dlimage.tar.gz* &gt; myimage.tar.gz
rm -f dlimage.tar.gz*</pre>
<p><strong>***POTENTIAL PITFALL***</strong><br />
If the new server isn&#8217;t large enough to hold the stock image, the downloaded images from Cloud Files, AND the concatenated image, you may run out of disk space. For this reason, you might want to just start with a huge 8GB (320GB Hard Drive) or 16GB (640GB Hard Drive) server and downsize after you are done with this.</p>
<p>Now that we have the one big image, we need to extract that out onto the filesystem. More than likely, you will need the newest version of tar to have the &#8211;hard-dereference option available. Your choices are to either download tar and install it from source, or grab a fully compiled version of tar here. (Thanks again Jordan). We&#8217;ll use the compiled version because it is just easier.</p>
<pre>wget http://joshprewitt.com/scripts/static_tar
chmod +x static_tar
./static_tar --strip-components=2 --hard-dereference -xpf myimage.tar.gz -C /</pre>
<p>This can take awhile.</p>
<p>Remember when we backed up /etc above? (You did that, right?) Now we will want to bring that back in. However, is we just completely overwrite the /etc directory that we just extracted we will lose things like our users, groups, iptables, etc because they will be overwritten with the default values. To make sure we always have the /etc directory from the tar available, save that as another backup directory:</p>
<pre>cp -a /etc /etc.tar</pre>
<p>Ok, now we have 3 etc directories:<br />
/etc = The version off of the backup<br />
/etc.bak = The stock image /etc directory with all defaults<br />
/etc.tar = A backup copy of the etc directory from the tarball</p>
<p>From here you can manually bring over your network config files and anything else necessary from the default image, but I prefer to just replace the entire /etc directory with stock data and bring over what I need from the /etc.tar directory later.</p>
<pre>cp -a /etc.bak/* /etc/
cp /etc.tar/passwd /etc.tar/shadow /etc.tar/group /etc/.</pre>
<p>Depending on what distro you are running, you will also want to grab your iptables rules from /etc.tar In anything RHEL based it would be:</p>
<pre>cp /etc.tar/sysconfig/iptables /etc/sysconfig/iptables</pre>
<p>That&#8217;s pretty much it. Cross your fingers, reboot and see if it comes back up!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/03/31/building-a-rackspace-cloud-server-from-cloud-files-manually/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rackspace Cloud Load Balancer as a Service Cheater Script</title>
		<link>http://joshprewitt.com/2011/03/30/rackspace-cloud-load-balancer-as-a-service-cheater-script/</link>
		<comments>http://joshprewitt.com/2011/03/30/rackspace-cloud-load-balancer-as-a-service-cheater-script/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 04:34:54 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Non-Website Related]]></category>
		<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=109</guid>
		<description><![CDATA[Rackspace Cloud Load Balancer as a Service is awesome. It is an amazing product that makes load balancing sites really easy and abstracts away having to setup and configure one on your own. As of right now, it is only &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/03/30/rackspace-cloud-load-balancer-as-a-service-cheater-script/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Rackspace Cloud Load Balancer as a Service is awesome. It is an amazing product that makes load balancing sites really easy and abstracts away having to setup and configure one on your own. As of right now, it is only available via the API while a full blown GUI is being developed for the control panel. The API docs are very good and can be found at <a href="http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf" target="_blank">http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf</a></p>
<p>UPDATE: Forget this exists. Caleb Groom has an awesome project on github that uses python and will let you manage your Load Balancers. <a href="https://github.com/calebgroom/clb">https://github.com/calebgroom/clb</a></p>
<p>Creating a Load Balancer requires you to authenticate with your Username and API key, and then create an XML request that you send that has all of your settings in it. I made a very, very simply bash script that will write the XML for you. I&#8217;m not a programmer. This can be improved immensely and there is no error catching or validation that what you type in is right.</p>
<p>Anyway, here is the script:</p>
<pre>#! /bin/bash
echo "What is the Auth Token?"
read AUTH
echo "What is the Account Number?"
read ACCT
echo "Choose a Location (dfw or ord)"
read LOC
echo "What type of IP do you want allocated to this server? (PUBLIC or PRIVATE)"
read VIP
echo "Load Balancer Name (AlphaNumeric, No Spaces or Underscores)"
read LBNAME
echo "What Port should the Load balancer listen on? (21, 80, 143, 110, 389, 636, 443, 993, 25)"
read LBPORT
echo "What Protocol should the Load Balancer Use (FTP, HTTP, IMAPv4, POP3, LDAP, LDAPS, HTTPS, IMAPS, POP3S, SMTP)"
read LBPROTO
echo "LB Algo (LEAST_CONNECTIONS, RANDOM, ROUND_ROBIN, WEIGHTED_LEAST_CONNECTIONS, WEIGHTED_ROUND_ROBIN)"
read LBALGO

echo "How Many nodes?"
read NUMNODES
set NODES=""
for (( I=1 ; I&lt;=$NUMNODES ; I++))
do
echo "Node $I Address"
read NODEIP
echo "Node $I port"
read NODEPORT
echo "Node $I Weight"
read NODEWEIGHT
NODES=$NODES""
done

SENDCURL="curl -H \"X-Auth-Token: $AUTH\" -H \"content-type: application/xml\" -d '$NODES' -X POST https://$LOC.loadbalancers.api.rackspacecloud.com/v1.0/$ACCT/loadbalancers"

echo $SENDCURL
</pre>
<p>So before you run that you will need to authenticate and get your Auth token. to do that, run the following curl:</p>
<p>curl -D &#8211; -H &#8220;X-Auth-User: YourUsername&#8221; -H &#8220;X-Auth-Key: YourAPIKey&#8221; https://auth.api.rackspacecloud.com/v1.0</p>
<p>After you run that, it will spit out a list of names and values, like this:</p>
<p>HTTP/1.1 204 No Content<br />
Date: Wed, 30 Mar 2011 04:15:28 GMT<br />
Server: Apache/2.2.3 (Mosso Engineering)<br />
X-Storage-Url: https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-1234567890<br />
X-Storage-Token: 63ea9670-c80f-402d-9657-1234567890<br />
X-CDN-Management-Url: https://cdn1.clouddrive.com/v1/MossoCloudFS_6f597497-4986-44ea-9081-68b8ee123456<br />
X-Auth-Token: 63ea9670-c80f-402d-9657-c59bdb123456<br />
X-Server-Management-Url: https://servers.api.rackspacecloud.com/v1.0/123456<br />
Content-Length: 0<br />
Connection: close<br />
Content-Type: application/octet-stream</p>
<p>You will need the Auth Token. In the made up example above that would be 63ea9670-c80f-402d-9657-c59bdb123456. You will also need your account number. In the example above that is listed under X-Server-Management. In the fake example that is 123456.</p>
<p>Once you have those, invoke the bash script above with something like</p>
<p>sh makelb.sh</p>
<p>It will ask you some questions, most of them give you a list of available options. Once it is done asking questions it will spit out the curl command for you to run. Here is an example:</p>
<pre>M0Z8AGY:bin josh.prewitt$ sh makelbass.sh
What is the Auth Token?
63ea9670-c80f-402d-9657-c59bdb123456
What is the Account Number?
123456
Choose a Location (dfw or ord)
ord
What type of IP do you want allocated to this server? (PUBLIC or PRIVATE)
PUBLIC
Load Balancer Name (AlphaNumeric, No Spaces or Underscores)
LB-Name-Test
What Port should the Load balancer listen on? (21, 80, 143, 110, 389, 636, 443, 993, 25)
80
What Protocol should the Load Balancer Use (FTP, HTTP, IMAPv4, POP3, LDAP, LDAPS, HTTPS, IMAPS, POP3S, SMTP)
HTTP
LB Algo (LEAST_CONNECTIONS, RANDOM, ROUND_ROBIN, WEIGHTED_LEAST_CONNECTIONS, WEIGHTED_ROUND_ROBIN)
ROUND_ROBIN
How Many nodes?
3
Node 1 Address
10.1.1.1
Node 1 port
80
Node 1 Weight
1
Node 2 Address
10.2.2.2
Node 2 port
80
Node 2 Weight
1
Node 3 Address
10.3.3.3
Node 3 port
80
Node 3 Weight
1
curl -H "X-Auth-Token: 63ea9670-c80f-402d-9657-c59bdb123456" -H "content-type: application/xml" -d '' -X POST https://ord.loadbalancers.api.rackspacecloud.com/v1.0/123456/loadbalancers</pre>
<p>That&#8217;s it, copy and paste the curl command that it spits out and that will create the Load Balancer for you. Like I said, this is a VERY simple script that I primarily use just for setting up test load balancers. If you improve on it and make it totally awesome drop me a link!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/03/30/rackspace-cloud-load-balancer-as-a-service-cheater-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Rackspace Cloud Load Balancers as a Service to host multiple SSL Sites</title>
		<link>http://joshprewitt.com/2011/03/27/using-rackspace-cloud-load-balancers-as-a-service-to-host-multiple-ssl-sites/</link>
		<comments>http://joshprewitt.com/2011/03/27/using-rackspace-cloud-load-balancers-as-a-service-to-host-multiple-ssl-sites/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 02:39:35 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=96</guid>
		<description><![CDATA[A few days ago I wrote an article about using SNI to host multiple SSL sites on a single IP. This method is excellent, and it works with Rackspace Cloud Load Balancers as a Service very well. The major drawback &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/03/27/using-rackspace-cloud-load-balancers-as-a-service-to-host-multiple-ssl-sites/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>A few days ago I wrote an article about <a href="http://joshprewitt.com/2011/03/11/using-sni-to-host-multiple-ssl-sites-on-a-single-ip-in-apache-using-rackspace-cloud/" target="_blank">using SNI to host multiple SSL sites on a single IP</a>. This method is excellent, and it works with Rackspace Cloud Load Balancers as a Service very well. The major drawback is that if your users are using a browser that does not support SNI, they won&#8217;t get the desired results. I want to first say that I am a huge fan of SNI, and as available IPv4 addresses become fewer and fewer, I think that SNI will be the preferred method of doing this. That being said, a lot of websites simply can not afford to write off anyone with an unsupported browser. For that reason, here are instructions on using Rackspace Cloud Load Balancer as a Service to host multiple SSL sites from the same pool of Web Servers.</p>
<h2>High Level Overview</h2>
<p>A high level overview is that you will have 2 Load Balancers for each site. The 2 Load Balancers will share a single Public IP address. One will listen on port 80 for standard HTTP traffic and the other will listen on port 443 for HTTPS traffic. In my proof of concept below, I will have two sites: test1.com and test2.com, ergo I will have four Load Balancers.</p>
<h2>Create the Load Balancers</h2>
<p>Let&#8217;s create the Load Balancers. Since Rackspace Cloud LoadBalancers as a Service is only available via the API at the time of this writing, that is what we will use.</p>
<p>First we authenticate (Obviously change out your username and API key for the made up values:</p>
<pre>curl -D - -H "x-auth-user: UserName" -H "x-auth-key: ABCDEFG-123456" https://auth.api.rackspacecloud.com/v1.0</pre>
<p>This will return a few headers, the one we care about is X-Auth-Token.</p>
<p>Now using that token we will build a Load Balancer in the datacenter of our choice. For my example, I will build into the DFW datacenter. If you want to build into ORD, just change out &#8216;dfw&#8217; for &#8216;ord&#8217; below.</p>
<p>First up, create an xml file for test1-http. Let&#8217;s call it createtest1-http.xml</p>
<pre>&lt;loadBalancer xmlns="http://docs.openstack.org/loadbalancers/api/v1.0"
name="test1-http"
port="80"
protocol="HTTP"&gt;
&lt;virtualIps&gt;
&lt;virtualIp type="PUBLIC"/&gt;
&lt;/virtualIps&gt;
&lt;nodes&gt;
&lt;node address="10.177.130.14" port="80" condition="ENABLED"/&gt;
&lt;node address="10.177.130.96" port="80" condition="ENABLED"/&gt;
&lt;/nodes&gt;
&lt;/loadBalancer&gt;</pre>
<p>Those values are pretty self explanatory, but you are giving the Load Balancer a name, telling it to listen on port 80 for HTTP traffic, requesting a public IP, and assigning it two nodes that it should send traffic to on port 80 as well.</p>
<p>Now that we have the xml file, let&#8217;s create the Load Balancer. Change out your Auth Code and your Account number in the example below:</p>
<pre>M0Z8AGY:LBaaS josh.prewitt$ curl -H "X-Auth-Token: f3ec3064-c855-4d9d-8291-410cd1098765" -H "content-type: application/xml" -d @createtest1-http.xml -X POST https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123456/loadbalancers</pre>
<pre>{"loadBalancer":{"name":"test1-http","id":156,"protocol":"HTTP","port":80,"algorithm":"RANDOM","status":"BUILD","cluster":{"name":"ztm-n05.lbaas.dfw1.rackspace.net"},"nodes":[{"address":"10.177.130.14","id":4377,"port":80,"status":"ONLINE","condition":"ENABLED","weight":1},{"address":"10.177.130.96","id":4378,"port":80,"status":"ONLINE","condition":"ENABLED","weight":1}],"virtualIps":[{"address":"174.143.139.241","id":88,"type":"PUBLIC","ipVersion":"IPV4"}],"created":{"time":"2011-03-26T05:31:11+0000"},"updated":{"time":"2011-03-26T05:31:11+0000"},"connectionLogging":{"enabled":false}}}</pre>
<p>The important take away from above is the new Public IP address and IP address ID. We will use the ID when we build the https load balancer so that they share the same IP.</p>
<p>Now, let&#8217;s build the test1-https Load Balancer. First, the xml file:</p>
<pre>&lt;loadBalancer xmlns="http://docs.openstack.org/loadbalancers/api/v1.0"
name="test1-https"
port="443"
protocol="HTTPS"&gt;
&lt;virtualIps&gt;
&lt;virtualIp id="88"/&gt;
&lt;/virtualIps&gt;
&lt;nodes&gt;
&lt;node address="10.177.130.14" port="444" condition="ENABLED"/&gt;
&lt;node address="10.177.130.96" port="444" condition="ENABLED"/&gt;
&lt;/nodes&gt;
&lt;/loadBalancer&gt;</pre>
<p>The changes here are going to be that we are giving it a different name, telling the Load Balancer to listen on port 443 for HTTPS traffic, and instead of requesting a new public IP, we are asking it to use the IP that we created above. In my case, that was IP ID 88. Also, note that we are asking it to send all traffic to the nodes on port 444. That&#8217;s not a typo. In order for the web nodes to distinguish  test1.com from test2.com we are going to send the traffic on different ports.</p>
<p>Now, the command to create this Load Balancer is just like above:</p>
<pre>M0Z8AGY:LBaaS josh.prewitt$ curl -H "X-Auth-Token:  f3ec3064-c855-4d9d-8291-410cd1098765" -H "content-type: application/xml"  -d @createtest1-https.xml -X POST  https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123456/loadbalancers</pre>
<pre>{"loadBalancer":{"name":"test1-https","id":158,"protocol":"HTTPS","port":443,"algorithm":"RANDOM","status":"BUILD","cluster":{"name":"ztm-n07.lbaas.dfw1.rackspace.net"},"nodes":[{"address":"10.177.130.96","id":4381,"port":444,"status":"ONLINE","condition":"ENABLED","weight":1},{"address":"10.177.130.14","id":4382,"port":444,"status":"ONLINE","condition":"ENABLED","weight":1}],"virtualIps":[{"address":"174.143.139.241","id":88,"type":"PUBLIC","ipVersion":"IPV4"}],"created":{"time":"2011-03-26T05:37:21+0000"},"updated":{"time":"2011-03-26T05:37:21+0000"},"connectionLogging":{"enabled":false}}}</pre>
<p>test2-http and test2-https will be just like above, but give them different names and have test2-https send traffic to the nodes on port 445.</p>
<pre>&lt;loadBalancer xmlns="http://docs.openstack.org/loadbalancers/api/v1.0"
name="test2-http"
port="80"
protocol="HTTP"&gt;
&lt;virtualIps&gt;
&lt;virtualIp type="PUBLIC"/&gt;
&lt;/virtualIps&gt;
&lt;nodes&gt;
&lt;node address="10.177.130.14" port="80" condition="ENABLED"/&gt;
&lt;node address="10.177.130.96" port="80" condition="ENABLED"/&gt;
&lt;/nodes&gt;
&lt;/loadBalancer&gt;</pre>
<pre>M0Z8AGY:LBaaS josh.prewitt$ curl -H "X-Auth-Token:  f3ec3064-c855-4d9d-8291-410cd1098765" -H "content-type: application/xml"  -d @createtest2-http.xml -X POST  https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123456/loadbalancers</pre>
<pre>{"loadBalancer":{"name":"test2-http","id":157,"protocol":"HTTP","port":80,"algorithm":"RANDOM","status":"BUILD","cluster":{"name":"ztm-n06.lbaas.dfw1.rackspace.net"},"nodes":[{"address":"10.177.130.14","id":4379,"port":80,"status":"ONLINE","condition":"ENABLED","weight":1},{"address":"10.177.130.96","id":4380,"port":80,"status":"ONLINE","condition":"ENABLED","weight":1}],"virtualIps":[{"address":"174.143.139.164","id":11,"type":"PUBLIC","ipVersion":"IPV4"}],"created":{"time":"2011-03-26T05:31:22+0000"},"updated":{"time":"2011-03-26T05:31:22+0000"},"connectionLogging":{"enabled":false}}}</pre>
<pre>&lt;loadBalancer xmlns="http://docs.openstack.org/loadbalancers/api/v1.0"
name="test2-https"
port="443"
protocol="HTTPS"&gt;
&lt;virtualIps&gt;
&lt;virtualIp id="11"/&gt;
&lt;/virtualIps&gt;
&lt;nodes&gt;
&lt;node address="10.177.130.14" port="445" condition="ENABLED"/&gt;
&lt;node address="10.177.130.96" port="445" condition="ENABLED"/&gt;
&lt;/nodes&gt;
&lt;/loadBalancer&gt;</pre>
<pre>M0Z8AGY:LBaaS josh.prewitt$ curl -H "X-Auth-Token:   f3ec3064-c855-4d9d-8291-410cd1098765" -H "content-type: application/xml"   -d @createtest2-https.xml -X POST   https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123456/loadbalancers</pre>
<pre>{"loadBalancer":{"name":"test2-https","id":159,"protocol":"HTTPS","port":443,"algorithm":"RANDOM","status":"BUILD","cluster":{"name":"ztm-n01.lbaas.dfw1.rackspace.net"},"nodes":[{"address":"10.177.130.14","id":4384,"port":445,"status":"ONLINE","condition":"ENABLED","weight":1},{"address":"10.177.130.96","id":4383,"port":445,"status":"ONLINE","condition":"ENABLED","weight":1}],"virtualIps":[{"address":"174.143.139.164","id":11,"type":"PUBLIC","ipVersion":"IPV4"}],"created":{"time":"2011-03-26T05:38:06+0000"},"updated":{"time":"2011-03-26T05:38:06+0000"},"connectionLogging":{"enabled":false}}}</pre>
<h2>Configure Apache on the Individual Nodes</h2>
<p>Ok, we now have 4 Load Balancers, now to take a look at the apache config for one of the web nodes. You will want to add the following:</p>
<pre>#Set it to listen on the right ports
Listen 80
Listen 444
Listen 445
#Set up Name Virtual Host
NameVirtualHost *:80
NameVirtualHost *:444
NameVirtualHost *:445
#test1.com traffic for http listening on port 80
&lt;VirtualHost *:80&gt;
DocumentRoot /var/www/vhosts/test1.com/html
ServerName test1.com
ErrorLog /var/www/vhosts/test1.com/logs/error.log
CustomLog /var/www/vhosts/test1.com/logs/access.log common
&lt;/VirtualHost&gt;
#test2.com traffic for http listening on port 80
&lt;VirtualHost *:80&gt;
DocumentRoot /var/www/vhosts/test2.com/html
ServerName test2.com
ErrorLog /var/www/vhosts/test2.com/logs/error.log
CustomLog /var/www/vhosts/test2.com/logs/access.log common
&lt;/VirtualHost&gt;
#test1.com for https listening on non-standard port 444
&lt;VirtualHost *:444&gt;
DocumentRoot /var/www/vhosts/test1.com/html
ServerName test1.com
ErrorLog /var/www/vhosts/test1.com/logs/error.log
CustomLog /var/www/vhosts/test1.com/logs/access.log common
SSLEngine ON
SSLCertificateFile /etc/httpd/certs/test1/server.crt
SSLCertificateKeyFile /etc/httpd/certs/test1/server.key
&lt;/VirtualHost&gt;
#test2.com for https listening on non-standard port 445
&lt;VirtualHost *:445&gt;
DocumentRoot /var/www/vhosts/test2.com/html
ServerName test2.com
ErrorLog /var/www/vhosts/test2.com/logs/error.log
CustomLog /var/www/vhosts/test2.com/logs/access.log common
SSLEngine ON
SSLCertificateFile /etc/httpd/certs/test2/server.crt
SSLCertificateKeyFile /etc/httpd/certs/test2/server.key
&lt;/VirtualHost&gt;</pre>
<p>That&#8217;s it &#8211; Apply those settings to all of the web nodes, open up iptables on the nodes for ports 80, 444 and 445, and start apache and you will be good to go. (Obviously, don&#8217;t forget to point DNS for test1.com to the IP of the loadbalancer for test1 and the same for test2.)</p>
<p>Related resource: The API guide for Load Balancers as a Service: <a href="http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf" target="_blank">http://docs.rackspacecloud.com/loadbalancers/api/clb-devguide-latest.pdf</a></p>
<p>I hope this helps! If anything doesn&#8217;t make sense or you have any comments leave a message below.</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/03/27/using-rackspace-cloud-load-balancers-as-a-service-to-host-multiple-ssl-sites/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using SNI to host multiple SSL Sites on a single IP in apache using Rackspace Cloud</title>
		<link>http://joshprewitt.com/2011/03/11/using-sni-to-host-multiple-ssl-sites-on-a-single-ip-in-apache-using-rackspace-cloud/</link>
		<comments>http://joshprewitt.com/2011/03/11/using-sni-to-host-multiple-ssl-sites-on-a-single-ip-in-apache-using-rackspace-cloud/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 20:48:04 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=91</guid>
		<description><![CDATA[Using SNI to host multiple SSL Sites on a single IP in apache using Rackspace Cloud Common hosting knowledge has always been that if you want to host multiple SSL Sites on a single server you need to assign each &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/03/11/using-sni-to-host-multiple-ssl-sites-on-a-single-ip-in-apache-using-rackspace-cloud/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Using SNI to host multiple SSL Sites on a single IP in apache using Rackspace Cloud</p>
<p>Common hosting knowledge has always been that if you want to host multiple SSL Sites on a single server you need to assign each website it&#8217;s own unique IP address. This makes sense. The whole purpose of SSL is that the request and response are encrypted. So when the request gets to Apache, Apache can not use standard name based hosting because it can not read the name of the site being requested since it is encrypted. To get around this, you can put sites on separate IP addresses and Apache will look at the request and say &#8220;I don&#8217;t know what site you are requesting, but I know you are requesting it on X IP address, so I will send you to the default site I have for X IP address.&#8221;</p>
<p>In a world with unlimited IP addresses this works just fine. The problem is that the world is quickly running out of IPv4 Addresses and that we might be stuck limping around on IPv4 for awhile waiting for ISPs to catch up with IPv6.</p>
<p>Enter SNI (Server Name Indication). SNI allows for browsers to send the hostname (domain) being requested separately un-encrypted so that the web server can understand the request and serve the right virtual host. It is not without it&#8217;s drawbacks though, let&#8217;s look at what those are:</p>
<h2>Server Pre-Requisites</h2>
<p>You must be running Apache 2.12 or higher, and you must be running openSSL 0.9.8f or higher. RHEL/CentOS 5.5 do not have both of these version available in the standard repositories or the extended EPEL repos, so yum install is out the window on those Distros. You will be stuck building from source. This is a game changer since your package manager is no longer aware of the installation of that software and will cause all sorts of headaches. Your options would be to search for a repo that does include these later versions and install it (I haven&#8217;t looked too hard yet), install from source, pray that 5.6 has it and wait, or go with Fedora 14.</p>
<p>For this example, I am going to go with Fedora 14 because it is the easiest way to demonstrate SNI since the necessary versions are in the yum repos.</p>
<h2>Browser Limitations</h2>
<p>Oh yeah, you don&#8217;t just have to worry about your server. You also have to worry about your user&#8217;s browsers. Not all of them support SNI, but most do. The following browsers work:</p>
<ul>
<li>Mozilla Firefox V2 and up.</li>
<li>Chrome</li>
<li>Opera 8.0 or higher</li>
<li>IE 7 or higher on Vista or higher. (Sorry, IE 7 on XP won&#8217;t work)</li>
<li>Safari 3.2.1 on OS X 10.5.6 or higher</li>
</ul>
<p>Ok, so that&#8217;s all the bad news. Is that enough to scare you away from it? Maybe. Only you can decide that, and as IPv4 addresses become more scarce and supply and demand kicks in prices for IPv4 addresses will go up. Only you can determine if this is the right solution for your business and website. Now let&#8217;s dive into a server!</p>
<h2>Proof of Concept</h2>
<p>Let&#8217;s see this in action! I am going to do these steps using a Fedora 14 Rackspace Cloud Server. I will do this using self-signed certs, and it will be a minimum install because it is simply proof of concept. I will be using domains test1.com and test2.com and modifying my hosts file to point to the IP of my server. Start up the server and login as root.</p>
<h3>Install what you will need</h3>
<pre>yum install openssl httpd mod_ssl</pre>
<h3>Add in Firewall Rules</h3>
<pre>iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 443 -j ACCEPT</pre>
<h3>Create Some Directories</h3>
<pre>mkdir -p /etc/httpd/certs/test1.com
mkdir -p /etc/httpd/certs/test2.com
mkdir -p /var/www/vhosts/test1/html
mkdir -p /var/www/vhosts/test2/html
mkdir -p /var/www/vhosts/test1/logs
mkdir -p /var/www/vhosts/test2/logs</pre>
<h3>Create Some Index Files</h3>
<p>Put something in them so we can see if it works</p>
<pre>echo "This is test 1" &gt; /var/www/vhosts/test1/html/index.html
echo "This is test 2" &gt; /var/www/vhosts/test2/html/index.html</pre>
<h3>Create the self-signed Certs</h3>
<p>Again, I am using test1.com and test2.com. Several of these commands will prompt you for input, just roll with it.</p>
<pre>cd /etc/httpd/certs/test1
openssl genrsa -des3 -out server.key 4096
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
openssl rsa -in server.key -out server.key.insecure</pre>
<p>Repeat those steps above for a self signed cert for test2.com</p>
<h3>Edit your Apache Config File</h3>
<p>add into /etc/httpd/conf/httpd.conf</p>
<pre>NameVirtualHost *:80
NameVirtualHost *:443

SSLStrictSNIVHostCheck off

&lt;VirtualHost *:80&gt;
 ServerAdmin someone@somewhere.com
 DocumentRoot /var/www/vhosts/test1/html
 ServerName test1.com
 ErrorLog /var/www/vhosts/test1/logs/error.log
 CustomLog /var/www/vhosts/test1/logs/access.log common
&lt;/VirtualHost&gt;

&lt;VirtualHost *:80&gt;
 ServerAdmin someone@somewhere.com
 DocumentRoot /var/www/vhosts/test2/html
 ServerName test2.com
 ErrorLog /var/www/vhosts/test2/logs/error.log
 CustomLog /var/www/vhosts/test2/logs/access.log common
&lt;/VirtualHost&gt;

&lt;VirtualHost *:443&gt;
 ServerAdmin someone@somewhere.com
 DocumentRoot /var/www/vhosts/test1/html
 ServerName test1.com
 SSLEngine ON
 SSLCertificateFile /etc/httpd/certs/test1.com/server.crt
 SSLCertificateKeyFile /etc/httpd/certs/test1.com/server.key
 ErrorLog /var/www/vhosts/test1/logs/error.log
 CustomLog /var/www/vhosts/test1/logs/access.log common
&lt;/VirtualHost&gt;

&lt;VirtualHost *:443&gt;
 ServerAdmin someone@somewhere.com
 DocumentRoot /var/www/vhosts/test2/html
 ServerName test2.com
 SSLEngine ON
 SSLCertificateFile /etc/httpd/certs/test2.com/server.crt
 SSLCertificateKeyFile /etc/httpd/certs/test2.com/server.key
 ErrorLog /var/www/vhosts/test2/logs/error.log
 CustomLog /var/www/vhosts/test2/logs/access.log common
&lt;/VirtualHost&gt;</pre>
<h3>Start Apache</h3>
<pre>service httpd start
</pre>
<p>That&#8217;s it &#8211; after you edit your local hosts file you should be able to go to https://test1.com and https://test2.com in a browser and see your 2 test files. Note that you WILL get SSL Errors in your browser with the above, but that is only because they are self signed certs. If you look at the error, you will see that it is NOT due to a host name mismatch, but because the signer is not trusted. If you actually buy the certs you won&#8217;t get an error.</p>
<p>Leave me a comment and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/03/11/using-sni-to-host-multiple-ssl-sites-on-a-single-ip-in-apache-using-rackspace-cloud/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Install PhpMyAdmin on CentOS 5.5 using Epel Repo</title>
		<link>http://joshprewitt.com/2011/03/08/install-phpmyadmin-on-centos-5-5-using-epel-repo/</link>
		<comments>http://joshprewitt.com/2011/03/08/install-phpmyadmin-on-centos-5-5-using-epel-repo/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 06:57:00 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Rackspace Cloud]]></category>
		<category><![CDATA[Tech Stuff]]></category>
		<category><![CDATA[Website Related]]></category>

		<guid isPermaLink="false">http://joshprewitt.com/?p=83</guid>
		<description><![CDATA[My last post on installing phpMyAdmin became pretty popular, so I wanted to let everyone know that there is another way to do it too. You can use the EPEL repository and do a yum install phpmyadmin and it will &#8230;<p class="read-more"><a href="http://joshprewitt.com/2011/03/08/install-phpmyadmin-on-centos-5-5-using-epel-repo/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>My last post on installing phpMyAdmin became pretty popular, so I wanted to let everyone know that there is another way to do it too.</p>
<p>You can use the EPEL repository and do a yum install phpmyadmin and it will work. Warning: The Epel repo is what is used by Fedora and is pretty much the latest and not-always-greatest version of software. If you choose to do this, be sure and disable the EPEL repo when done.</p>
<p>First up, install MySQL.</p>
<h2>Install MySQL</h2>
<p>To get started we need to install MySQL</p>
<pre>yum install mysql-server</pre>
<p>Now start it up</p>
<pre>service mysqld start OR /etc/init.d/mysqld start</pre>
<p>Now we need to secure it:</p>
<pre>/usr/bin/mysql_secure_installation</pre>
<p>It is going to ask you handful of questions:</p>
<h3>Current Root Password</h3>
<p>You will be asked for your current root password. Because this is a  new installation it is set to none. Press enter.</p>
<h3>Set Root Password</h3>
<p>If the above step worked correctly you should be prompted with a   question asking you if you would like to set your root password. Please   press Y and press Enter.</p>
<p>You will be asked for your root password twice. If it works you will  see Success!</p>
<h3>Removing Anonymous Users</h3>
<p>You will be prompted to remove the MySQL anonymous users. For   security reasons we want to do this. The text above the question   explains this topic in more detail. Press Y and then Enter.</p>
<h3>Disallow Root Login</h3>
<p>You will be asked if you would like to disallow remote login for the   root user and only allow connections from the server itself. To keep  our  server secure you want to say Y and press Enter.</p>
<h3>Delete test Database</h3>
<p>MySQL ships with a default database called test. This is not needed   and can be deleted. Press Y and then Enter to delete the test database   and it&#8217;s associated users.</p>
<h3>Reload Privilege Tables</h3>
<p>This step will reload the user settings (called privilege tables) so   all user changes will take effect. Press Y and then Enter to continue.</p>
<p>This post won&#8217;t go into setting up additional users besides root and   assigning them privileges. For information on that, check out the Cloud   Servers Knowledge Base:  <a title="http://cloudservers.rackspacecloud.com/index.php/CentOS_5.4#MySQL" href="http://cloudservers.rackspacecloud.com/index.php/CentOS_5.4#MySQL" target="_blank">http://cloudservers.rackspacecloud.com/index.php/CentOS_5.4#MySQL</a></p>
<h2>Install EPEL Repo</h2>
<p>Now that MySQL is installed, let&#8217;s install the EPEL Repo. To do that, as root run</p>
<pre>rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
</pre>
<p>Now, if you ls -al /etc/yum.repos.d/ you should see epel.repo and epel-testing.repo. Nice.</p>
<h2>Install phpMyAdmin</h2>
<p>Next up, just do a yum install of phpmyadmin:</p>
<pre>yum install phpmyadmin</pre>
<p>This will gather all of the dependencies and install apache and php for you if they aren&#8217;t already there.</p>
<p>Next, we need to modify the phpMyAdmin apache conf file because by default it restricts access to only localhost. Personally, I think you are better off getting your IP and only allowing that IP instead of opening up phpMyAdmin to the world. Head over to <a href="http://icanhazip.com/">http://icanhazip.com/</a> and grab your IP address (thanks to Major at <a href="http://rackerhacker.com" target="_blank">RackerHacker.com</a> for the link). Once you have your IP, edit the file /etc/httpd/conf.d/phpMyAdmin.conf to allow that IP. For example, let&#8217;s say your IP is 70.115.251.196. You would change the part of the file that looks like this:</p>
<pre>&lt;Directory /usr/share/phpMyAdmin/&gt;
order deny,allow
deny from all
allow from 127.0.0.1
allow from ::1
&lt;/Directory&gt;</pre>
<p>To instead look like this:</p>
<pre>&lt;Directory /usr/share/phpMyAdmin/&gt;
order deny,allow
deny from all
allow from 127.0.0.1
allow from ::1
allow from 70.115.251.196
&lt;/Directory&gt;</pre>
<p>Save the file, and then start apache:</p>
<pre>/etc/init.d/apache restart</pre>
<p>You may need to also add in iptables rule by running the following commands:</p>
<pre>iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save</pre>
<p>That&#8217;s it. Visit http://IpOfTheServer/phpmyadmin in a browser and login as the root user and whatever mysql password you setup.</p>
<h2>House Cleaning</h2>
<p>Disable the EPEL repo. This is generally a good idea because if you wanted Fedora you would have installed Fedora instead of CentOS. Edit the /etc/yum.repos.d/epel.repo file and epel-testing.repo file and change anywhere that it says &#8216;enabled=1&#8242; to be &#8216;enabled=0&#8242;</p>
<p>If you found this useful or have anything to add please post a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://joshprewitt.com/2011/03/08/install-phpmyadmin-on-centos-5-5-using-epel-repo/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
