<?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>KarkomaOnline &#187; Articles</title>
	<atom:link href="http://www.karkomaonline.com/index.php/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.karkomaonline.com</link>
	<description>a Blog for SysAdmins and Unix stuff in general</description>
	<lastBuildDate>Thu, 25 Nov 2010 07:49:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Package management in Debian</title>
		<link>http://www.karkomaonline.com/index.php/2006/02/package-management-in-debian/</link>
		<comments>http://www.karkomaonline.com/index.php/2006/02/package-management-in-debian/#comments</comments>
		<pubDate>Fri, 24 Feb 2006 10:40:22 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Linux Debian]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.karkoma.info/index.php/2006/02/24/package-management-in-debian/</guid>
		<description><![CDATA[I use Debian since a while and i must say that i consider that it is the simpler distribution that i know. Well you can ever become some difficulties to install some drivers from proprietary stuff or new brand hardware but once you have your system running, believe me it is the simplest for maintaining, [...]]]></description>
			<content:encoded><![CDATA[<p>I use Debian since a while and i must say that i consider that it is the simpler distribution that i know. Well you can ever become some difficulties to install some drivers from proprietary stuff or new brand hardware but once you have your system running, believe me it is the simplest for maintaining, installing and removing in your system. And dpkg/apt are not least in the last assumption.</p>
<p>The first front-end at which you will stick is dselect, which is a menu based program.</p>
<p>I will not be extended with it because it is simple. What you need to know is that you can update the list of available packages with update, you can select which of them you will install with select. In this option, you go out of the help (going out of the help is the more tricky part) with the space bar (ubuntu like i thing it is with &#8220;enter&#8221;).</p>
<p>You can look for a package named for example firebird tipping &#8220;/fire&#8221; (without quote), and it will look for the first in the list named fire-something package and typing &#8220;n&#8221; you go through this list. Of course it is better typping &#8220;firebird&#8221;. If you want to select for installing you tip &#8220;+&#8221; (&#8220;-&#8221; for deinstalling) and dselect present you the list of conflicting, recommended &#8230; packages that you can choose with the same +- method (you go out of the list by typing enter). Once you&#8217;re satisfied, you tip &#8220;enter&#8221; and it go through the install process.</p>
<p>dselect is easy, not always the more flexible but the more secure and stable you can dream about. But let me present you the second soft of the debian classical tools collection: DPKG.</p>
<p>dpkg is a command line based tool. You can save the list of the installed packages on your system with:</p>
<blockquote><p>dpkg &#8211;get-selections &gt; selections.dpkg</p></blockquote>
<p>Don&#8217;t be so shy and edit this text file. If you want to recover the state of your package selections you type:</p>
<blockquote><p>dpkg &#8211;set-selections (no description available)<br />
pn lynx-cur-wrapp (no description available)<br />
un lynx-ssl (no description available)</p></blockquote>
<p>and if you wish to know all the files that install or simply modify the installation of a package:</p>
<blockquote><p>dpkg -L lynx</p></blockquote>
<blockquote><p>/.<br />
/usr<br />
/usr/bin<br />
/usr/bin/lynx.stable<br />
/usr/share<br />
/usr/share/man<br />
/usr/share/man/man1<br />
/usr/share/man/man1/lynx.1.gz<br />
&#8230;<br />
/etc<br />
/etc/lynx.cfg<br />
&#8230;
</p></blockquote>
<p>You want the information on a package (lynx for example)?</p>
<blockquote><p>dpkg -p lynx</p></blockquote>
<blockquote><p>Package: lynx<br />
Priority: optional<br />
Section: web<br />
Installed-Size: 4292<br />
Maintainer: James Troup<br />
Architecture: i386<br />
&#8230;<br />
Description: Text-mode WWW Browser<br />
Lynx is a fully-featured World Wide Web (WWW) client for users<br />
running cursor-addressable, character-cell display devices (e.g.,<br />
&#8230;</p></blockquote>
<p>That is what a look at <em>/var/lib/dpkg/available</em> will give you after a painful search.</p>
<p>The status of the package can be found with:</p>
<blockquote><p>dpkg -s lynx</p></blockquote>
<p>Imagine that you find a strange file in you system (bad news&#8230;), and you want to make sure which package it comes from:</p>
<blockquote><p>dpkg -S /etc/lynx.cfg</p></blockquote>
<blockquote><p>lynx: /etc/lynx.cfg</p></blockquote>
<p>And you can run again the pre-installation process thanks to:</p>
<blockquote><p>dpkg-reconfigure xserver-xfree86</p></blockquote>
<p>It will replay the pre/post install script at wich you can take a look at /var/lib/dpkg/info/. For example, we had in my company a problem with bacula director&#8217;s instalation because there was a mistake in /var/lib/dpkg/info/bacula-director-mysql.postinst. We had this faultly line:</p>
<blockquote><p>MYSQL_PSWD_STRING=&#8221;-p&#8221;$MYSQL_ROOT_PASSWORD&#8221;"</p></blockquote>
<p>So the given root password was never the one bacula use to connect to mysql as root, we had to transform in:</p>
<blockquote><p>MYSQL_PSWD_STRING=&#8221;-p $MYSQL_ROOT_PASSWORD&#8221;</p></blockquote>
<p>(without the escaped quote)</p>
<p>Of course we have tried to reach the packager. But that&#8217;s not all folks. Now comes the bestpart: &lt;i&gt;apt&lt;/i&gt;. You do not have to download the lynx_2.8.5-sarge1_i386.deb and after install with dpkg -i. No! Just lauch your branded 16k modem to become the line up and type:</p>
<blockquote><p>apt-get install lynx</p></blockquote>
<p>You have heard about a new security update, retrieve it with&#8230;</p>
<blockquote><p>apt-get update</p></blockquote>
<p>Same effect as&#8230;</p>
<blockquote><p>dselect upgrade</p></blockquote>
<p>&#8230;with:</p>
<blockquote><p>apt-get upgrade</p></blockquote>
<p>If you wish to look into the code:</p>
<blockquote><p>apt-get source lynx</p></blockquote>
<p>And all the magic stuff is controlled through <em>/etc/apt/sources.list</em>.</p>
<blockquote><p>deb file:///cdrom/ sarge main<br />
deb http://ftp.de.debian.org/debian/ sarge main non-free contrib<br />
deb-src http://ftp.de.debian.org/debian/ sarge main non-free contrib<br />
deb http://security.debian.org/ sarge/updates main contrib non-free</p></blockquote>
<p>Or better with a mirror:</p>
<blockquote><p>deb http://ftp.rediris.es/debian/ stable main non-free contrib<br />
deb-src http://ftp.rediris.es/debian/ stable main non-free contrib
</p></blockquote>
<p>Or the best, an apt-proxy which proxies your downloads (karkoma, will you write an apt-proxy article, don&#8217;t you?):</p>
<blockquote><p>deb http://aptserv.dmz:9999/debian/ sarge main non-free contrib<br />
deb-src http://aptserv.dmz:9999/debian sarge main non-free contrib<br />
deb http://aptserv.dmz:9999/debian-volatile sarge/volatile main<br />
deb http://aptserv.dmz:9999/security/ sarge/updates main contrib non-free</p></blockquote>
<p>Note the debian-volatile: this is for the highly upgraded packages like clamav, dcc,&#8230;</p>
<p>Another file that can be quite useful is /etc/apt/apt.conf. For example if you have an http proxy for going out in internet you will add in this file:</p>
<blockquote><p>Acquire::http::Proxy &#8220;http://proxy.yourcompany:3128&#8243;;;</p></blockquote>
<p>Or you can simply set the http_proxy=http://proxy.yourcompany:3128 in your environment). In the precedent case of the apt-proxy, if you have an http_proxy and of course you don&#8217;t want to proxy your apt-proxy you can control it by adding in this file:</p>
<blockquote><p>Acquire<br />
{<br />
http<br />
{<br />
Proxy::no_proxy=comm.dmz;<br />
}<br />
}</p></blockquote>
<p>Or add no_proxy=http://aptserv.dmz:9999 in your environment). Note that you have two syntaxes (the first one is the old one and the second one is the new). Don&#8217;t be confused with upgrade and update: update is when the source-list has been changed to synchronize the list of the mirrors and upgrade is to synchronize the list of the new availables packages.</p>
<p>One good tool in case of problems with apt is apt-config. dump&gt; will dump for you your configuration with all the parameters (the defaults too):</p>
<blockquote><p>$ apt-config dump<br />
APT &#8220;&#8221;;<br />
APT::Architecture &#8220;i386&#8243;;<br />
APT::Build-Essential &#8220;&#8221;;<br />
&#8230;<br />
DPkg::Pre-Install-Pkgs:: &#8220;/usr/sbin/dpkg-preconfigure &#8211;apt || true&#8221;;<br />
Acquire &#8220;&#8221;;<br />
Acquire::http &#8220;&#8221;;</p></blockquote>
<p>Caution! When you upgrade to a new distribution of debian (it occurs once every two years more or less, that could be the only criticism of debian), change your source-list, perform an apt-get update, an apt-get upgrade and after that an apt-get dist-upgrade.</p>
<p>One last word. Comes aptitude, a new tool (there is a lot of graphical tools that i don&#8217;t know&#8230;). but for sarge it seems to me that the old ones do a better works (i must take a closer look&#8230;).</p>
<p>Enjoy Debian without moderation&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2006/02/package-management-in-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implementing High Availability in MySQL</title>
		<link>http://www.karkomaonline.com/index.php/2004/01/implementing-high-availability-in-mysql/</link>
		<comments>http://www.karkomaonline.com/index.php/2004/01/implementing-high-availability-in-mysql/#comments</comments>
		<pubDate>Sat, 24 Jan 2004 23:18:41 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.karkoma.info/index.php/2004/01/24/implementing-high-availability-in-mysql/</guid>
		<description><![CDATA[MySQL provides a built-in data replication functionality for maintaining identical copies of its data to one or more backend servers, thus providing a simple High Availability mechanism. On the other hand, the Open Source community has several projects to implement failover techniques, being one of them Heartbeat. This article will show you how to implement [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL provides a built-in data replication functionality for maintaining identical copies of its data to one or more backend servers, thus providing a simple High Availability mechanism. On the other hand, the Open Source community has several projects to implement failover techniques, being one of them Heartbeat.</p>
<p>This article will show you how to implement a clustered, highly available and inexpensive solution based on GNU/Linux and combining <a href="http://www.mysql.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/?referer=');">MySQL</a> as the database engine and <a href="http://linux-ha.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/linux-ha.org/?referer=');">Heartbeat</a> as the failover mechanism. The configuration will consist of a 2-node active/passive cluster.</p>
<p><span id="more-63"></span></p>
<p>I assume you have MySQL up and running on both nodes and that your are working with MySQL 4.0.13 or above. If not, please refer to MySQL manual <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_Installing.html#Installing" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/documentation/mysql/bychapter/manual_Installing.html_Installing?referer=');">here</a> and download a recent copy <a href="http://www.mysql.com/downloads/index.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/downloads/index.html?referer=');">here</a>.</p>
<p><strong>How does replication works in MySQL</strong></p>
<p>Replication in MySQL is very simple: one machine acts as the master server and one or more machines act as the backup servers (the replica servers). The master server keeps all changes made to its databases in binary log files, so the backup server(s) can read these files and apply the changes to its own copy of the data.</p>
<p>In more detail, the binary log file records all the changes (UPDATE, DELETE, INSERT&#8230;) made to the master&#8217;s databases since the first time the replication was configured and started. The master also creates and maintains an index file to keep track of the binary logs created. Upon connecting, the slave server(s) obtains new updates from the binary log and aplies them to its copy of the data.</p>
<p><strong>Note:</strong> As MySQL suggests, visit their <a href="http://www.mysql.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/?referer=');">website</a> often to check the latest changes and improvements to its database replication implementation.</p>
<p><strong>How does Heartbeat works</strong></p>
<p>Heartbeat is a piece of software that provides High Availability features such as monitoring the availability of the machines in the cluster, transferring the virtual IPs (more on this later) in case of failures and starting and stopping services.</p>
<p>The Heartbeat software running on the slave server periodically checks the health of the master server by listening to its heartbeats sent via null modem cable and/or a crossover ethernet cable. Note that in the best scenario slave&#8217;s main task is nothing but to monitor the health of its master. In case of a crash the slave will not receive the heartbeats from the master and then it will take over the virtual IPs and the services offered by the master.</p>
<p><strong>The overall picture</strong></p>
<p>Next figure shows the picture of our cluster.</p>
<p><a href="http://www.karkomaonline.com/wp-content/uploads/2007/08/2004012416185184_1.png" title="The cluster layout"><img src="http://www.karkomaonline.com/wp-content/uploads/2007/08/2004012416185184_1.png" alt="The cluster layout" /></a></p>
<p>As previously stated, our configuration will consist of a 2-node active/passive cluster: dbserv1, the master server and dbserv2, the slave server. Both machines are linked via serial COM port /dev/ttyS0 (null modem cable) and a crossover ethernet cable (eth0), through which they send its heartbeats to each other.</p>
<p>The 192.168.1.103 IP address at eth1:0 is the floating IP address, the virtual IP. This is the service IP where the master listens to and that will be transferred to the slave in case of a failure in the master. Requests from the application servers will be made through the virtual IP.</p>
<p>Both servers have another IP address that can be used to administer the machines: 192.168.1.101 and 192.168.1.102. Bear in mind that the virtual IP (192.168.1.103) is set up by Heartbeat, meaning that if it is not up and running in the active server there will be no access to the virtual service.</p>
<p><strong>Setting up replication</strong></p>
<p>1. Create a replication user on the master:</p>
<blockquote><p>mysql -u root -p</p></blockquote>
<p>At MySQL prompt type:</p>
<blockquote><p>GRANT REPLICATION SLAVE ON *.* TO replica@&#8221;%&#8221; IDENTIFIED BY &#8216;replica_passwd&#8217;;</p></blockquote>
<p>2. Stop MySQL on both the master server and the slave server. Take a snapshot of your databases from the master.</p>
<blockquote><p>/etc/init.d/mysql stop<br />
tar cvzf mysqldb.tgz /path/to/your/databases</p></blockquote>
<p>In my configuration I would&#8230;</p>
<blockquote><p>/etc/init.d/mysql stop<br />
tar cvzf mysqldb.tgz /var/mysql-data/*</p></blockquote>
<p>3. Copy the data to the slave</p>
<blockquote><p>scp /path/to/mysqldb.tgz  admin@dbserv2:/path/to/your/databases</p></blockquote>
<p>If you are using InnoDB tables, copy your tablespace file(s) and associated log files to the slave. In my case, the tablespace is called ibdata and the log files are those ib_*. So:</p>
<blockquote><p>scp /var/mysql-data/ibdata admin@dbserv2:/var/mysql-data<br />
scp /var/log/mysql/ib_* admin@dbserv2:/var/log/mysql</p></blockquote>
<p>4. Activate the binary log and assign a unique ID to the master:</p>
<blockquote><p>vi /etc/my.cnf</p></blockquote>
<p>Then add/change the following</p>
<blockquote><p> [mysqld]<br />
&#8230;..<br />
# Enable binary logs. Path to bin log is optional<br />
log-bin=/var/log/mysql/dbserv1<br />
# If the binary log exceeds 10M, rotate the logs<br />
max_binlog_size=10M<br />
# Set master server ID<br />
server-id=1<br />
&#8230;..</p></blockquote>
<p>Now you can start mysqld on the master. Watch the logs to see if there are problems.</p>
<blockquote><p>/etc/init.d/mysql start</p></blockquote>
<p>5. Log in on the slave.</p>
<blockquote><p>vi /etc/my.cnf</p></blockquote>
<p>Then add/change the following:</p>
<blockquote><p>server-id=2<br />
# This is eth0. Take a look at figure 1<br />
master-host=192.168.100.1<br />
master-user=replica<br />
master-password=replica_passwd<br />
# Port that master server is listening to<br />
master-port=3306<br />
# Number of seconds before retrying to connect to master. Defaults to 60 secs<br />
#master-connect-retry</p></blockquote>
<p>6. Uncompress the databases</p>
<blockquote><p>cd /path/to/your/databases<br />
tar xvzf mysqldb.tgz</p>
<p>chown -R mysql.mysql /path/to/your/databases</p></blockquote>
<p>Make sure your tablespace file(s) and associated files are in place (/path/to/your/databases in our example).</p>
<p>7. Start mysqld on the slave. Watch the logs to see if there are problems.</p>
<blockquote><p>/etc/init.d/mysql start</p></blockquote>
<p>8. Check if replication is working. For example, log in on the master, create a database and see if it is replicated on the slave:</p>
<blockquote><p>mysql -u root -p</p>
<p>create database replica_test;<br />
show databases;</p></blockquote>
<p><code><br />
+----------------+<br />
| Database       |<br />
+----------------+<br />
| replica_test    |<br />
| mysql           |<br />
| test              |<br />
| tmp              |<br />
+----------------+</code></p>
<p>Log in on the slave server and make sure the database replica_test is created:</p>
<blockquote><p> mysql -u root -p<br />
show databases;</p></blockquote>
<p><code><br />
+----------------+<br />
| Database             |<br />
+----------------+<br />
| replica_test     |<br />
| mysql                   |<br />
| test                     |<br />
| tmp                       |<br />
+----------------+</code></p>
<p>If you have problems, please refer to MySQL manual <a href="http://www.mysql.com/documentation/mysql/bychapter/manual_Replication.html#Replication" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/documentation/mysql/bychapter/manual_Replication.html_Replication?referer=');">here</a>.</p>
<p><strong>Installing and setting up Heartbeat</strong></p>
<p>Download a recent copy of Heartbeat from <a href="http://linux-ha.org/download/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/linux-ha.org/download/?referer=');">here</a> and then as usual&#8230;.</p>
<blockquote><p>configure<br />
make<br />
make install</p></blockquote>
<p>or:</p>
<blockquote><p>rpm -Uhv heartbeat-1.0.4-1.i386.rpm</p></blockquote>
<p>if you downloaded the RPM based package.</p>
<p><strong> Configuring heartbeat</strong></p>
<p>There are three files involved in the configuration of heartbeat:</p>
<ul>
<li>ha.cf: the main configuration file that describes the machines involved and how they behave.</li>
<li>haresources: this configuration file specifies virtual IP (VIP) and services handled by heartbeat.</li>
<li>authkeys: specifies authentication keys for the servers.</li>
</ul>
<p><strong>Sample /etc/ha.d/ha.cf</strong></p>
<blockquote><p># Time between heartbeats in seconds<br />
keepalive 1<br />
# Node is pronounced dead after 15 seconds<br />
deadtime 15<br />
# Prevents the master node from re-acquiring cluster resources after a failover<br />
nice_failback on<br />
# Device for serial heartbeat<br />
serial  /dev/ttyS0<br />
# Speed at which to run the serial line (bps)<br />
baud    19200<br />
# Port for udp (default)<br />
udpport 694<br />
# Use a udp heartbeat over the eth0 interface<br />
udp     eth0</p>
<p>debugfile /var/log/ha/ha.debug<br />
logfile /var/log/ha/ha.log</p>
<p># First node of the cluster (must be uname -a)<br />
node    dbserv1<br />
# Second node of the cluster (must be uname -a)<br />
node    dbserv2</p></blockquote>
<p><strong>Sample /etc/ha.d/haresources</strong></p>
<blockquote><p>dbserv1 Ipaddress::192.168.1.103::eth1</p></blockquote>
<p>This tells Heartbeat to set up 192.168.1.103 as the virtual IP (VIP). See figure above.</p>
<p><strong>Sample /etc/ha.d/authkeys</strong></p>
<blockquote><p>auth 1<br />
1 crc<br />
2 sha1 HI!<br />
3 md5 Hello!</p></blockquote>
<p>This file determines the authentication keys. Must be mode 600. As I assume that our network is relatively secure I configure crc as the authentication method. There is also md5 and sha1 available.</p>
<p>Now start heartbeat on dbserv1 and the on dbserv2, watch the logs, then stop heartbeat on the first node and see what happens on the second node. Start again heartbeat on the first node and stop it on the second and see the logs. If all is okay, you have a 2-node cluster up and running.</p>
<p><strong> What we have</strong></p>
<p>At this point we have a 2-node cluster with certain degree of availability and fault tolerance. Despite this could be a valid solution for non-critical environments, in really critical environments this configuration should be improved.</p>
<p><strong>Advantages</strong></p>
<ul>
<li>The cluster is fault tolerant</li>
<li>The cluster is relatively secure</li>
<li>There is no single point of failure (comments?)</li>
<li>Automatic fail over mechanism</li>
<li>Proven and solid OpenSource software for production environment (my experience)</li>
<li> Simple and easy to install and configure</li>
<li>Easy to administer</li>
<li>Inexpensive</li>
</ul>
<p><strong>Disadvantages</strong></p>
<p>Our cluster presents almost one serious problem in critical environments (i.e. 99,99% availability). As you know, when the master node fails, the standby node takes over the service and the virtual IP address. In this scenario, when the master comes back online again, it will act as the stand-by node (remember nice_failback on from /etc/ha.d/ha.cf?). As our configuration has not implemented a two-way replication mechanism, the actual master is not generating binary logs and the actual slave is not configured to act as such. There are means to avoid this disadvantage, but this is your homework <img src='http://www.karkomaonline.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Let me know your progress.</p>
<p>As usual, comments are very welcome.</p>
<p><strong> References:</strong></p>
<ul>
<li><a href="http://www.mysql.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.mysql.com/?referer=');">Mysql</a></li>
<li><a href="http://linux-ha.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/linux-ha.org/?referer=');">Heartbeat</a></li>
<li><a href="http://www.karkomaonline.com/links.php?category=Clustering+and+High+Availability" target="_blank">More links</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2004/01/implementing-high-availability-in-mysql/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>What time is it? Introduction to NTP</title>
		<link>http://www.karkomaonline.com/index.php/2004/01/what-time-is-it-introduction-to-ntp/</link>
		<comments>http://www.karkomaonline.com/index.php/2004/01/what-time-is-it-introduction-to-ntp/#comments</comments>
		<pubDate>Sat, 17 Jan 2004 09:41:38 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.karkoma.info/index.php/2004/01/17/what-time-is-it-introduction-to-ntp/</guid>
		<description><![CDATA[Once I read somewhere that Time has been invented in the universe so that everything would not happen at once. NTP (Network Time Protocol) provides accurate and syncronised time across the Internet. This introductory article will try to show you how to use NTP to control and synchronize your system clock. First approach NTP is [...]]]></description>
			<content:encoded><![CDATA[<p>Once I read somewhere that Time has been invented in the universe so that everything would not happen at once.</p>
<p>NTP (Network Time Protocol) provides accurate and syncronised time across the Internet. This introductory article will try to show you how to use NTP to control and synchronize your system clock.</p>
<p><strong>First approach</strong></p>
<p>NTP is organised in a hierarchical client-server model. In the top of this hierarchy there are a small number of machines known as <em>reference clocks</em>. A reference clock is known as <em>stratum 0</em> and is typically a cesium clock or a Global Positioning System (GPS) that receives time from satellites. Attached to these machines there are the so-called <em>stratum 1</em> servers (that is, stratum 0 clients), which are the top level time servers available to the Internet, that is, they are the best NTP servers available.</p>
<p><strong>Note</strong>: in the NTP lingo measure for synchronization distance is termed as stratum: the number of steps that a system lies from a primary time source.</p>
<p><span id="more-61"></span></p>
<p>Following this hierarchy, the next level in the structure are the stratum 2 servers which in turn are the clients for stratum 1 servers. The lowest level of the hierarchy is made up by stratum 16 servers. Generally speaking, every server syncronized with a stratum n server is termed as being at stratum n+1 level. So, there are a few stratum 1 servers which are referenced by stratum 2 servers, wich in turn are refenced by stratum 3 servers, which are referenced by stratum 4 and so on.</p>
<p>NTP servers operating in the same stratum may be associated with others in a peer to peer basis, so they may decide who has the higher quality of time and then can synchronise to the most accurate.</p>
<p>In addition to the client-server model and the peer to peer model, a server may broadcast time to a broadcast or multicast IP addresses and clients may be configured to synchronise to these broadcast time signals.</p>
<p>So, at this point we know that NTP clients can operate with NTP servers in three ways:</p>
<ul>
<li>in a client-server basis</li>
<li>in a peer to peer mode</li>
<li>sending the time using broadcast/multicast</li>
</ul>
<p><strong>How does it work</strong></p>
<p>Whenever ntpd starts it checks its configuration file (/etc/ntp.conf) to determine syncronization sources, authentication options, monitoring options, access control and other operating options. It also checks the frequency file (/etc/ntp/drift) that contains the latest estimate of clock frequency error. If specified, it will also look for a file containing the authentication keys (/etc/ntp/keys).</p>
<p><strong>Note</strong> that the path and/or name of these configuration files may vary in your system. Check the -c command line option.</p>
<p>Once the NTP daemon is up and running, it will operate by exchanging packets (time and sanity check exchanges) with its configured servers at poll intervals and its behaviour will depend on the delay between the local time and its reference servers. Basically, the process starts when the NTP client sends a packet containing its timestamp to a server. When the server receives such a packet, it will in turn store its own timestamp and a transmit timestamp into the packet and send it back to the client. When the client receives the packet it will log its receipt time in order to estimate the travelling time of the packet.</p>
<p>The packet exchange takes place until a NTP server is accepted as a synchronization source, which take about five minutes. The NTP daemon tries to adjust the clock in small steps and will continue until the client gets the accurate time. If the delay between both the server and client is big enough the daemon will terminate and you will need to adjust the time manually and start the daemon again.<br />
<strong>Sample ntp.conf configuration file</strong></p>
<blockquote><p>server 134.214.100.6<br />
server pool.ntp.org</p>
<p>peer 192.168.100.125<br />
peer 192.168.100.126<br />
peer 192.168.100.127</p>
<p>driftfile /etc/ntp/drift<br />
#multicastclient                 # listen on default 224.0.1.1<br />
#broadcastdelay  0.008</p>
<p>authenticate no</p>
<p>#keys           /etc/ntp/keys<br />
#trustedkey     65535<br />
#requestkey     65535<br />
#controlkey     65535</p>
<p># by default ignore all ntp packets<br />
restrict 0.0.0.0 mask 0.0.0.0 ignore</p>
<p># allow localhost<br />
restrict 127.0.0.1 mask 255.255.255.255</p>
<p># accept packets from&#8230;<br />
restrict 192.168.100.125 mask 255.255.255.255<br />
restrict 192.168.100.126 mask 255.255.255.255<br />
restrict 192.168.100.127 mask 255.255.255.255</p></blockquote>
<p>Take a look at references below to understand the configuration options.</p>
<p><strong>References:</strong></p>
<ul>
<li><a href="http://www.ntp.org/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.ntp.org/?referer=');">NTP homepage</a></li>
<li><a href="http://www.eecis.udel.edu/~mills/ntp/html/ntpd.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.eecis.udel.edu/_mills/ntp/html/ntpd.html?referer=');">ntpd</a></li>
<li><a href="http://www.faqs.org/rfcs/rfc1305.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.faqs.org/rfcs/rfc1305.html?referer=');">Network time protocol (version 3) specification</a></li>
<li><a href="http://www.eecis.udel.edu/~mills/ntp/servers.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.eecis.udel.edu/_mills/ntp/servers.html?referer=');">Public NTP Time Servers</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2004/01/what-time-is-it-introduction-to-ntp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache and SSL</title>
		<link>http://www.karkomaonline.com/index.php/2003/07/apache-and-ssl/</link>
		<comments>http://www.karkomaonline.com/index.php/2003/07/apache-and-ssl/#comments</comments>
		<pubDate>Sun, 13 Jul 2003 19:33:53 +0000</pubDate>
		<dc:creator>karkoma</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Articles]]></category>

		<guid isPermaLink="false">http://www.karkoma.info/index.php/2003/07/13/apache-and-ssl/</guid>
		<description><![CDATA[When you want to transmit information through an untrusted channel (i.e. internet) and want to keep that information private, guarantee it&#8217;s integrity and keep the authenticity then you need something like SSL. The mod_ssl module provides strong cryptography for the Apache web server through the SSL (Secure Sockets Layer, v2/v3) and the TLS (Transport Layer [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to transmit information through an untrusted channel (i.e. internet) and want to keep that information private, guarantee it&#8217;s integrity and keep the authenticity then you need something like SSL. The mod_ssl module provides strong cryptography for the Apache web server through the SSL (Secure Sockets Layer, v2/v3) and the TLS (Transport Layer Security, v1) protocols implementation of OpenSSL. It also provides message digest mechanism to guarantee messages integrity and digital signature for authenticity.</p>
<p><span id="more-13"></span> <strong>Understanding SSL and TLS</strong></p>
<p>WebAdmins tend to transmit sensitive information safely and securely. To protect yourself from threats like eavesdropping, tampering and impersonation OpenSSL provides mechanisms to encrypt, check message integrity and authenticate your sensitive information.</p>
<p>The communication between both ends starts by the so called handshake process. The handshake allows the server to authenticate itself to the client using public-key techniques, then allows the client and the server to cooperate in the creation of symmetric keys used for rapid encryption, decryption, and tamper detection during the session that follows. Optionally, the handshake also allows the client to authenticate itself to the server.</p>
<p>The process starts when the client sends its SSL version number, random data, etc and a list of cipher suites it supports to the Apache webserver. The cipher suite is a set of cryptographic algorithms that will be used for authentication and session encryption. Apache then sends back its SSL version and other data and chooses a cipher suite (the strongest enabled cipher suites they have in common) from the list sent by the client, notifies to client the choosen cipher suite and sends its certificate (which contains the server&#8217;s public key).</p>
<p>Upon receiving the server&#8217;s certificate, the client checks it and tries to authenticate the server.</p>
<ul>
<li>Checks the certificate&#8217;s validity period.</li>
<li>The client maintains a list of trusted Certificate Authorities (CA) certificates (the root certificate for the key that was used to sign the server&#8217;s certificate) that determines which server certificates the client will accept. To verify the certificate the client checks if the issuing CA is in the list of trusted CAs. More specifically, does the distinguished name (DN) of the issuing CA match the DN of a CA on the client&#8217;s list of trusted CAs?</li>
<li>From its list of trusted CAs, the client compares the public key from the CA&#8217;s certificate to the one being presented in the server&#8217;s certificate.</li>
<li>Check if the domain name in the certificate match the domain name of the server itself.</li>
</ul>
<p>If all the above cuestions are succesfully resolved the server is authenticated and the client proceeds with the SSL handshake.</p>
<p>Once all is okay, the client creates and sends a premaster key (which is used as the basis of the session key) encrypted with the server&#8217;s public key.</p>
<p>If the Apache webserver is configured to request client authentication (optional in the handshake), the client sends the server both a certificate and a separate piece of signed data to authenticate itself. Now Apache will try to authenticate client&#8217;s identity:</p>
<ul>
<li> Apache checks if the client&#8217;s digital signature could be validated with the public key in the certificate.</li>
<li>Checks the certificate&#8217;s validity period.</li>
<li>As in the client side, Apache maintains a list of trusted Certificate Authorities (CA) certificates that determines which client certificates the server will accept. To verify the certificate, Apache checks if the issuing CA is in the list of trusted CAs.</li>
<li>Is the client authorized to access this resource?</li>
</ul>
<p>If all the above cuestions are succesfully resolved the client is authenticated and allowed to continue.</p>
<p>At this point Apache decrypts the premaster key with its private key and generates a master key which is sent to the client. Both the client and the server use the master key to generate the session keys. The interesting point here is having both the client and the server agree on a session key without ever sending it as plaintext over the network (this depends on the cipher suite selected). Now both ends inform each other that future messages will be encrypted with the session key and that the handshake is finished. This is the end of the SSL handshake and the start of the SSL session.</p>
<p><strong>Configuring Apache to support SSL/TLS</strong></p>
<p>Now I will show you how to configure your Apache webserver with SSL support. I assume you have Apache correctly configured and compiled with SSL support. If not, please take a look at References below.</p>
<p>Edit your httpd.conf and add the following if necessary or modify it accordingly to your needs:</p>
<blockquote><p>&#8230;..<br />
LoadModule ssl_module         extramodules/libssl.so<br />
&#8230;..</p>
<p>AddModule mod_ssl.c<br />
&#8230;..<br />
AddType application/x-x509-ca-cert .crt<br />
AddType application/x-pkcs7-crl    .crl<br />
&#8230;..<br />
&#8230;..<br />
Listen 443<br />
SSLPassPhraseDialog  builtin<br />
SSLSessionCache         dbm:/var/log/httpd/ssl_scache<br />
SSLSessionCacheTimeout  300</p>
<p>SSLMutex  sem<br />
SSLRandomSeed startup builtin<br />
SSLRandomSeed connect builtin</p>
<p>SSLLog /var/log/httpd/ssl_engine.log<br />
SSLLogLevel error</p>
<p>##<br />
## SSL Virtual Host Context<br />
##</p>
<p>&lt;VirtualHost 192.168.100.1:80&gt;</p>
<p>DocumentRoot /var/www<br />
ServerAdmin karkoma@karkomaonline.com<br />
ServerName www.karkomaonline.com<br />
ErrorLog /var/log/httpd/error.log<br />
CustomLog /var/log/httpd/access.log common</p>
<p>&lt;Location /server-status&gt;<br />
SetHandler server-status<br />
Order deny,allow<br />
Deny from all<br />
Allow from 192.168.100.<br />
&lt;/Location&gt;<br />
&#8230;..</p>
<p>SSLEngine on<br />
SSLProtocol SSLv3</p>
<p>SSLCipherSuite HIGH:MEDIUM</p>
<p>SSLCertificateFile /path/to/your/ssl/www.karkomaonline.com.crt<br />
SSLCertificateKeyFile /path/to/your/ssl/www.karkomaonline.com.key<br />
SSLCACertificateFile /path/to/your/ssl/karkomaCA/karkomaCA.crt<br />
SSLVerifyClient require<br />
SSLVerifyDepth  1<br />
&#8230;..</p>
<p>&lt;/VirtualHost&gt;</p></blockquote>
<p><strong>Generating your own certificate infrastructure</strong></p>
<p>Depending on you needs you must pay a fee to Certificate Authority such as Thawte or VeriSign to get your site widely recognized as a secure site by an international CA. Or you can become a CA and create your own client and/or server certificates, sign and distribute them for your intranet for example or other needs.</p>
<p>Let&#8217;s start by creating our CA key and certificate:</p>
<blockquote><p>openssl genrsa -rand /var/log/messages -out karkomaCA.key 1024<br />
openssl req -new -x509 -key karkomaCA.key -out karkomaCA.crt</p></blockquote>
<p>Okay, we have our private key and the corresponding certificate which will be used to sign the Certificate Signing Requests (CSR) requested by our clients. Note that in the above httpd.conf sample file SSLCACertificateFile directive points to this cert, this is the root certificate for the client certificates you&#8217;ll sign karkomaCA.crt. You could also add other CA&#8217;s root certificate if you plan to use them.</p>
<p>Now we are going to create a key and a Certificate Signing Request for the Apache webserver and sign it with our CA certificate; karkomaCA.</p>
<blockquote><p>openssl genrsa -rand /var/log/messages -out www.karkomaonline.com.key 1024<br />
openssl req -new -key www.karkomaonline.com.key -out www.karkomaonline.com.csr</p>
<p>openssl x509 -req -days 365 -in www.karkomaonline.com.csr -CA karkomaCA.crt -CAkey karkomaCA.key -CAcreateserial -out www.karkomaonline.com.crt</p></blockquote>
<p>Finally create a CSR from your client and sign it with your CA cert:</p>
<blockquote><p>openssl genrsa -rand /var/log/messages -out client.key 1024<br />
openssl req -new -key client.key -out client.csr</p>
<p>openssl x509 -req -days 365 -in client.csr -CA karkomaCA.crt -CAkey karkomaCA.key -CAcreateserial -out client.crt</p></blockquote>
<p>Now you are able to handle your sensitive information from your servers and clients in a more accurate form. You can implement this in your organization&#8217;s intranet as a means of handling private documents, test your internal developments based on SSL, etc. Please, see the References below to get an indepth knowledge of the SSL technology.</p>
<p>That&#8217;s all for now. Your comments are very welcome!</p>
<p><strong>References</strong></p>
<ul>
<li>The <a href="http://www.openssl.org/" onclick="pageTracker._trackPageview('/outgoing/www.openssl.org/?referer=');">OpenSSL</a> project homepage</li>
<li>This is the <a href="http://httpd.apache.org/" onclick="pageTracker._trackPageview('/outgoing/httpd.apache.org/?referer=');">Apache</a> module that enables the webserver to communicate through Secure Sockets Layer</li>
<li><a href="http://www.faqs.org/rfcs/rfc2246.html" onclick="pageTracker._trackPageview('/outgoing/www.faqs.org/rfcs/rfc2246.html?referer=');">RFC 2246</a> specifies Version 1.0 of the Transport Layer Security (TLS) protocol and here SSLv3 specification.</li>
<li><a href="http://www.ietf.org/rfc/rfc2818.txt" onclick="pageTracker._trackPageview('/outgoing/www.ietf.org/rfc/rfc2818.txt?referer=');">RFC 2818</a> specifies HTTP over TLS</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.karkomaonline.com/index.php/2003/07/apache-and-ssl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

