<?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>Mohanjith&#039;s Blog &#187; Lighttpd</title> <atom:link href="http://mohanjith.net/blog/topics/lighttpd/feed" rel="self" type="application/rss+xml" /><link>http://mohanjith.net/blog</link> <description>MOHA blogging news and thoughts...</description> <lastBuildDate>Wed, 14 Dec 2011 14:18:18 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3</generator> <item><title>Load balanced and High Availability cluster for your web site under USD 60 pm &#8211; Part 2</title><link>http://mohanjith.net/blog/2009/04/load-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html</link> <comments>http://mohanjith.net/blog/2009/04/load-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html#comments</comments> <pubDate>Tue, 14 Apr 2009 14:21:13 +0000</pubDate> <dc:creator>S H Mohanjith</dc:creator> <category><![CDATA[Lighttpd]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[authentication keys]]></category> <category><![CDATA[config]]></category> <category><![CDATA[High Availability]]></category> <category><![CDATA[keygen]]></category> <category><![CDATA[MySQL]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[public key]]></category> <category><![CDATA[root logins]]></category> <category><![CDATA[rsa]]></category> <category><![CDATA[SSH]]></category> <category><![CDATA[ssh tunnel]]></category> <category><![CDATA[tunnels]]></category> <category><![CDATA[vpn]]></category><guid
isPermaLink="false">http://mohanjith.net/blog/?p=273</guid> <description><![CDATA[TweetUpdate 2009-09-02: Now I&#8217;m using a single Linode and a Xen VPS from my very own hosting service. This means the VPSes have one less thing in common; hosting company. As I promised, here is the post that will discuss in detail how I configured my cluster of 2 nodes to host my sites. Setting [...]]]></description> <content:encoded><![CDATA[<p><span
style="float: right; margin: 5px 0px 0px 5px;" ><a
class="twitter-share-button"  data-via="mohanjith" data-count="vertical" data-related="" data-lang="en" data-url="http://mohanjith.net/blog/2009/04/load-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html" data-text="Load balanced and High Availability cluster for your web site under USD 60 pm &#8211; Part 2" href="http://twitter.com/share?via=mohanjith&#038;count=vertical&#038;related=&#038;lang=en&#038;url=http%3A%2F%2Fmohanjith.net%2Fblog%2F2009%2F04%2Fload-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html&#038;text=Load%20balanced%20and%20High%20Availability%20cluster%20for%20your%20web%20site%20under%20USD%2060%20pm%20%26%238211%3B%20Part%202" >Tweet</a></span><strong>Update 2009-09-02:</strong> Now I&#8217;m using a single Linode and a Xen VPS from my very own <a
href="http://mohanjith.com/xen-linux-vps.html">hosting service</a>. This means the VPSes have one less thing in common; hosting company.</p><p>As I promised, here is the post that will discuss in detail how I configured my cluster of 2 nodes to host my sites.</p><p><strong>Setting up SSH tunnels</strong></p><p>You have to setup a SSH tunnel between the nodes. In order to do that you need to allow restricted root logins into your nodes. Using your favourite text editor edit <code>/etc/ssh/sshd_config</code> and change the line <code>PermitRootLogin</code> to <code>PermitRootLogin forced-commands-only</code>.</p><p>Then generate SSH authentication keys for all your nodes and add the public keys to <code>/root/.ssh/authorized_keys</code> on other nodes. Keys can be generated by running <code>ssh-keygen</code>. By default your private key is stored in <code>/root/.ssh/id_rsa</code> and public key in <code>/root/.ssh/id_rsa.pub</code>. Your public key will look similar to bellow (Key shortened for brevity)</p><p><code><pre class="brush: plain; toolbar: false; gutter: false;">
ssh-rsa AAAA...w== root@example.com
</pre><p></code></p><p>To enable tunnel only access via root you need to add <code>tunnel="0",command="/sbin/ifdown tun0;/sbin/ifup tun0" </code> before your public key in <code>/root/.ssh/authorized_keys</code>. Your <code>/root/.ssh/authorized_keys</code> will look something like bellow.</p><p><code><pre class="brush: plain; toolbar: false; gutter: false;">
tunnel=&#039;0&#039;,command=&#039;/sbin/ifdown tun0;/sbin/ifup tun0&#039; ssh-rsa AAAA...w== root@example.com
</pre><p></code></p><p>Now setup the actual tunnel. Add following lines to <code>/etc/network/interfaces</code> in the &#8220;server&#8221;</p><p><code><pre class="brush: plain; ">

