<?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>/dev/pawwa</title>
	<atom:link href="http://www.pawwa.in.rs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pawwa.in.rs</link>
	<description>hi-tech / lo-life blogging.</description>
	<lastBuildDate>Sat, 12 May 2012 23:55:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>sar: a quick way to report system activity</title>
		<link>http://www.pawwa.in.rs/2012/05/sar-a-quick-way-to-report-system-activity/</link>
		<comments>http://www.pawwa.in.rs/2012/05/sar-a-quick-way-to-report-system-activity/#comments</comments>
		<pubDate>Thu, 03 May 2012 16:40:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=364</guid>
		<description><![CDATA[I just love the ability to quickly check the historical system activity information by using sar utility which is commonly installed by default. To get the current day statistics simply run the following: sar &#8212; CPU statistics sar -r &#8212; RAM statistics sar -b &#8212; I/O statistics sar -n DEV &#8212; network devices statistics sar [...]]]></description>
			<content:encoded><![CDATA[<p>I just love the ability to quickly check the historical system activity information by using <em>sar</em> utility which is commonly installed by default.</p>
<p><span id="more-364"></span></p>
<p>To get the current day statistics simply run the following:</p>
<ul>
<li><strong>sar</strong> &#8212; CPU statistics</li>
<li><strong>sar -r</strong> &#8212; RAM statistics</li>
<li><strong>sar -b</strong> &#8212; I/O statistics</li>
<li><strong>sar -n DEV</strong> &#8212; network devices statistics</li>
<li><strong>sar -A</strong> &#8212; all available statistics!</li>
</ul>
<p>If you want historical data, use sar with the following switches:</p>
<ul>
<li><strong>-s</strong> to define starting time of date</li>
<li><strong>-e</strong> to define ending time of date</li>
<li><strong>-f /var/log/sa01</strong> to use the data for the first day of the current month</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2012/05/sar-a-quick-way-to-report-system-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SELinux overview</title>
		<link>http://www.pawwa.in.rs/2012/05/selinux-overview/</link>
		<comments>http://www.pawwa.in.rs/2012/05/selinux-overview/#comments</comments>
		<pubDate>Wed, 02 May 2012 16:46:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[RHEL]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SELinux]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=331</guid>
		<description><![CDATA[This post summarizes SELinux documentation, some publicly available articles and presentations, and part of Linux Advanced Security course that I had attended at the Faculty of Electrical Engineering Education Center in Belgrade two years ago. Introduction Linux implements discretionary access control. The controls are discretionary (voluntary and selective) in the sense that a subject is [...]]]></description>
			<content:encoded><![CDATA[<p>This post summarizes SELinux documentation, some publicly available articles and presentations, and part of <a href="http://ec.etf.rs/?p=L403">Linux Advanced Security</a> course that I had attended at the Faculty of Electrical Engineering Education Center in Belgrade two years ago.</p>
<p><span id="more-331"></span></p>
<h2>Introduction</h2>
<p>Linux implements discretionary access control. The controls are discretionary (voluntary and selective) in the sense that a subject is capable of transferring permissions to other subjects &#8211; for example, a process can change security properties of resources. Main features of this traditional access control in Linux are:</p>
<ul>
<li>processes are running under UID and GID (real and effective)</li>
<li>object access is based on ownership and permissions</li>
<li>users define access control for their objects</li>
</ul>
<p>The kernel has hard-coded access policy. The main problem is that the access is based on users&#8217; access. Kernel can&#8217;t distinguish users from processes. For example, a compromised web browser can read all of the user&#8217;s files, including ssh private keys!  A compromised email client can make the users email files world readable. Furthermore, root user can bypass all the restrictions and it&#8217;s not easy to set minimum privileges.</p>
<p>To address these problems NSA initially developed SELinux (Security-Enchanced Linux) which is a set of kernel modifications to provide mandatory access control to Linux. SELinux is now developed mostly by RedHat (Dan Walsh is the lead SELinux developer).</p>
<p>So basically SELinux provides an additional security layer:</p>
<ul>
<li>processes and resources have new <strong>security contexts</strong></li>
<li><strong>policy</strong> defines <strong>relationship between those contexts</strong></li>
<li>users <strong>can&#8217;t bypass</strong> the policy</li>
</ul>
<p>Features of SELinux are:</p>
<ul>
<li>it is mandatory</li>
<li>it is modular</li>
<li>it is granular</li>
<li>there is a possibility to define minimum privileges</li>
<li>root isn&#8217;t almighty</li>
<li>it is transparent for applications</li>
</ul>
<p>Benefits of SELinux are:</p>
<ul>
<li>access is based on user <em>and</em> application function</li>
<li>processes run with least-privilege</li>
<li>privilege escalation tightly controlled (compromise of Apache is limited by the policy)</li>
</ul>
<h2>Three forms of access control</h2>
<p>There are 3 forms of access control:</p>
<ol>
<li>Type enforcement (primary mechanism)</li>
<li>Role-based access control</li>
<li>Multi-level security</li>
</ol>
<p>Access control is <strong>configurable</strong> via policy language (targeted, strict, mls). SELinux follows the model of least-privilege: <strong>access is denied by default</strong>.</p>
<h2>Type enforcement overview</h2>
<p>Security contexts are stored in extended file system attributes (<em>xattr</em>, metadata). Security context is assigned by <em>labeling</em> of the file system. Look at the following security contexts for httpd process and /var/www/html directory:</p>
<pre class="brush: shell; gutter: false">$ sudo ps -Z -C httpd | head -2
LABEL                             PID TTY          TIME CMD
system_u:system_r:httpd_t:s0     1404 ?        00:00:00 httpd
$ sudo ls -dZ /var/www/html/
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html/</pre>
<p>&#8216;system_u:system_r:httpd_t:s0&#8242; and &#8216;system_u:object_r:httpd_sys_content_t:s0&#8242; are security contexts. The fields represent user:role:type:level respectively. For type enforcement the <strong>key field is type</strong>. <strong>Access is allowed solely by type</strong>. The policy defines that httpd_t can read httpd_sys_content_t, while everything else is denied.</p>
<p>Files and directories are assigned type by the configuration file which specifies default context. New files in folders inherit the security contexts of directories. Process types are inherited from the parent process or are set by policy (<em>type transition</em> rule) or by application. Transition must be allowed by policy &#8211; e.g. apache cannot start processes in init_t.</p>
<h2>Targeted policy</h2>
<p>Targeted policy is default in RHEL. It is important to have in mind that with targeted policy<strong> processes are unconfined by default &#8211; the policy confines only targeted services</strong>. Unconfined processes behave almost the same as SELinux is disabled. By default user processes run in unconfined_t, while system processes run in initrc_t domain. Transition of unconfined_t into the type that is defined by the policy is automatic upon starting up of the process.</p>
<h2>SELinux configuration</h2>
<p>SELinux stores its configuration files in /etc/selinux:</p>
<pre class="brush: bash; gutter: false">$ ls -l /etc/selinux/
total 20
-rw-r--r--. 1 root root  449 Apr 28 19:05 config
-rw-r--r--. 1 root root  113 Feb 14 21:49 restorecond.conf
-rw-r--r--. 1 root root   76 Feb 14 21:49 restorecond_user.conf
-rw-r--r--. 1 root root 1766 Dec  7 23:44 semanage.conf
drwxr-xr-x. 5 root root 4096 Apr 28 19:11 targeted</pre>
<p>/etc/selinux/config defines enforcing mode and policy type and /etc/sysconfig/selinux is a symlink to this file on RHEL systems. /etc/selinux/targeted directory contains targeted policies and following subdirectories:</p>
<ul>
<li><strong>contexts</strong> &#8211; object context definitions</li>
<li><strong>modules</strong> &#8211; modules used to build the policy</li>
<li><strong>policy</strong> &#8211; compiled (binary) policy file</li>
</ul>
<p>The /etc/selinux/targeted/contexts/files includes the following:</p>
<ul>
<li><strong>file_contexts</strong> &#8211; basic contexts</li>
<li><strong>file_contexts.local</strong> &#8211; local rewrites of contexts</li>
<li><strong>file_contexts.homedir</strong> &#8211; user files</li>
<li><strong>media</strong> &#8211; removable devices</li>
</ul>
<p>There are man pages for SELinux policy documentation for several confined services:</p>
<pre class="brush: bash; gutter: false">$ man -k _selinux
abrt_selinux         (8)  - Security-Enhanced Linux Policy for the ABRT daemon
ftpd_selinux         (8)  - Security-Enhanced Linux policy for ftp daemons
git_selinux          (8)  - Security Enhanced Linux Policy for the Git daemon
httpd_selinux        (8)  - Security Enhanced Linux Policy for the httpd daemon
kerberos_selinux     (8)  - Security Enhanced Linux Policy for Kerberos
mysql_selinux        (8)  - Security-Enhanced Linux Policy for the MySQL daemon
named_selinux        (8)  - Security Enhanced Linux Policy for the Internet Name server (named) daemon
nfs_selinux          (8)  - Security Enhanced Linux Policy for NFS
pam_selinux          (8)  - PAM module to set the default security context
rsync_selinux        (8)  - Security Enhanced Linux Policy for the rsync daemon
samba_selinux        (8)  - Security Enhanced Linux Policy for Samba
squid_selinux        (8)  - Security-Enhanced Linux Policy for the squid daemon
ypbind_selinux       (8)  - Security Enhanced Linux Policy for NIS</pre>
<h2>Packages and utilities</h2>
<p>Several standard utilities are modified to support SELinux:</p>
<ul>
<li>ls -Z</li>
<li>id -Z</li>
<li>ps auxZ</li>
<li>lsof -Z</li>
<li>netstat -Z</li>
<li>find / -context</li>
</ul>
<p>Other modified programs are:</p>
<ul>
<li>Login programs, PAM (sshd, login, xdm)</li>
<li>Password utilites (passwd, useradd, groupadd)</li>
<li>rpm</li>
</ul>
<p>Backup and disk management support:</p>
<ul>
<li>tar, zip (both have extended attribute support)</li>
<li>rsync (-X, -xattrs)</li>
<li>star</li>
<li>amanda</li>
<li>tar &#8211;selinux</li>
<li>tar xv | restorecon -f &#8211; (<strong>good option</strong>)</li>
</ul>
<p><strong>libselinux</strong> package:</p>
<ul>
<li>getenforce &#8211; check whether machine is enforcing or permissive</li>
<li>setenfroce 1/0 &#8211; sets the machine in enforcing/permissive</li>
<li>selinuxenabled &#8211; used in scripts</li>
<li>matchpathcon &#8211; shows the default context of file/directory</li>
<li>avcstat &#8211; display SELinux AVC statistics</li>
</ul>
<p><strong>coreutils</strong> package:</p>
<ul>
<li>chcon &#8211; changes security context of the file</li>
</ul>
<p><strong>policycoreutils</strong> package:</p>
<ul>
<li>sestatus &#8211; shows SELinux status</li>
<li>semodule &#8211; loads the module into the policy</li>
<li>setsebool &#8211; sets booleans</li>
<li>genhomedircon &#8211; generates file_contexts. homedir</li>
<li>setfiles &#8211; executes initial file system labeling</li>
<li>restorecon &#8211; sets default context defined by the policy</li>
<li>fixfiles &#8211; correct contexts database on file systems</li>
</ul>
<p><strong>checkpolicy </strong>package:</p>
<ul>
<li>checkmodule &#8211; compiles module</li>
<li>checkpolicy &#8211; compiles policy</li>
</ul>
<p><strong>policycoreutils-python </strong>package:</p>
<ul>
<li>semanage &#8211; makes queries and changes the policy</li>
<li>audit2allow &#8211; generates the rules based on activity logs</li>
</ul>
<p><strong>policycoreutils-gui</strong> package:</p>
<ul>
<li>system-config-selinux &#8211; SELinux administration</li>
<li>selinux-polgengui &#8211; wizard for making new policies</li>
</ul>
<p><strong>setroubleshoot</strong>  and <strong>setroubleshoot-server</strong> packages:</p>
<ul>
<li>setroubleshootd &#8211; searches and processes AVC messages</li>
<li>sealert &#8211; shows description of AVC messages</li>
<li>seapplet &#8211; pops SELinux realted messages to the user in X</li>
</ul>
<h2>File labeling</h2>
<p>File context can be changed with the fundamental utility <strong>chcon</strong> (which is similar to chmod):</p>
<pre class="brush: bash; gutter: false">$ chcon -R -t httpd_sys_content_t /srv/www</pre>
<p>This change will be active until next relabeling. <strong>restorecon</strong> command sets contexts that are defined by policy rules. If there is /.autorelabel file, the file system will be relabeled during the next system boot. To make the change permanent use <strong>semanage</strong> utility to set the context.</p>
<p>The policy defines contexts in /etc/selinux/targeted/contexts/files/file_contexts file, by using regular expressions to indicate the paths. &#8220;&#8211;&#8221; in the second column indicates regular files, &#8220;-d&#8221;directories, &#8220;-b&#8221; block devices, &#8220;-c&#8221; character devices, &#8220;-l&#8221; links, etc. Special context &#8220;&lt;&lt;none&gt;&gt;&#8221; indicates that the context should not be changed.</p>
<h2>Log files</h2>
<p>SELinux messages are in the form of AVC &#8211; access vector cache. You can usually find them in /var/log/messages or /var/log/audit/audit.log (if auditd is running):</p>
<pre class="brush: text; gutter: false">May  1 19:46:55 www kernel: type=1400 audit(1335901615.836:28093): avc:  denied  { open } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;parts&quot; dev=xvdj ino=7823 scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=dir
May  1 19:46:55 www kernel: type=1400 audit(1335901615.837:28094): avc:  denied  { getattr } for  pid=13595 comm=&quot;clamscan&quot; path=&quot;/var/amavis/tmp/amavis-20120501T141957-11544/parts/p002&quot; dev=xvdj ino=7822 scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=file
May  1 19:46:55 www kernel: type=1400 audit(1335901615.837:28095): avc:  denied  { read } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;p002&quot; dev=xvdj ino=7822 scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=file
May  1 19:46:55 www kernel: type=1400 audit(1335901615.837:28096): avc:  denied  { open } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;p002&quot; dev=xvdj ino=7822 scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=file
May  1 19:46:55 www kernel: type=1400 audit(1335901615.868:28097): avc:  denied  { write } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;tmp&quot; dev=xvdj ino=7515 scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=dir
May  1 19:46:55 www kernel: type=1400 audit(1335901615.868:28098): avc:  denied  { add_name } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;clamav-2e86f23064829c5cae67d7e8bc85d569&quot; scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=dir
May  1 19:46:55 www kernel: type=1400 audit(1335901615.868:28099): avc:  denied  { create } for  pid=13595 comm=&quot;clamscan&quot; name=&quot;clamav-2e86f23064829c5cae67d7e8bc85d569&quot; scontext=system_u:system_r:clamscan_t:s0 tcontext=system_u:object_r:amavis_var_lib_t:s0 tclass=dir</pre>
<p>AVC messages appear because of the:</p>
<ul>
<li>mislabeled files (file_t, default_t, mv&#8217;ed files, solution: restorecon)</li>
<li>process running under the wrong context</li>
<li>bug in policy</li>
<li>intrusion</li>
</ul>
<p>Explanation of AVC messages can be shown by using the sealert command. If you don&#8217;t have the sealert command, install the following package:</p>
<pre class="brush: shell; gutter: false">$ sudo yum install setroubleshoot-server</pre>
<p>setroubleshootd analyzes the log messages and can send email alerts. The configuration for it is at /etc/setroubleshoot/setroubleshoot.conf. sealert is a setroubleshoot client that is used to diagnose SELinux denials and attempts to provide user friendly explanations and recommendations for how one might adjust the system to prevent the denial in the future.</p>
<p>AVC messages could also be suppressed by the policy rule dontaudit. Sometimes this could be problematic when troubleshooting and to disable dontaudit rules run the following command:</p>
<pre class="brush: shell; gutter: false">$ sudo semanage dontaudit off</pre>
<p>Another useful tools for troubleshooting log files can be found in policycoreutils-python package. audit2allow generates policy allow rules from logs of denied operations. Let&#8217;s see whats the problem with clamscan on my system:</p>
<pre class="brush: shell; gutter: false">$ sudo grep clamscan /var/log/messages | audit2allow 

#============= clamscan_t ==============
#!!!! The source type &#039;clamscan_t&#039; can write to a &#039;dir&#039; of the following type:
# clamscan_tmp_t

allow clamscan_t amavis_var_lib_t:dir { write search read create open getattr add_name };
allow clamscan_t amavis_var_lib_t:file { read getattr open };</pre>
<p>This tells me that clamav policy is missing allow rules for allowing clamscan to access amavis&#8217; directory to scan the files. I will use this specification to compile policy module:</p>
<pre class="brush: shell; gutter: false">$ sudo grep clamscan /var/log/messages | audit2allow -M clamscan
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i clamscan.pp</pre>
<p>audit2allow created type enforcement file clamscan.te and clamscan.pp policy package. Next step involves loading the policy package file:</p>
<pre class="brush: shell; gutter: false">$ sudo semodule -vi clamscan.pp
Attempting to install module &#039;clamscan.pp&#039;:
Ok: return value of 0.
Committing changes:
Killed</pre>
<p>Whoops what was that? It turns out that the kernel killed the process because it made the system ran out of memory:</p>
<pre class="brush: shell; gutter: false">May  2 12:56:57 www kernel: Out of memory: Kill process 3375 (semodule) score 312 or sacrifice child
May  2 12:56:57 www kernel: Killed process 3375, UID 0, (semodule) total-vm:309008kB, anon-rss:292076kB, file-rss:104kB</pre>
<p>I freed some of the reserved memory and compiled the module successfully:</p>
<pre class="brush: shell; gutter: true">$ sudo semodule -l | grep clamscan
clamscan	1.0</pre>
<p>This change is permanent and survives a restart. If I ever wanted to remove that policy I would execute the following:</p>
<pre class="brush: shell; gutter: false">$ sudo semodule -r clamscan</pre>
<h2>Policy customization</h2>
<p>Policies usually have <strong>booleans</strong> associated that enable run time customization of the policy. Booleans are if/then/else statements in the policy.</p>
<ul>
<li>getsebool &#8211; shows variable value</li>
<li>togglesebool &#8211; changes variable value</li>
<li>setsebool &#8211; by using -P parameter you can change the value permanently</li>
</ul>
<p>Remember to check the particular policy man page for variables description.</p>
<p><strong>semanage</strong> utility is pretty important and it can list and change policy parameters:</p>
<ul>
<li>semanage user -l &#8212; list SELinux users</li>
<li>semanage port -l &#8211;list SELinux ports</li>
<li>semanage fcontext -a -t httpd_sys_content_t &#8220;/web(/.*)?&#8221; &#8212; allow Apache to serve content from /web</li>
<li>semanage port -a -t http_port_t -p tcp 81 &#8212; allow Apache to listen on non-standard port 81</li>
<li>semanage permissive -a httpd_t &#8212; disable httpd protection</li>
<li>semanage permissive -d httpd_t &#8212; enable httpd protection</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2012/05/selinux-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LAMP considerations, installation and tuning</title>
		<link>http://www.pawwa.in.rs/2012/04/lamp-considerations-installation-and-tuning/</link>
		<comments>http://www.pawwa.in.rs/2012/04/lamp-considerations-installation-and-tuning/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 22:43:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache httpd]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=192</guid>
		<description><![CDATA[It&#8217;s been three years since I had been involved in mass hosting back at one of the biggest ISPs in my country. Well, it&#8217;s time to refresh memory and catch up with the change log. This article presents somewhat basic overview of different building blocks of the traditional LAMP application stack. It also provides few [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been three years since I had been involved in mass hosting back at one of the <a title="EUnet Hosting" href="http://www.eunethosting.com" target="_blank">biggest ISPs</a> in my country. Well, it&#8217;s time to refresh memory and catch up with the change log. This article presents somewhat basic overview of different building blocks of the traditional LAMP application stack. It also provides few tips on installing and optimizing some of those components on a VPS with limited resources.</p>
<p><span id="more-192"></span></p>
<h2>Apache httpd</h2>
<h3>Versions</h3>
<p>As of 21th February 2012 the new major release of Apache httpd is 2.4, while the previous one was 2.2. There are numerous welcoming enhancements in the latest major version, many of them being well suited for cloud environment. The primary goal of new release is to deliver more performance, directly aiming at <a title="nginx official web site" href="http://nginx.org" target="_blank">nginx</a> (which has the reputation of providing better performance and lower memory footprint).</p>
<p>New features include:</p>
<ul>
<li>Improved performance (lower resource utilization and better concurrency)</li>
<li>Reduced memory usage</li>
<li>Dynamic reverse proxy configuration</li>
<li>Performance on par, or better, than pure event-driven Web servers</li>
<li>More granular timeout and rate/resource limiting capability</li>
<li>More finely-tuned caching support, tailored for high traffic servers and proxies</li>
<li>Dynamic loadable MPMs</li>
<li>mod_ssl with OCSP support</li>
<li>Event MPM is now fully supported</li>
</ul>
<p>For the overview of all of the new features visit <a title="Apache 2.4 New Features" href="http://httpd.apache.org/docs/2.4/new_features_2_4.html" target="_blank">this link</a>.</p>
<h3>Architecture</h3>
<p>Instead of implementing a single architecture, Apache provides several Multi-Processing Modules (MPMs) which allow Apache to run in a process based, hybrid based (processes and threads) and event based modes, to better match different demands. These modules are responsible for basic web server operation: binding to network ports on the machine, accepting requests and dispatching children to handle requests.</p>
<p>In the following paragraphs different Apache MPMs that are available for GNU/Linux are described.</p>
<p><strong>prefork</strong> &#8211; safer choice, traditional, non-threaded, forking</p>
<p>A single control process is responsible for spawning child processes which listen for connections and serve them when they arrive. The control process is started as root to bind to port 80, while child processes are launched as less-privileged users (<em>User</em> and <em>Group</em> directives). Apache always tries to maintain a number of spare (idle) processes which stand ready to serve incoming requests.  Prefork is the best choice if Apache has to use non-thread-safe libraries (such as mod_php) and it is ideal for request (process) isolation. It is process per request model.</p>
<p><strong>worker</strong> &#8211; hybrid multi-process, multi-threaded</p>
<p>A single process is responsible for spawning child processes. Each child process creates a fixed number of threads, as well as listener thread which listens for connections and passes them to server thread for processing. Basically worker uses threads to serve requests so it is being able to serve a large number of request by using less system resources than a prefork, process-based web server. It retains much of the stability of the process-based server by maintaining multiple processes available, each with many threads. Apache always tries to maintain a pool of spare or idle server threads, which stand ready to serve incoming requests. The main process is started as root, while the child processes and threads are launched as a less-privileged user (<em>User</em> and <em>Group</em> directives). Though, keep in mind that PHP&#8217;s thread safety is highly disputed.</p>
<p><strong>event</strong> &#8211; consuming threads only for connections with active processing, based on worker</p>
<p>Event MPM is designed to allow more requests to be served simultaneously by passing some processing work to supporting threads, freeing up the main threads to work on new processes. Event MPM is experimental in 2.2, but stable and supported in 2.4.</p>
<p>I will also mention two more MPMs that are written to address the privilege separation problem (running virtual hosts under different UID and GID): <strong>mpm-itk</strong> and <strong>mpm-peruser</strong>. I won&#8217;t go into describing these as each of these have their own shortcomings, such as peruser MPM is considered not to be production ready, while mpm-itk processes request headers as root, switches to the target UID, and then kills the httpd process when finished serving the connection. Processing headers as root is very dangerous and opens the web server up to many potential security problems.</p>
<p>So to conclude MPMs &#8211; prefork is a safer choice, while threading should have better performance with less overhead (should be more effective within multiprocessor environments).</p>
<p>Apache allows the use of <strong>filters</strong> to process incoming or outgoing data in a configurable manner. Some examples of filter modules include mod_ssl for https, mod_deflate for compression/decompression on the fly and mod_ext_filter for running external programs as filters.</p>
<p>Apache also uses <strong>handlers</strong> which define action to be performed when a file is called. Handlers may be configured based on either file type, filename extensions or on location, without relation to file type. Some types of built-in handlers are server-status and server-info.</p>
<h3>Installation and optimization</h3>
<p>Since I want everything to install quickly and easily for the purpose of this article, I will not go for the newest version, but will instead install httpd version 2.2.15 from CentOS 6.2 repositories:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ sudo yum install httpd</pre>
<p>Query the set of the modules that are compiled directly into the binary:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ httpd -l
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c</pre>
<p>The httpd version from the repositories has the common prefork MPM compiled in. If we needed the worker MPM we would have to compile httpd from source with enabled support for the worker module.</p>
<p>Next, ensure that the service starts on boot:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ chkconfig --list httpd
httpd          	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[pawwa@www2 ~]$ sudo chkconfig --level 35 httpd on
[pawwa@www2 ~]$ chkconfig --list httpd
httpd          	0:off	1:off	2:off	3:on	4:off	5:on	6:off</pre>
<p>Start the service with the default configuration and check its memory footprint and number of processes:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ sudo service httpd start
Starting httpd:                                            [  OK  ]
[pawwa@www2 ~]$ sudo netstat -tlnp | grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      4408/httpd
[pawwa@www2 ~]$ sudo ps -C httpd -O user,ppid,vsz,rss --forest
  PID USER      PPID    VSZ   RSS S TTY          TIME COMMAND
 4408 root         1 175524  3796 S ?        00:00:00 /usr/sbin/httpd
 4410 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4411 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4412 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4413 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4414 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4415 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4416 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd
 4417 apache    4408 175524  2412 S ?        00:00:00  \_ /usr/sbin/httpd</pre>
<p>This confirms that we are using prefork MPM: there is one parent httpd process that is listening on http port which launched several child processes. 8 server processes are started because of the &#8216;StartServers 8&#8242; directive in httpd.conf. The listing shows virtual memory size of 175524 KB (VSZ is entire virtual memory of a process, pretty much irrelevant, VmLib + VmExe + VmData + VmStk) and resident set size of 2413 of individual child processes (RSS is the non-swapped physical memory that a task has used,  including code, data and stack segments). Keep in mind that GNU/Linux ps utility does not report the real memory usage of the process, only the approximation, since it assumes that the single process is the only one running on the system, while there are of course dozen of running processes at any given time that share single copies of referenced libraries (such as libc). The more realistic representation of memory usage can be acquired with pmap -d PID command but its output is somewhat hard to interpret. To make it short, &#8220;r-x&#8221; are code segments, while &#8220;rw-&#8221; are data segments. If you factor out the shared libraries code segments, you end up with wirtable/private figure that is shown at the end of the pmap output, which in my example shows 1996K for httpd child process:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ sudo pmap -d 4417 | tail -1
mapped: 175524K    writeable/private: 1996K    shared: 580K</pre>
<p>This is different and less than approximated 2412K reported by ps. This information becomes crucial for configuring MaxClients directive which determines how many concurrent requests the web server can actually handle. Another trick to get detailed stats is to check  /proc/PID/status of a process.</p>
<p>Next step is to comment LoadModule directives in httpd.conf for the dynamicly shared modules (DSOs) that are not being used. When I have cleaned my configuration out of unnecessary modules I reduced the size of a single httpd child process by ~500K. Here&#8217;s a dump of modules at this point:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ httpd -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 authn_file_module (shared)
 authn_default_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 authz_groupfile_module (shared)
 authz_default_module (shared)
 log_config_module (shared)
 logio_module (shared)
 setenvif_module (shared)
 mime_module (shared)
 autoindex_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 actions_module (shared)
 alias_module (shared)
Syntax OK</pre>
<p>Later on I will be adding modules such as mod_rewrite, mod_deflate and mod_ssl, which will increase httpd&#8217;s memory footprint for about 500K.</p>
<p>Next, move-on to prefork MPM optimization. The most important directive is MaxClients, which defines the number of simultaneous requests that can be served. It defines the hard limit on the number of running child httpd processes. The default value of 256 sounds like a lot and should be reduced on smaller systems. A too high setting can pre-fork a lot of httpd processes which could use all of the servers available memory. This could cause the system to come to an OOM state and start thrashing (performing more memory management and paging in and out then any real work). One should furthermore carefully tune this parameter if the server is running DBMS and any other subsystems. The more memory you leave for the operating system, the more space it will have to perform file system caching. Choosing values for MaxClients involves some trial and error, and measuring number of processes at peak times. Basically, the figure could be calculated as:</p>
<p>( total memory &#8211; operating system memory &#8211; DBMS memory ) / memory footprint of httpd</p>
<p>Eliminate all the extra checks the Web server must do. Some well known optimization techniques are to disable hostname lookups, enable FollowSymLinks (saves a lot on disk activity), disable .htaccess checks on every directory (move .htaccess configuration to httpd.conf whenever possible), avoid wild cards as parts of directives, experiment on keep alive values for handling persistent connections, and similar.</p>
<p>From the hardware perspective, <span style="text-decoration: underline;">RAM is crucial</span> for performance (caching, mod_mem_cache for dynamic content), while heavily dynamic websites have higher CPU requirements. RAID arrays with striping modes of operation increase file serving performance.</p>
<p>&nbsp;</p>
<h2>PHP: Hypertext Preprocessor</h2>
<p>PHP is a general purpose scripting language that is most frequently embedded into HTML. Ultimately, the code is interpreted by a web server containing a PHP processor module which generates a web page.</p>
<h3>Versions</h3>
<p>PHP 5 is the current generation of PHP. At the time of writing this article the supported versions are 5.3.10 and 5.4.0. One can run several versions on a single system and contain debug builds.</p>
<h3>PHP handling</h3>
<p>There are different ways to integrate PHP with Apache httpd. Each handler affects web server performance and features that can be used by employing them. The basics of a few popular PHP handlers are presented below.</p>
<p><strong>mod_php</strong> runs as Apache <strong>DSO</strong> module. This means excellent performance, but not so flexible, and poor security as all PHP code is run as the user that has launched httpd process (defined with the <em>User</em> directive within httpd.conf). This is the most usual way to use PHP tough.</p>
<p><strong>suPHP</strong> runs as a CGI module, but executes scripts as the user who owns them. It consists of an Apache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apache module to change the uid of the process executing the PHP interpreter. It is more secure as the scripts not owned by a particular user will not be executable. Also, the files that have permissions set to world writable will likewise be non-executable. You can have a custom php.ini per site and run PHP 4 and PHP 5 at the same time. The drawback is that suPHP runs higher on CPU making it a slower solution than mod_php (mod_php is about 20-30% faster) and it does not support opcode caching.</p>
<p><strong>FastCGI</strong> is high performance CGI. It has the security benefits of user separation, very good performance and support for opcode caching. The caveat: high memory usage. This is because rather then creating a process per PHP request, it keeps a persistent session open in the background. One benefit is that you can have FastCGI running on different machine.</p>
<p><strong>PHP-FPM</strong> (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. It is good in security and performance terms, but I am interested in the stability.</p>
<p>There is also <strong>mod_ruid2</strong>, which isn&#8217;t a PHP handler but can work with one (except with FastCGI). It is an Apache extension that allows all requests to a domain to run as the owner of that domain. It is usually deployed in conjunction with mod_php to leverage security of user separation through POSIX capabilities, while having excellent performance. It also supports opcode caching, as oposed to suPHP, but allows only one php.ini for all web sites. I am interested in how stable this module really is, as one benchmark marked it as bad in terms of stability.</p>
<p>In terms of security, almost all of these modules are subject to a server compromise if Apache was hacked, and because of that I would recommend employing additional security layers, such as mandatory access control mechanisms.</p>
<h3>Installation</h3>
<p>To deploy PHP to prefork-based Apache for a VPS that is tight on CPU and RAM, I choose mod_php and mod_ruid2 for user-based security. Follow installation instructions from mod_ruid2&#8242;s README file, while a simple &#8216;yum install php&#8217; will install mod_php and all the necessary files such as php.ini, few PHP modules, php.conf configuration for httpd and such.</p>
<p>If you need additional PHP modules for your applications, search for their corresponding package names by executing &#8216;yum search php. module&#8217;. For example, if you will be connecting to MySQL database from your PHP scripts you will need to install php-mysql package. Keep in mind that you should install only the modules you will actually need!</p>
<p>PHP files don&#8217;t need to be executable, since they are handled by the module directly (AddHandler Apache directive). The php.ini configuration file is read when PHP starts up, which happens only once  &#8211; when the web server has started. Remember to copy the recommended <strong>php.ini-production</strong> file over /etc/php.ini for production environment. You can set PHP configuration directives in httpd.conf and .htaccess files also as far as you have &#8216;AllowOverride Options&#8217; or &#8216;AllowOverride All&#8217; privileges.</p>
<p>Keep an eye on the following PHP resource settings:</p>
<ul>
<li><strong>max_execution_time</strong> – how much CPU seconds a script can use (30)</li>
<li><strong>max_input_time</strong> &#8211; How long (seconds) a script can wait for input data (60)</li>
<li><strong>memory_limit</strong> &#8211; How much memory (bytes) a script can consume before being killed (32M)</li>
<li><strong>output_buffering</strong> &#8211; How much data (bytes) to buffer before sending out to the client (4096)</li>
</ul>
<p>Since my VPS has a small amount of RAM I will not employ opcode caching. If you have more RAM, install opcode cache such as eAccelerator, APC or ionCube Accelerator. Opcode is a binary representation of the code to be executed. An opcode cache saves compiled opcode and reuses it the next time the page is called. This saves a considerable amount of time.</p>
<p>&nbsp;</p>
<h2>MySQL</h2>
<p>MySQL is a popular database for use in web applications. It is also used in many large-scale web sites such as wikipedia, google, facebook, twitter, youtube and others.</p>
<h3>Versions</h3>
<p>Versions 5.0.x and below are no longer actively developed. Current stable release is <strong>5.5.23</strong>. As of version 5.1 there are two offerings that have a common code base: the open source MySQL Community Server and commercial MySQL Enterprise Server.</p>
<p>Since Sun Microsystems was acquired by Oracle, MySQL database had gotten a community-developed fork under the name of MariaDB. The aim of the project is to provide a drop-in replacement to MySQL while being licensed under GNU/GPL.</p>
<h3>Features and database engines</h3>
<p>MySQL had grown into a full featured RDBMS. Among other features, it supports transactions, stored procedures, triggers, SSL, query caching, ACID compliance, replication, clustering, &#8230; It supports several different storage engines which provide CRUD (create, read, update, delete) functions on the database. The most popular ones are:</p>
<p><strong>MyISAM</strong> &#8211; <strong>for read speed</strong>, but no transactions. Table-level locking (performance can suffer with high profile applications). Full-text indexes and searches. They crash relatively often. In the case of a crash, it has to rescan whole indexes and possibly tables to recover. There is a myisamchk utility to repair the database in the case of data corruption, but it is not guaranteed to work. Many hosting providers only support MyISAM.  Each table is presented as three files on disk with the following extensions: frm (definition), MYD (data) and MYI (index data).</p>
<p><strong>InnoDB</strong> &#8211; default as of 5.5, <strong>ACID</strong> compliant <strong>transactional features</strong>, referential integrity through foreign keys, higher concurrency. Row-level locking. In the case of a crash it recovers faster from the transactional log.</p>
<h3>Installation and tuning</h3>
<p>Install mysql server and client packages:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ sudo yum install mysql mysql-server</pre>
<p>Start mysqld service and run mysql_secure_installation to set the root password, remove test database and anonymous users:</p>
<pre class="brush: bash; gutter: false">[pawwa@www2 ~]$ sudo mysql_secure_installation</pre>
<p>If the goal of database tuning is to reduce the memory footprint of the database, eliminating various buffers will certainly help, at the expense of query speed and application performance. Instead, one of the metrics should be application response time, which opens up tuning possibilities other than just the database&#8217;s memory usage. Always look at optimizing your queries first though &#8211; the most dramatic benefits usually come from proper indexing and carefully written queries.</p>
<p>Here are some parameters to tune:</p>
<ul>
<li><strong>key_buffer_size</strong> &#8211; the most useful single variable to tweak (some rough suggestions are to set it to at least a quoter of available memory). The larger you set it, the more of your MyISAM table indexes you store in memory.</li>
<li><strong>innodb_buffer_pool_size</strong> &#8211; while the key_buffer_size is the variable to target for MyISAM tables, for InnoDB tables it is innodb_buffer_pool_size.</li>
<li><strong>table_open_cache</strong> &#8211; each time MySQL accesses a table, it places it in the cache. If your system accesses many tables, it is faster to have these in the cache. A good way to see whether your system needs to increase this is to examine the value of open_tables at peak times. Variables to watch are Open_tables and Opened_tables.</li>
<li><strong>sort_buffer</strong> &#8211; it can be useful if performing large numbers of sorts.</li>
<li><strong>read_rnd_buffer_size</strong> &#8211; if you use many queries with ORDER BY, increasing this parameter can improve performance.</li>
<li><strong>tmp_table_size</strong> &#8211; This variable determines the maximum size for a temporary table in memory. If the table becomes too large, a MyISAM table is created on disk. Try to avoid temporary tables by optimizing the queries where possible, but where this is not possible, try to ensure temporary tables are always stored in memory. Watching the processlist for queries with temporary tables that take too long to resolve can give you an early warning that tmp_table_size needs to be increased.</li>
<li>&#8230;<strong></strong></li>
</ul>
<p>&nbsp;</p>
<p>This is the end of this longish article <img src='http://www.pawwa.in.rs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  As a final tip remember that constant measurement of performance really helps in tuning and optimizing. Watch CPU, IO, bandwidth, etc. Spot trends. React.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2012/04/lamp-considerations-installation-and-tuning/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bachelor thesis: Cloud Computing Concepts and Technologies</title>
		<link>http://www.pawwa.in.rs/2012/04/bachelor-thesis-cloud-computing-concepts-and-technologies/</link>
		<comments>http://www.pawwa.in.rs/2012/04/bachelor-thesis-cloud-computing-concepts-and-technologies/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 16:47:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cloud Computing]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=242</guid>
		<description><![CDATA[&#160; I had the &#8220;fortunate&#8221; opportunity of becoming a student in early 2000s &#8211; a period in which Bologna Process was forming academic degree standards in Europe which is today known as Bologna Declaration document. When I graduated college in year 2007, I was expecting a degree that was promised by the school &#8211; a bachelor&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>I had the &#8220;fortunate&#8221; opportunity of becoming a student in early 2000s &#8211; a period in which <em>Bologna Process</em> was forming academic degree standards in Europe which is today known as <em>Bologna Declaration</em> document. When I graduated college in year 2007, I was expecting a degree that was promised by the school &#8211; a bachelor&#8217;s degree, but I didn&#8217;t get one as <em>Bologna Process</em> wasn&#8217;t finished. What I had got was an academic title of a Bachelor of Engineering that couldn&#8217;t be easily recognized in the rest of the world I suppose.</p>
<p>As in the meanwhile the <em>Bologna Declaration</em> was signed, I decided to claim the bachelor&#8217;s title that belongs to me. What I had to do was to put together an extra one more bachelor thesis document, so I decided to write about <strong>cloud computing</strong>. Although it is completely written in Serbian language, here&#8217;s an English abstract that describes the main goals so you can get the impression of what&#8217;s it about:</p>
<p>&nbsp;</p>
<hr />
<p><em>This paper describes the cloud computing model and technology.</em></p>
<p><em>The first section presents virtualization technology, whose introduction and wider acceptance enabled architecting of optimized data centers which can nowadays support the cloud computing model. In addition to general definitions, terms and types of virtualization, also being presented are a number of leading open-source virtualization projects.</em></p>
<p align="JUSTIFY"><em>The second chapter deals with the topic of cloud computing. It interprets the architecture, presents the characteristics and describes deployment and service models.<br />
</em></p>
<p><em>The last chapter presents a number of popular open-source software projects for implementing the infrastructure as a service cloud model. It also specifies the typical and general Service License Agreement conditions, and gives a comprehensive real-world implementation example on the case of Amazon Web Services.</em></p>
<hr />
<p>&nbsp;</p>
<p>If you can read in Serbian language feel free to download and check my work:</p>
<ul>
<li><a href="http://www.pawwa.in.rs/wp-content/uploads/2012/04/koncepti_i_tehnologije_cloud_racunarstva.pdf">Bachelor thesis: Cloud Computing Concepts and Technologies</a> - main document</li>
<li><a href="http://www.pawwa.in.rs/wp-content/uploads/2012/04/koncepti_i_tehnologije_cloud_racunarstva_prezentacija.pdf">Bachelor thesis: Cloud Computing Concepts and Technologies</a> &#8211; a presentation</li>
</ul>
<p>Note that the presentation PDF is more like a quick personal reminder than a real presentation (lots of small sized fonts <img src='http://www.pawwa.in.rs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ).</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2012/04/bachelor-thesis-cloud-computing-concepts-and-technologies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes on awkward Debian Squeeze netinst experience</title>
		<link>http://www.pawwa.in.rs/2012/03/notes-on-awkward-debian-squeeze-netinst-experience/</link>
		<comments>http://www.pawwa.in.rs/2012/03/notes-on-awkward-debian-squeeze-netinst-experience/#comments</comments>
		<pubDate>Fri, 16 Mar 2012 23:47:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=174</guid>
		<description><![CDATA[Few weeks ago I have decided to install Debian Squeeze on one of my machines. I have obtained and burned the latest netinst image so I could install the most current and up-to-date packages from the repositories. Unfortunately, and surprisingly, this wasn&#8217;t such a comfortable ride&#8230; Wireless problems I use cable broadband and a home [...]]]></description>
			<content:encoded><![CDATA[<p>Few weeks ago I have decided to install <em>Debian Squeeze</em> on one of my machines. I have obtained and burned the latest <a title="http://www.debian.org/CD/netinst" href="http://www.debian.org/CD/netinst">netinst</a> image so I could install the most current and up-to-date packages from the repositories. Unfortunately, and surprisingly, this wasn&#8217;t such a comfortable ride&#8230;<span id="more-174"></span></p>
<h2>Wireless problems</h2>
<p>I use cable broadband and a home WLAN for providing Internet access to the connecting clients, and thus wanted to perform a network installation via wireless connection. This is where it had all begun.</p>
<p>I know &#8211; <em>Equi donati dentes non inspiciuntur</em>, but this PCI wireless NIC that I had in the machine was an unsupported and notorious <strong><em>Broadcom</em></strong> chip. When the d-i (<em>debian-installer</em>) tried to load a driver for it, it failed, and the console output complained about <strong>missing firmware</strong>. This device needs proprietary firmware to be loaded onto the chip before it can operate. Ok, so I performed a couple of reboots to search the net for the right firmware for my WiFi device, and when I finally found one, d-i had loaded the firmware but it <strong>could not sense the link</strong>. I tried a couple of different firmwares I had found on the Internet, but without luck. Finally, I though my wireless card was dying.</p>
<p>Luckily enough, I have had another USB powered WiFi NIC. Since this was a <em>RealTek</em>, it had no problems with missing firmware, but again it could not sense the link. So another half an hour of troubleshooting, and I had found out what was the problem &#8211; the <em>Debian</em> installer <strong>does not support encrypted <em>WPA</em></strong>! This was a shock. When I reconfigured my wireless router to use <em>WEP</em>, it worked.</p>
<h2>Overlapping partitions problem</h2>
<p>Debian installer <strong>could not recognize</strong> my existing and <strong>working partition table</strong> (this machine had a working setup consisted of <em>Windows XP</em> and <em>Ubuntu</em>). I tried several moves to resolve this, such as writing the partition table again with <em>fdisk</em> and similar, but at the end I had found that I had overlapping partitions problem. It was resolved by using a powerful and free data recovery utility <a title="TestDisk" href="http://www.cgsecurity.org/wiki/TestDisk" target="_blank">testdisk</a>.</p>
<h2>Audio playing faster problem</h2>
<p>On this machine I have a professional audio interface,<strong><em> E-MU 0404</em></strong> PCI variant. The lack of driver support for it on <em>Linux</em> was the main reason why this machine wasn&#8217;t used primarily as a <em>Linux</em> box. Since <em>ALSA</em> did include the support for this interface, I wanted to give it a try. I installed the module (<em>snd_emu10k1</em>) and it worked out of the box but the <strong>playback was slightly faster</strong> <img src='http://www.pawwa.in.rs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  This was resolved by changing the sampling rate to 48kHz by creating the file <em>/etc/asound.conf</em> with the following configuration:</p>
<pre class="brush: bash; gutter: true">pcm.!default {
        type plug
        slave {
                pcm &quot;hw:0,0&quot;
                rate 48000
        }
}</pre>
<p>Aaaand, this machine was finally usable <img src='http://www.pawwa.in.rs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  I am not saying that this is all <em>Debian</em>&#8216;s fault of course (although <em>WPA</em> support during install time and some hints regarding partition table recognition would be nice), but I had just remembered how <em>Linux</em> installation used to be a pain in the ass a long time ago <img src='http://www.pawwa.in.rs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Yet this kind of working-my-way-through was sure one of the things that attracted me to <em>GNU/Linux</em> in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2012/03/notes-on-awkward-debian-squeeze-netinst-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jd-gui &#8211; yet another fast Java decompiler</title>
		<link>http://www.pawwa.in.rs/2011/12/jd-gui-yet-another-fast-java-decompiler/</link>
		<comments>http://www.pawwa.in.rs/2011/12/jd-gui-yet-another-fast-java-decompiler/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 15:15:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=154</guid>
		<description><![CDATA[Sometimes jd-gui, java class decompiler, really comes in handy (if the code is not obfuscated or protected in some other way of course): http://java.decompiler.free.fr/?q=jdgui]]></description>
			<content:encoded><![CDATA[<p>Sometimes jd-gui, java class decompiler, really comes in handy (if the code is not obfuscated or protected in some other way of course): <a title="jd-gui" href="http://java.decompiler.free.fr/?q=jdgui">http://java.decompiler.free.fr/?q=jdgui</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2011/12/jd-gui-yet-another-fast-java-decompiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Correct driver for a device</title>
		<link>http://www.pawwa.in.rs/2011/12/correct-driver-for-a-device/</link>
		<comments>http://www.pawwa.in.rs/2011/12/correct-driver-for-a-device/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 17:16:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=155</guid>
		<description><![CDATA[Here&#8217;s a tip to check whether your piece of hardware is supported by the installed Linux kernel modules on your machine. First, check lspci output for let&#8217;s say a wireless card: $ lspci &#124; grep -i wireless 01:00.0 Network controller: Atheros Communications Inc. AR928X Wireless Network Adapter (PCI-Express) (rev 01) Note the number 01:00.0 in [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a tip to check whether your piece of hardware is supported by the installed Linux kernel modules on your machine.</p>
<p><span id="more-155"></span>First, check lspci output for let&#8217;s say a wireless card:</p>
<pre class="brush: bash; gutter: false">$ lspci | grep -i wireless
01:00.0 Network controller: Atheros Communications Inc. AR928X Wireless Network Adapter (PCI-Express) (rev 01)</pre>
<p>Note the number <strong>01:00.0</strong> in lspci output, in which 01 represents the bus number the device is attached to, 00 is the device number and final 0 is PCI device function. To get more information on that device we could list the entries in /sys/bus/pci/devices/0000:01:00.0 directory of sysfs (a RAM file system that exports kernel structures, attributes and their inner links. udev uses sysfs also to create dynamic device files). lspci actually reads sysfs.</p>
<p>Next, we print <strong>raw</strong> (<strong>-n</strong> option) PCI identification data that includes the previous numbers:</p>
<pre class="brush: bash; gutter: false">$ lspci -n | grep 01:00.0
01:00.0 0280: 168c:002a (rev 01)</pre>
<p>These numbers are from /usr/share/misc/pci.ids file. Lets brake down the numbers:</p>
<ul>
<li>01:00.0 &#8211; 01 is bus number, 00 device number, 0 device function</li>
<li>0280 &#8211; device class</li>
<li>168c &#8211; vendor ID</li>
<li>002a &#8211; device ID</li>
</ul>
<p>We use the vendor ID and device ID numbers and compare them to a modinfo of kernel drivers:</p>
<pre class="brush: actionscript3; gutter: true">$ find /lib/modules/$(uname -r)/kernel/drivers -type f -exec modinfo "{}" \; | grep -B 200 -i 168c | grep -B 50 -i 002a | grep filename
filename:       /lib/modules/2.6.31-23-generic/kernel/drivers/net/wireless/ath/ath5k/ath5k.ko
filename:       /lib/modules/2.6.31-23-generic/kernel/drivers/net/wireless/ath/ath9k/ath9k.ko</pre>
<p>So, my wireless card is supported by the ath9k driver. If I didn&#8217;t got the output from modinfo, it would probably mean that the hardware is not supported and that I need to get the driver from the device vendor. I could also search only for the vendor ID to get some results but that could yield some unexpected results I suppose.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2011/12/correct-driver-for-a-device/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Servers and racks compability (EIA-310)</title>
		<link>http://www.pawwa.in.rs/2011/11/servers-and-racks-compability-eia-310/</link>
		<comments>http://www.pawwa.in.rs/2011/11/servers-and-racks-compability-eia-310/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 10:09:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Hardware]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=137</guid>
		<description><![CDATA[One of the things to check in a planning process of acquiring a new rack-mount server, is if it will fit in your existing server rack. As www.server-racks.com states: not all racks are created equal and not all servers will fit in all racks. No mater if you have a 19&#8243; rack, some servers might [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things to check in a planning process of acquiring a new rack-mount server, is if it will fit in your existing server rack. As <a title="server-racks.com" href="www.server-racks.com">www.server-racks.com</a> states: not all racks are created equal and not all servers will fit in all racks.</p>
<p><span id="more-137"></span> No mater if you have a 19&#8243; rack, some servers might not fit in. There is a standard named EIA-310-D which defines &#8220;standard rack&#8221; and specifies design features for 19&#8243; racks.</p>
<p>The problem is that this standard does not define some details such as how deep is rack&#8217;s mounting width, rack holes (threaded, rounded, square&#8230;). For example, rack holes are the number one problem for server and rack incompatibility. Things should be good if you have square holes on your rack &#8211; you can always add threads with a cage nut if you need them.</p>
<p>In December of 1995 the EIA-310-D standard was updated. The changes made were mostly grammatical. The mechanical requirements were left unchanged. The updated documentation was originally known as EIA-310-E. It is currently referred to as EIA/ECA-310-E</p>
<p>So, be careful when choosing new servers for your racks, always double check the compatibility between them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2011/11/servers-and-racks-compability-eia-310/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open source fingerprint biometrics</title>
		<link>http://www.pawwa.in.rs/2011/11/open-source-fingerprint-biometrics/</link>
		<comments>http://www.pawwa.in.rs/2011/11/open-source-fingerprint-biometrics/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 11:46:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=111</guid>
		<description><![CDATA[DigitalPersona has open sourced its fingerprint minutiae extraction technology &#8211; FingerJetFX OSE. It is released under LGPL license and is MINEX-certified (fingerprint template interoperability standard). It&#8217;s written in C++ and can run on Linux, Windows, Android and some other operating systems. FingerJetFX runs well on embedded chips, desktop computers and servers. They say that it [...]]]></description>
			<content:encoded><![CDATA[<p>DigitalPersona has open sourced its fingerprint minutiae extraction technology &#8211; <strong>FingerJetFX</strong> <strong>OSE</strong>.</p>
<p>It is released under LGPL license and is <a title="MINEX" href="http://www.nist.gov/itl/iad/ig/minex.cfm">MINEX</a>-certified (fingerprint template interoperability standard). It&#8217;s written in C++ and can run on Linux, Windows, Android and some other operating systems. FingerJetFX runs well on embedded chips, desktop computers and servers. They say that it is easy to use &#8211; it can be used with as little as one function call.</p>
<p>More information @ <a href="http://digitalpersona.com/fingerjetfx">http://digitalpersona.com/fingerjetfx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2011/11/open-source-fingerprint-biometrics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which hardware for virtualization server?</title>
		<link>http://www.pawwa.in.rs/2011/11/which-hardware-for-virtualization-server/</link>
		<comments>http://www.pawwa.in.rs/2011/11/which-hardware-for-virtualization-server/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 13:45:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://www.pawwa.in.rs/?p=112</guid>
		<description><![CDATA[Here are some notes that I took when I was choosing components for a server to run the KVM-based virtualized environment. Introduction The new server was meant to be placed in our DMZ and should run a few virtual machines providing services to external clients. Some basic hardware requirements were: 1U rack mount 1 x [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some notes that I took when I was choosing components for a server to run the KVM-based virtualized environment.</p>
<p><span id="more-112"></span></p>
<h1>Introduction</h1>
<p>The new server was meant to be placed in our DMZ and should run a few virtual machines providing services to external clients.</p>
<p>Some basic hardware requirements were:</p>
<ul>
<li>1U rack mount</li>
<li>1 x Xeon based CPU</li>
<li>8 GB RAM</li>
<li>2 x 500 GB</li>
<li>Hardware RAID</li>
<li>2 x Intel NIC, 1Gbps</li>
</ul>
<p>The software and services which are planned to be installed or implemented:</p>
<ul>
<li>Debian Squeeze</li>
<li>KVM</li>
<li>MySQL</li>
<li>NTP</li>
<li>JBoss</li>
<li>EJBCA</li>
<li>VPN</li>
<li>&#8230;</li>
</ul>
<h2>Some virtualization notes</h2>
<p>There are different performance goals:</p>
<ul>
<li>Single guest performance</li>
<li>Aggregate performance</li>
<li>Density (as much guests running on single host)</li>
</ul>
<p>Virtualization optimization depends on the needs. Experiment with transparent huge pages, try different IO schedulers, try hyperthreading&#8230; High performance virtualization is <strong>hard</strong>. Some things just cannot be emulated efficiently. Timekeeping has always been a virtualization headache. It is good to have a tickless kernel, and pvclock so guests can ask the host what time it is.</p>
<h1>KVM</h1>
<p>KVM (Kernel-based Virtual Machine) is virtualization hypervisor. It is integrated in kernel, lightweight and great in performance. The host machines need to be running either Intel VT or AMD-V chipsets that support hardware-assisted virtualization.</p>
<h1>Hardware</h1>
<h2>CPU</h2>
<p>Since Xeon was on the requirements list, I was looking for ones with the following capabilities:</p>
<ul>
<li>VT-x</li>
<li>Hyperthreading (?)</li>
<li>ECC</li>
</ul>
<p>From the Xeon-5500 series, probably the best model for virtualization is E5520 (2.26GHz) in price/performance estimation. We have chosen quad-core <a href="http://ark.intel.com/products/47925/Intel-Xeon-Processor-E5620-%2812M-Cache-2_40-GHz-5_86-GTs-Intel-QPI%29">Intel® Xeon® E5620</a>. It is a quad core CPU that supports VT-x, ECC memory and hyperthreading.</p>
<p>By the way, the main difference between some cheaper consumer CPU&#8217;s such as Intel&#8217;s I7 and enterprise targeted CPU&#8217;s such as Intel&#8217;s Xeon, is the support for ECC memory which is a must for mission critical applications.</p>
<h3>VT</h3>
<p>Nowadays, Virtualization Technology instruction set is implemented inside the CPU&#8217;s, which makes hypervisors simpler, thus providing better performance over software-only virtualization solutions.</p>
<h3>Hyperthreading</h3>
<p>Is Hyperthreading an advantage or can it have even a negative impact on the system? Because HT takes advantage of unknown variables (cache misses for example), it is hard to take advantage of HT. It seems that nobody has a real idea of how HT impacts on application performances. Depending on application internal architecture HT execution of threads can be a benefit or a real pain. Some suggest switching HT off.</p>
<p>Hyperthreading can reduce scheduling latencies, which reduces spinlock worst case overhead.</p>
<h2>Memory</h2>
<h2>Registered on unbuffered?</h2>
<p>In enterprise server systems, it is a question of registered or unbuffered memory modules. Registered (also called buffered) memory modules have a register between the DRAM modules and the system&#8217;s memory controller. They place less electrical load on the memory controller and allow single systems to <strong>remain stable with more memory modules</strong> than they would have otherwise.</p>
<p>The difference between registered memory and unbuffered memory is whether there are registers on the memory module. Almost all system memory in today’s PCs is unbuffered memory. For those who need to utilize more than 4GB of memory (maybe more like 16GB or 32GB) in a system, registered memory is absolutely a must-have. Registered memory is all about scalability and <strong>stability</strong>. A small performance hit is generally incurred.</p>
<h2>ECC</h2>
<p>ECC stands for Error Checking and Correction. ECC detects and corrects memory errors so it is highly advisable to use this type of modules in servers that utilize multi-gigabytes of memory and usually run 24/7, and have increased probability of soft errors.</p>
<h2>Storage adapter (RAID)</h2>
<p>Beware of fakeraid controllers! Check driver support for your operating system or support in Linux vanilla kernel, and decide whether to use battery backed cache. The cache memory in RAID controllers improves performance to some extent by storing information that was recently used, or that the controller predicts will be used in the future, so it can be supplied to the system at high speed if requested instead of necessitating reads from the slow hard disk platters. Battery backed cache is for data protection from unexpected power outage. In every case, the goal of the cache is the same: to provide a temporary storage area that allows a faster device to run without having to wait for a slower one.</p>
<p>One area where caching can impact performance significantly is write caching, sometimes also called write-back caching. When enabled, on a write, the controller tells the system that the write is complete as soon as the write enters the controller&#8217;s cache; the controller then &#8220;writes back&#8221; the data to the drives at a later time. The reason that write-back caching is so important with RAID is while writes are slightly slower than reads for a regular hard disk, for many RAID levels they are much slower.</p>
<p>Read performance under mirroring is far superior to write performance.</p>
<p>Chosen controller for our system is <a href="http://www.redbooks.ibm.com/abstracts/tips0738.html">ServeRAID M5014 SAS/SATA Controllers</a> because it is supported in Linux vanilla kernel (driver name is <em>megaraid_sa</em>s), and it provides additional performance advantages of an adequate amount of cache (256MB) + we ordered a standard battery backup unit.</p>
<h2>Hard drives</h2>
<p>We have chosen 2 x IBM 500GB 7200 6Gbps NL SAS 2.5&#8243; SFF Slim-HS HDD.</p>
<h3>SAS vs. SATA</h3>
<ul>
<li>SAS is full duplex</li>
<li>SATA uses the ATA command set; SAS uses the <acronym title="Small Computer System Interface">SCSI</acronym> command set</li>
<li>SAS hardware allows multipath I/O to devices while SATA (prior to SATA 3Gb/s) does not</li>
<li>SATA is more consumer, SAS targets critical server applications</li>
<li>SAS error-recovery and error-reporting use <acronym title="Small Computer System Interface">SCSI</acronym> commands which have more functionality than the ATA SMART commands used by SATA drives</li>
</ul>
<h2>Network adapters</h2>
<p>We have chosen Intel Ethernet Dual Port Server Adapter I340-T2 for IBM System x, as it is based on 82580 chip that is supported by Linux in <a title="IBM link to igb driver" href="http://downloadcenter.intel.com/detail_desc.aspx?agr=Y&amp;DwnldID=13663">igb</a> driver.:</p>
<pre class="brush: actionscript3; gutter: true"># dpkg -S "igb.ko"
linux-image-2.6.31-19-generic: /lib/modules/2.6.31-19-generic/kernel/drivers/net/igb/igb.ko
linux-image-2.6.31-20-generic: /lib/modules/2.6.31-20-generic/kernel/drivers/net/igb/igb.ko
linux-image-2.6.31-14-generic: /lib/modules/2.6.31-14-generic/kernel/drivers/net/igb/igb.ko
linux-image-2.6.31-22-generic: /lib/modules/2.6.31-22-generic/kernel/drivers/net/igb/igb.ko
linux-image-2.6.31-23-generic: /lib/modules/2.6.31-23-generic/kernel/drivers/net/igb/igb.ko</pre>
<pre class="brush: actionscript3; gutter: true">...
01:00.0 Ethernet controller: Intel Corporation 82580 Gigabit Network Connection (rev 01)
        Subsystem: Intel Corporation Ethernet Server Adapter I340-T2
...</pre>
<p>When choosing network adapter always be careful to look if the device is supported by Linux (for example, for some Broadcom NeXtreme NIC&#8217;s you don&#8217;t have a driver for Debian).</p>
<h1>Software</h1>
<h2>Operating system</h2>
<p>KVM supports both 32 and 64 bit guests. According to KVM&#8217;s guest list, Debian Squeeze is supported.</p>
<h1>References</h1>
<ol>
<li><a href="http://www.linux-kvm.org/page/Main_Page" target="_blank">http://www.linux-kvm.org/page/Main_Page</a></li>
<li><a title="KVM HOWTO" href="http://www.linux-kvm.org/page/HOWTO" target="_blank">http://www.linux-kvm.org/page/HOWTO</a></li>
<li><a href="http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=/liaai/kvminstall/liaaikvminstallstart.htm" target="_blank">http://publib.boulder.ibm.com/infocenter/lnxinfo/v3r0m0/index.jsp?topic=/liaai/kvminstall/liaaikvminstallstart.htm</a></li>
<li><a href="http://searchservervirtualization.techtarget.com/answer/Hyperthreading-in-virtualized-environments" target="_blank">http://searchservervirtualization.techtarget.com/answer/Hyperthreading-in-virtualized-environments</a></li>
<li><a href="http://www.redhat.com/promo/summit/2010/presentations/summit/in-the-weeds/thurs/riel-420-kernel/summit2010-kvm-optimizations.pdf">http://www.redhat.com/promo/summit/2010/presentations/summit/in-the-weeds/thurs/riel-420-kernel/summit2010-kvm-optimizations.pdf</a></li>
<li><a href="http://www.pcguide.com/ref/hdd/perf/raid/conf/advCaching-c.html">http://www.pcguide.com/ref/hdd/perf/raid/conf/advCaching-c.html</a></li>
<li><a href="http://blog.fastmail.fm/2009/10/19/ibm-x3550-m2-or-x3650-m2-and-debianubuntu/">http://blog.fastmail.fm/2009/10/19/ibm-x3550-m2-or-x3650-m2-and-debianubuntu/</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.pawwa.in.rs/2011/11/which-hardware-for-virtualization-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

