<?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>Technical Diary &#187; web</title>
	<atom:link href="http://andriigrytsenko.net/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://andriigrytsenko.net</link>
	<description>With Andrii Grytsenko</description>
	<lastBuildDate>Wed, 28 Jul 2010 09:02:46 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HA cluster for production utilization</title>
		<link>http://andriigrytsenko.net/2009/07/ha-cluster-for-production-utilization/</link>
		<comments>http://andriigrytsenko.net/2009/07/ha-cluster-for-production-utilization/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 14:41:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[clusters]]></category>
		<category><![CDATA[ha cluster]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=171</guid>
		<description><![CDATA[It&#8217;s more difficult and reliability solution in comparison with my previous one. And it&#8217;s suits for production.

From wikipedia we know that:
High-availability clusters (also known as HA Clusters or Failover Clusters) are computer clusters that are implemented primarily for the purpose of providing high availability of services which the cluster provides. They operate by having redundant [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s more difficult and reliability solution in comparison with my previous one. And it&#8217;s suits for production.</p>
<p><span id="more-171"></span></p>
<p>From wikipedia we know that:<br />
<em>High-availability clusters (also known as HA Clusters or Failover Clusters) are computer clusters that are implemented primarily for the purpose of providing high availability of services which the cluster provides. They operate by having redundant computers or nodes which are then used to provide service when system components fail. Normally, if a server with a particular application crashes, the application will be unavailable until someone fixes the crashed server.  </em></p>
<p>We try to make cluster for production system which provide web services and consisted of 2 nodes. Let&#8217;s call it srv1 and srv2 as hostnames.</p>
<p>There is ifconfig for srv1 :</p>
<pre>eth0      Link encap:Ethernet  HWaddr 08:00:27:7B:7E:40
          inet addr:10.0.30.1  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::a00:27ff:fe7b:7e03/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:347 errors:1 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:86003 (83.9 KiB)  TX bytes:8214 (8.0 KiB)
          Interrupt:11 Base address:0xc020</pre>
<pre>
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:560 (560.0 b)  TX bytes:560 (560.0 b)</pre>
<p>and for srv2:</p>
<pre>eth0      Link encap:Ethernet  HWaddr 08:00:27:7B:7E:03
          inet addr:10.0.30.2  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: fe80::a00:27ff:fe7b:7e03/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:347 errors:1 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:86003 (83.9 KiB)  TX bytes:8214 (8.0 KiB)
          Interrupt:11 Base address:0xc020</pre>
<pre>
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:560 (560.0 b)  TX bytes:560 (560.0 b)</pre>
<p>As you can see there is no virtual interfaces for now. Let&#8217;s look at hosts file it should be the same for both of nodes: </p>
<pre>cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               srv2 localhost.localdomain localhost
10.0.30.1       srv1
10.0.30.2       srv2</pre>
<p>Ok now we have to installed heartbeat.<br />
The centos, fedora core and RH users able to use this command:</p>
<pre>yum install heartbeat </pre>
<p>For debian users this one :</p>
<pre>apt-get install heartbeat</pre>
<p>For other distros you can do it according to your distros package manager documentation or compile from sources. The sources are always available at <a href="http://linux-ha.org/DownloadSoftware">official site</a> of the project.</p>
<p>Copy configuration files from examples into your work directory(default for heartbeat is /etc/ha.d): </p>
<pre>cp /usr/share/doc/heartbeat*/hareshare /etc/ha.d/
cp /usr/share/doc/ha.cf /hareshare /etc/ha.d/
cp /usr/share/doc/heartbeat*/authkeys /etc/ha.d/</pre>
<p>And edit it like this :</p>
<pre>cat /etc/ha.d/ha.cf
debugfile /var/log/ha-debug</pre>
<p> # set debug log</p>
<pre>logfile /var/log/ha-log</pre>
<p> # set common log </p>
<pre>logfacility     local0 </pre>
<p># set syslog channel </p>
<pre>keepalive 2 </pre>
<p># time between checks</p>
<pre>udpport 694 </pre>
<p># port where heartbeat will be listened on</p>
<pre>bcast   eth0</pre>
<p>   # interface for broadcast message</p>
<pre>auto_failback on </pre>
<p>#listing of node. Keep in mind that names of node should be as `uname -n` for each nodes</p>
<pre>node srv1 </pre>
<pre>node srv2</pre>
<p>All configuration files is pretty documented by developing team. Therefore I will not  describe it&#8217;s so deeply. Next config file is haresources:</p>
<pre>cat /etc/ha.d/haresources
active            10.0.30.3 httpd script1 script2</pre>
<p>this consist of three main fields:<br />
1-st  &#8211; It&#8217;s still not clear for me. (As I understand any name can be used here as well).<br />
2-nd  &#8211; the ip address for virtual interface<br />
3-rd  &#8211; the name of scripts or script located at /etc/init.d which should be brought up in case of crash active node. </p>
<p>Unfortunately in the event of crashing one of the defined services heartbeat doesn&#8217;t migrate cluster group to another node:( In other words if your web site is goes down the current node will stay active. Maybe this feature is available, but I have found nothing in official documentation about this issue. </p>
<p>And last one config file. It has quite simple configuration which consist of 2 lines. And uses for determine which encryption has to be used. </p>
<pre>cat /etc/ha.d/authkeys
auth 1
1 sha1 "HI!"
</pre>
<p>&#8220;sha1&#8243; provide connection with encryption as well as the &#8220;md5&#8243;. To switch off encryption set &#8220;crc&#8221; instead of &#8220;sha1&#8243;. </p>
<p>Now try to start it: </p>
<pre>/etc/init.d/heartbeat start </pre>
<p>If it&#8217;s start without any errors you able run it at second node. Copy your edited config files:</p>
<pre>scp /etc/hosts 10.0.30.2:/etc/
scp /etc/ha.d/ha* 10.0.30.2:/etc/ha.d/
scp /etc/ha.d/authkeys 10.0.30.2:/etc/ha.d/</pre>
<p>And go to the second node to start heartbeat there:</p>
<pre>srv2:#/etc/init.d/heartbeat start </pre>
<p>If you done everything right -> one of the your node should be has
<pre>eth0:0</pre>
<p> interface which indicate active node. Its looks like this:</p>
<pre>srv1:# ifconfig eth0:0
          eth0:0    Link encap:Ethernet  HWaddr 08:00:27:7B:7E:03
          inet addr:10.0.30.3  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:11 Base address:0xc020
</pre>
<p>The last one step in our configuration is checking the cluster. Go to active node and run: </p>
<pre>reboot</pre>
<p>In several seconds you will see that httpd processes were started and
<pre>eth0:0</pre>
<p> interface is appears at another node. </p>
<pre>srv2:# ifconfig eth0:0
          eth0:0    Link encap:Ethernet  HWaddr 08:00:27:7B:7E:03
          inet addr:10.0.30.3  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:11 Base address:0xc020</pre>
<pre>ps uax | grep http | grep -v grep
root      2300  0.0  3.6  23004  9424 ?        Ss   02:37   0:01 /usr/sbin/httpd
apache    2323  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2324  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2325  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2326  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2327  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2328  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2331  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd
apache    2332  0.0  1.8  23004  4780 ?        S    02:37   0:00 /usr/sbin/httpd</pre>
<p>Looks like everything done well. </p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2009/07/ha-cluster-for-production-utilization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple HA cluster for linux</title>
		<link>http://andriigrytsenko.net/2009/06/103/</link>
		<comments>http://andriigrytsenko.net/2009/06/103/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 10:03:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[clusters]]></category>
		<category><![CDATA[ha cluster]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=103</guid>
		<description><![CDATA[There is the description of concept of simple HA for Linux consist of 2 nodes .

Week ago I start to read book about Linux clustering. When I learned about high available cluster I have decided to made some script which will be able to implement it. 
THEORY:
We have 2 Linux machine, local network, Internet connection [...]]]></description>
			<content:encoded><![CDATA[<p>There is the description of concept of simple HA for Linux consist of 2 nodes .<br />
<span id="more-103"></span></p>
<p>Week ago I start to read book about Linux clustering. When I learned about high available cluster I have decided to made some script which will be able to implement it. </p>
<p>THEORY:<br />
We have 2 Linux machine, local network, Internet connection and border gateway.<br />
<img src="http://andriigrytsenko.net/files/Diagram1.jpeg" alt="Diagram1" /><br />
As you can see at Figure.1.<br />
Node1 and Node2 have internal IPs 10.0.30.1 and 10.0.30.2 respectively. Default route has ip 10.0.30.254. And it provide PAT(Port Address Translation) support . In other words translates all request from internet web clients to web server into localnet virtual ip 10.0.30.3 which always assigned to active node. I will skip how to install PAT support but share my knowledge&#8217;s in rest part of project. </p>
<p>PRACTICE:<br />
First of all we need machine with preinstalled Linux OS, web server, rsync and ssh. In this example I used CentOS and apache but it does not metter. </p>
<p>Try to build network connections.<br />
Network configuration for  Node #1 : </p>
<pre>#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:7B:7E:03
ONBOOT=yes
IPADDR=10.0.30.2
GATEWAY=10.0.30.254
</pre>
<p>For node #2: </p>
<pre>#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:B9:50:94
ONBOOT=yes
IPADDR=10.0.30.1</pre>
<p>GATEWAY=10.0.30.254 </p>
<p>In next step you need to enable rsync in xinted config: </p>
<pre>#cat /etc/xinetd.d/rsync
service rsync
{
        <strong>disable = no</strong>
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon
        log_on_failure  += USERID
}
</pre>
<p>And restart it:</p>
<pre>/etc/init.d/xinted restart</pre>
<p>Also you need to enable some SELinux bool: </p>
<pre>#setsebool -P rsync_export_all_ro=on</pre>
<p>Add user rsync in group root for both nods and generate ssh keys for they. Below described step-by-step actions: </p>
<p>For Node #1 :<br />
Add user: </p>
<pre>#useradd -g root rsycn </pre>
<p>Login as rsync </p>
<pre>#su - rsync </pre>
<p>Generate new rsa key:</p>
<pre>#ssh-keygen -t rsa -b 2048 -f rsync.key</pre>
<p>When ssh-keygen asks you to provide passprase. Hit Enter twice to get non-password access in the future.</p>
<p>Copy public key to the remote host:</p>
<pre>#scp rsync.key.pub root@10.0.30.2:/root/.ssh</pre>
<p>For node #2 :</p>
<pre>#useradd -g root rsycn
#mv ~/.ssh/rsync.key.pub  ~rsync/.ssh/authorized_keys
#chown rsync ~rsync/.ssh/authorized_keys
#chmod 600 ~rsync/.ssh/authorized_keys
#su - rsync
#ssh-keygen -t rsa -b 2048 -f rsync.key
#scp rsync.key.pub root@10.0.30.1:/root
</pre>
<p>Back to Node #1 and perform next actions: </p>
<pre>#mv ~/rsync.key.pub  ~rsync/.ssh/authorized_keys
#chown rsync ~rsync/.ssh/authorized_keys
#chmod 600 ~rsync/.ssh/authorized_keys
</pre>
<p>To check if the keys and rsync works properly. Run this on Node #2:</p>
<pre>#rsycn -e ssh rsync@10.0.30.1:/var/www/html /var/www/</pre>
<p>After that if you have done everything right. The web files from Node #1 should be transfered to your local web directory. </p>
<p>Let&#8217;s check our config file: </p>
<pre>#cat node.conf
another_node_addr=10.0.30.1
# this is comment
virtual_addr=10.0.30.3
max_sleep_time=10
max_ping_cnt=5
log_facility=local6
debug=1
</pre>
<p>All lines begging from &#8220;#&#8221; interpreted as a comments. Therefore it&#8217;s ignored by script. </p>
<p><strong>another_node_addr</strong>  &#8211; defined internal ip of other node<br />
<strong>virtual_addr</strong> &#8211; defined common virtual ip for both node<br />
<strong>max_sleep_time</strong>  &#8211;  max value for sleep(in seconds) between pings<br />
<strong>max_ping_cnt</strong>  &#8211;  max amount of ping attempts<br />
<strong>log_facility</strong> &#8211; the syslog facility for the logging<br />
<strong>sycn_time</strong> &#8211; time for syncronization web documents from master to slave web-server. &#8220;d&#8221; &#8211; for day, &#8220;h&#8221; &#8211; hours, &#8220;min&#8221; &#8211; minutes, &#8220;mon&#8221; &#8211; months. For example:<br />
sync_time=50min &#8211; means that files have to be syncronized every 50 minutes.<br />
<strong>debug</strong> &#8211; the value &#8220;1&#8243; is turn on debug </p>
<p>Be careful the maximum migration time you can calculate in next way:<br />
<strong>max_sleep_time*(max_ping_cnt+1)+crontab </strong>,<br />
by default it&#8217;s 10*(5+1)= 60 + 60 (crontab) =120 seconds.</p>
<p>Download <a href="http://andriigrytsenko.net/files/check_node.txt">main script</a> and <a href="http://andriigrytsenko.net/files/node.conf">config file</a> and put these into the your nodes.  </p>
<p>You can see a little bit of explanation about how to script works in block scheme below.<br />
<img src="http://andriigrytsenko.net/files/diagram2_small.jpeg" alt="block scheme" /></p>
<p>After these steps you are ready to tune your syslog and crontab configuration. <strong>Actions described below should be done on both node&#8217;s</strong>.<br />
Put into the /etc/syslog.conf:</p>
<pre>log_facility.*                                                -/var/log/node.log</pre>
<p>Where log_facility is log facility defined at node.conf.</p>
<p>Put this into crontab to make script run by crontab every minute: </p>
<pre>#crontab -e
*/1 * * * *     /PATH/TO/check_node.pl /PATH/TO/node.conf</pre>
<p>I suppost it will be worked for you as well as for me.<br />
The End.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2009/06/103/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Make redirection from one web site to another via htaccess</title>
		<link>http://andriigrytsenko.net/2009/06/make-rediraction-from-one-domain-to-another-via-htaccess/</link>
		<comments>http://andriigrytsenko.net/2009/06/make-rediraction-from-one-domain-to-another-via-htaccess/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 13:01:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[httpd]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=86</guid>
		<description><![CDATA[Here is some example how to redirect web users from one domain to another one.

In the event of you have 2 domains and you want to use one of this as general one. And redirect all requests from one domain to another one.  For example redirect requests from test.com.ua to test.com you need to [...]]]></description>
			<content:encoded><![CDATA[<p>Here is some example how to redirect web users from one domain to another one.<br />
<span id="more-86"></span><br />
In the event of you have 2 domains and you want to use one of this as general one. And redirect all requests from one domain to another one.  For example redirect requests from test.com.ua to test.com you need to install apache with mod_rewrite module. For debian you have to make next command(as root): </p>
<pre>
#cd /etc/apache2/mods-enabled
# ln -s ../mods-available/rewrite.load  rewrite.load
</pre>
<p>For another distros you able to compile apache from sources with option &#8220;&#8211;enable-module=rewrite&#8221;. </p>
<p>Also you should put or change some lines in the apache configuration file (apache2.conf OR httpd.conf). In main section: </p>
<pre>
AccessFileName .htaccess
</pre>
<p>In the Directory section : </p>
<pre>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</pre>
<p>After that restart apache server: </p>
<pre>
# /etc/init.d/apache2 restart</pre>
<p>Now you are ready to make your .htaccess file. Go to the your web directory: </p>
<pre># cd /var/www/
# cat > .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.com\.ua$
RewriteRule (.*) http://test.ua/$1 [L,R]</pre>
<p>Check your web site via browser. If you have done everything describe above in proper way you will be redirected from test.com.ua to test.ua. </p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2009/06/make-rediraction-from-one-domain-to-another-via-htaccess/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