auto tun0
iface tun0 inet static
address 10.100.2.1
netmask 255.255.255.0
pointopoint 10.100.2.2
</pre><p></code></p><p>and the following in the &#8220;client&#8221;</p><p><code><pre class="brush: plain; ">

auto tun0
iface tun0 inet static
pre-up ssh -S /var/run/ssh-myvpn-tunnel-control -M -f -w 0:0 example.com true
pre-up sleep 5
address 10.100.2.2
pointopoint 10.100.2.1
netmask 255.255.255.0
up route add -net 10.100.2.0 netmask 255.255.255.0 gw 10.100.2.0 tun0
post-down ssh -S /var/run/ssh-myvpn-tunnel-control -O exit example.com
</pre><p></code></p><p>Now you only have to restart  networking to enable the tunnel. Now your nodes will be in their own VPN.</p><p><strong>Setting up document root replication (<code>rsync</code>)</strong></p><p>Share /var/www via rsync. You need to install rsync and add following to /etc/rsyncd.conf if they are not already there.</p><p><code><pre class="brush: plain; ">
max connections = 2
log file = /var/log/rsync.log
timeout = 300

[www]
comment = DOC Root
path = /var/www
read only = yes
list = yes
uid = www-data
gid = www-data
auth users = replicator
secrets file = /etc/rsyncd.secrets
</pre><p></code></p><p>Add following cron jobs to www-data crontab (crontab -e)</p><p><code><pre class="brush: plain; gutter: false; toolbar: false;">

1/10 *  *   *   *    test -r /tmp/rsync.docroot.lock || touch /tmp/rsync.docroot.lock &amp;&amp; rsync -aP rsync://replicator@10.100.2.2/www/ /var/www/ --password-file=/etc/rsync.secrets  --contimeout=30  &gt; /dev/null 2&gt;1 &amp;&amp; rm /tmp/rsync.docroot.lock
</pre><p></code></p><p><code><pre class="brush: plain; gutter: false; toolbar: false;">

1/10 *  *   *   *    test -r /tmp/rsync.docroot.lock || touch /tmp/rsync.docroot.lock &amp;&amp; rsync -aP rsync://replicator@10.100.2.1/www/ /var/www/ --password-file=/etc/rsync.secrets  --contimeout=30 &gt; /dev/null 2&gt;1 &amp;&amp; rm /tmp/rsync.docroot.lock
</pre><p></code></p><p><strong>Setting up <code>session_mysql</code></strong></p><p>Next let us setup <code>session_mysql</code> such that we can forget  about replicating PHP session <img
src='http://cdn.mohanjith.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><p>Install php5-dev and libmysql++-dev, download <a
href="http://websupport.sk/~stanojr/projects/session_mysql/" target="_blank"><code>session_mysql</code></a> and extract it, running following commands as root within the extracted location.</p><p><code><pre class="brush: bash; ">
export PHP_PREFIX=&#039;/usr&#039;
$PHP_PREFIX/bin/phpize
./configure --enable-session-mysql --with-php-config=$PHP_PREFIX/bin/php-config --with-mysql=$PHP_PREFIX
make
make install
</pre><p></code></p><p>Create the database to store the session data with the following SQL</p><p><code><pre class="brush: sql; ">

create database phpsession;
grant all privileges on phpsession.* to phpsession identified by &#039;phpsession&#039;; -- CHANGE DEFAULT PASSWORD
create table phpsession(
sess_key char(64) not null,
sess_mtime int(10) unsigned not null,
sess_host char(64) not null,
sess_val mediumblob not null,

index i_key(sess_key(6)),
index i_mtime(sess_mtime),
index i_host(sess_host)
);
</pre><p></code></p><p>Add the following to your <code>php.ini</code> (or <code>/etc/php5/conf.d/session_mysql.ini</code>)</p><p><code><pre class="brush: plain; ">

