<?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>REMSYS technical resources</title>
	<atom:link href="http://www.rslab.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rslab.net</link>
	<description>technical articles, howtos</description>
	<lastBuildDate>Tue, 24 Aug 2010 10:55:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Security audits</title>
		<link>http://www.rslab.net/2010/08/security-audits94/</link>
		<comments>http://www.rslab.net/2010/08/security-audits94/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 10:46:00 +0000</pubDate>
		<dc:creator>mr</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=94</guid>
		<description><![CDATA[[Introduction]
Please note that this article is about practical side of security audit.
You can easily find many teoretical materials on this subject (for example at wikipedia http://en.wikipedia.org/wiki/Information_technology_security_audit).
One of our customers asked us to make a security audit of his server. He had suspicions that his system has been compromised (this indirectly has been confirmed by the [...]]]></description>
			<content:encoded><![CDATA[<h3><strong>[Introduction]</strong></h3>
<p>Please note that this article is about practical side of security audit.<br />
You can easily find many teoretical materials on this subject (for example at wikipedia http://en.wikipedia.org/wiki/Information_technology_security_audit).</p>
<p>One of our customers asked us to make a security audit of his server. He had suspicions that his system has been compromised (this indirectly has been confirmed by the increased load, which was not so high before). He had a CentOS 5.4 server running Apache, MySQL, vsftpd server and so on. In a nutshell, it was a typical LAMP configuration.</p>
<h3><strong>[Start:: definining security perimeter]</strong></h3>
<p>Before proceeding to the audit, we have discussed with customer detailed list of components over which we have to focus. This stage helped us to determine security perimeter. Final list consisted of the following items:</p>
<p>* System kernel and modules<br />
* System services<br />
* Logging<br />
* Backups<br />
* Firewall rules<br />
* General security policy</p>
<h3><strong>[Analysing system:: detailed picture of the perimeter]</strong></h3>
<p><span id="more-94"></span></p>
<p>Given the high probability of breaking the system, we immediately started to collect information and security checks. It is nearly impossible to create strict scenario of such work. It always include some kind of improvisation. However we came to few steps that help us. These steps convenient to use in the form of questions.</p>
<h4>— Who is working on a server right now?</h4>
<p>To answer this question, we have used system utilities such as &#8216;w&#8217; and &#8216;last&#8217;.</p>
<blockquote>
<ul>
<li><strong><em>w</em></strong> -	Displays list of logged users and shows what commands they run at the moment.&#8221;</li>
</ul>
<ul>
<li> <strong><em>last -i</em></strong> - 	Will show who, when and from which ip addresses logined to server.</li>
</ul>
</blockquote>
<p>Logs were analyzed as well. We have checked /var/log/audit/audit.log and /var/log/secure. After that we checked for suspicious entries /etc/passwd, /etc/shadow, /etc/group, /etc/sudoers</p>
<h4>— What processes are running?</h4>
<h4>— Which ones should run on this host?</h4>
<p>Right, these are two questions. And this step is most important. It needs the maximum attention and highest  concentration. You should rembember that there is possibility of changing the system binaries. So we used few ways of checking the running processes.</p>
<blockquote>
<ul>
<li><strong><em>ps auxf</em></strong></li>
</ul>
<ul>
<li><strong><em> pstree</em></strong></li>
</ul>
<ul>
<li><strong><em> cat /proc/*/stat | awk &#8216;{print $1,$2}&#8217; </em></strong></li>
</ul>
</blockquote>
<p>There is common trick used by hackers together with binaries replacement. They put to their applications immutable flag, which is not seen by usual ls. But there is an effective way of finding such binaries:</p>
<blockquote>
<ul>
<li><em><strong>lsattr `echo $PATH | tr &#8216;:&#8217; &#8216; &#8216;` | grep i&#8211;</strong></em></li>
</ul>
</blockquote>
<p>In most cases the process list shows us that there was intrusion and this case was the one of them. We have found two crond processess running:  /usr/sbin/cron and /usr/sbin/crond. Path to default cron daemon binary on rh-based systems is /usr/sbin/crond. Second one was listening on port 2283 and telnet to this port opened a root shell on the server.<br />
To find out what is doing a process on server usually are used strace and lsof utilities. If you didn’t get enough information from these utilities &#8211; then can be checked /proc/PID filesystem:</p>
<blockquote>
<ul>
<li><strong><em>lsof -p PID</em></strong><em> </em>- Displays files, sockets and ports opened by a process.</li>
</ul>
<ul>
<li><strong><em> strace -p PID -F</em></strong> &#8211; Can help to trace what a process doing (call and signals) and its forks.</li>
</ul>
<ul>
<li><strong><em> mc -sd</em></strong><em> &#8211; /proc/PID	Browsins proc using a file manager. </em></li>
</ul>
</blockquote>
<p>Here you can find a little description of procfs pseudo filesystem.</p>
<blockquote><p>/proc/PID/cmdline - 	Command which started the process<br />
/proc/PID/cwd	- Symlink to working directory.<br />
/proc/PID/environ	- Enviroment variables which affect the process.<br />
/proc/PID/exe	- Symlink to executable file<br />
/proc/PID/fd	- Directory with symlinks to opened file descriptors<br />
/proc/PID/root	- Symlink to filesystem root of this process<br />
/proc/PID/status	- Contains basuc information on process status<br />
/proc/PID/task &#8211; Directory with hardlinks to child processes</p></blockquote>
<h4>— What processes opened ports of connections?</h4>
<p>Besides all of above we are checking the network activity for all processes. This can be easily done using netstat, lsof and nmap utilities:</p>
<blockquote>
<ul>
<li><strong><em>netstat -tapn</em></strong> &#8211; Displays network activity on server</li>
</ul>
<ul>
<li><strong><em> lsof -i -n</em></strong> &#8211; Will display same result as netstat</li>
</ul>
<ul>
<li><strong><em> nmap -sT -sU -p 1-65535 localhost</em></strong> &#8211; Scanning for open ports</li>
</ul>
</blockquote>
<h4>— What automated checks say?</h4>
<p>At the last we check the system using some automated utilities: rkhunter, chkrootkit and clamdscan. They can be installed using default package manager (yum install application-name)</p>
<blockquote>
<ul>
<li><em><strong>rkhunter -с</strong></em> &#8211; Checks the system using series of automated checks. Before start is better to start rkhunder &#8211;update.</li>
</ul>
<ul>
<li><em><strong> chkrootkit</strong></em> &#8211; Checks system in the same way as rkhunder does, but has more false-positive alerts. Analyzing chkrootkit -x | less is more easy.</li>
</ul>
<ul>
<li> <em><strong>clamscan</strong></em> -	Checks file for injections, trojans, shell-scripts. Time of checking depends on harddrive size.</li>
</ul>
</blockquote>
<p>Check for / may take long time, so it is better to check separate folders / mount points (/home, /tmp, etc)</p>
<p>In our case rkhunder output was not so usefull, but clamscan found few interesting files”</p>
<blockquote><p><em>/home/vhosts/domain.tpl/httpdocs/tmp/cc.php: PHP.Hide FOUND<br />
/home/vhosts/domain.tpl/httpdocs/tmp/mass.pl: Perl.Defacer FOUND</em></p></blockquote>
<p>Files were created few hour ago, that increased the possibility to find intruision signs in logs. After checking the apache logs for domain we could find entries about accessing these scripts from web. These scripts were accessed from the same ip, that simplified for us next steps of analyzing the atatckers actiosn. First attacker requests were looking like this:</p>
<blockquote><p><em>xxx.xxx.xxx.xxx [DATE:11:19:24 /index.php?option=com_ckforms&amp;controller=ck<br />
data&amp;view=ckformsdata&amp;layout=detail&amp;task=detail&amp;fid=-2+union+select+1,2,3,<br />
concat(0x3a,username,0x3a,email,0x3a,activation),5,6,7,8,9,10,11,12,13,14,<br />
15,16,17,18,19+from+jos_users--</em></p></blockquote>
<p>In this request we noticed two known things. First of all, option=com_ckforms, gives us idea that site has Joomla installed on it. Second, the last part of request is a SQL-injection. As we found later, attacke used  ckforms-index-sql-injection (56988) vulnerability to gain administrator rights in cms.</p>
<p>FTP logs contained same ip. Attacker used ftp to upload few perl scripts and a kernel exploit. Firstg things that we did - we checked the config file for Joomla to check if mysql and ftp password for this domain are the same. We found that passwords were the same, so most probably attackers used same technology to gain the passwords.</p>
<p>Thus we could understand how attackers tactic and causes of successful attack:</p>
<ul>
<li> Old Joomla version</li>
</ul>
<ul>
<li> Same password for ftp and mysql</li>
</ul>
<ul>
<li> Weak firewall policy, that allowed to open ports for incoming connections</li>
</ul>
<ul>
<li> Old version of kernel prone to attacks (CVE-2009-3547)</li>
</ul>
<p>Elimination of foresaid causes is only a part of work we are doing during audit. This case is not so tipic as during analyzis we found that system is already compromised. In most cases we have to find the ways of break-ins. There is some irony in the fact  that  attacker did a part of work for us.</p>
<h3><strong>[Risk analysis]</strong></h3>
<p>Another part of the work that we perform in such cases is<br />
risk analysis. The process of analysis is divided into three phases:<br />
1) Analysis of processes related to perimeter of security<br />
2) Analysis in a perimeter<br />
3) Analysis of the human factor (random error, the dismissed employee)</p>
<p>In this article we will not go into details of the analysis, we describe only<br />
basic concepts. The concept is to find opportunities to compromise the perimeter. Each of such possibilities, depending on the situation, is assigned a level. In our practice, we use three levels &#8220;High&#8221;, &#8220;medium&#8221; and &#8220;low&#8221;. Each level includes certain points. Correspondingly more points perimeter gains &#8211; worse it is protected.</p>
<h3><strong>[Finding the appropriate solution]</strong></h3>
<p>We must understand that absolute security is not a subject to discuss in real life. Security is a process that assumes a cyclical and even better permanent search for solutions and methods of their use. At the same time we should not forget about comfort and usability. In most cases enhancing security makes us to decrease comfort or usability. For anyone is not so pleasant to take off shoes at the airport, but the possibility to be in the same plane with a terrorrist  is more unpleasant. It is very important to search suitable compromises. For example using ftp is not secure, because data and moreover passwords are transmitted in an unencrypted form. A good solution might be to use ssh authentication with rsa keys (+ passphrase). However, the probability of successful man-in-the-middle attack to ftp is not so high. It is worth to carefully consider the risks before changing the working processes that are already used. Ftp problem can be solved in several ways. Though its replacement by sftp is reliable but not always is acceptable. In this case we are allowed to access ftp from certain ips only, which solves the problem and thus reduces the discomfort to the minimum.</p>
<h3><strong>[Implementation and Monitoring]</strong></h3>
<p>Of course setting up the firewall with the default policy to DENY is only a part of measures aimed at improve the security. We preffer to use nagios and nrpe. We even built a distributed cluster based on it, to reduce to minimum false-positive alerts. Distributed monitoring will be discussed here but later, in other article. Of course we performed update for all software on the server and set up a common security policy (using sudo, configured passwords lifetime, etc.). We have developed procedures for updating and checking the server, which help client to be informed of how things are going on on his server. Customer continues to use our services and we are pleased in our partnership. We hope this article helped you to discover and learn something new from the world of security.<br />
Thank you for your attention.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2010/08/security-audits94/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fail-safe Master-master MySQL replication</title>
		<link>http://www.rslab.net/2010/06/fail-safe-master-master-mysql-replication/</link>
		<comments>http://www.rslab.net/2010/06/fail-safe-master-master-mysql-replication/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 06:25:55 +0000</pubDate>
		<dc:creator>floyd</dc:creator>
				<category><![CDATA[clusters]]></category>
		<category><![CDATA[high-availability]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=64</guid>
		<description><![CDATA[Reference:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html
Assumptions:

Server1 IP: 10.1.1.1
Server2 IP: 10.1.1.2
We will completely replicate all databases
Servers are not in production yet. If they are &#8211; be careful when rsyncing data

Notes:

This setup can be used in HA environments, provided that only one of the servers is used for writes (INSERTs, UPDATEs, DELETEs) at a given moment
In case one of the servers crashes, [...]]]></description>
			<content:encoded><![CDATA[<p>Reference:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html</p>
<p>Assumptions:</p>
<ol>
<li>Server1 IP: 10.1.1.1</li>
<li>Server2 IP: 10.1.1.2</li>
<li>We will completely replicate all databases</li>
<li>Servers are not in production yet. If they are &#8211; be careful when rsyncing data</li>
</ol>
<p>Notes:</p>
<ul>
<li>This setup can be used in HA environments, provided that only one of the servers is used for writes (INSERTs, UPDATEs, DELETEs) at a given moment</li>
<li>In case one of the servers crashes, and data corruption occurs (by corrupting binlogs or innodb data files), there is the possibility that replication will fail and data will have to be re-synchronized from the known good server to the other one</li>
</ul>
<p><span id="more-64"></span><br />
Run (on 1st server, replace &#8220;password&#8221; with actual password):<br />
<code>GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.1.1.%' IDENTIFIED BY 'password';</code></p>
<p>Stop mysql on both servers, rsync the mysql datadir from 1st to 2nd server, delete any existing binlogs or relay logs.</p>
<p>The global my.cnf should be quite similar on both servers (including any parameters used for tuning, like max_heap_table_size, etc), apart from the replication-related settings (very important: sync_binlog, and auto_increment_*, which ensure fail-safe replication):<br />
Server1:<br />
<code>server-id = 1<br />
master-host = 10.1.1.2<br />
master-user = repl<br />
master-password = password<br />
sync_binlog=1<br />
auto_increment_increment=2<br />
auto_increment_offset=1<br />
#adjusted due to mysql 5.x placing relay logs in wrong directory<br />
relay-log=/var/lib/mysql/slave-relay.log<br />
relay-log-index=/var/lib/mysql/slave-relay-log.index<br />
relay-log-info-file=/var/lib/mysql/slave-relay.info</code></p>
<p>Server2:<br />
<code>server-id = 2<br />
master-host = 10.1.1.1<br />
master-user = repl<br />
master-password = password<br />
sync_binlog=1<br />
auto_increment_increment=2<br />
auto_increment_offset=2<br />
#adjusted due to mysql 5.x placing relay logs in wrong directory<br />
relay-log=/var/lib/mysql/slave-relay.log<br />
relay-log-index=/var/lib/mysql/slave-relay-log.index<br />
relay-log-info-file=/var/lib/mysql/slave-relay.info</code></p>
<p>Start mysql on both servers, run:<br />
<code>SHOW MASTER STATUS;<br />
SHOW SLAVE STATUS \G</code><br />
on both servers to check the status.</p>
<p>In order to achieve a HA solution, we can setup heartbeat on both servers, similar to the setup in <a title="Service high-availability using open-source tools" href="http://www.rslab.net/2010/03/service-high-availability-using-open-source-tools/" target="_blank">http://www.rslab.net/2010/03/service-high-availability-using-open-source-tools/</a></p>
<p>We can use mon or monit to detect mysql failures.</p>
<p>In case we are using monit, following configuration can be used:</p>
<p><code>check process mysqld with pidfile /var/run/mysql/mysql.pid<br />
if failed host 127.0.0.1 port 3306 protocol mysql then exec "/etc/monit-scripts/stop-heartbeat.sh"</code></p>
<p>/etc/monit-scripts/stop-heartbeat.sh itself should contain:<br />
<code>#!/bin/bash<br />
/etc/init.d/mysql stop<br />
/usr/lib64/heartbeat/hb_standby local</code></p>
<p>sync_binlog=1 indicated above will add a performance loss, since every query / transaction has to be logged immediately to the binlog. It can be safely disabled, but in case of hardware failures on one of the MySQL servers, there&#8217;s no guarantee that after it will come back up, replication will be intact.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2010/06/fail-safe-master-master-mysql-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Referral Whois and ARIN&#8217;s rwhoisd</title>
		<link>http://www.rslab.net/2010/06/referral-whois-and-arins-rwhoisd/</link>
		<comments>http://www.rslab.net/2010/06/referral-whois-and-arins-rwhoisd/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 11:45:16 +0000</pubDate>
		<dc:creator>floyd</dc:creator>
				<category><![CDATA[internet]]></category>
		<category><![CDATA[standards]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=69</guid>
		<description><![CDATA[Without strict standards, the internet would be just a bunch of interconnected networks, and finding valid information about some specific resource would be next to impossible.
The most simple example (not directly related to the Internet or IT, but illustrating the main idea):
Imagine the modern telephone system. Each country has it&#8217;s own area code, each state/district/region [...]]]></description>
			<content:encoded><![CDATA[<p>Without strict standards, the internet would be just a bunch of interconnected networks, and finding valid information about some specific resource would be next to impossible.</p>
<p>The most simple example (not directly related to the Internet or IT, but illustrating the main idea):</p>
<p>Imagine the modern telephone system. Each country has it&#8217;s own area code, each state/district/region has it&#8217;s own area code too, inside the country. Each smaller region has an area code too.</p>
<p>For example, you want to call someone in Vienna, Virginia, with the local number 123 4567.</p>
<p>You will have to lookup the U.S international code first (+1 in this case). After, you will need to find the Virginia&#8217;s area code. You will use something like a phone-book for this. In the phone book &#8211; we can notice that Virginia, U.S has multiple area codes (276, 434, 540, 571, 703, 757, 804 in this particular example). In the same phone book, we find that Vienna&#8217;s area code is 703, so, we will have to dial: +1 703 123 4567 (where 123 4567 is the local phone number).</p>
<p>So, to find the intermediary codes you have to dial in order to be able to reach the local phone number, you have consulted a phone book, or the equivalent of a &#8220;Directory Service&#8221; (The information in the phone book being the directory itself).</p>
<p>A similar logic is hidden, for example, behind the DNS (Domain Name System) hierarchical naming system.  We won&#8217;t go to deep into DNS structure, but in order to find valid information about a specific domain name, you will have to take similar steps as with the phone system.</p>
<p><span id="more-69"></span></p>
<p>Let&#8217;s say we want to find the IP address of the 4th level domain headquarters.servercompany.co.uk. We firstly need to know who controls the .uk TLD. After that &#8211; we will need to find who controls the .co.uk 2nd level domain, and so on until we obtain the needed IP address.</p>
<p>In theory, a &#8220;directory&#8221; refers to a database of information that is highly optimized for read operations, which should provide the ability of browse, lookup or search information using some specific criteria.</p>
<p>On the internet, we deal with hierarchical data structures too.<br />
Most notable are: DNS and IP networks.<br />
We gave a DNS-related example earlier. The situation with IPv4 IP adresses is similar, but instead of dividing domain names into TLD, 2nd level, 3rd level domains, etc, IP networks can be divided by applying shorter bitmask to the base 2 notation of an initial ip address.</p>
<p>Thus, 74.125.39.99 is part of the 74.125.39.0/24 network, which in turn is part of 74.125.36.0/22, which is part of 74.125.0.0/18, which is also a subnet of the 74.112.0.0/12 network, and so on.</p>
<p>By definition, RWhois or Referral Whois is an application protocol for querying of distributed databases of Internet domain names, address allocations, and other directory information.<br />
It is in some way an extension of the Whois protocol, which was meant to be used earlier for the same purpose, but which was appropriate only during the beginning of the Internet, more exactly on the ARPANET.<br />
As the internet evolved &#8211; a single server for keeping all this data is not enough, nor is it scalable.</p>
<p>Rwhois enhances Whois, and adds hierarchy and scalability to it.<br />
Rwhois is documented in detail in RFC 2167, which supersedes a few older standards.<br />
The most used rwhois server daemon is rwhoisd (http://projects.arin.net/rwhois/) developed by ARIN.<br />
We will proceed with the standard install and basic configuration of the rwhoisd server.<br />
The install process will be OS-independent, so we will install it from the source tarball provided by ARIN, using the last (1.5.9.5) version.<br />
==========================================================<br />
<code>[root@server src]# wget http://projects.arin.net/rwhois/ftp/rwhoisd-1.5.9.5.tar.gz<br />
[root@server src]# tar zxf rwhoisd-1.5.9.5.tar.gz<br />
[root@server src]# cd rwhoisd-1.5.9.5</code><br />
If we are installing this on Linux, we will have to adjust a small detail, because of different syntax of the `sort` parameters on FreeBSD and Linux:<br />
<code>[root@server rwhoisd-1.5.9.5]# nano mkdb/index.c</code><br />
Before the next lines:<br />
<code>#ifdef NEW_STYLE_BIN_SORT<br />
#define SORT_COMMAND "sort -o %s -k 5,5 -k 4,4n -t : %s"<br />
#else<br />
#define SORT_COMMAND "sort -o %s +4 +3 -t : %s "<br />
#endif<br />
</code><br />
add:<br />
<code>#define NEW_STYLE_BIN_SORT</code><br />
Compiling and installing:<br />
<code>[root@server rwhoisd-1.5.9.5]# ./configure --prefix=/usr/local/rwhois<br />
[root@server rwhoisd-1.5.9.5]# make<br />
[root@server rwhoisd-1.5.9.5]# make install</code><br />
Creating an init script for the rwhoisd daemon:<br />
<code>[root@server rwhoisd-1.5.9.5]# nano /etc/init.d/rwhoisd<br />
#!/bin/bash<br />
#<br />
# /etc/rc.d/init.d/rwhoisd<br />
#<br />
# Source function library.<br />
. /etc/init.d/functions<br />
test -x /usr/local/rwhois/sbin/rwhoisd || exit 0<br />
RETVAL=0<br />
#<br />
# See how we were called.<br />
#<br />
prog="rwhoisd"<br />
start() {<br />
# Check if atd is already running<br />
if [ ! -f /var/lock/subsys/rwhoisd ]; then<br />
echo -n $"Starting $prog: "<br />
daemon /usr/local/rwhois/sbin/rwhoisd -d -c /usr/local/rwhois/etc/demo/rwhoisd.conf<br />
RETVAL=$?<br />
[ $RETVAL -eq 0 ] &amp;&amp; touch /var/lock/subsys/rwhoisd<br />
echo<br />
fi<br />
return $RETVAL<br />
}<br />
stop() {<br />
echo -n $"Stopping $prog: "<br />
killproc /usr/local/rwhois/sbin/rwhoisd<br />
RETVAL=$?<br />
[ $RETVAL -eq 0 ] &amp;&amp; rm -f /var/lock/subsys/rwhoisd<br />
echo<br />
return $RETVAL<br />
}<br />
restart() {<br />
stop<br />
start<br />
}<br />
reload() {<br />
restart<br />
}<br />
case "$1" in<br />
start)<br />
start<br />
;;<br />
stop)<br />
stop<br />
;;<br />
reload|restart)<br />
restart<br />
;;<br />
condrestart)<br />
if [ -f /var/lock/subsys/rwoisd ]; then<br />
restart<br />
fi<br />
;;<br />
*)<br />
echo $"Usage: $0 {start|stop|restart|condrestart}"<br />
exit 1<br />
esac<br />
exit $?<br />
exit $RETVAL</code></p>
<p><code>[root@server rwhoisd-1.5.9.5]# chmod +x /etc/init.d/rwhoisd<br />
[root@server rwhoisd-1.5.9.5]# chkconfig --add rwhoisd<br />
[root@server rwhoisd-1.5.9.5]# chkconfig rwhoisd on<br />
[root@server rwhoisd-1.5.9.5]# mkdir /usr/local/rwhois/etc/demo<br />
[root@server rwhoisd-1.5.9.5]# rsync -a /usr/local/rwhois/etc/rwhoisd/samples/ /usr/local/rwhois/etc/demo/<br />
[root@server rwhoisd-1.5.9.5]# cd /usr/local/rwhois/etc/demo/<br />
[root@server demo]# nano rwhoisd.conf</code><br />
Adjust the following parameters:<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
<code>root-dir: /usr/local/rwhois/etc/demo<br />
local-host: rwhois.rservers.com<br />
local-port: 4321<br />
userid: rwhois<br />
max-children: 30</code><br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
<code>[root@server demo]# chown -R rwhois:rwhois /usr/local/rwhois/etc/demo/net-*<br />
[root@server demo]# touch /usr/local/rwhois/etc/demo/rwhoisd.log<br />
[root@server demo]# chown -R rwhois:rwhois /usr/local/rwhois/etc/demo/rwhoisd.log<br />
[root@server demo]# /usr/local/rwhois/bin/rwhois_indexer -i -c /usr/local/rwhois/etc/demo/rwhoisd.conf -v -C network -s txt<br />
[root@server demo]# /etc/init.d/rwhoisd restart</code></p>
<p>To add new networks to this rwhois system &#8211; you will need to copy an existing subnet&#8217;s directory from /usr/local/rwhois/etc/demo/ to a new one, and adjust rwhoisd.auth_area to include the new network.</p>
<p>Also, these procedures can be automated, and integrated with a web interface which would greatly simplify management.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2010/06/referral-whois-and-arins-rwhoisd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Things to know about file hosting services</title>
		<link>http://www.rslab.net/2010/03/things-to-know-about-file-hosting-services/</link>
		<comments>http://www.rslab.net/2010/03/things-to-know-about-file-hosting-services/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 17:29:32 +0000</pubDate>
		<dc:creator>floyd</dc:creator>
				<category><![CDATA[clusters]]></category>
		<category><![CDATA[high load]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=49</guid>
		<description><![CDATA[What to account for when starting a file hosting platform
*The following article is in no way a complete &#8220;HOWTO&#8221; on designing and implementing a file hosting platform. It is to be taken as a series of recommendations on the subject*


First of all, we need fast storage servers.

One would think that a few bulky servers with [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What to account for when starting a file hosting platform</strong><br />
<em>*The following article is in no way a complete &#8220;HOWTO&#8221; on designing and implementing a file hosting platform. It is to be taken as a series of recommendations on the subject*</em>
</p>
<p>
First of all, we need fast storage servers.<br />
<br />
One would think that a few bulky servers with lots of HDD space, fast RAID10 arrays and Gig uplinks would be enough. In a real-world situation &#8211; this is not too correct. You will soon notice that you can&#8217;t get even 2-300Mbit traffic from these servers, since the bottleneck in this situation would be the hard drives, which will have to do random multiple reads and writes concurrently.<br />
<br />
A better option would be to use a few raid1 arrays. or even better, a few separate drives, since MTBF is pretty high for the current HDD models on the market.<br />
<br />
This way, for the storage servers, you could use Dual or Quad CPU machines, with 10 &#8211; 20 x 1TB hard drives (how many drives &#8211; depends on the SCSI/SAS/SATA controller model), also the system partitions should be placed better on a separate RAID1 array. Usually &#8211; 2&#215;36 or 2&#215;72 GB SAS/SCSI drives would be a better setup.<br />
This will ensure necessary performance at a reasonable cost.
</p>
<p><span id="more-49"></span></p>
<p></p>
<p>With high performance storage that provides high disk I/O, comes the need in faster network links. Putting these servers on 100Mbps links would mean to underutilise the disk resources. 1Gbps links are more than welcome, but, be aware that the maximum throughput of a gig link in practice is somewhere around 700-800Mbps, and if your hosting provider is billing you for the allocated bandwidth &#8211; it is more convenient to get 800Mbps allotment from them, than get 1Gig and pay the extra 200-300Mbps while not using them.
</p>
<p>
Apart from high-performance hardware, we must use appropriate software for this job.<br />
The most popular and most used open-source web server &#8211; Apache &#8211; won&#8217;t give us the appropriate performance since it is not best-suited for serving (lots of) static content.<br />
Instead, we consider nginx (http://sysoev.ru/nginx/ ) a much better alternative.<br />
Nginx &#8211; a very fast and small footprint http server (it also has IMAP/POP3/SMTP proxy functions, but that is not related to the current subject), makes use of kqueue (FreeBSD), epoll (Linux), and sendfile (both OSs).
</p>
<p>
Now, the following highly depends on your application&#8217;s architecture, and also on the possible amount of visitors that you are going to have, but there are some common ways to achieve the final design of all the infrastructure. Also, if your budget permits it, it is way better to have more resources from the start, and to expand later, than to find very quick that your implementation is not scalable, and be forced to re-design parts of the system and add new resources in a hurry.
</p>
<p>
Ask yourself:<br />
- how will the users upload files, is this FTP? HTTP?<br />
- how will they download the files? FTP/HTTP?<br />
- do the end-users authenticate when downloading?<br />
- will you separate users with paid accounts, and the others with free access?
</p>
<p>
If FTP is involved &#8211; you will need to use a ftp server that supports virtual user accounts, virtual quotas, and can be integrated with MySQL (or any other DBMS that you are going to use)<br />
Candidates:<br />
- pure-ftpd<br />
- proftpd<br />
- vsftpd
</p>
<p>
For the web part, this meaning the site, the eventual payment system, it is highly recommended to start with a few servers, not a single one, though this is the part that can be adjusted and scaled easier (than the DB backend for example).<br />
<br />
To reduce the load on the web servers, don&#8217;t use only Apache. Separate the static content (images, js, css files) from the scripts:<br />
1. separate the static content to a different subdomain (this needs to be done within the application), and serve it through nginx<br />
2. at the webserver level, setting up nginx in front of apache, and serve all content through nginx. requests to the dynamic content &#8211; should be proxied to apache.<br />
3. in case you are using php-coded scripts, same as (2), but get rid of apache and proxy the requests to the .php files to a FastCGI backend (like PHP with the Php-fpm patch)
</p>
<p>
Once you run out of resources, you can easily add a new web server, mount the web content from a common NFS share, and:<br />
1. Round-robin dns load-balancing<br />
2. Add a software load balancer in front of the web servers, either nginx (in this case you can have multiple apache or fastcgi backends and serve static content dirrectly from the balancer), or Haproxy (which can only proxy the requests, but has advanced health checks, ACLs and other interesting features)<br />
3. Add a hardware load balancer (Like alteon / radware / big-ip)
</p>
<p>
The most sensitive part: DB servers.<br />
We will give examples assuming that you are going to use MySQL.<br />
<br />
Implementing a successful topology from the start greatly depends on your application structure.<br />
It is great if the application is able to separate database reads and writes, this gives you greater flexibility. It is also great if the application can use multiple DB servers.<br />
<br />
When comes to hardware:<br />
Use fast 15k rpm SCSI/SAS drives, RAID1 or RAID10. Get lots of RAM, DB servers love huge amounts of RAM.<br />
Try to avoid RAID5 if possible, since it&#8217;s write performance is slower than RAID1/RAID10, and also a RAID5 is slower if one of the drives is failed.
</p>
<p>
Use a scalable architecture.<br />
As stated above with regards to the application structure, it is great if we can separate reads and writes to different servers. In this case we can use Master-Slave replication, and even better, Master-Multiple Slave replication. DB Inserts / Updates / Deletes should be performed on the master, all Selects can be performed on the slaves.<br />
<br />
On the master: Store Databases and binary logs on different RAID1 arrays. Different physical devices &#8211; faster random reads/writes.<br />
<br />
The most sensitive server is the Master. You can double it with an intermediary slave, which can became a Master in case the current Master fails (think about some automatization here. Tip: heartbeat / wackamole)
</p>
<p>
A sample diagram is attached, which includes the last few discussed details:<br />
<br />
<a href="http://www.rslab.net/wp-content/uploads/2010/03/file-storage-platform.png"><img class="alignnone size-full wp-image-54" title="file-storage-platform" src="http://www.rslab.net/wp-content/uploads/2010/03/file-storage-platform.png" alt="" width="673" height="519" /></a>
</p>
<p>References:</p>
<p>http://dev.mysql.com/doc/refman/5.0/en/replication.html</p>
<p>http://en.wikipedia.org/wiki/RAID</p>
<p>http://en.wikipedia.org/wiki/Standard_RAID_levels#RAID_5_performance</p>
<p>http://sysoev.ru/nginx/</p>
<p>http://haproxy.1wt.eu/</p>
<p>http://www.pureftpd.org/project/pure-ftpd</p>
<p>http://www.proftpd.org/</p>
<p>http://vsftpd.beasts.org/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2010/03/things-to-know-about-file-hosting-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Service high availability using open-source tools</title>
		<link>http://www.rslab.net/2010/03/service-high-availability-using-open-source-tools/</link>
		<comments>http://www.rslab.net/2010/03/service-high-availability-using-open-source-tools/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:24:06 +0000</pubDate>
		<dc:creator>floyd</dc:creator>
				<category><![CDATA[clusters]]></category>
		<category><![CDATA[high-availability]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=35</guid>
		<description><![CDATA[People want their servers, and of course the projects that are running on them, to be available all the time, and to bring maximum revenue at the same time.
In a real-life situation, it is more than clear that pure 100% availability is impossible to achieve, especially if a single hardware device is involved. There can [...]]]></description>
			<content:encoded><![CDATA[<p>People want their servers, and of course the projects that are running on them, to be available all the time, and to bring maximum revenue at the same time.<br />
In a real-life situation, it is more than clear that pure 100% availability is impossible to achieve, especially if a single hardware device is involved. There can be unpredicted factors that affect availability, either at software or hardware level.<br />
Most common examples:</p>
<ul>
<li>power failures</li>
<li>network device failures</li>
<li>sysadmin&#8217;s mistakes</li>
</ul>
<p>
Most of these factors can be excluded, or their impact can be reduced to a minimum by a careful initial design and planning, and eliminating any SPOF (*single point of failure), whenever possible of course.<br />
<br />
We also have to define the notion of downtime: it is the amount of time when the service is unavailable, or the system fails to provide the services it should be providing.<br />
<br />
Downtime can be: Planned or Unplanned<br />
In a HA (*high-availability) environment, we need to exclude unplanned downtimes.<br />
Planned downtime &#8211; is the result of maintenance procedures executed on the system. This may include:</p>
<ul>
<li>hardware components replacement</li>
<li>applying security patches or OS updates, that require a system reboot</li>
<li>performing hardware upgrades</li>
<li>system redesign</li>
</ul>
<p>
In this article we are designing a high-availability solution for a web service, using open-source software.<br />
<br />
<span id="more-35"></span><br />
<br />
There are multiple ways of achieving a HA web service. Most common include:<br />
1. DNS load-balancing &#8211; this implies using two or more A records in the dns zone for a web site, with a low TTL, thus the requests will be round-robin distributed to all the servers (or &#8220;nodes&#8221;) that the A dns records point to.<br />
Example: google.com (though they aren&#8217;t using DNS load balancing only. They also seem to use geodns, anycast and other related technologies)<br />
<code><br />
;; QUESTION SECTION:<br />
;google.com.            IN    A</p>
<p>;; ANSWER SECTION:<br />
google.com.        300    IN    A    209.85.135.99<br />
google.com.        300    IN    A    209.85.135.103<br />
google.com.        300    IN    A    209.85.135.104<br />
google.com.        300    IN    A    209.85.135.105<br />
google.com.        300    IN    A    209.85.135.106<br />
google.com.        300    IN    A    209.85.135.147<br />
</code><br />
<br />
This method has some drawbacks in a simple 2-3 node cluster.<br />
If one node goes down, manual (or automatic) modification of the DNS records for this domain is required, and at least a few minutes (interval equal to the DNS TTL), a part of the requests will still go to the affected node.<br />
<br />
We will adopt the following schema (that can be extended of course, but we are using a minimum of resources):</p>
<ul>
<li>two servers, that will have both the role of web servers, file servers and load balancers. Servers are running latest CentOS 5.4</li>
<li>two networks, one public, that links to the ISP/Datacenter network, and an OOB network (Local to these servers)</li>
</ul>
<p>
Following open-source software will be used:</p>
<ul>
<li>unison (<a title="http://www.cis.upenn.edu/~bcpierce/unison/" href="http://www.cis.upenn.edu/~bcpierce/unison/">http://www.cis.upenn.edu/~bcpierce/unison/</a>) &#8211; open source file synchronization tool</li>
<li>nginx (<a title="http://sysoev.ru/nginx/" href="http://sysoev.ru/nginx/">http://sysoev.ru/nginx/</a>) &#8211; small-footprint and very fast HTTP server, especially for static content serving.</li>
<li>heartbeat (<a title="http://linux-ha.org/" href="http://linux-ha.org/">http://linux-ha.org/</a>) &#8211; &#8220;a daemon that provides cluster infrastructure (communication and membership) services to its clients&#8221;</li>
<li>apache (<a title="http://httpd.apache.org/" href="http://httpd.apache.org/">http://httpd.apache.org/</a>) &#8211; most known and popular open-source HTTP server</li>
<li>mon (<a title="http://mon.wiki.kernel.org/index.php/Main_Page" href="http://mon.wiki.kernel.org/index.php/Main_Page">http://mon.wiki.kernel.org/index.php/Main_Page</a>) &#8211; &#8220;tool for monitoring the availability of services, and sending alerts on prescribed events&#8221;</li>
<li>mod_rpaf for apache (<a title="http://stderr.net/apache/rpaf/" href="http://stderr.net/apache/rpaf/">http://stderr.net/apache/rpaf/</a>) &#8211; changes the remote address of the client visible to other Apache modules.</li>
</ul>
<p>All software is installed from standard repositories, except nginx and mon, which will be installed from the EPEL repositories (<a title="http://fedoraproject.org/wiki/EPEL" href="http://fedoraproject.org/wiki/EPEL">http://fedoraproject.org/wiki/EPEL</a>)<br />
<br />
Both servers should have similar configuration<br />
<br />
Typical network wiring:<br />
<a href="http://www.rslab.net/wp-content/uploads/2010/02/oss-cluster.png"><img class="size-full wp-image-36 aligncenter" title="oss-cluster" src="http://www.rslab.net/wp-content/uploads/2010/02/oss-cluster.png" alt="" width="422" height="482" /></a><br />
<br />
We will use the following IP adresses.<br />
1. Public network:<br />
2.2.2.1 &#8211; gateway<br />
2.2.2.2 &#8211; srv1<br />
2.2.2.3 &#8211; srv2<br />
2.2.2.4, 2.2.2.5 &#8211; are used for the sites, and will be migrated from one server to another automatically by heartbeat.<br />
<br />
2. Private network:<br />
10.0.0.2 &#8211; srv1<br />
10.0.0.3 &#8211; srv2<br />
10.0.0.4, 10.0.0.5 &#8211; used for the OOB VIPs.<br />
<br />
First of all, we will add the EPEL repository:<br />
<code>rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm<br />
</code><br />
<br />
Install all required software:<br />
<code>yum install nginx heartbeat mon httpd php php-mysql unison httpd-devel<br />
</code></p>
<p>mod_rpaf will be installed manually:<br />
<code>wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz<br />
tar zxf mod_rpaf-0.6.tar.gz<br />
cd mod_rpaf-0.6<br />
apxs -cia mod_rpaf-2.0.c<br />
</code><br />
<br />
Adjust the apache config by adding:<br />
<code> RPAFenable On<br />
RPAFsethostname On<br />
RPAFproxy_ips 127.0.0.1 10.0.0.2 10.0.0.3 10.0.0.4 10.0.0.5<br />
RPAFheader X-Forwarded-For<br />
</code><br />
next to the<br />
<code>LoadModule rpaf_module libexec/apache2/mod_rpaf-2.0.so</code> directive.<br />
<br />
Also make sure to install any other php modules needed.<br />
<br />
Heartbeat configuration (config files are similar on both servers):<br />
Please refer to the documetation in case some parameter is not completely clear.<br />
File /etc/ha.d/ha.cf:<br />
&#8212;&#8212; cut &#8212;&#8212;-<br />
<code>node srv1.example.com<br />
node srv2.example.com<br />
bcast eth0<br />
bcast eth1<br />
udpport 694<br />
ucast eth0 2.2.2.2<br />
ucast eth0 2.2.2.3<br />
ucast eth1 10.0.0.2<br />
ucast eth1 10.0.0.3<br />
ping 2.2.2.1<br />
baud 19200<br />
crm off<br />
use_logd on<br />
keepalive 1<br />
deadtime 10<br />
initdead 30</code><br />
&#8212;&#8212; cut &#8212;&#8212;-</p>
<p>
File /etc/ha.d/haresources:<br />
&#8212;&#8212; cut &#8212;&#8212;-<br />
<code>srv1.example.com 2.2.2.4/24 10.0.0.4/24<br />
srv2.example.com 2.2.2.5/24 10.0.0.5/24</code><br />
&#8212;&#8212; cut &#8212;&#8212;-<br />
<br />
In case you are using some iptables-based firewall, make sure to allow all traffic between the two servers, on both public and private networks.<br />
<br />
Start the heartbeat service on both servers:<br />
<code>service heartbeat start</code><br />
<br />
You should notice that 2.2.2.4, 10.0.0.4 IPs will be brought up automatically on srv1, and 2.2.2.5, 10.0.0.5 on srv2.<br />
<br />
Next, to the file synchronization setup.<br />
Assuming that all virtual hosts are stored in /home/websites, we will setup the following script on srv1 and add it to the root user&#8217;s crontab, to run once per minute (or more, if the content isn&#8217;t changing frequently):<br />
/root/bin/usync.sh:<br />
<code><br />
#!/usr/local/bin/bash<br />
LOCK="/root/.unison";<br />
if [ -f $LOCK ];<br />
then<br />
echo "unison already running";<br />
exit 1;<br />
fi<br />
touch $LOCK<br />
/usr/bin/unison -batch<br />
rm -f $LOCK</code><br />
<br />
Also we must create the unison config in /root/.unison/default.prf<br />
<br />
<code># Unison preferences file<br />
root = /home/websites/<br />
root = ssh://10.0.0.3//home/websites/<br />
ignore = Path {logs/*}<br />
log = true</code></p>
<p>Please note above that you can exclude some specific paths that don&#8217;t need to be synchronized, like logs or temporary files.<br />
<br />
Configure a sample vhost in apache (we will setup apache to listen on 8000 port only, adjust the Listen directive if needed):<br />
<code><br />
NameVirtualHost *:8000<br />
&lt;VirtualHost *:8000&gt;<br />
DocumentRoot "/home/websites/example.com"<br />
ServerName example.com<br />
ServerAlias www.example.com<br />
&lt;Directory "/home/websites/example.com"&gt;<br />
Allow from all<br />
Options -Indexes FollowSymLinks<br />
&lt;/Directory&gt;<br />
ErrorLog /home/websites/logs/example.com-error.log<br />
CustomLog /home/websites/logs/example.com-access.log combined<br />
ErrorDocument 404 /error/index.php<br />
&lt;/VirtualHost&gt;<br />
</code><br />
<br />
Configure the vhost in nginx:<br />
<code>upstream backend {<br />
# add the internal VIPs here, the requests will be forwarded to all ip:port combinations listed here.<br />
# in case hardware configuration is different on these servers - you can adjust the 'weight' parameter<br />
server 10.0.0.4:8000 weight=50;<br />
server 10.0.0.5:8000 weight=50;<br />
}<br />
server<br />
{<br />
listen  80;<br />
server_name example.com www.example.com;<br />
location /<br />
{<br />
proxy_pass     http://backends;<br />
proxy_redirect  off;<br />
log_not_found   off;</p>
<p>proxy_set_header   Host             $host;<br />
proxy_set_header   X-Real-IP        $remote_addr;<br />
proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;</p>
<p>client_max_body_size       30m;<br />
client_body_buffer_size    128k;</p>
<p>proxy_connect_timeout      30;<br />
proxy_send_timeout         30;<br />
proxy_read_timeout         60;</p>
<p>proxy_buffer_size          4k;<br />
proxy_buffers              4 32k;<br />
proxy_busy_buffers_size    64k;<br />
proxy_temp_file_write_size 64k;<br />
}<br />
location ~* ^.+\.(jpg|jpeg|gif|png|css|js|ico|zip|rar|swf)$ {<br />
root  /home/websites/example.com;<br />
access_log /home/logs/example.com-access.log main;<br />
error_page 404 = @fallback;<br />
}<br />
location @fallback {<br />
proxy_pass http://backends;<br />
proxy_set_header Host $host;<br />
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br />
proxy_set_header X-Real-IP $remote_addr;<br />
}<br />
}</code></p>
<p>
Ok, start apache, nginx.<br />
<br />
You should use the public VIPs (2.2.2.4, 2.2.2.5) to access the web sites.<br />
In case one of the servers will fail, heartbeat will ensure the ips are brought up automatically on the 2nd server.<br />
Now we have to configure automatic failover in case the servers do not fail, but the web service is inaccessible on one of them. We are going to use &#8216;mon&#8217; for this.<br />
<br />
File: /etc/mon/mon.cf<br />
<code>### global options<br />
cfbasedir   = /etc/mon<br />
pidfile     = /var/run/mon.pid<br />
statedir    = /var/lib/mon/state.d<br />
logdir      = /var/lib/mon/log.d<br />
dtlogfile   = /var/lib/mon/log.d/downtime.log<br />
alertdir    = /usr/lib64/mon/alert.d<br />
mondir      = /usr/lib64/mon/mon.d<br />
maxprocs    = 20<br />
histlength  = 100<br />
randstart   = 60s<br />
authtype    = pam<br />
userfile    = /etc/mon/userfile</p>
<p>### group definitions (hostnames or IP addresses)<br />
hostgroup www 2.2.2.4<br />
watch www<br />
service httpd<br />
interval 30s<br />
monitor http.monitor -p 80 -u /index.php 2.2.2.4<br />
period wd {Mon-Sun}<br />
alert stop-heartbeat.alert<br />
alert mail.alert -S "Apache on Node 1 Down" monitoring@example2.com<br />
upalert start-heartbeat.alert<br />
alertevery 1h</p>
<p>service nginx<br />
interval 30s<br />
monitor http.monitor -p 80 -u /nginx-status 192.168.1.232<br />
period wd {Mon-Sun}<br />
alert stop-heartbeat.alert<br />
alert mail.alert -S "Nginx on Node 1 Down" monitoring@example2.com<br />
upalert start-heartbeat.alert<br />
alertevery 1h<br />
</code><br />
<br />
We will need to make two simple scripts that will stop/start heartbeat on demand:<br />
/usr/lib64/mon/alert.d/stop-heartbeat.alert:<br />
<code>#!/bin/bash<br />
/etc/init.d/heartbeat stop<br />
</code><br />
<br />
and /usr/lib64/mon/alert.d/start-heartbeat.alert:<br />
<code>#!/bin/bash<br />
/etc/init.d/heartbeat start<br />
</code></p>
<p>As you may have noticed, we did not mention MySQL in our setup,<br />
This is left as an exercise to the reader, as well as the initial server and network setup, and eventual ftp/sftp, dns or firewall configuration.<br />
A HA MySQL cluster will be discussed in a later article.<br />
<br />
<a title="http://en.wikipedia.org/wiki/Downtime" href="http://en.wikipedia.org/wiki/Downtime">http://en.wikipedia.org/wiki/Downtime</a><br />
<a title="http://en.wikipedia.org/wiki/High_availability" href="http://en.wikipedia.org/wiki/High_availability"> http://en.wikipedia.org/wiki/High_availability</a><br />
<a title="http://linux-ha.org/" href="http://linux-ha.org/"> http://linux-ha.org/</a><br />
<a title="http://www.cis.upenn.edu/~bcpierce/unison/" href="http://www.cis.upenn.edu/~bcpierce/unison/"> http://www.cis.upenn.edu/~bcpierce/unison/</a><br />
<a title="http://sysoev.ru/nginx/" href="http://sysoev.ru/nginx/"> http://sysoev.ru/nginx/</a><br />
<a title="http://httpd.apache.org/" href="http://httpd.apache.org/"> http://httpd.apache.org/</a><br />
<a title="http://mon.wiki.kernel.org/index.php/Main_Page" href="http://mon.wiki.kernel.org/index.php/Main_Page"> http://mon.wiki.kernel.org/index.php/Main_Page</a><br />
<a title="http://stderr.net/apache/rpaf/" href="http://stderr.net/apache/rpaf/"> http://stderr.net/apache/rpaf/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2010/03/service-high-availability-using-open-source-tools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configuring DSR on the Alteon load balancers</title>
		<link>http://www.rslab.net/2009/04/configuring-dsr-on-the-alteon-load-balancers/</link>
		<comments>http://www.rslab.net/2009/04/configuring-dsr-on-the-alteon-load-balancers/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 12:00:09 +0000</pubDate>
		<dc:creator>gr</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[load balancing]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=7</guid>
		<description><![CDATA[This article is covering the configuration of the DSR load balancing mode  on the Alteon load balancers running WebOS 10 and a couple of Linux systems acting  as real servers. 
Alteon 180/184 series load balancers is a cheap solution to handle at least 1 Gigabit of load balanced web traffic, when using DSR.

As per Wikipedia, [...]]]></description>
			<content:encoded><![CDATA[<p>This article is covering the configuration of the DSR load balancing mode  on the Alteon load balancers running WebOS 10 and a couple of Linux systems acting  as real servers. </p>
<p>Alteon 180/184 series load balancers is a cheap solution to handle at least 1 Gigabit of load balanced web traffic, when using DSR.</p>
<p></p>
<p>As per Wikipedia, load balancing is a technique to spread work between two or more computers, network links, CPUs, hard drives, or other resources, in order to get optimal resource utilization, maximize throughput, and minimize response time. Using multiple components with load balancing, instead of a single component, may increase reliability through redundancy.<br />
</br></br></br><br />
DSR is a way for outbound traffic to bypass the load balancer, sending traffic directly to the default router of that network.<br />
DSR uses the loopback interface on a server to spoof the address of the VIP (virtual ip address) on the load balancer when sending traffic out, making it look as the load balancer sent the packet instead of the server, thus eliminating the need for the load balancer to process that traffic. The loopback interface is a special kind of network interface inside the machine. Usually, it is used only by the operating system for internal network communications, but it can be used for other purposes, such as DSR.<br />
</br></br></br><br />
<center><a href="http://www.rslab.net/wp-content/uploads/2009/04/diagram1.jpg"><img class="size-full wp-image-8" title="DSR diagram" src="http://www.rslab.net/wp-content/uploads/2009/04/diagram1.jpg" alt="DSR diagram" width="500" height="190" /></a><br />
</center><br />
</br></br></br><br />
Basically there are four necessary steps for DSR setup:<br />
</br></br></br><br />
</br></br></br><br />
<b>1. Configure the IP alias on the server loopback interface with the IP address of the load balancer VIP.</b><br />
</br></br><br />
On a RedHat/CentOS -like server the config file /etc/sysconfig/network-scripts/ifcfg-lo:0 will look like this:</p>
<p></br></br></br><br />
<code>DEVICE=lo:0<br />
IPADDR=10.0.0.1<br />
NETMASK=255.255.255.255<br />
ONBOOT=yes</code><br />
</br></br></br><br />
On Linux running kernel 2.6  there is one more thing to adjust,  because the Linux boxes will respond to the ARP requests for that VIP, when they are not supposed to. This can be prevented by specific kernel arp settings, added to the configuration file /etc/sysctl.conf  (2.6 kernel only) and rebooting the server:</p>
<p><code><br />
net.ipv4.conf.all.rp_filter=0<br />
net.ipv4.conf.all.arp_ignore=1<br />
net.ipv4.conf.eth0.arp_ignore=1<br />
net.ipv4.conf.eth1.arp_ignore=1<br />
net.ipv4.conf.all.arp_announce=2<br />
net.ipv4.conf.eth0.arp_announce=2<br />
net.ipv4.conf.eth1.arp_announce=2<br />
</code><br />
</br></br><br />
The following commands may be used to change the settings interactively during runtime:</p>
<p><code><br />
echo 0 &gt; /proc/sys/net/ipv4/conf/all/rp_filter<br />
echo 1 &gt; /proc/sys/net/ipv4/conf/all/arp_ignore<br />
echo 1 &gt; /proc/sys/net/ipv4/conf/eth0/arp_ignore<br />
echo 1 &gt; /proc/sys/net/ipv4/conf/eth1/arp_ignore<br />
echo 2 &gt; /proc/sys/net/ipv4/conf/all/arp_announce<br />
echo 2 &gt; /proc/sys/net/ipv4/conf/eth0/arp_announce<br />
echo 2 &gt; /proc/sys/net/ipv4/conf/eth1/arp_announce<br />
</code><br />
</br></br><br />
Unfortunately there seems to be no general and simple solution for for kernel 2.4. For additional information about the nature of the problem (and other solutions) check http://linux-ip.net/html/ether-arp.html#ether-arp-flux .<br />
</br></br><br />
<b>2. Configure the web server to bind to both the real IP address (so the load balancer can still perform health checks) and the new loopback IP address.</b><br />
</br></br><br />
A config snippet example for Apache  :</p>
<p><code><br />
&lt;VirtualHost 10.0.0.1 10.0.0.100&gt;<br />
ServerAdmin support@example.com<br />
DocumentRoot /var/www/html<br />
ServerName www1.example.com<br />
ErrorLog logs/error_log<br />
CustomLog logs/access_log common<br />
&lt;/VirtualHost&gt;<br />
</code></p>
<p></br></br></br></p>
<p></br></br><br />
<b>3. Point the default route on the web servers directly towards the router (rather than through the load balancer).</b><br />
</br></br><br />
In this example, run on the Linux server :<br />
</br></br><br />
<code>route add default gw 10.0.0.254</code><br />
</br></br><br />
and save this configuration in the init scripts (/etc/sysconfig/network OR /etc/sysconfig/network-scripts/ifcfg-ethX) .</p>
<p></br><br />
<b>4. Configure the load balancer to enable DSR.</b></p>
<p></br></br></p>
<p>In this test scenario I`m using the following ip addresses :<br />
</br><br />
10.0.0.1 and 10.0.0.2 as web servers RIPs<br />
10.0.0.100 the Alteon VIP<br />
10.0.0.254 the router, acting as gateway for servers as well as for the Alteon.<br />
</br></p>
<p></br></br><br />
A <a href="http://www.rslab.net/wp-content/uploads/2009/04/alteon_config.txt" target="_blank">sample config</a> of the alteon load balancer with two real servers behind a single VIP address.<br />
</br></br></br><br />
The most important advantage of using DSR is performance, because the load balancer handles about one packet in for every eight packets out, depending on the traffic profile, the load balancer does substantially less work.<br />
The disadvantages of using DSR is a most complex setup and because this method may perform only layer 4 load balancing, as layer 7 (URL parsing and cookie persistence)  requires the ability to completely proxy a connection.<br />
</br></br><br />
<b>References:</b></p>
<p>1. http://en.wikipedia.org/wiki/Load_balancer<br />
2. http://lbwiki.com/index.php/DSR<br />
3. http://www.inlab.de/balanceng/faq.html<br />
4. Tony Bourke: Server Load Balancing, O&#8217;Reilly, ISBN 0-596-00050-2</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2009/04/configuring-dsr-on-the-alteon-load-balancers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSMail Mail Server Management</title>
		<link>http://www.rslab.net/2008/10/rsmail-mail-server-management/</link>
		<comments>http://www.rslab.net/2008/10/rsmail-mail-server-management/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 12:00:57 +0000</pubDate>
		<dc:creator>gr</dc:creator>
				<category><![CDATA[mail]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[rsmail]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[webadmin]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=5</guid>
		<description><![CDATA[RSMail is a complete mail server management software.
People can easily manage their mail server, POP3/IMAP server, configure spam filters and antivirus protection in its web based interface.
We created a small page with several screenshots, for people interested in its actual state.
]]></description>
			<content:encoded><![CDATA[<p>RSMail is a complete mail server management software.<br />
People can easily manage their mail server, POP3/IMAP server, configure spam filters and antivirus protection in its web based interface.<br />
We created a <a title="small page" href="http://rsmail.remsys.net" target="_self">small page</a> with several screenshots, for people interested in its actual state.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2008/10/rsmail-mail-server-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache system activity report (asar)</title>
		<link>http://www.rslab.net/2008/08/apache-system-activity-report-asar/</link>
		<comments>http://www.rslab.net/2008/08/apache-system-activity-report-asar/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 16:11:22 +0000</pubDate>
		<dc:creator>gr</dc:creator>
				<category><![CDATA[Apache]]></category>

		<guid isPermaLink="false">http://www.rslab.net/?p=3</guid>
		<description><![CDATA[One of our customers asked to made a script which will suspend his hosting customers if they are using too much resources.
The goal was to collect cpu usage by
1. apache and mod_php
2. mysql
3. cgi/daemons
4. mail
The tool will get actual resource usage every 5 minutes and save the data in a dbm database.
Actually we started with [...]]]></description>
			<content:encoded><![CDATA[<p>One of our customers asked to made a script which will suspend his hosting customers if they are using too much resources.</p>
<p>The goal was to collect cpu usage by</p>
<p>1. apache and mod_php<br />
2. mysql<br />
3. cgi/daemons<br />
4. mail</p>
<p>The tool will get actual resource usage every 5 minutes and save the data in a dbm database.<br />
Actually we started with apache resources usage.<br />
The utility is collecting cpu usage per user , vhost and even requested url.<br />
The first try could be downloaded <a href="http://dl.remsys.net/asar/" target="_blank">here</a>, available for Cpanel servers only.<br />
I do not recommend at all to run it on non-Cpanel servers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rslab.net/2008/08/apache-system-activity-report-asar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
