<?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>Weird rocketry &#187; amazon</title>
	<atom:link href="http://webapp.org.ua/tag/amazon/feed" rel="self" type="application/rss+xml" />
	<link>https://webapp.org.ua</link>
	<description>Flights to outer code</description>
	<lastBuildDate>Sat, 16 Jul 2016 11:12:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Installing OpenVZ on Amazon EC2</title>
		<link>https://webapp.org.ua/sysadmin/installing-openvz-on-amazon-ec2/</link>
		<comments>https://webapp.org.ua/sysadmin/installing-openvz-on-amazon-ec2/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 13:49:27 +0000</pubDate>
		<dc:creator>bananos</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[openvz]]></category>
		<category><![CDATA[pv-grub]]></category>

		<guid isPermaLink="false">http://webapp.org.ua/?p=172</guid>
		<description><![CDATA[Imagine, that your system is pretty complicated and consists of a number of components, each deployed into separate machine.  For development &#38; testing needs it&#8217;s always too costly to keep up &#38; running all these machines.  It&#8217;s not that as easy to make modification into your system structure, i.e. adding new machines with different roles, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://webapp.org.ua/wp-content/uploads/2011/12/aws_logo.jpg"><img class="size-medium wp-image-177 alignleft" title="aws_logo" src="http://webapp.org.ua/wp-content/uploads/2011/12/aws_logo-300x109.jpg" alt="" width="300" height="109" /></a>Imagine, that your system is pretty complicated and consists of a number of components, each deployed into separate machine.  For development &amp; testing needs it&#8217;s always too costly to keep up &amp; running all these machines.  It&#8217;s not that as easy to make modification into your system structure, i.e. adding new machines with different roles, etc.</p>
<p>One solution is to virtualize all your stuff &amp; isolate environment of each component.  An easy way would be to buy a hardware &amp; setup hardware virtualization such as <a href="http://xen.org">XEN</a> for instance, but there is more popular approach &#8212; using <a href="http://aws.amazon.com/ec2/">Amazon EC2</a> cloud services.</p>
<p><a href="http://webapp.org.ua/wp-content/uploads/2011/12/OpenVZ-logo.png"><img class="size-medium wp-image-178 alignright" title="OpenVZ-logo" src="http://webapp.org.ua/wp-content/uploads/2011/12/OpenVZ-logo-300x76.png" alt="" width="300" height="76" /></a>In this post I&#8217;m going to show you how to setup OpenVZ virtualization on Amazon EC2 node (which, actually itself is virtualized XEN node)</p>
<p>We&#8217;re going to use as a base a CentOS 5.6 Amazon image with <a href="http://wiki.xen.org/xenwiki/PvGrub">pv-grub</a> enabled (this is required to be able to boot into custom kernel)</p>
<p><span id="more-172"></span></p>
<p>Ok, from the AWS console start CentOS 5.6/x64  (centos-5.6-64bit-ebs-pvgrub / ami-a14f1ce4), obtain public DNS name &amp; make sure that default ssh 22 port is enabled:</p>
<pre><code class="bash">
ssh -i ~/aws_ssh.key root@ec2-50-18-60-65.us-west-1.compute.amazonaws.com
</code></pre>
<h2>Install OpenVZ &amp; some dependencies</h2>
<pre><code class="bash">
yum -y install gcc.x86_64 gcc-c++.x86_64 java-1.6.0-openjdk iptables openssl-devel zlib-devel pkgconfig glib2-devel

#Open VZ, Install XEN-compatible kernel!
wget -O /etc/yum.repos.d/openvz.repo http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
yum --enablerepo=openvz-kernel-rhel5 -y install ovzkernel-xen.x86_64 ovzkernel-xen-devel.x86_64 vzctl.x86_64 vzquota.x86_64
</code></pre>
<h2>Override some kernel parameters</h2>
<pre><code class="bash">
echo "net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.accept_source_route = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296" &gt; /etc/sysctl.conf
# reload from disk
sysctl -p

#Substitute default kernel by OpenVZ
sed -i 's/kernel/ovzkernel/' /etc/sysconfig/kernel
</code></pre>
<h2>Install ntpd</h2>
<p>This will help to sync time between all virtual machines.</p>
<pre><code class="bash">yum install -y ntp.x86_64
/usr/sbin/ntpdate 0.rhel.pool.ntp.org europe.pool.ntp.org
# start on next boot
chkconfig ntpd on
</code></pre>
<h2>Enable rpmforge repo</h2>
<p>Chances are pretty high that you&#8217;ll want something from this repo (latest git for example), so you&#8217;d better install it now.</p>
<pre><code class="bash">rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
wget -O /tmp/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uvh /tmp/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
yum -y install --enablerepo=rpmforge git.x86_64

</code></pre>
<h2>Setup firewall</h2>
<pre><code class="bash">#Setup firewall
echo "*filter" &gt; /etc/sysconfig/iptables
echo "COMMIT" &gt;&gt; /etc/sysconfig/iptables
</code></pre>
<h2>Install OpenVZ kernel to boot by default</h2>
<p>For some reason, yum install process does not add OpenVZ kernel into grub bootlist, therefore we&#8217;re doing it manually:</p>
<div class="gfm-content">WP_GFM HttpError: server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none</div>
<p>Check your <code>/boot/grub/menu.lst</code>, it should look like following:</p>
<pre><code class="bash">default=1
title centos5.6
  root (hd0)
  kernel /boot/vmlinuz-2.6.18-238.5.1.el5xen root=/dev/sda1
  initrd /boot/initrd-2.6.18-238.5.1.el5xen.img

title CentOS-openvz-xen
  root (hd0)
  kernel /boot/vmlinuz-2.6.18-274.3.1.el5.028stab094.3xen root=/dev/sda1
  initrd /boot/initrd-2.6.18-274.3.1.el5.028stab094.3xen.img

</code></pre>
<p>Reboot and then login again to check that you&#8217;re on OpenVZ kernel:</p>
<pre><code class="bash">
ssh -i ~/aws_ssh.key root@ec2-204-236-152-176.us-west-1.compute.amazonaws.com
Last login: Tue Nov 29 05:34:50 2011 from 94.45.135.130
[root@ip-10-176-46-67 ~]# uname -a
Linux ip-10-176-46-67 2.6.18-274.7.1.el5.028<strong>stab</strong>095.1xen #1 SMP Mon Oct 24 21:00:35 MSD 2011 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<h2>Download &amp; install OpenVZ CentOS5 template:</h2>
<pre><code class="bash">wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz

#Symlink OpenVZ CentOS template
[ -d /vz/template/cache ] || mkdir -p /vz/template/cache
ln -s /root/centos-5-x86_64.tar.gz /vz/template/cache
</code></pre>
<h2>Create your first OpenVZ container(VM)</h2>
<pre><code class="bash">vzctl create 101 --ostemplate centos-5-x86_64 &gt; /dev/null
vzctl set 101 --ipadd 10.0.102.101 --save &gt; /dev/null
vzctl set 101 --nameserver 8.8.8.8 --save &gt; /dev/null
vzctl set 101 --name "APP1" --save &gt; /dev/null
vzctl set 101 --onboot yes --save &gt; /dev/null
</code></pre>
<p>Try to login into APP1 shell:</p>
<pre><code class="bash">vzctl enter 101
</code></pre>
<p>At this point, if you was able to create APP1 container, you can setup other components of your system &#8212; Database, Cache server, whatever you want.</p>
]]></content:encoded>
			<wfw:commentRss>https://webapp.org.ua/sysadmin/installing-openvz-on-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