session.save_handler = &#039;mysql&#039;
session_mysql.db=&#039;host=localhost db=phpsession user=phpsession pass=phpsession&#039;
</pre><p></code></p><p>Do not forget to change the default password. Restart Apache or Lighttpd (or any other web server you are using).</p><p><strong>MySQL asynchronous two way replication</strong></p><p>I&#8217;m sure some of you are asking why I went for asynchronous replication. Main reasons being flexibility and lack of nodes (My cluster is just 2 nodes).</p><p>Stop MySQL from listening only to local connections. Remember to review your user table (<code>mysql.user</code>) to make sure you don&#8217;t grant wild card access like <code>'user'@'%'</code>. Comment out bind-address in<code>/etc/mysql/my.cnf</code> in all nodes. Then add following to node1</p><p><code><pre class="brush: plain; ">
server-id               = 1
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset   = 1
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M

master-host = 10.100.2.2
master-user = slave_user_0
master-password = your$password
master-connect-retry = 60
</pre><p></code></p><p>and following to node2</p><p><code><pre class="brush: plain; ">
server-id               = 2
replicate-same-server-id = 0
auto-increment-increment = 2
auto-increment-offset   = 2
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M

master-host = 10.100.2.1
master-user = slave_user_1
master-password = your$password
master-connect-retry = 60
</pre><p></code></p><p>Now create the users only granting them with replication rights. Also make sure you specify the hostname or the IP to make sure someone is not offloading your data <img
src='http://cdn.mohanjith.net/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> . Following SQL will create the users given in the example. You will have to run the command in both nodes as the data in either node is identical.</p><p><code><pre class="brush: sql; ">
CREATE USER &#039;slave_user_1&#039;@&#039;10.100.2.1&#039; IDENTIFIED BY &#039;your$password&#039;;

GRANT REPLICATION SLAVE ON * . * TO &#039;slave_user_1&#039;@&#039;10.100.2.1&#039; IDENTIFIED BY &#039;your$password&#039; WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER &#039;slave_user_2&#039;@&#039;10.100.2.2&#039; IDENTIFIED BY &#039;your$password&#039;;

GRANT REPLICATION SLAVE ON * . * TO &#039;slave_user_2&#039;@&#039;10.100.2.2&#039; IDENTIFIED BY &#039;your$password&#039; WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
</pre><p></code></p><p>Now start MySQL and run following in <code>mysql</code> prompt on each of the nodes.</p><p><code><pre class="brush: sql; ">
reset master;
stop slave;
start slave;
</pre><p></code></p><p><strong>Finally</strong></p><p>Now you have a cluster of 2 nodes where you can run your PHP site. Your databases are replicated, your user  session data is replicated and your document root is replicated. Have fun, if you have issues please post it as a comment.</p><div
id="fb-like" style=""><iframe
src="http://www.facebook.com/plugins/like.php?href=http://mohanjith.net/blog/2009/04/load-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html&amp;layout=standard&amp;show_faces=true&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:30px"></iframe></div>]]></content:encoded> <wfw:commentRss>http://mohanjith.net/blog/2009/04/load-balanced-and-high-availability-cluster-for-your-web-site-under-usd-60-pm-part-2.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>WSO2 WSF/PHP with Lighttpd</title><link>http://mohanjith.net/blog/2008/01/wso2-wsfphp-with-lighttpd.html</link> <comments>http://mohanjith.net/blog/2008/01/wso2-wsfphp-with-lighttpd.html#comments</comments> <pubDate>Sat, 12 Jan 2008 22:52:00 +0000</pubDate> <dc:creator>S H Mohanjith</dc:creator> <category><![CDATA[Debian]]></category> <category><![CDATA[Lighttpd]]></category> <category><![CDATA[Lighty]]></category> <category><![CDATA[Linux]]></category> <category><![CDATA[WSF/PHP]]></category> <category><![CDATA[WSO2]]></category><guid
isPermaLink="false">http://mohanjith.net/wordpress/?p=26</guid> <description><![CDATA[TweetI wanted to test drive WSO2 WSF/PHP on Lighttpd because I couldn&#8217;t find any documentation specific for Lighttpd, or any one complaining that it cannot be done. I set up a new VMWare image running Debian so that I can blog all the steps involved in getting WSO2 WSF/PHP working on Lighttpd running on Debian. [...]]]></description> <content:encoded><![CDATA[<p><span
style="float: right; margin: 5px 0px 0px 5px;" ><a
class="twitter-share-button"  data-via="mohanjith" data-count="vertical" data-related="" data-lang="en" data-url="http://mohanjith.net/blog/2008/01/wso2-wsfphp-with-lighttpd.html" data-text="WSO2 WSF/PHP with Lighttpd" href="http://twitter.com/share?via=mohanjith&#038;count=vertical&#038;related=&#038;lang=en&#038;url=http%3A%2F%2Fmohanjith.net%2Fblog%2F2008%2F01%2Fwso2-wsfphp-with-lighttpd.html&#038;text=WSO2%20WSF%2FPHP%20with%20Lighttpd" >Tweet</a></span>I wanted to test drive <a
href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a> on <a
href="http://www.lighttpd.net/">Lighttpd</a> because I couldn&#8217;t find any documentation specific for Lighttpd, or any one complaining that it cannot be done. I set up a new VMWare image running Debian so that I can blog all the steps involved in getting WSO2 WSF/PHP working on Lighttpd running on Debian.</p><p>Step 1: Install Lighttpd, PHP5</p><p>I used apt-get to install Lighttpd and PHP5<pre> $ sudo apt-get install lighttpd php5 </pre><p>Step 2: Download and install WSO2 WSF/PHP.</p><p>I downloaded the Debian package.<pre> $ axel -an 5 http://dist.wso2.org/products/wsf/php/wso2-wsf-php-1.2.0-debian.deb $ dpkg -i wso2-wsf-php-1.2.0-debian.deb</pre><p>Step 3: Enable WSO2 WSF/PHP</p><p>I created a new file /etc/php5/conf.d/wsf.ini and added the following line.<pre> extension=wsf.so </pre><p> Step 4: Enable FastCGI and PHP</p><p>Fastest method to run PHP on Lighttpd is FastCGI, so we will be enabling FastCGI.<pre> $ sudo lighty-enable-mod fastcgi</pre><p>On Debian Lighttpd FastCGI configuration file contains the configuration for PHP4. We will have to edit /etc/lighttpd/conf-enable/10-fastcgi.conf to look like bellow.<pre>server.modules   += ( "mod_fastcgi" )

## Start an FastCGI server for php5 (needs the php5-cgi package)fastcgi.server    = ( ".php" =>     ((             "bin-path" => "/usr/bin/php5-cgi",             "socket" => "/tmp/php.socket",             "max-procs" => 2,             "idle-timeout" => 20,             "bin-environment" => (                     "PHP_FCGI_CHILDREN" => "4",                     "PHP_FCGI_MAX_REQUESTS" => "10000"             ),             "bin-copy-environment" => (                     "PATH", "SHELL", "USER"             ),             "broken-scriptfilename" => "enable"     )))</pre><p>Step 5: Restart Lighttpd</p><p>You have to reload the Lighttpd configuration files.<pre> $ sudo /etc/init.d/lighttpd restart</pre><p> You have successfully installed WSO2 WSF/PHP on PHP5 and Lighttpd. It is time to test whether it is a success. Simplest approach would be to see <code>phpinfo()</code> page. Create a php file with the following line of code and place it in the document root. Then using a web browser goto that URL. In the page search for wsf section. This contains all the configurations about the WSF extension.</p><p>I went throught to the trouble of actually consuming a SOAP web service to see whether this setup actually works and it was a success, but that is simply out of the scope of this post. These instructions should work on other Linux distributions with minor changes and any platform with few changes.</p><p>Fly WSO2 WSF/PHP with Lighttpd. Have fun.</p><div
id="fb-like" style=""><iframe
src="http://www.facebook.com/plugins/like.php?href=http://mohanjith.net/blog/2008/01/wso2-wsfphp-with-lighttpd.html&amp;layout=standard&amp;show_faces=true&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:30px"></iframe></div>]]></content:encoded> <wfw:commentRss>http://mohanjith.net/blog/2008/01/wso2-wsfphp-with-lighttpd.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Flying light with lighty</title><link>http://mohanjith.net/blog/2008/01/flying-light-with-lighty.html</link> <comments>http://mohanjith.net/blog/2008/01/flying-light-with-lighty.html#comments</comments> <pubDate>Fri, 11 Jan 2008 22:21:00 +0000</pubDate> <dc:creator>S H Mohanjith</dc:creator> <category><![CDATA[Apache HTTP Server]]></category> <category><![CDATA[fast]]></category> <category><![CDATA[FastCGI]]></category> <category><![CDATA[Lighttpd]]></category> <category><![CDATA[Lighty]]></category> <category><![CDATA[Linux]]></category><guid
isPermaLink="false">http://mohanjith.net/wordpress/?p=24</guid> <description><![CDATA[TweetI moved all my sites to my all new server. There I&#8217;m running Lighttpd as the front facing web server. I do have Apache HTTP Server running for the sake of svn serving. It was not very hard to migrate sites from Apache HTTP Server to Lighttpd. Only feature I missed was .htaccess file support [...]]]></description> <content:encoded><![CDATA[<p><span
style="float: right; margin: 5px 0px 0px 5px;" ><a
class="twitter-share-button"  data-via="mohanjith" data-count="vertical" data-related="" data-lang="en" data-url="http://mohanjith.net/blog/2008/01/flying-light-with-lighty.html" data-text="Flying light with lighty" href="http://twitter.com/share?via=mohanjith&#038;count=vertical&#038;related=&#038;lang=en&#038;url=http%3A%2F%2Fmohanjith.net%2Fblog%2F2008%2F01%2Fflying-light-with-lighty.html&#038;text=Flying%20light%20with%20lighty" >Tweet</a></span>I moved all my sites to my all new server. There I&#8217;m running <a
href="http://www.lighttpd.net/">Lighttpd</a> as the front facing web server. I do have Apache HTTP Server running for the sake of svn serving. It was not very hard to migrate sites from <a
href="http://httpd.apache.org/">Apache HTTP Server</a> to Lighttpd. Only feature I missed was .htaccess file support or substitute. I just had to migrate all the operations taking place in the .htaccess files to the Lighty configuration file.</p><p>Overall migration was smooth. I have nothing to complain, memory foot print is small as it could get. Since I&#8217;m serving only PHP and Python I&#8217;m making use of FastCGI and it is really fast. You wouldn&#8217;t believe me if I tell you the performance gains. I can serve 700 requests per second when it  comes to my <a
href="http://geoinfo.mohanjith.net">Geo-IP</a> web service (I believe the limit was the resources on the test machine), the server is not even sweating. If I was running the same application on Apache HTTP Server it would barely serve 230 requests per second, 204% performance gain.</p><p>If you visit any of my sites except for the blog itself (which is hosted at Blogger.com) you would see the performance. <a
href="http://mohanjith.net">mohanjith.net</a> responds within a second, that&#8217;s lighting fast. All this with a Debian running on Xen with 128MB physical memory and 256MB swap.</p><p>I would recommend Lighty to any one with simple serving requirements. It saves lot of server resources.</p><div
id="fb-like" style=""><iframe
src="http://www.facebook.com/plugins/like.php?href=http://mohanjith.net/blog/2008/01/flying-light-with-lighty.html&amp;layout=standard&amp;show_faces=true&amp;width=300&amp;action=like&amp;font=&amp;colorscheme=light&amp;locale=en_US" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:300px; height:30px"></iframe></div>]]></content:encoded> <wfw:commentRss>http://mohanjith.net/blog/2008/01/flying-light-with-lighty.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: basic (User agent is rejected)
Database Caching 11/19 queries in 0.076 seconds using memcached
Object Caching 0/0 objects using memcached
Content Delivery Network via cdn.mohanjith.net

Served from: mohanjith.net @ 2012-02-11 18:15:04 -->
