<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technical Diary</title>
	<atom:link href="http://andriigrytsenko.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://andriigrytsenko.net</link>
	<description>With Andrii Grytsenko</description>
	<lastBuildDate>Sat, 28 Jan 2012 12:41:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Puppet modules mini how-to</title>
		<link>http://andriigrytsenko.net/2011/08/puppet-modules-mini-how-to/</link>
		<comments>http://andriigrytsenko.net/2011/08/puppet-modules-mini-how-to/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 17:53:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=1078</guid>
		<description><![CDATA[Here I will try do describe basics in making puppet modules. I will divide it on the 3 little parts: Structure of puppet modules Modules manifests Files Temlates 1. Structure of puppet modules Puppet modules represents itself as a standalone directory inside the directory specified by modulepath variable at /etc/puppet/puppet.conf: The directory tree has next [...]]]></description>
			<content:encoded><![CDATA[<p>Here I will try do describe basics in making puppet modules.</p>
<p><span id="more-1078"></span></p>
<p>I will divide it on the 3 little parts:</p>
<ol>
<li><a href="#structure_of_puppet_modules">Structure of puppet modules</a></li>
<li><a href="#modules_manifests">Modules manifests</a></li>
<li><a href="#files">Files</a></li>
<li><a href="#templates">Temlates</a></li>
</ol>
<p><a name="structure_of_puppet_modules"><br />
<h2 style="text-align: center;">1. Structure of puppet modules</h2>
<p></a><br />
Puppet modules represents itself as a standalone directory inside the directory specified by <em>modulepath</em> variable at <em>/etc/puppet/puppet.conf</em>:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">

modulepath = /etc/puppet/modules
</pre>
<p>The directory tree has next structure:</p>
<pre>my_module
        |- files
        |      |
        |      \- some_config.conf
        |- manifests
        |         |
        |         \- init.pp
        \- templates
                  |
                  \- some_template.erb</pre>
<p>The module directory name should be the name of module and should match class name.</p>
<p>So there are three basic directories <strong>files</strong>, <strong>manifests</strong>, <strong>template</strong>.</p>
<p>The main directory is <strong>manifests</strong> and it should be exists as well as manifest file <strong>init.pp</strong> inside it.</p>
<p><strong>files </strong> &#8211; contains configuration or other files which should be shared between other hosts. Like <em>resolv.conf</em></p>
<p><strong>templates</strong> &#8211; contains templates.<br />
<a name="modules_manifests"><br />
<h2 style="text-align: center;">2. Modules manifests</h2>
<p></a><br />
Let&#8217;s look inside <strong>init.pp</strong> file. It have to contain at least one class with name matching madule name:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
class my_module {
}
</pre>
<p>It also can inherits some other module/class</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
class my_module inherits other_module  {
}
</pre>
<p>It can be useful if some resource from third modules should be involved in your module&#8217;s manifest.</p>
<p>For example if you change <em>php.ini</em> in <em>php</em> module then after deployment you need to reload httpd daemon to make changes to take effect. Here is the part of <em>httpd</em> modules describes reload:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
class httpd {
...
  exec { &quot;httpd-reload&quot;:
      command =&gt; &quot;/etc/init.d/httpd reload&quot;,
      refreshonly =&gt; true,
      require =&gt; [Package['httpd'], Exec[&quot;httpd-test-config&quot;] ],
  }

  exec { &quot;httpd-test-config&quot;:
      command =&gt; &quot;/usr/sbin/apachectl configtest&quot;,
      refreshonly =&gt; true,
  }

...
}
</pre>
<p>and part used in <em>php</em> module:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
class php inherits httpd {
...
  file { &quot;/etc/php.ini&quot;:
         ensure =&gt; present,
         owner  =&gt; root,
         group  =&gt; root,
         mode   =&gt; 644,
         source =&gt; &quot;puppet:///php/php.init&quot;,
         notify =&gt; Service[&quot;httpd&quot;],
  }
...
}
</pre>
<p>The class can have next objects:</p>
<ul>
<li>package</li>
<li>service</li>
<li>file</li>
<li>exec</li>
</ul>
<p>Examples of each of them:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
package { package_name:
        ensure =&gt; present|latest,
    }
</pre>
<p>&nbsp;</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
service { &quot;service_name&quot;:
    ensure =&gt; stopped|running,
    enable =&gt; false|true,
}
</pre>
<p>&nbsp;</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
exec { &quot;exec_name&quot;:
    command =&gt; &quot;some command to reload&quot;,
}
</pre>
<p><a name="files"><br />
<h2 style="text-align: center;">3. Files</h2>
<p></a><br />
There are no any special requirement to share a file between system. To deploy file to systems with activated module create new object in manifest:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
file { &quot;/where/to/deploy/filename&quot;:
  ensure =&gt; link|directory|present|absent,
  target =&gt; &quot;/path/to/deployed/file&quot;,
  owner  =&gt; &quot;root&quot;,
  group  =&gt; &quot;root&quot;,
  mode   =&gt; &quot;777&quot;,
  recurse =&gt; true|false,
  ignore =&gt; [&quot;.svn&quot;, &quot;some_file&quot;], # applied to directories
  source =&gt; &quot;puppet:///module_name/file_to_deploy/&quot;,
  notify =&gt; Service[&quot;my_service&quot;],
}
</pre>
<p>Most interesting parameters are <strong>notify</strong> and <strong>source</strong>. First parameter triggers some command <em>my_service</em>(described earlier in this or in inherited class) shortly afterwards file changed. And second parameter is specified path to file at puppet side. Value <em>puppet:///module_name/php.d/</em> means that file should be located at <em>/path/to/puppet/modules/modules_name/file/file_to_deploy</em>. So if your need to deploy <em>php.ini</em> from <em>php</em> class to <em>/etc/php.ini</em> on client node put file <em>php.ini</em> into <em>/etc/puppet/modules/php/files/php.ini</em>(it&#8217;s default module path).</p>
<p><a name="templates"><br />
<h2 style="text-align: center;">4. Templates</h2>
<p></a><br />
Template allows describe content of file depends on user&#8217;s and system&#8217;s variables using loops and conditions. To use file in class as well as file &#8211; describe it as <strong>content</strong> instead of <strong>source</strong></p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
file { '/test.file':
   content =&gt; template(&quot;my-modules/test.file.erb&quot;),
}
</pre>
<p>Here are couple examples of using templates.<br />
/etc/resolv.conf:</p>
<p>define variables at manifest:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
$domainname = example.com
$nameservers = ['192.168.0.1', '192.168.0.2']
</pre>
<p>resolv.conf.erb:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
domain
search

nameserver
</pre>
<p>On client side we&#8217;ll get:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">
domain example.com
nameserver 192.168.0.1
nameserver 192.168.0.2
</pre>
<p>Example #2 sent different content depends on node name:</p>
<pre class="brush: ruby; collapse: false; title: ; notranslate">

   content for node host1
   where fqdm stands for fully qualified domain name

   content for all node who hostname match 'host2*' regexp
</pre>
<p>Template file should be located at <em>/etc/puppet/modules/my-module/manifests/</em> directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/08/puppet-modules-mini-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP Super Cache plugin</title>
		<link>http://andriigrytsenko.net/2011/08/wp-super-cache-plugin/</link>
		<comments>http://andriigrytsenko.net/2011/08/wp-super-cache-plugin/#comments</comments>
		<pubDate>Sat, 06 Aug 2011 23:03:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=1055</guid>
		<description><![CDATA[I&#8217;ve installed new plugin to my blog. It&#8217;s called WP Super Cache. And I want to show you some benchmarks. I download siege to make benchmarks: Then prepared list of urls, actually I took it from my sitemap.xml and normalized it in next format: Then run siege with/without caching plugin with next arguments: where -t1M [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve installed new plugin to my blog. It&#8217;s called WP Super Cache. And I want to show you some benchmarks.</p>
<p><span id="more-1055"></span></p>
<p>I download siege to make benchmarks:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
apt-get install siege
</pre>
<p>Then prepared list of urls, actually I took it from my sitemap.xml and normalized it in next format:</p>
<pre class="brush: bash; title: ; notranslate">
root@laptop:~# head url.txt

http://andriigrytsenko.net

http://andriigrytsenko.net/2011/07/apache-vs-nginx-vs-lighttpd-and-static-content

http://andriigrytsenko.net/2011/07/ldap-mss-replication

http://andriigrytsenko.net/2011/07/pacemaker-and-apache
</pre>
<p>Then run siege with/without caching plugin with next arguments:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
siege -t1M -i -A 'Chrome/12.0.742.112 Safari/534.30' -f url.txt
</pre>
<p>where<br />
-t1M &#8211; means run siege during one minute<br />
-i &#8211; download links randomly from the list<br />
-A &#8211; user-agent description<br />
-f &#8211; path to file contains urls.</p>
<p>And get next results:</p>
<table width="100%" border="1" cellspacing="5" cellpadding="5">
<tbody>
<tr>
<th>Description</th>
<th>With caching</th>
<th>Without caching</th>
</tr>
<tr>
<td><span style="color: #ff0000;">Transactions(hits)</span></td>
<td><span style="color: #ff0000;">1609</span></td>
<td><span style="color: #ff0000;">252</span></td>
</tr>
<tr>
<td>Availability(%)</td>
<td>100.00</td>
<td>100.00</td>
</tr>
<tr>
<td>Elapsed time(s)</td>
<td>59.82</td>
<td>59.72</td>
</tr>
<tr>
<td>Data transferred(MB)</td>
<td>16.75</td>
<td>10.30</td>
</tr>
<tr>
<td><span style="color: #ff0000;">Response time(s)</span></td>
<td><span style="color: #ff0000;">0.05</span></td>
<td><span style="color: #ff0000;">3.01</span></td>
</tr>
<tr>
<td>Transaction rate(trans/sec)</td>
<td>26.90</td>
<td>4.22</td>
</tr>
<tr>
<td>Throughput(MB/sec)</td>
<td>0.28</td>
<td>0.17</td>
</tr>
<tr>
<td>Concurrency</td>
<td>1.47</td>
<td>12.72</td>
</tr>
<tr>
<td>Successful transactions</td>
<td>1609</td>
<td>252</td>
</tr>
<tr>
<td>Failed transactions</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td><span style="color: #ff0000;">Longest transaction</span></td>
<td><span style="color: #ff0000;">0.55</span></td>
<td><span style="color: #ff0000;">10.39</span></td>
</tr>
<tr>
<td><span style="color: #ff0000;">Shortest transaction</span></td>
<td><span style="color: #ff0000;">0.02</span></td>
<td><span style="color: #ff0000;">1.44</span></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>If you blog doesn&#8217;t have a lot of updates like my does, then apparently it is a good idea to install and active caching plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/08/wp-super-cache-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache vs Nginx vs Lighttpd and static content</title>
		<link>http://andriigrytsenko.net/2011/07/apache-vs-nginx-vs-lighttpd-and-static-content/</link>
		<comments>http://andriigrytsenko.net/2011/07/apache-vs-nginx-vs-lighttpd-and-static-content/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 21:40:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=753</guid>
		<description><![CDATA[Here I would like to show you http servers benchmark. I take 3 more popular unix http server and make some little statistic for them. First I will create 4 files(test,test2,test3,test4) with appropriate size 2GB,700MB,100Mb and 2MB. dd if=/dev/zero of=test count=1024 bs=2000000 dd if=/dev/zero of=test2 count=1024 bs=700000 dd if=/dev/zero of=test3 count=1024 bs=100000 dd if=/dev/zero of=test4 [...]]]></description>
			<content:encoded><![CDATA[<p>Here I would like to show you http servers benchmark.</p>
<p><span id="more-753"></span></p>
<p>I take 3 more popular unix http server and make some little statistic for them. First I will create 4 files(test,test2,test3,test4) with appropriate size 2GB,700MB,100Mb and 2MB.</p>
<pre>dd if=/dev/zero of=test count=1024 bs=2000000
dd if=/dev/zero of=test2 count=1024 bs=700000
dd if=/dev/zero of=test3 count=1024 bs=100000
dd if=/dev/zero of=test4 count=1024 bs=2000</pre>
<p>here they are:</p>
<pre>andrii@agrytsenko:~/tmp/test/web$ ls -lh
total 2.7G
-rw-r--r-- 1 andrii vboxusers 2.0G May 13 11:15 test
-rw-r--r-- 1 andrii vboxusers 684M May 13 12:14 test2
-rw-r--r-- 1 andrii vboxusers  98M May 13 12:15 test3
-rw-r--r-- 1 andrii vboxusers 2.0M May 13 12:15 test4</pre>
<p style="text-align: center;">Next step downloading and compilation of servers. If will show only configuration flags and skip all the rest of it.<br />
<strong>APACHE </strong></p>
<pre>./configure --prefix=~/tmp/test/http --disable-include --disable-filter \
--disable-charset-lite --disable-log-config --disable-env --disable-version \
--disable-mime --disable-status --disable-autoindex --disable-asis --disable-cgid \
--disable-cgi --disable-negotiation --disable-dir --disable-actions --disable-userdir \
--disable-alias --without-pcre --without-ssl</pre>
<p style="text-align: center;"><strong>NGINX</strong></p>
<pre>./configure --prefix=~/tmp/test/http2 --without-http_ssi_module \
--without-http_access_module --without-http_userid_module --without-http_geo_module \
--without-http_map_module --without-http_rewrite_module \
--without-http_proxy_module --without-http_fastcgi_module \
--without-http_limit_zone_module --without-http_browser_module \
--without-pcre --without-http-cache</pre>
<p style="text-align: center;"><strong>LIGHTTPD</strong></p>
<pre>./configure --prefix=/home/sheva/tmp/test/http3 --disable-silent-rules\
  --disable-dependency-tracking  --disable-libtool-lock --disable-ipv6 \
--without-pcre --without-bzip2 --without-mysql --without-ldap  \
--without-openssl --without-zlib --without-kerberos5</pre>
<p>All of them uses port 1234 to listen. It will prevent all servers work simultaneously and it by turn prevent from distorted results.</p>
<p>I used default configuration so result can be far away from reality. I&#8217;ve made 2 tests make result more realistic and fetch files with wget through local TCP/IP stack. </p>
<p>This is result of first one:</p>
<table border="2">
<tbody>
<tr>
<td></td>
<td>Apache<br />
2.2.15</td>
<td>Nginx<br />
0.8.8</td>
<td>Lighttpd<br />
1.4.26</td>
</tr>
<tr>
<td>2GB</td>
<td>9.53 MB/s</td>
<td>9.10 MB/s</td>
<td>9.69 MB/s</td>
</tr>
<tr>
<td>700MB</td>
<td>22.7 MB/s</td>
<td>37.0 MB/s</td>
<td>33.1 MB/s</td>
</tr>
<tr>
<td>100MB</td>
<td>153 MB/s</td>
<td>161 MB/s</td>
<td>133 MB/s</td>
</tr>
<tr>
<td>2MB</td>
<td>61.0 MB/s</td>
<td>81.0 MB/s</td>
<td>81.4 MB/s</td>
</tr>
</tbody>
</table>
<p>Second attempt with next results:</p>
<table border="2">
<tbody>
<tr>
<td></td>
<td>Apache<br />
2.2.15</td>
<td>Nginx<br />
0.8.8</td>
<td>Lighttpd<br />
1.4.26</td>
</tr>
<tr>
<td>2GB</td>
<td>9.51 MB/s</td>
<td>8.81 MB/s</td>
<td>10.3 MB/s</td>
</tr>
<tr>
<td>700MB</td>
<td>35.5 MB/s</td>
<td>35.7 MB/s</td>
<td>34.0 MB/s</td>
</tr>
<tr>
<td>100MB</td>
<td>157.0 MB/s</td>
<td>163.0 MB/s</td>
<td>170.0 MB/s</td>
</tr>
<tr>
<td>2MB</td>
<td>55.9 MB/s</td>
<td>164.0 MB/s</td>
<td>54.6 MB/s</td>
</tr>
</tbody>
</table>
<p>This is final average results table:</p>
<table border="2">
<tbody>
<tr>
<td></td>
<td>Apache<br />
2.2.15</td>
<td>Nginx<br />
0.8.8</td>
<td>Lighttpd<br />
1.4.26</td>
</tr>
<tr>
<td>2GB</td>
<td>9.52 MB/s</td>
<td>8,955 MB/s</td>
<td><span style="color: #ff0000;">9,99</span> MB/s</td>
</tr>
<tr>
<td>700MB</td>
<td>29,1 MB/s</td>
<td><span style="color: #ff0000;">36,35</span> MB/s</td>
<td>33,55 MB/s</td>
</tr>
<tr>
<td>100MB</td>
<td>155.0 MB/s</td>
<td><span style="color: #ff0000;">162.0</span> MB/s</td>
<td>151,5 MB/s</td>
</tr>
<tr>
<td>2MB</td>
<td>58,45 MB/s</td>
<td><span style="color: #ff0000;">122,5</span> MB/s</td>
<td>68.0 MB/s</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/07/apache-vs-nginx-vs-lighttpd-and-static-content/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LDAP MSS replication</title>
		<link>http://andriigrytsenko.net/2011/07/ldap-mss-replication/</link>
		<comments>http://andriigrytsenko.net/2011/07/ldap-mss-replication/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 14:57:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=1021</guid>
		<description><![CDATA[LDAP Master &#8211; Slave &#8211; Slave replication Here the scheme illustrates the distributed LDAP system between severals networks located in different part of world: This can be used for centralized authentication system shared between different data centers or like LDAP fail-over as well . MASTER Create ldap user replication in directory People. Append three lines [...]]]></description>
			<content:encoded><![CDATA[<p>LDAP Master &#8211; Slave &#8211; Slave replication</p>
<p><span id="more-1021"></span><br />
Here the scheme illustrates the distributed LDAP system  between severals networks located in different part of world:<br />
<img class="alignnone" src="http://andriigrytsenko.net/files/ldap.jpg" alt="ldap scheme" width="526" height="297" /></p>
<p>This can be used for centralized authentication system shared between different data centers or like LDAP fail-over as well .</p>
<h2 style="text-align: center;">MASTER</h2>
<p>Create ldap user <strong>replication</strong> in directory <strong>People</strong>.</p>
<p>Append three lines at the end of your <em>slapd.conf</em>: </p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
overlay syncprov
syncprov-checkpoint 1000 60
syncprov-sessionlog 100
</pre>
<p><strong>overlay syncprov</strong> &#8211; to make ldap instance act as a provider<br />
<strong>syncprov-checkpoint &#8216;ops&#8217; &#8216;minutes&#8217;</strong> &#8211; if number of operations or time passed more then specified then new checkpoint is set up.<br />
<strong>syncprov-sessionlog &#8216;time&#8217;</strong> &#8211; is the maximum number of session log entries the session log can record.</p>
<h2 style="text-align: center;">SLAVES</h2>
<p>The configuration for slave are almost the same. Except <strong>rid</strong> parameter they are must be unique for each node.</p>
<h3>SLAVE #1</h3>
<pre class="brush: bash; collapse: false; title: ; notranslate">
syncrepl rid=102
    provider=ldap://10.2.2.1:389
    type=refreshOnly
    interval=00:00:01:00
    searchbase=&quot;dc=cloudstores,dc=com&quot;
    filter=&quot;(objectclass=*)&quot;
    attrs=&quot;*,+&quot;
    scope=sub
    schemachecking=off
    bindmethod=simple
    binddn=&quot;cn=replication,ou=People,dc=cloudstores,dc=com&quot;
    credentials=replication_password
</pre>
<h3>SLAVE #2</h3>
<pre class="brush: bash; collapse: false; title: ; notranslate">
syncrepl rid=103
    provider=ldap://10.2.2.1:389
    type=refreshOnly
    interval=00:00:01:00
    searchbase=&quot;dc=cloudstores,dc=com&quot;
    filter=&quot;(objectclass=*)&quot;
    attrs=&quot;*,+&quot;
    scope=sub
    schemachecking=off
    bindmethod=simple
    binddn=&quot;cn=replication,ou=People,dc=cloudstores,dc=com&quot;
    credentials=replication_password
</pre>
<p><strong>rid</strong> &#8211; node identification number should be unique for every node.<br />
<strong>provider=ldap[s]://hostname[:port]</strong> &#8211; path to ldap master server.<br />
<strong>[type='refreshOnly|refreshAndPersist']</strong> &#8211; can be <em>refreshOnly</em> and <em>refreshAndPersist</em>. If set <em>refreshOnly</em> replication will be run with interval specified at <em>interval</em> directive.<br />
<strong>[interval=dd:hh:mm:ss]</strong> &#8211; interval time for replication.<br />
<strong>[searchbase='base DN']</strong> &#8211; root DN.<br />
<strong>[filter='filter str']</strong>  &#8211; filter for replication<br />
<strong>[attrs='attr list']</strong>  -sort returned entries based on attributes. The zero-length attributes sorts entries by DN.<br />
<strong>[scope='sub|one|base']</strong> &#8211; specify a base object, one-level, or subtree  search.   The default is sub.<br />
<strong>[schemachecking='on|off']</strong> &#8211; default value is off. If turned on slapd will be checking every entry on compliance with schema definition.<br />
<strong>[bindmethod='simple|sasl']</strong> &#8211; <em>simple</em> or <em>sasl</em>. Describe replication authentication method<br />
<strong>[binddn='DN']</strong> &#8211; dn name of replication user.<br />
<strong>[credentials='passwd']</strong> &#8211; password of replication user.</p>
<p><a href="http://www.openldap.org/doc/admin22/slapdconfig.html#syncrepl">Find more about syncrepl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/07/ldap-mss-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pacemaker and apache</title>
		<link>http://andriigrytsenko.net/2011/07/pacemaker-and-apache/</link>
		<comments>http://andriigrytsenko.net/2011/07/pacemaker-and-apache/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 20:52:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cluster]]></category>
		<category><![CDATA[heartbear]]></category>
		<category><![CDATA[pacemaker]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=996</guid>
		<description><![CDATA[How to configure pacemaker apache fail-over system with pacemaker. This is how it&#8217;s should be looks like at the end: First, install all needed packages for pacemaker: Start service and make it bootable during the system startup: After installation generate corosync key for nodes: Copy corosync key to second node: create /etc/corosync/service.d/pcmk on nodes with [...]]]></description>
			<content:encoded><![CDATA[<p>How to configure pacemaker apache fail-over system with pacemaker.</p>
<p><span id="more-996"></span></p>
<p>This is how it&#8217;s should be looks like at the end:<br />
<img src="http://andriigrytsenko.net/files/pacemaker.jpeg" alt="apache_pacemaker" /></p>
<p>First, install all needed packages for pacemaker:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
yum install heartbeat corosync pacemaker
</pre>
<p>Start service and make it bootable during the system startup:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
/etc/init.d/corosync start
</pre>
<p>After installation generate corosync key for nodes:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
corosync-keygen
</pre>
<p>Copy corosync key to second node:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
scp /etc/corosync/authkey 192.168.0.2:/etc/corosync/authkey
</pre>
<p>create /etc/corosync/service.d/pcmk on nodes with content :</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
service {
        name: pacemaker
        ver:  0
}
</pre>
<p>Edit configuration files on both nodes:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
mv /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf
</pre>
<p>Set <strong>bindnetaddr</strong> to network address others directives can be left without the changes:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
bindnetaddr: 192.168.0.0
</pre>
<p>Now configure Virtual IP resource for this nodes. Nodes have to check each other every 20 seconds:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
 crm configure primitive P_IP ocf:heartbeat:IPaddr2 \
        params ip=&quot;192.168.0.3&quot; cidr_netmask=&quot;255.255.255.0&quot; \
        op monitor interval=&quot;20s&quot;
</pre>
<p>And go up to next level. Httpd server resource:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
 crm configure primitive P_APACHE ocf:heartbeat:apache \
        params configfile=&quot;/etc/httpd/conf/httpd.conf&quot; statusurl=&quot;http://localhost/server-status&quot; \
        op monitor interval=&quot;40s&quot;
</pre>
<p>where<br />
<strong>P_APACHE</strong> &#8211; resource name<br />
<strong>configfile</strong> &#8211; path to apache configuration file<br />
<strong>statusurl</strong> &#8211; url to status page( below how to configures one)<br />
<strong>interval</strong> &#8211; time between checks</p>
<p>To prevent situation when resource apache migrate to node002 and resource IP stays at node001(It happens when apache at node001 hung but network stack works well) we need to make <strong>colocation</strong></p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
 crm configure colocation WEB_SITE inf: P_APACHE P_IP
</pre>
<p>To make pacemaker start up apache only after IP is set up. In other words describe start up order run:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
 crm configure order START_ORDER inf: P_IP P_APACHE
</pre>
<p>Describe location priority:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
location L_IP_NODE001 P_IP 100: node001.example.com
location L_IP_NODE002 P_IP 100: node002.example.com
</pre>
<p>Now set priority threshold. Value 110 is enough to prevent resource migration back. It could be happens when next scenario occurs:<br />
1. node001 fails and resources  are moved to node002.<br />
2. then node001 is going online<br />
3. resources are migrated to node001</p>
<p>To stick resources to node002 and prevent from further migration add <strong>resource-stickiness</strong>:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate">
 crm configure rsc_defaults resource-stickiness=&quot;110&quot;
</pre>
<pre class="brush: bash; collapse: false; title: ; notranslate">
# crm configure show
node node001.example.com
node node002.example.com
primitive P_APACHE ocf:heartbeat:apache \
        params configfile=&quot;/etc/httpd/conf/httpd.conf&quot; statusurl=&quot;http://localhost/server-status&quot; \
        op monitor interval=&quot;40s&quot;
primitive P_IP ocf:heartbeat:IPaddr2 \
        params ip=&quot;10.22.48.138&quot; cidr_netmask=&quot;255.255.255.240&quot; \
        op monitor interval=&quot;20s&quot;
colocation WEB_SITE inf: P_APACHE P_IP
order START_ORDER inf: P_IP P_APACHE
property $id=&quot;cib-bootstrap-options&quot; \
        dc-version=&quot;1.0.10-da7075976b5ff0bee71074385f8fd02f296ec8a3&quot; \
        cluster-infrastructure=&quot;openais&quot; \
        expected-quorum-votes=&quot;2&quot; \
        stonith-enabled=&quot;false&quot; \
        no-quorum-policy=&quot;ignore&quot;
</pre>
<p>Keep in mind that server-status page should be described at apache configuration files on both nodes as next:</p>
<pre class="brush: bash; title: ; notranslate">
&lt;VirtualHost 127.0.0.1:80&gt;
    ServerAdmin webmaster@dummy-host.example.com
    ServerName localhost
    ErrorLog logs/dummy-host.example.com-error_log
    CustomLog logs/dummy-host.example.com-access_log common
    &lt;Location /server-status&gt;
        SetHandler server-status
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    &lt;/Location&gt;
&lt;/VirtualHost&gt;
</pre>
<p>Finally check you pacemaker status: </p>
<pre class="brush: bash; title: ; notranslate">
crm_mon
============
Last updated: Wed Jul  6 15:17:46 2011
Stack: openais
Current DC: node001.example.com - partition with quorum
Version: 1.0.10-da7075976b5ff0bee71074385f8fd02f296ec8a3
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ node001.example.com node001.example.com ]

P_APACHE        (ocf::heartbeat:apache):        Started node001.example.com
P_IP        (ocf::heartbeat:IPaddr2):       Started node001.example.com
</pre>
<p>That means that two resources started at node001 where node002 in stand-by mode.<br />
There are couples ways to move resources to other node:<br />
1. Set active node to standby:</p>
<pre class="brush: bash; title: ; notranslate">
crm node standby node001.example.com
</pre>
<p>2. Or directly move resource</p>
<pre class="brush: bash; title: ; notranslate">
crm resource [resource_name] [node_name]
</pre>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/07/pacemaker-and-apache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nginx and perl module</title>
		<link>http://andriigrytsenko.net/2011/05/nginx-and-perl-module/</link>
		<comments>http://andriigrytsenko.net/2011/05/nginx-and-perl-module/#comments</comments>
		<pubDate>Sun, 29 May 2011 11:18:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=947</guid>
		<description><![CDATA[Nginx module which allows you to put perl code inside into nginx configuration. To enable module you need to compile nginx with &#8211;with-http_perl_module for CentOS build this possability has being already built inside. When you done with it you need inculude you lib to nginx configuration: where perl_modules &#8211; path to your module(s) perl_require &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Nginx module which allows you to put perl code inside into nginx configuration.<br />
<span id="more-947"></span></p>
<p>To enable module you need to compile nginx with <strong>&#8211;with-http_perl_module</strong> for CentOS build this possability has being already built inside. When you done with it you need inculude you lib to nginx configuration:</p>
<pre class="brush: perl; title: ; notranslate">
perl_modules        /root/libs;
perl_require        test.pm;
</pre>
<p>where<br />
<strong>perl_modules</strong> &#8211; path to your <a href="http://en.wikipedia.org/wiki/Perl_module">module(s)</a><br />
<strong>perl_require</strong> &#8211; the filename of your module</p>
<p>Then describe the location where scripts where run:</p>
<pre class="brush: perl; title: ; notranslate">
location /statistics {
perl test::runcmd;
}
</pre>
<p>Means if  you go to <strong>http://your_site/statistics</strong> script function <strong>runcmd</strong> from <strong>test.pm</strong> file will be executed.</p>
<pre class="brush: perl; title: ; notranslate">
package test;

use nginx;

sub runcmd {
     my $r = shift;

    $r-&gt;send_http_header(&quot;text/html&quot;);
    return OK if $r-&gt;header_only;

    my %commands = (
        'netstat' =&gt; 'netstat -lnp |',
        'ls' =&gt; 'ls -la /var/log/nginx |',
        'pass' =&gt; 'cat /etc/passwd |'
    );

    my $file = $r-&gt;filename;

    my $cmd;
    $file =~ /^.*\/([^\/]+$)/;
    my $meth = $1;
    $r-&gt;print(&quot;Command is $commands{$meth}&lt;br&gt;&lt;br&gt;&quot;);

    open(NETSTAT, &quot;$commands{$meth}&quot;);
    my $cont;
    $cont .= &quot;$_&lt;br&gt;&quot; while (&lt;NETSTAT&gt;);
    close NETSTAT;
    $r-&gt;print(&quot;$cont&quot;);
    return OK;
}

1;
__END__
</pre>
<p>If you open <strong>http://your_site/statistics/netstat</strong> script run <strong>netstat -lnp</strong> command and redirect output to your browser.</p>
<p>There is also possibility to run perl function from <a href="http://en.wikipedia.org/wiki/Server_Side_Includes">SSI</a>:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!- # perl sub=&quot;module::function&quot; arg=&quot;parameter1&quot; arg=&quot;parameter2&quot;... &gt;
</pre>
<p>And dont forget to reload nginx after changing configuration:</p>
<pre class="brush: bash; title: ; notranslate">/etc/init.d/nginx reload</pre>
<p>For more details go to <a href="http://wiki.nginx.org/EmbeddedPerlModule">official souce</a>.</p>
<p>And btw I still didn&#8217;t find any practical appliance yet:(.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/05/nginx-and-perl-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nginx + php-fpm for Debian</title>
		<link>http://andriigrytsenko.net/2011/05/nginx-php-fpm-for-debian/</link>
		<comments>http://andriigrytsenko.net/2011/05/nginx-php-fpm-for-debian/#comments</comments>
		<pubDate>Sat, 28 May 2011 23:35:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-fpm]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=944</guid>
		<description><![CDATA[Since I didn&#8217;t found php-fpm package for debian I decided to compile it by myself PHP-FPM If you are going to use PHP 5.3.3 or higher you don&#8217;t need to patch your php sources by PHP-FPM patch anymore. Install all required debian packages: Then download and unzip your php sources and go inside the dir [...]]]></description>
			<content:encoded><![CDATA[<p>Since I didn&#8217;t found php-fpm package for debian I decided to compile it by myself<br />
<span id="more-944"></span></p>
<h2 style="text-align: center;">PHP-FPM</h2>
<p>If you are going to use PHP 5.3.3 or higher you don&#8217;t need to patch your php sources by PHP-FPM patch anymore.<br />
Install all required debian packages:</p>
<pre class="brush: bash; collapse: false; title: ; notranslate"> apt-get install libxml2-dev \
libxml2 libssl-dev libevent-dev libbz2-dev libcurl4-openssl-dev \
libjpeg62-dev libpng12-dev libxpm-dev libfreetype6-dev libt1-dev \
libmcrypt-dev libmysql++-dev libmysqld-dev libmysqlclient-dev \
libxslt1-dev autoconf </pre>
<p>Then download and unzip your php sources and go inside the dir and run <em>buildconf</em>:</p>
<pre class="brush: bash; title: ; notranslate">
./buildconf --force
</pre>
<p>if no errors occur run configure:</p>
<pre class="brush: bash; title: ; notranslate">
./configure \
--prefix=/opt/php5 \
--with-config-file-path=/opt/php5/etc \
--with-curl \
--with-pear \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-xpm-dir \
--with-freetype-dir \
--with-t1lib \
--with-mcrypt \
--with-mhash \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--with-openssl \
--with-xmlrpc \
--with-xsl \
--with-bz2 \
--with-gettext \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-fpm \
--enable-exif \
--enable-wddx \
--enable-zip \
--enable-bcmath \
--enable-calendar \
--enable-ftp \
--enable-mbstring \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--with-libevent-dir=/usr/lib/
</pre>
<p>After finish without errors proceed and compile and install it:</p>
<pre class="brush: bash; title: ; notranslate">
make &amp;&amp; make install
</pre>
<p>The place where you can find all php-fpm related files and default prefix is <strong>/opt/php5</strong>. Now customize your configuration at <strong>/opt/php5/etc/php-fpm.conf</strong></p>
<pre class="brush: bash; title: ; notranslate">
[global]
pid = /opt/php5/var/run/php-fpm.pid
error_log = /opt/php5/var/log/php-fpm.log
log_level = warning
daemonize = yes # set yes to make php work as a daemon

[www]
listen = 127.0.0.1:9000 # the ip and port for php to listen; the port which nginx are going to work with
user = www-data # set user of new php instances(children)
group = www-data
pm = dynamic
pm.max_children = 50 # the maximum concurrent user's request which can be served by php
pm.min_spare_servers = 5 # the minimum idle processes
pm.max_spare_servers = 35
</pre>
<p>More details about how to children and servers work you can get here <a href="http://httpd.apache.org/docs/2.0/mod/mpm_common.html#maxclients">pm.max_children</a>, <a href="http://httpd.apache.org/docs/2.0/mod/mpm_common.html#maxsparethreads">pm.max_spare_servers</a>, <a href="http://httpd.apache.org/docs/2.0/mod/mpm_common.html#minsparethreads">pm.min_spare_servers</a>. Its works for apache just in the same way as for php-fpm.</p>
<p>The next step is making init scripts&#8230; Okay I&#8217;ve done it for you. Just enjoy:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/bash

### BEGIN INIT INFO
# Provides:          php-fpm
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php-fpm daemon
# Description:       starts php-fpm daemon
### END INIT INFO

function start {
    $DAEMON -c $CONFIG &amp;&gt; /dev/null
}

function stop {
#    killall php-fpm &amp;&gt; /dev/null
    kill `cat /opt/php5/var/run/php-fpm.pid 2&gt;/dev/null` &amp;&gt; /dev/null
}

. /lib/lsb/init-functions

CONFIG=/opt/php5/etc/php-fpm.conf
DAEMON=/opt/php5/sbin/php-fpm
DESC=&quot;php-fpm daemon&quot;
PID=/opt/php5/var/run/php-fpm.pid

test -x $DAEMON || exit 0
test -d $CONFIG_DIR || exit 0

kill -0 `cat /opt/php5/var/run/php-fpm.pid 2&gt;/dev/null` &amp;&gt; /dev/null
running=$?
case $1 in
start)
    if [ 0 -eq $running ]; then
        echo &quot;Process php-fpm is already running... Nothing to do...&quot;
        exit
    fi
    start &amp;&amp; echo &quot;Process php-fpm was successfully started ... &quot;
;;
stop)
    if [ 0 -ne $running ]; then
        echo &quot;Process php-fpm is not running...&quot;
        exit
    fi
    stop &amp;&amp; echo &quot;Process php-fpm was successfully stoped ... &quot;
;;
restart)
    stop &amp;&amp; start;
    echo &quot;Process php-fpm was successfully restarted ... &quot;
;;
status)
    if [ 0 -eq $running ]; then
        echo &quot;Process php-fpm is running...&quot;
    else
        echo &quot;Process php-fpm is not running...&quot;
    fi
;;
*)
    echo &quot;$0 [start|stop|restart|status]&quot;
;;
esac
</pre>
<p>Then make the stuff work after reboot add it to runlevels:</p>
<pre class="brush: bash; title: ; notranslate">
update-rc.d php-fpm defaults
</pre>
<h2 style="text-align: center;">NGINX</h2>
<p>With nginx installation there is easier way. Simply install it with <strong>apt-get</strong> package manager:</p>
<pre class="brush: bash; title: ; notranslate">apt-get install nginx </pre>
<p>I&#8217;m not going to describe all configuration just mention about php part. To make nginx work with php let it know about. Go to <strong>server</strong> section and add:</p>
<pre class="brush: bash; title: ; notranslate">
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/nginx$fastcgi_script_name;
    include        fastcgi_params;
    }
</pre>
<p>The <strong>fastcgi_pass</strong> should be the similar to section <strong>listen</strong> in <strong>php-fpm.conf</strong>.<br />
Directive <strong>fastcgi_param</strong> you need to specify path to your dir where php files are located(i.e. for me its <em>/var/www/nginx</em>)</p>
<h2 style="text-align: center;">VERIFICATION</h2>
<p>To verify that everything work well. Use an old method with <strong>phpinfo</strong> function. Create php file in you htroot direcory with next content:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
phpinfo();
?&gt;
</pre>
<p>Then give the name like <strong>info.php</strong> or whatever(but should with <strong>.php</strong> extension anyway). And try to open in your browser. If works it would be looks like <a href="http://andriigrytsenko.net/info.php">that</a>.</p>
<h2 style="text-align: center;">PROFIT&#8230;</h2>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/05/nginx-php-fpm-for-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable Fn function key</title>
		<link>http://andriigrytsenko.net/2011/04/disable-fn-function-key/</link>
		<comments>http://andriigrytsenko.net/2011/04/disable-fn-function-key/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 20:09:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[hp g62]]></category>
		<category><![CDATA[laptop]]></category>
		<category><![CDATA[linut]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=945</guid>
		<description><![CDATA[Disable Fn function key on my HP G62 laptop. My keyboards Fn key was invented for a long time. It was driving me crazy all the time when I used console. So finally I decided to find a solution it&#8217;s takes couple minutes but I have checked a lot of links before find useful. So [...]]]></description>
			<content:encoded><![CDATA[<p>Disable Fn function key on my HP G62 laptop. </p>
<p><span id="more-945"></span></p>
<p>My keyboards Fn key was invented for a long time. It was driving me crazy all the time when I used console. So finally I decided to find a solution it&#8217;s takes couple minutes but I have checked a lot of links before find useful. So I wanna share this with you.</p>
<p>To make Fn key work properly restart you computer and go to the BIOS installation(press F10 as soon as computer will start) then go to <strong>System Configuration</strong> -> <strong>Action Keys Mode</strong> set as <strong>Disable</strong>. </p>
<p>So that&#8217;s all. </p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/04/disable-fn-function-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql master/slave replication</title>
		<link>http://andriigrytsenko.net/2011/02/mysql-replication/</link>
		<comments>http://andriigrytsenko.net/2011/02/mysql-replication/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 23:33:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=873</guid>
		<description><![CDATA[The replication mechanism is very powerful and useful feature. Here I will try to briefly describe how to set it up. You can read more about replication there. To get to know more about replication format and which is more suitable for you read this. There are different relationship type of replication which can be [...]]]></description>
			<content:encoded><![CDATA[<p>The replication mechanism is very powerful and useful feature. Here I will try to briefly describe how to set it up.<br />
<span id="more-873"></span><br />
You can read more about replication <a href="http://en.wikipedia.org/wiki/Replication_(computer_science)#Database_replication" target="_blank">there</a>. To get to know more about replication format and which is more suitable for you read <a href="http://dev.mysql.com/doc/refman/5.1/en/replication-formats.html" target="_blank">this</a>.</p>
<p>There are different relationship type of replication which can be applied. Here I gonna set up MASTER&lt;-&gt;SLAVE scheme.</p>
<h3>MASTER</h3>
<p>These actions should be taken at master side. Go to <em>/etc/mysql</em>:</p>
<pre class="brush: bash; title: ; notranslate"> cd /etc/mysql </pre>
<p>And edit your mysql configuration file <em>my.cfg</em>:</p>
<pre class="brush: bash; title: ; notranslate">
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = monitoring
binlog_do_db = roundcube
binlog_do_db = information_schema
</pre>
<p>Here I defined 3 databases for replication: <em>monitoring</em>, <em>roundcube</em> and <em>information_schema</em>.<br />
Where directive <em>server-id</em> should be always be <strong>1</strong> for master host and &gt;1 for any other slave. Also to define more than one database for replication use directive <em>binlog_do_db</em> for each DB. <strong>Never ever</strong> try to put all database in one line and separate by comma or whatever(It is a trap I spent a lot of time doing this stuff:( ).</p>
<p>To replicate all databases from master skip variable <strong>binlog_do_db</strong>.</p>
<p>Restart your mysql when done:</p>
<pre class="brush: bash; title: ; notranslate">/etc/init.d/mysql restart</pre>
<p>Connect to your mysql master server:</p>
<pre class="brush: bash; title: ; notranslate">mysql -u root -p</pre>
<p>and run these mysql statements:</p>
<pre class="brush: sql; title: ; notranslate">
mysql&gt; CREATE USER 'repl'@'192.168.7.177' IDENTIFIED BY 'slavepass';
mysql&gt; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.7.177';</pre>
<p>This two lines create new user <strong>repl</strong> with password <strong>slavepass</strong> allow it connects only from ip address <strong>192.168.7.177</strong>(set &#8216;%&#8217; instead of 192.168.7.177 if you want to open access for any host). And grand permission for that user to do replication operations.</p>
<pre class="brush: sql; title: ; notranslate">mysql&gt; FLUSH TABLES WITH READ LOCK;
mysql&gt; SHOW MASTER STATUS;</pre>
<p>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| File                          | Position | Binlog_Do_DB                                                  | Binlog_Ignore_DB |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br />
| mysql-bin.000001 | 98            | monitoring,roundcube,information_schema |                                    |<br />
+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+</p>
<p>From these statements you need keep in mind value of <em>Position</em> it will be useful when you will run slave.</p>
<p>Before you run mysqlump you need to lock database(don&#8217;t close the session before backup done):</p>
<pre class="brush: sql; title: ; notranslate">mysql&gt;LOCK TABLES;</pre>
<p>And run mysqldump in another console window</p>
<pre class="brush: bash; title: ; notranslate">mysqldump --lock-all-tables -u root -p --databases monitoring, roundcube, informantion_scheman &gt;dbdump.db</pre>
<p>In case you have decided that you going to replicate all dbs:</p>
<pre class="brush: bash; title: ; notranslate">mysqldump --lock-all-tables -u root -p --all-databases &gt;dbdump.db</pre>
<p>Now you can unlock the database. To do it you can either close mysql session where you run <em>LOCK TABLES</em> (then tables will be automatically unlocked) or run:</p>
<pre class="brush: sql; title: ; notranslate">mysql&gt; UNLOCK TABLES;</pre>
<p>Then you are ready to transfer snapshot to slave host:</p>
<pre class="brush: bash; title: ; notranslate">scp dbdump.db user@slave:/tmp</pre>
<h3>SLAVE:</h3>
<p>The same actions with mysql config in <em>/etc/mysql</em>directory but slave side:</p>
<pre class="brush: bash; title: ; notranslate">server-id = 2
replicate-do-db = monitoring
replicate-do-db = roundcube
replicate-do-db = information_schema</pre>
<p>If you want replicate all databases skip variables <strong>replicate-do-db</strong>.<br />
Run mysql client and set up connection with master:</p>
<pre class="brush: bash; title: ; notranslate">mysql&gt; CHANGE MASTER TO
         MASTER_HOST='192.168.7.5',
         MASTER_USER='repl',
         MASTER_PASSWORD='slavepass',
         MASTER_LOG_FILE='mysql-bin.000001',
         MASTER_LOG_POS=98;</pre>
<p>Where,<br />
<strong>MASTER_HOST</strong> &#8211; ip or domain address of your master host.<br />
<strong>MASTER_USER</strong> &#8211; the name of user you created above.<br />
<strong>MASTER_PASSWORD</strong>- the password<br />
<strong>MASTER_LOG_FILE</strong> &#8211; field file from <em>SHOW MASTER STATUS</em> statement above.<br />
<strong>MASTER_LOG_POS</strong> the value from you <strong>Position</strong> field at <em>SHOW MASTER STATUS</em>.</p>
<p>And restart mysql:</p>
<pre class="brush: bash; title: ; notranslate">/etc/init.d/mysql restart</pre>
<h3>TESTING</h3>
<p>To check replication status run on slave:</p>
<pre class="brush: bash; title: ; notranslate">mysql&gt; show slave status \G </pre>
<p>And you get something like that:</p>
<pre class="brush: bash; title: ; notranslate">
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: xxx.xxx.xxx.xxx
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: bin-log.000463
          Read_Master_Log_Pos: 694544815
               Relay_Log_File: relay-log.001607
                Relay_Log_Pos: 130280711
        Relay_Master_Log_File: bin-log.000463
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 694544815
              Relay_Log_Space: 130280860
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)
</pre>
<p>Most important position you got to check is <strong>Slave_IO_Running  </strong>and <strong>Slave_SQL_Running</strong> if one of then is <strong>No</strong> something is definetly wrong with your replication and you need to check variables <strong>Last_IO_Error</strong> and <strong>Last_SQL_Error</strong> for more details.</p>
<p>If both <strong>Slave_IO_Running  </strong>and <strong>Slave_SQL_Running</strong> are <strong>Yes</strong> than make some test changes(little data modification) at master in replicated database and value in <strong>Read_Master_Log_Pos</strong> should be increased in some way. If so than it works well.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/02/mysql-replication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache as reverse proxy for https server</title>
		<link>http://andriigrytsenko.net/2011/02/apache-as-reverse-proxy-for-https-server/</link>
		<comments>http://andriigrytsenko.net/2011/02/apache-as-reverse-proxy-for-https-server/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 18:56:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=878</guid>
		<description><![CDATA[Configuration of https server located inside local network. To make local https server visible to outside world. You can make PAT(Port Address Translation) but what if 443 port is already binded? Than you probably want to make a reverse proxy like I did. So to configure apache&#8217;s virtual domain to work with ssl http do [...]]]></description>
			<content:encoded><![CDATA[<p>Configuration of https server located inside local network.<br />
<span id="more-878"></span></p>
<p>To make local https server visible to outside world. You can make PAT(<a href="http://en.wikipedia.org/wiki/Port_address_translation" target="_blank">Port Address Translation</a>) but what if 443 port is already binded? Than you probably want to make a reverse proxy like I did. So to configure apache&#8217;s virtual domain to work with ssl http do several easy steps.</p>
<p>First, you need to load mod_proxy&#8217;s modules into apache and make them available after the restart(for debian there is kind of exotic way to do that):</p>
<pre class="brush: bash; title: ; notranslate">
cd /etc/apache2/mods-enabled
ln -s ../mods-available/proxy.conf proxy.conf
ln -s ../mods-available/proxy.load proxy.load
ln -s ../mods-available/proxy_connect.load proxy_connect.load
ln -s ../mods-available/proxy_http.load proxy_http.load
</pre>
<p>The idea that contents of each file put in <em>mods-enabled</em> becomes a part of main configuration after restart or configuration re-read.</p>
<p>For example, if file contains line like that </p>
<pre class="brush: bash; title: ; notranslate">
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
</pre>
<p>It is the same if we put this line directly in <em>apache2.conf</em> or <em>httpd.conf</em> of whatever you have.</p>
<p>Hope it is pretty clear. Than let&#8217;s move on and create new virtual host configuration file:</p>
<pre class="brush: bash; title: ; notranslate">cd /etc/apache2/sites-available
touch ssl-proxy
</pre>
<p>Here the example how it&#8217;s should be looks like:</p>
<pre class="brush: bash; highlight: [10,11,12]; title: ; notranslate">
&lt;VirtualHost *:443&gt;

  ServerName mail.center.ua
  ProxyRequests Off
  &lt;Proxy *&gt;
    Order deny,allow
    Allow from all
  &lt;/Proxy&gt;

  SSLProxyEngine On
  ProxyPass / https://192.168.1.3/
  ProxyPassReverse / https://192.168.1.3/

  # logging section
  LogLevel info
  ErrorLog /var/log/apache2/ssl-proxy.log
  CustomLog /var/log/apache2/ssl-proxy.log combined

  SSLEngine on
  SSLProtocol all
  SSLCertificateFile /etc/ssl/apache/server.crt
  SSLCertificateKeyFile /etc/ssl/apache/server.key
&lt;/VirtualHost&gt;
</pre>
<p>About <em>SSLCertificateFile</em> and <em>SSLCertificateKeyFile</em> you need to generate keys. Use google to figure how to <a href="http://www.google.com.ua/search?hl=uk&#038;source=hp&#038;q=apache+generate+ssl+certificate&#038;aq=0&#038;aqi=g1&#038;aql=&#038;oq=apache+genera" target="_blank">do it</a>. </p>
<p>The mechanism of virtual host is similar to mods mechanism. So create new link in sites-enabled:</p>
<pre class="brush: bash; title: ; notranslate">ln -s ../sites-available/ssl-proxy ssl-proxy</pre>
<p>And restart apache:</p>
<pre class="brush: bash; title: ; notranslate">/etc/init.d/apache2 restart</pre>
<p>Good look!</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/02/apache-as-reverse-proxy-for-https-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nagios3 installation</title>
		<link>http://andriigrytsenko.net/2011/01/nagios3-installation/</link>
		<comments>http://andriigrytsenko.net/2011/01/nagios3-installation/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 18:43:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=853</guid>
		<description><![CDATA[Nagios installation and basic configuration. INSTALLATION Installation takes just a few easy steps. As I installed it on Debian box so used apt-get for installation: apt-get install nagios3 After nagios was installed I created new monitoring user root with password root123 to have access to web page: htpasswd -cb /etc/nagios3/htpasswd.users root root123 And start new [...]]]></description>
			<content:encoded><![CDATA[<p>Nagios installation and basic configuration.<br />
<span id="more-853"></span></p>
<h3><strong>INSTALLATION</strong></h3>
<p>Installation takes just a few easy steps. As I installed it on Debian box so used apt-get for installation:<br />
<code>apt-get install nagios3</code></p>
<p>After nagios was installed I created new monitoring user <strong>root</strong> with password <strong>root123</strong> to have access to web page:<br />
<code>htpasswd -cb /etc/nagios3/htpasswd.users root root123</code></p>
<p>And start new service:<br />
<code>/etc/init.d/nagios3 start</code></p>
<h3><strong>SETTING UP</strong></h3>
<p><del>All</del> Almost all configuration are stored at <em>/etc/nagios3/conf.d</em>.</p>
<p>I have one administrator and one contact group of course. So I remained example configuration and change only my mail address at <em>contacts_nagios2.cfg</em>:<br />
<code>email                           my@address.com</code></p>
<p>I&#8217;m gonna monitoring 3 linux hosts plus one router with next services:<br />
1. Master</p>
<ul>
<li>dns</li>
<li>httpd</li>
<li>http + ssl</li>
<li>samba</li>
<li>nis</li>
<li>ftp</li>
<li>openvpn  ( don&#8217;t have corresponding script. Probably make my own.)</li>
<li>ping</li>
<li>smtp</li>
<li>imap</li>
<li>mysql</li>
<li>ssh</li>
<li>processes</li>
<li>disk usage</li>
<li>swap utilization</li>
<li>users</li>
<li>uptime</li>
<li>current load</li>
</ul>
<p>2. Slave</p>
<ul>
<li>processes</li>
<li>swap</li>
<li>disk usage</li>
<li>users</li>
<li>http</li>
<li>ssh</li>
<li>current load</li>
<li>ping</li>
<li>uptime</li>
</ul>
<p>3. Test</p>
<ul>
<li>ldap ( was unable  to configure script check through  the tcp_check)</li>
<li>ping</li>
<li>ssh</li>
<li>samba</li>
</ul>
<p>4. Router</p>
<ul>
<li>ping</li>
</ul>
<p>First of all you need to define all hosts in <em>localhost_nagios2.cfg</em>:<br />
<code>define host{<br />
use                     generic-host            ; Name of host template to use<br />
host_name               secondary<br />
alias                   Secondary<br />
address                 192.168.7.177<br />
}</code></p>
<p>Where, <strong>use</strong> refers to <strong>generic-host</strong> in <em>generic-host_nagios2.cfg</em>. I left everything as was:<br />
<code>define host{<br />
name                            generic-host   ; The name of this host template<br />
notifications_enabled           1       ; Host notifications are enabled<br />
event_handler_enabled           1       ; Host event handler is enabled<br />
flap_detection_enabled          1       ; Flap detection is enabled<br />
failure_prediction_enabled      1       ; Failure prediction is enabled<br />
process_perf_data               1       ; Process performance data<br />
retain_status_information       1       ; Retain status information across program restarts<br />
retain_nonstatus_information    1       ; Retain non-status information across program restarts<br />
check_command                   check-host-alive<br />
max_check_attempts              10<br />
notification_interval           0<br />
notification_period             24x7<br />
notification_options            d,u,r<br />
contact_groups                  admins<br />
register                        0       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!<br />
}<br />
</code></p>
<p>You can customize it &#8211; set group who will be notified in case of emergency and time-frame for notification.</p>
<p>Also you can make  some host groups if you want. It&#8217;s not necessary but it can simplify service management if  you have a lot of hosts. To define host group go to <em>hostgroups_nagios2.cfg</em>:<br />
<code><br />
define hostgroup {<br />
hostgroup_name  all<br />
alias           All Servers<br />
members         *<br />
}define hostgroup {<br />
hostgroup_name  debian-servers<br />
alias           Debian GNU/Linux Servers<br />
members         secondary, master<br />
}</p>
<p></code></p>
<p>Here we created two groups of hosts: <strong>all</strong> and <strong>debian-servers</strong>. <strong>All</strong> contains all defined hosts in configuration and <strong>debian-servers</strong> just a <strong>secondary</strong> and <strong>master</strong> hosts.</p>
<p>And at the end most interesting and most resource-intensive part &#8211; services. For example if you need to monitor HTTP server on host <em>master</em> put next lines in <em>services_nagios2.cfg</em>:<br />
<code><br />
define service {<br />
host_name                  master<br />
service_description             HTTP<br />
check_command                   check_http<br />
use                             generic-service<br />
notification_interval           0<br />
}</code></p>
<p>Next example if you want to just ping router put:<br />
<code>define service {<br />
host_name                  router<br />
service_description             PING<br />
check_command                   check_ping!100.0,20%!500.0,60%<br />
use                             generic-service<br />
notification_interval           0<br />
}</code></p>
<p>If you need sent arguments to monitoring script separate it by <em>&#8216;!&#8217;</em>.<br />
To monitor group of servers use <em>hostgroup_name</em> intead of <em>host_name</em>, like:<br />
<code>hostgroup_name all</code><br />
- to monitoring all servers described in hostgroup <strong>all</strong>.</p>
<p>To monitoring such stuff like disk usage, process, users, swap and memory utilization I followed direction from <a href="http://wiki.nagios.org/index.php/Howtos:checkbyssh_RedHat">official site</a>.</p>
<h3><strong>PROBLEMS</strong></h3>
<p>The mail notifications wasn&#8217;t work for me. I suggest because there is no mail server on box. I tried to described it in the configuration but haven&#8217;t found anything could help me. So I wrote little script to send a mail directly to another smtp server:<br />
<code><br />
#!/usr/bin/perluse strict;<br />
use MIME::Lite;<br />
use Getopt::Long;</p>
<p>my ($to,$subject);<br />
my  $result = GetOptions ("s=s"   =&gt; \$subject, "t=s"  =&gt;  \$to );<br />
my $smtp = 'xxx.xx.xx.xx';<br />
my $from = 'xxx@xxx.net';</p>
<p>while (&lt;&gt;){<br />
my $msg = MIME::Lite-&gt;new(<br />
From    =&gt; $from,<br />
To      =&gt; $to,<br />
Subject =&gt; $subject,<br />
Type     =&gt; 'TEXT',<br />
Data     =&gt; "$_"<br />
);<br />
$msg-&gt;send('smtp',$smtp,Debug=&gt;0);<br />
}</p>
<p></code></p>
<p>Please define variables <em>smtp</em> and <em>to</em> by yourself. And remember that perl modules <a href="http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm">MIME::Lite</a> and <a href="http://search.cpan.org/~jv/Getopt-Long-2.38/lib/Getopt/Long.pm">Getopt::Long</a> have to be preinstalled in the system.</p>
<p>And change lines at <em>/etc/nagios3/commands.cfg</em> appropriately:<br />
<code>command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$</code><br />
and<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /root/scripts/mail.pl -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -t $CONTACTEMAIL$</code></p>
<p>To those ones:<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | <span style="color: #ff0000;">/path/to/mail.pl</span> -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" <span style="color: #ff0000;">-t</span> $CONTACTEMAIL$</code><br />
and<br />
<code> command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | <span style="color: #ff0000;">/root/scripts/mail.pl</span> -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" <span style="color: #ff0000;">-t</span> $CONTACTEMAIL$</code></p>
<p>Where, <em>/root/scripts/mail.pl</em> path to script mail.pl which was provided above.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2011/01/nagios3-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lsof installation on solaris 10</title>
		<link>http://andriigrytsenko.net/2010/08/lsof-installation-on-solaris-10/</link>
		<comments>http://andriigrytsenko.net/2010/08/lsof-installation-on-solaris-10/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 08:22:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=847</guid>
		<description><![CDATA[Details inside the post. Get new version of package: wget ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/lsof_1106-4.80-sol10-sparc-local.gz Unpack it: gunzip lsof_1106-4.80-sol10-sparc-local.gz And run installation command as root: pkgadd -d lsof_1106-4.80-sol10-sparc-local The following packages are available: 1 SMClsof lsof (sparc) 4.80 Select package(s) you wish to process (or 'all' to process all packages). (default: all) [?,??,q]: all ## Verifying package dependencies in [...]]]></description>
			<content:encoded><![CDATA[<p>Details inside the post.<br />
<span id="more-847"></span></p>
<p>Get new version of package:</p>
<pre>wget ftp://ftp.sunfreeware.com/pub/freeware/sparc/10/lsof_1106-4.80-sol10-sparc-local.gz</pre>
<p>Unpack it:</p>
<pre>gunzip lsof_1106-4.80-sol10-sparc-local.gz</pre>
<p>And run installation command as root:</p>
<pre>pkgadd -d lsof_1106-4.80-sol10-sparc-local                                                                   

The following packages are available:
  1  SMClsof     lsof
                 (sparc) 4.80        

Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: <span style="color: #ff0000;">all</span>
## Verifying package  dependencies in zone 

Files that are setuid and/or setgid will be installed and/or modified
for package  on zone .                         

Do you want to continue with the installation of  [y,n,?] <span style="color: #ff0000;">y</span>
..............skipped................
Do you want to install these as setuid/setgid files [y,n,?,q] <span style="color: #ff0000;">y</span>

..............skipped................
Installation of  on zone  was successful.</pre>
<p>And finally check it out:</p>
<pre>lsof -v
....skipped....
<span style="color: #ff0000;">revision: 4.80</span></pre>
<p>Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/08/lsof-installation-on-solaris-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software RAID level 1 behavior</title>
		<link>http://andriigrytsenko.net/2010/07/software-raid-level-1-behavior/</link>
		<comments>http://andriigrytsenko.net/2010/07/software-raid-level-1-behavior/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:47:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[fs]]></category>
		<category><![CDATA[mdadm]]></category>
		<category><![CDATA[raid]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=827</guid>
		<description><![CDATA[Here I will try to describe behavior of SW RAID level 1 in case of crash. There will be two scenario: Delete partition by fdisk and restart the computer. Delete and create empty partition by fdisk and restart the computer. Delete whole storage device from the system and restart computer. Delete and create whole storage [...]]]></description>
			<content:encoded><![CDATA[<p>Here I will try to describe behavior of SW RAID level 1 in case of crash.<br />
<span id="more-827"></span></p>
<p>There will be two scenario:</p>
<ol>
<li> Delete partition by <strong>fdisk</strong> and restart the computer.</li>
<li> Delete and create empty partition by <strong>fdisk</strong> and restart the computer.</li>
<li> Delete whole storage device from the system and restart computer.</li>
<li> Delete and create whole storage device from the system and restart computer.</li>
</ol>
<h3 style="text-align: center;"><strong>1.  Delete partition by fdisk and restart the computer.</strong></h3>
<p>First, I gotta create the <em>raid</em> device:</p>
<pre>[root@node1 ~]# mdadm -C /dev/md0 -n 2 -l 1 /dev/hdd1 /dev/hdb8
mdadm: largest drive (/dev/hdb8) exceed size (476160K) by more than 1%
Continue creating array? y
mdadm: array /dev/md0 started.</pre>
<p>and build <strong>ext3</strong> file system on the device:</p>
<pre>[root@node1 ~]# mke2fs -j /dev/md0</pre>
<p>Edit <em>/etc/fstab</em> according to the changes:</p>
<pre>/dev/md0                /test                   ext3    defaults        0 0</pre>
<p>and mount everything is contained at <strong>/etc/fstab</strong>:</p>
<pre>[root@node1 ~]#mount -a</pre>
<p>Copy some files to <strong>/test</strong>(to be able to check files integrity in the future):</p>
<pre>[root@node1 ~]# cp -rfv /var/* /test/</pre>
<p>Now, delete <strong>/dev/hdd1</strong> through <strong>fdisk</strong>:</p>
<pre>[root@node1 ~]# fdisk  /dev/hdd

The number of cylinders for this disk is set to 8322.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): d
Selected partition 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.</pre>
<p>and restart computer:</p>
<pre>[root@node1 ~]# reboot</pre>
<p>During the system booting I got next error(the same I got when try to manually mount <strong>md0</strong>):</p>
<pre>mount: wrong fs type, bad option, bad superblock on /dev/md0,
       missing codepage or other error
       (could this be the IDE device where you in fact use
       ide-scsi so that sr0 or sda or so is needed?)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so</pre>
<p><strong>/proc/mdstat</strong> doesn&#8217;t see any  local raid devices:</p>
<pre>[root@node1 ~]# cat /proc/mdstat
Personalities :
unused devices:</pre>
<p>Let&#8217;s create new <strong>mdadm.conf</strong> :</p>
<pre>[root@node1 ~]#  mdadm --examine --scan  /dev/hdb8 &gt; /etc/mdadm.conf

[root@node1 ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 level=raid1 num-devices=2 UUID=c1ce0c10:035aa2a3:829450b6:84b7a236</pre>
<p>And active everything from mdadm.conf:</p>
<pre>[root@node1 ~]#  mdadm -A -s
mdadm: /dev/md0 has been started with 1 drive (out of 2).</pre>
<p>The <strong>md0</strong> was activated, but only with one disk:</p>
<pre>[root@node1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdb8[1]
      476160 blocks [2/1] [_U]</pre>
<p><strong>Conclusion:</strong> If it was a root partition your system wouldn&#8217;t boot at all. And you would have to dance with boot disk to make you system alive.</p>
<h3 style="text-align: center;"><strong>2. Delete and create empty partition by fdisk and restart the computer.</strong></h3>
<p>The same actions as above and additional create partition <strong>/dev/hdd1</strong> in <strong>fdisk</strong>.<br />
After system booted. None of raid&#8217;s are active :</p>
<p></strong></p>
<pre>[root@node1 ~]# cat /proc/mdstat
Personalities :
unused devices:</pre>
<p>But after restore procedure system is going to work in full-fledged mode(with 2 disks):</p>
<pre>[root@node1 ~]#  mdadm --examine --scan  /dev/hdb8 &gt; /etc/mdadm.conf
[root@node1 ~]# mdadm -A -s
mdadm: /dev/md0 has been started with 2 drives.
[root@node1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdd1[0] hdb8[1]
475136 blocks [2/2] [UU]</pre>
<p>The new device has no influence on system behavior at all. Result is similar to previous one.</p>
<h3 style="text-align: center;"><strong>3. Delete whole storage device from the system and restart computer.</strong></h3>
<p>During this test the <strong>md0</strong> was restored and mounted during system boot without any problem or delays. Also next notice message were generated and put into the syslog facility <strong>kernel</strong>:</p>
<pre>kernel: raid1: raid set md0 active with 1 out of 2 mirrors</pre>
<h3 style="text-align: center;"><strong>4. Delete and create whole storage device from the system and restart computer.</h3>
<p></strong><br />
During boot raid wasn&#8217;t rebuilt by itself: </p>
<pre>
[root@node1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdb8[1]
      475136 blocks [2/1] [_U]
</pre>
<p>And has to be re-built manually :</p>
<pre>
[root@node1 ~]# mdadm -a /dev/md0 /dev/hdd1
mdadm: re-added /dev/hdd1
</pre>
<p>Still recovering :) : </p>
<pre>
[root@node1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdd1[0] hdb8[1]
      475136 blocks [2/1] [_U]
      [====>................]  recovery = 21.5% (103296/475136) finish=0.4min speed=12912K/sec
</pre>
<p><strong>NOTE: partition type for new partition should be set to &#8216;Linux raid autodetect&#8217; (FD in a hex code). Frankly speaking I didn&#8217;t test whether it works without that, that&#8217;s why it may be or may _not_ useless procedure. My advice is: just do it! </strong></p>
<pre>
[root@node1 ~]# fdisk -l /dev/hdd

Disk /dev/hdd: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hdd1               1         943      475240+  fd  Linux raid autodetect
</pre>
<h3><strong>P.S. System information:</strong></h3>
<p>Tests were performed at virtual machine:<br />
<strong>virtualbox-2.1.4<br />
virtualbox-ose-guest-modules-2.6.26-1-686</strong><br />
Software installed inside VM:<br />
<strong>CentOS(kernel-2.6.18-128.el5)<br />
mdadm-2.6.9-2.el5</strong></p>
<p></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/07/software-raid-level-1-behavior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trick: DOC to PDF on Linux</title>
		<link>http://andriigrytsenko.net/2010/07/trick-doc-to-pdf-on-linux/</link>
		<comments>http://andriigrytsenko.net/2010/07/trick-doc-to-pdf-on-linux/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 12:07:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=814</guid>
		<description><![CDATA[Here is little trick how to convert *.doc files into the *.pdf on Linux. PRE-REQUIREMENTS: oowriter has to be already installed. It is provided by Open Office system(for Debian its openoffice.org-writer package). Unfortunately, I can&#8217;t remember the source where this macros is came from. Anyway here my script: #!/bin/bash # Written by Andrii Grytsenko # [...]]]></description>
			<content:encoded><![CDATA[<p>Here is little trick how to convert *.doc files into the *.pdf on Linux.</p>
<p><span id="more-814"></span></p>
<p><span style="color: #ff0000;">PRE-REQUIREMENTS: </p>
<p><strong>oowriter</strong> has to be already installed. It is provided by Open Office system(for Debian its <strong>openoffice.org-writer</strong> package).</span></p>
<p>Unfortunately, I can&#8217;t remember the source where this macros is came from. Anyway here my script:</p>
<pre>#!/bin/bash
# Written by Andrii Grytsenko
# pp: AndriiGrytsenko.net

if [ $# -lt 1 ]; then
    echo "Example: pdf2doc [doc_file] [output_dir]"
    echo "in case output_dir is missing generate into current dir"
fi

DOCDIR=$(dirname $1)
DOCFILE=$(basename $1)
PDFFILE=$(echo $DOCFILE | sed -e 's/\.doc$/\.pdf/g')
CURRENT_DIR=$(pwd)
OUT_DIR=$2

# if output_dir is missing set current
if [ -z $OUT_DIR ]; then
    OUT_DIR=$CURRENT_DIR
fi

if  echo $DOCDIR | grep -E "^\.$" &gt; /dev/null; then
        DOCDIR=$CURRENT_DIR
elif ! echo $DOCDIR | grep -E "^/" &gt; /dev/null; then
        DOCDIR=$CURRENT_DIR/$DOCDIR
fi

cd $DOCDIR
/usr/bin/oowriter -invisible "macro:///Standard.Module1.ConvertWordToPDF($DOCDIR/$DOCFILE)"
sleep 2 # for big files generation can take more time
mv $PDFFILE $OUT_DIR/
cd $CURRENT_DIR</pre>
<p>Put file into the catalog from PATH env variable, into the /usr/bin for example. And call doc2pdf.</p>
<p>To generate question.pdf from question.doc and put it into the /tmp, run this:</p>
<pre>doc2pdf ~/tmp2/questions.doc /tmp/</pre>
<p><span style="color: #ff0000;"><strong>PROFIT:</strong></span><span style="color: #ff0000;"><strong> </strong></span></p>
<pre>andrii@agrytsenko:~$ ls -l /tmp/questions.pdf
-rw-r--r-- 1 andrii vboxusers 53226 Jul 16 14:17 /tmp/questions.pdf</pre>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/07/trick-doc-to-pdf-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl and cookies auth</title>
		<link>http://andriigrytsenko.net/2010/06/perl-and-cookies-auth/</link>
		<comments>http://andriigrytsenko.net/2010/06/perl-and-cookies-auth/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:05:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=794</guid>
		<description><![CDATA[I made little overview how to make http authorization through the PERL. I&#8217;m not gonna describe how to make HTML form and how to parse input data from html. I leave these as you your homework ;). As storage for HTTP sessions I chose database(specifically MYSQL). Here is my table with sessions : desc mc_sessions; [...]]]></description>
			<content:encoded><![CDATA[<p>I made little overview how to make http authorization through the PERL.</p>
<p><span id="more-794"></span></p>
<p>I&#8217;m not gonna describe <a href="http://www.google.com.ua/search?hl=en&amp;source=hp&amp;q=html+form&amp;aq=f&amp;aqi=g10&amp;aql=&amp;oq=&amp;gs_rfai=">how to make HTML form</a> and <a href="http://www.google.com.ua/search?hl=en&amp;q=how+to+parse+input+data+from+html+in+perl&amp;aq=f&amp;aqi=&amp;aql=&amp;oq=&amp;gs_rfai="> how to parse input data from html</a>. I leave these as you your homework ;). As storage for HTTP sessions I chose database(specifically MYSQL).</p>
<p>Here is my table with sessions :</p>
<pre>desc mc_sessions;
+-----------------+--------------+------+-----+---------+-------+
| Field           | Type         | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| user_name       | varchar(50)  | YES  |     | NULL    |       |
| session_id      | varchar(255) | NO   | PRI | NULL    |       |
| expiration_time | int(11)      | YES  |     | NULL    |       |
+-----------------+--------------+------+-----+---------+-------+</pre>
<pre class="brush: perl; title: ; notranslate">
use CGI qw/:standard/;
use CGI::Cookie;

sub set_cookies {.
    my ($db,$user_name,$user_passwd) = @_;

    my $exp_time = time() + 259200; #(3 days)
    my $session_id = md5_hex($user_id.''.$user_name.''.$user_passwd.''.$exp_time);

    my $sth = $dbh-&amp;gt;prepare(&quot;INSERT INTO $table (user_name,session_id,expiration_time) VALUES (?,?,?)&quot;);
    $sth-&amp;gt;execute($user_name,$session_id,$exp_time);

    my $cookie1 = new CGI::Cookie(-name=&amp;gt;'SessionID',-value=&amp;gt;&quot;$session_id&quot;);
    my $cookie2 = new CGI::Cookie(-name=&amp;gt;'ExpirationTime',-value=&amp;gt;&quot;$exp_time&quot;);

    print header(-cookie=&amp;gt;[$cookie1,$cookie2]);

    return 1;
}

sub check_auth {
    my ($dbh) = @_;

    my %cookies = fetch CGI::Cookie;
    my %cook_hash;

    foreach my $key (sort keys %cookies) {
        $cookies{$key} =~ /=(.*);/;
        $cook_hash{$key} = $1;
    }

    return -1 if (!defined($cook_hash{SessionID}));

    my $user_name = is_session_valid($dbh,$cook_hash{SessionID});

    return -1 if ($user_name == -1);

    return $user_name;
}

sub is_session_valid {
    my ($dbh,$session_id) = @_;

    my ($exp_time);

    my $sth = $dbh-&amp;gt;prepare(&quot;SELECT * FROM sessions WHERE session_id=? and expiration_time &amp;gt; ?&quot;);
    $sth-&amp;gt;execute($session_id,time());

    while ( my @array = $sth-&amp;gt;fetchrow_array ) {
            ($user_name,$session_id,$exp_time) = @array;
    }

    return $user_name if (defined($user_name) and $exp_time &amp;gt; time());

    return -1;
}
</pre>
<p>As result we have 3 functions.</p>
<ol>
<li><span style="color: #000000;"><strong>set_cookies</strong></span><span style="color: #000000;"> &#8211; this function generate, put in database and send cookies to user&#8217;s browser.</span></li>
<li><strong>check_auth</strong> &#8211; check if user has already have some cookies from server if yes call <em>is_session_valid</em> for future checking.</li>
<li><strong>is_session_valid</strong> &#8211; look about user&#8217;s  session id  and check whether this session was expired or not.</li>
</ol>
<p><span style="color: #ff0000;"><strong><span style="text-decoration: underline;">Pay attention:</span></strong></span></p>
<p><span style="color: #ff0000;"><strong></strong></span><span style="color: #ff6600;"><span style="color: #ff0000;">Each function receives variable </span><strong><span style="color: #ff0000;">$dbh</span></strong><span style="color: #ff0000;"> it&#8217;s </span><a href="http://search.cpan.org/~timb/DBI-1.611/DBI.pm#Outline_Usage"><span style="color: #ff0000;">database connection identificator</span></a><span style="color: #ff0000;"> and should be created before function run.</span></span></p>
<h2 style="text-align: center;">How does it use?</h2>
<p>Edit you CGI code. And take care that all pages checks sessions id.<br />
Put this function call after authorization by password to send cookies to user:</p>
<pre class="brush: perl; title: ; notranslate">
set_cookies($dbh,$username,$password);
</pre>
<p>And these in all remains site&#8217;s pages to prevent site from unauthorized actions:</p>
<pre class="brush: perl; title: ; notranslate">
my $user_name = check_auth($dbh);

if ( $user_id == -1 ) {
        some action[s]
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/06/perl-and-cookies-auth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MYSQL quick overview</title>
		<link>http://andriigrytsenko.net/2010/05/mysql-quick-overview/</link>
		<comments>http://andriigrytsenko.net/2010/05/mysql-quick-overview/#comments</comments>
		<pubDate>Tue, 18 May 2010 11:10:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=762</guid>
		<description><![CDATA[Here I systematized some of my MYSQL knowledges. First I decide to make some test database to do everything step-by-step. This will be companies database contains information about all employers, projects and departments. CREATE DATABASE company Go in: USE company And make 4 tables. Employers employer_id int primary key name varchar(15) surname varchar(25) hire_date date [...]]]></description>
			<content:encoded><![CDATA[<p>Here I systematized some of my MYSQL knowledges.<br />
<span id="more-762"></span></p>
<p>First I decide to make some test database to do everything step-by-step. This will be companies database contains information about all employers, projects and departments.</p>
<pre>CREATE DATABASE company</pre>
<p>Go in:</p>
<pre>USE company</pre>
<p>And make 4 tables.</p>
<table border="1">
<tbody></tbody>
<caption style="text-align: center;"><strong>Employers</strong></caption>
<tbody>
<tr>
<td>employer_id</td>
<td>int primary key</td>
</tr>
<tr>
<td>name</td>
<td>varchar(15)</td>
</tr>
<tr>
<td>surname</td>
<td>varchar(25)</td>
</tr>
<tr>
<td>hire_date</td>
<td>date</td>
</tr>
<tr>
<td>department_id</td>
<td>int</td>
</tr>
<tr>
<td>fired</td>
<td>int</td>
</tr>
</tbody>
</table>
<table border="1">
<tbody></tbody>
<caption style="text-align: center;"><strong>projects</strong></caption>
<tbody>
<tr>
<td>project_id</td>
<td>int primary key</td>
</tr>
<tr>
<td>name</td>
<td>varchar(255)</td>
</tr>
</tbody>
</table>
<table border="1">
<tbody></tbody>
<caption style="text-align: center;"><strong>departments</strong></caption>
<tbody>
<tr>
<td>department_id</td>
<td>int primary key</td>
</tr>
<tr>
<td>name</td>
<td>varchar(255)</td>
</tr>
</tbody>
</table>
<p>This table consists relation between employer and projects:</p>
<table border="1">
<tbody></tbody>
<caption><strong>project_involved</strong></caption>
<tbody>
<tr>
<td>employer_id</td>
<td>int</td>
</tr>
<tr>
<td>project_id</td>
<td>int</td>
</tr>
</tbody>
</table>
<p>Let&#8217;s create its in DB:</p>
<pre>CREATE TABLE employers (
employer_id int primary key auto_increment,
name varchar(15),
surname varchar(25),
hire_date date,
department_id int,
fired int);</pre>
<pre>CREATE TABLE projects (
project_id int primary key auto_increment,
name varchar(255));</pre>
<pre>CRETE TABLE departments (
department_id int primary key auto_increment,
name varchar(255));</pre>
<pre>CREATE TABLE project_involved (
employer_id int,
project_id int);</pre>
<p>And insert some data into them. I will show you only few of them:</p>
<pre>INSERT INTO projects (departments) VALUES ('General Project');</pre>
<p>In this insert I use <a href="http://dev.mysql.com/doc/refman/5.0/en/subqueries.html">subquery</a>:</p>
<pre>INSERT INTO employers
(name,surname,hire_date,department_id,fired)
VALUES ('Jonh','Smith','2007-10-30',
(SELECT department_id FROM departments WHERE name='Department A'),
0);</pre>
<p>Format of date should be the next:</p>
<p><strong><span style="color: #ff0000;">YYYY-MM-DD</span></strong></p>
<p>There is also some example of <strong>SELECT</strong> query in the <strong>UPDATE</strong> statement:</p>
<pre>INSERT INTO projects (name) VALUES ('General Project');</pre>
<pre>INSERT INTO project_involved (employer_id,project_id)
VALUES (
(SELECT employer_id FROM employers WHERE name='Jonh' AND surname='Smith'),
(SELECT project_id FROM projects WHERE name='General Project')
);</pre>
<p>In the ending of filling db up I&#8217;ve got next results:</p>
<pre>SELECT * FROM employers;
+-------------+------+---------+------------+---------------+-------+
| employer_id | name | surname | hire_date  | department_id | fired |
+-------------+------+---------+------------+---------------+-------+
|           1 | Jonh | Smith   | 2007-10-30 |             1 |     0 |
|           2 | Yan  | Brown   | 2008-11-23 |             2 |     0 |
+-------------+------+---------+------------+---------------+-------+
2 rows in set (0.00 sec)</pre>
<pre>SELECT * FROM project_involved;
+-------------+------------+
| employer_id | project_id |
+-------------+------------+
|           1 |          1 |
|        NULL |          2 |
+-------------+------------+
2 rows in set (0.00 sec)</pre>
<pre>SELECT * FROM projects;
+------------+-----------------+
| project_id | name            |
+------------+-----------------+
|          1 | General Project |
|          2 | Second Project  |
+------------+-----------------+
2 rows in set (0.00 sec)</pre>
<pre>SELECT * FROM departments;
+---------------+---------------+
| department_id | name          |
+---------------+---------------+
|             1 | departament A |
|             2 | departament B |
+---------------+---------------+
2 rows in set (0.00 sec)</pre>
<p>If you need to to remove something from your table(<em><span style="text-decoration: underline;">Department D</span></em> from <em><span style="text-decoration: underline;">departments</span></em> for example):</p>
<pre>DELETE FROM departments WHERE name='Department D';</pre>
<p>I&#8217;ve totally forgot about some column should be at <em><span style="text-decoration: underline;">employers</span></em> table. Column <span style="text-decoration: underline;"><em>position</em></span> has to be added. To change the structure of the table use <strong>ALTER</strong>:</p>
<pre>ALTER TABLE employers
ADD COLUMN position varchar(255) AFTER surname;</pre>
<p>in the same way you can remove needed column from the table:</p>
<pre>ALTER TABLE employers DROP COLUMN position;</pre>
<p>To rename column name run:</p>
<pre>ALTER TABLE table_name CHANGE old_name new_name INTEGER</pre>
<p>Now update the data:</p>
<pre>UPDATE employers SET position='system engineer'
WHERE surname='Smith' AND name='Jonh';</pre>
<p>There are few examples with subqueries. If you need to select all data from <em><span style="text-decoration: underline;">emloyers</span></em> table and resolve department name from <em><span style="text-decoration: underline;">departments</span></em> table. Run:</p>
<pre>SELECT employers.name, employers.surname, employers.hire_date, departments.name
FROM employers INNER JOIN departments USING (department_id);</pre>
<p>To simplify a query use <a href="http://www.google.com.ua/search?hl=en&amp;source=hp&amp;q=mysql+alias&amp;aq=f&amp;aqi=g10&amp;aql=&amp;oq=&amp;gs_rfai=">alias</a>:</p>
<pre>SELECT <span style="color: #ff0000;">e</span>.name, <span style="color: #ff0000;">e</span>.surname, <span style="color: #ff0000;">e</span>.hire_date, <span style="color: #ff0000;">d</span>.name FROM employers <span style="color: #ff0000;">e</span>
INNER JOIN departments <span style="color: #ff0000;">d</span> USING (department_id);
+------+---------+------------+---------------+
| name | surname | hire_date  | name          |
+------+---------+------------+---------------+
| Jonh | Smith   | 2007-10-30 | departament A |
| Yan  | Brown   | 2008-11-23 | departament C |
+------+---------+------------+---------------+
2 rows in set (0.00 sec)</pre>
<p>Here is more complex query which is involves all 4 tables:</p>
<pre>SELECT e.name, e.surname, e.position, e.hire_date, d.name department, p.name project
FROM projects p
INNER JOIN project_involved USING (project_id)
INNER JOIN employers e USING (employer_id)
INNER JOIN departments d USING (department_id);
+------+---------+-----------------+------------+---------------+-----------------+
| name | surname | position        | hire_date  | department    | project         |
+------+---------+-----------------+------------+---------------+-----------------+
| Jonh | Smith   | system engineer | 2007-10-30 | departament A | General Project |
| Jonh | Smith   | system engineer | 2007-10-30 | departament A | Second Project  |
+------+---------+-----------------+------------+---------------+-----------------+
2 rows in set (0.00 sec)</pre>
<p>To remove database or table use <strong>DROP</strong>:</p>
<pre>DROP [database|table]</pre>
<p>For example:</p>
<pre>DROP employers;</pre>
<p>To see database or table structure use <strong>SHOW CREATE</strong>:</p>
<pre>SHOW CREATE TABLE table;</pre>
<pre>SHOW CREATE DATABASE company;</pre>
<pre>SHOW CREATE DATABASE company;
+----------+--------------------------------------------------------------------+
| Database | Create Database                                                    |
+----------+--------------------------------------------------------------------+
| company  | CREATE DATABASE `company` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+--------------------------------------------------------------------+</pre>
<h3 style="text-align: center;"><strong>BACKUPS</strong></h3>
<p>To make backups of your database use <strong>mysqldump</strong> :</p>
<pre>mysqldump -u root -p --database company &gt; company.sql</pre>
<p>To restores from backups :</p>
<pre>mysql -u root -p -e 'source company.sql' company</pre>
<p style="text-align: center;"><strong>CREATE USER</strong></p>
<pre>GRANT [privileges] ON [resource] TO [identity]</pre>
<p>In example I create user <em><span style="text-decoration: underline;">company_admin</span></em> which has  all privileges on all tables in database <span style="text-decoration: underline;"><em>company</em></span> from host <em><span style="text-decoration: underline;">localhost</span></em> with password <em><span style="text-decoration: underline;">secret-password</span></em>:</p>
<pre>GRANT ALL PRIVILEGES ON company.* TO company_admin@localhost
IDENTIFIED BY 'secret_password';</pre>
<p>There are some of the privileges, almost all of them is self-explained:</p>
<p><em>ALTER<br />
CREATE<br />
DELETE<br />
DROP<br />
GRANT<br />
INSERT<br />
SELECT<br />
UPDATE</em></p>
<p>For more details concerning <strong>GRANT</strong> go to <a href="http://dev.mysql.com/doc/refman/5.0/en/grant.html">ofdocs</a>.</p>
<p style="text-align: center"><strong>MYISAM VS INNODB</strong></p>
<p>InnoDB is set by default. And it&#8217;s speed and mature way to store simple data.</p>
<p>Advantages of InnoDB:</p>
<ol>
<li>transaction support</li>
<li>row-level locking</li>
<li>foreign key constraints</li>
</ol>
<p>To disadvantages we can attribute the next:</p>
<ol>
<li>don&#8217;t support full-text searching</li>
<li>some troubles with AUTO_INCREMENT columns</li>
</ol>
<p>To change of the table engine run:</p>
<pre>ALTER TABLE table ENGINE=[engine]</pre>
<pre>ALTER TABLE employers ENGINE=InnoDB</pre>
<p style="text-align: center;"><strong>FOREIGN KEY</strong></p>
<p>This feature help you to prevent your data from human mistake and keep it integrity.<br />
First, you need to convert your tables into InnoDB:</p>
<pre>ALTER TABLE table ENGINE=InnoDB;</pre>
<p>and set dependency:</p>
<pre>ALTER TABLE employers ADD CONSTRAINT dep_id_cons
FOREIGN KEY (department_id) REFERENCES departments (department_id);</pre>
<p>Now when we try to set employers.department_id which is not at departments.department_id. As result changes is not committed and we get an error:</p>
<pre>INSERT INTO employers (name,surname,department_id)
VALUES ('test','test','123');
ERROR 1452 (23000): Cannot add or update a child row:
a foreign key constraint fails (`company/employers`,
CONSTRAINT `dep_id_cons` FOREIGN KEY (`department_id`)
REFERENCES `departments` (`department_id`))</pre>
<p>To delete foreign key run:</p>
<pre>ALTER TABLE employers DROP FOREIGN KEY dep_id_cons;</pre>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/05/mysql-quick-overview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UA-IX checker</title>
		<link>http://andriigrytsenko.net/2010/04/ua-ix-checker/</link>
		<comments>http://andriigrytsenko.net/2010/04/ua-ix-checker/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 08:31:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=737</guid>
		<description><![CDATA[Based on this post I have decided make some program which able to detect weather IP is a part of some network (in this case UA-IX network) or not. Speaking about UA-IX, from wikipedia we know: The Ukrainian traffic exchange network (UA-IX) (Ukrainian: Українська мережа обміну інтернет-трафіком) is an Internet exchange point that was established [...]]]></description>
			<content:encoded><![CDATA[<p>Based on <a href="http://andriigrytsenko.net/2010/03/ipcalc-on-perl/">this post</a> I have decided make some program which able to detect weather IP is a part of some network (in this case UA-IX network) or not.<br />
<span id="more-737"></span></p>
<p>Speaking about UA-IX, from <a href="http://en.wikipedia.org/wiki/Ukrainian_Internet_Exchange_Network">wikipedia</a> we know: </p>
<blockquote><p>The Ukrainian traffic exchange network (UA-IX) (Ukrainian: Українська мережа обміну інтернет-трафіком) is an Internet exchange point that was established in Kiev, the capital of Ukraine, on July 2000 and is the daughter company of Ukrainian Internet Association. Companies that established Ukrainian traffic exchange network are major Ukrainian businesses that work expanding Ukrainian Internet market.</p></blockquote>
<p>Here the <a href="http://noc.ix.net.ua/ua-list.txt">list</a> of all networks which belongs to UA-IX net. Download it to your machine and save as <em>ua-list.txt</em>.</p>
<p>Content of file. We have some networks list here:</p>
<pre>$ head -3 ua-list.txt
8.8.4.0/24
8.8.8.0/24
62.16.0.0/19
</pre>
<p>Here is the script:</p>
<pre>$cat uaix.pl
#!/usr/local/bin/perl
# Written by Andrii Grytsenko 2010
# PP: http://andriigrytsenko.net     

use POSIX;
use strict;

sub dec2bin {
   my $hex = shift;
   my $pack = unpack("B32",pack("N",$hex));
   my $pack = substr($pack,-8);
   return $pack;
}

my $bin_ip;
$bin_ip .= dec2bin($_) foreach (split(/\./,$ARGV[0]));

open(IP, "<$ARGV[1]");
while(<IP>){
    chomp();
    my ($ip,$net_mask) = split(/\//,$_);
    $net_mask = 24 if (!defined($net_mask));
    my $bin_network;
    $bin_network .= dec2bin($_) foreach (split(/\./,$ip));
    my $net_net_part = substr($bin_network,0,$net_mask);
    my $net_ip_part  = substr($bin_ip,0,$net_mask);
    if ( $net_net_part == $net_ip_part) {
        print "IP $ARGV[0] belong to network $_\n";
        exit;
    }
}

print "IP $ARGV[0] is not part of UA-IX\n";
close(IP);</pre>
<p>To run the script: </p>
<pre>$ perl uaix.pl [ip_addr] [path/to/ua-list.txt]</pre>
<p>For example: </p>
<pre>$ perl uaix.pl 72.14.228.156 ua-list.txt
IP 72.14.228.156 belong to network 72.14.192.0/18</pre>
<p>There is also some ways to use script on your own&#8230; You can use your list of networks to detect ;)</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/04/ua-ix-checker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPCalc on Perl</title>
		<link>http://andriigrytsenko.net/2010/03/ipcalc-on-perl/</link>
		<comments>http://andriigrytsenko.net/2010/03/ipcalc-on-perl/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 18:52:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=720</guid>
		<description><![CDATA[Today I decided to make my own IPCalc program. I had two reason for that. First to learn perl&#8217;s binary operations and second one to make some IP calculation points more clear for me. There is some listing of my script I hope this example help you to understand some fundamental points in IP math. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I decided to make my own IPCalc program. I had two reason for that. First to learn perl&#8217;s binary operations and second one to make some IP calculation points more clear for me.<br />
<span id="more-720"></span></p>
<p>There is some listing of my script I hope this example help you to understand some fundamental points in IP math.</p>
<pre class="brush: perl; title: ; notranslate">
#!/usr/local/bin/perl
# Written by Andrii Grytsenko 2010
# PP: http://andriigrytsenko.net    

use POSIX;

sub hex2bin {
   my $hex = shift;
   my $pack = unpack(&quot;B32&quot;,pack(&quot;N&quot;,$hex));
   my $pack = substr($pack,-8);
   return $pack;
}                                          

sub bin2hex {
   my $bin = shift;
   return unpack(&quot;N&quot;, pack(&quot;B32&quot;, substr(&quot;0&quot; x 32 . $bin, -32)))
}                                                               

sub bin2ip {
    my $bin = shift;
    my $type = shift;
    my $ip;
    $ip .= bin2hex(substr($bin,0,8)) .&quot;\.&quot;;
    $ip .= bin2hex(substr($bin,8,8)) .&quot;\.&quot;;
    $ip .= bin2hex(substr($bin,16,8)) .&quot;\.&quot;;
    if ( $type eq 'first') {
        $ip .= bin2hex(substr($bin,24,8)) + 1 ;
    } elsif ($type eq 'broad') {
        $ip .= bin2hex(substr($bin,24,8)) - 1 ;
    } else {
        $ip .= bin2hex(substr($bin,24,8));
    }
    return $ip;
}

sub normalization {
    my $line = shift;
    my ($ip,$mask) = split(/\//,$line);
    return($ip,$mask);
}

my ($ip,$net_mask) = normalization(@ARGV[0]);

my $host_mask = 32-$net_mask;
my $max_host = POSIX::pow(2,$host_mask)-2;
my $bin_mask = &quot;1&quot; x $net_mask . &quot;0&quot; x $host_mask;

my $bin_ip ;
$bin_ip .= hex2bin($_) foreach (split(/\./,$ip));

my $min = $bin_ip &amp; $bin_mask;
my $max_mask = &quot;0&quot; x $net_mask . &quot;1&quot; x $host_mask;
my $max = $bin_ip  | $max_mask;

my $min_ip = bin2ip($min);
my $min_host_ip = bin2ip($min,'first');
my $max_ip = bin2ip($max);
my $max_host_ip = bin2ip($max,'broad');

print \&lt;\&lt; EOF
IP ADDRESS:\t $ip\t $bin_ip
NETWORK MASK:\t \/$net_mask\t\t $bin_mask
WILDCARD:\t \/$host_mask\t\t $max_mask
NETWORK IP:\t $min_ip\/$net_mask\t $min
BROADCAST ADDR:\t $max_ip\t $max
FIRST ADDR:\t $min_host_ip
LAST ADDR:\t $max_host_ip
MAX HOSTS\t $max_host
EOF
</pre>
<p>Run scripts with one argument ip/netmask&#8230; Unfortunately, you can use only short network mask type :</p>
<pre>./ipcalc 192.157.9.3/21</pre>
<p>the output looks like this:</p>
<pre>
IP ADDRESS:      192.157.9.3     11000000100111010000100100000011
NETWORK MASK:    /21             11111111111111111111100000000000
WILDCARD:        /11             00000000000000000000011111111111
NETWORK IP:      192.157.8.0/21  11000000100111010000100000000000
BROADCAST ADDR:  192.157.15.255  11000000100111010000111111111111
FIRST ADDR:      192.157.8.1
LAST ADDR:       192.157.15.254
MAX HOSTS        2046
</pre>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/03/ipcalc-on-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clean up the shared memory in Solaris</title>
		<link>http://andriigrytsenko.net/2010/03/clean-up-the-shared-memory-in-solaris/</link>
		<comments>http://andriigrytsenko.net/2010/03/clean-up-the-shared-memory-in-solaris/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 15:44:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[*nix]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=713</guid>
		<description><![CDATA[Here is short trick how to clean the shared memory up in Solaris OS. Here is short info about the host(solaris 5.9, arch sparc): uname -a SunOS hostname1 5.9 Generic_118558-25 sun4u sparc SUNW,Sun-Fire-V890 Solaris To see all shared memory segment, use ipcs user1@~>ipcs -m -a IPC status from as of Wed Mar 10 16:26:20 CET [...]]]></description>
			<content:encoded><![CDATA[<p>Here is short trick how to clean the shared memory up in Solaris OS. </p>
<p><span id="more-713"></span></p>
<p>Here is short info about the host(solaris 5.9, arch sparc):</p>
<pre>uname -a
SunOS hostname1 5.9 Generic_118558-25 sun4u sparc SUNW,Sun-Fire-V890 Solaris
</pre>
<p>To see all shared memory segment, use <em>ipcs</em></p>
<pre>
user1@~>ipcs -m -a
IPC status from <running system> as of Wed Mar 10 16:26:20 CET 2010
T         ID      KEY        MODE        OWNER    GROUP  CREATOR   CGROUP NATTCH      SEGSZ  CPID  LPID   ATIME    DTIME    CTIME
Shared Memory:
m       4608   0x5efaa728 --rw-r-----   oracle oinstall   oracle oinstall     23 3992993792  5720 18925 16:24:47 16:24:47 11:59:42
m    5246977   0x517b6233 --rw-r--r-- user1   os_int user1   os_int     32    7352048 10685 16417 16:21:26 16:21:26 16:13:35
m    1969154   0x22b80b3e --rw-r--r-- user1   os_int user1   os_int      3   72552448 10689 11443 16:14:19 16:13:51 16:13:37
m    1967619   0x1b68b6e6 --rw-r--r-- user1   os_int user1   os_int      8  438326272 10689 16417 16:21:26 16:21:26 16:13:38
m    1966084   0x5724f977 --rw-r--r-- user1   os_int user1   os_int     14  212926464 10689 11379 16:14:27 16:13:50 16:13:40
m    1966085   0x534aab2a --rw-r--r-- user1   os_int user1   os_int     10  216572928 10689 11442 16:14:38 16:13:51 16:13:42
m   11391045   0x7bfc552e --rw-r--r-- user2   os_int user2   os_int      0    7352048  8047  9445 14:43:22 14:43:40 13:41:22
m   10461766   0x63fcba9b --rw-r--r-- user2   os_int user2   os_int      0   72552448  8114  9457 14:43:22 14:43:38 13:41:25
m    9721415   0x5cad6643 --rw-r--r-- user2   os_int user2   os_int      0  583097344  8114  9459 14:43:22 14:43:38 13:41:27
m    9655368   0x1869a8d4 --rw-r--r-- user2   os_int user2   os_int      0  212926464  8114  9466 14:43:22 14:43:38 13:41:29
m    9753673   0x148f5a87 --rw-r--r-- user2   os_int user2   os_int      0  216572928  8114  9473 14:43:22 14:43:38 13:41:31
</pre>
<p>To delete/destroy/remove any segment of the shared memory, use <em>ipcrm</em>. You can specify segment by  <em>shmkey</em>(3-rd field in ipcs output) or by <em>shmid</em>(2-nd field) use <strong>-M</strong> and <strong>-m</strong> accordingly . Like : </p>
<pre>ipcrm -m 4608</pre>
<p>or </p>
<pre>ipcrm -M 0x5efaa728</pre>
<p>To remove all segment in shared memory where owner is <em>user1</em>, run </p>
<pre>ipcs -m -a | awk '{if($5 ~ /user1/ &#038;&#038; $1 ~ /m/) print "ipcrm -m "$2;}' | bash</pre>
<p>END.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/03/clean-up-the-shared-memory-in-solaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl performance optimization</title>
		<link>http://andriigrytsenko.net/2010/03/perl-performance-optimization/</link>
		<comments>http://andriigrytsenko.net/2010/03/perl-performance-optimization/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 18:05:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://andriigrytsenko.net/?p=671</guid>
		<description><![CDATA[I&#8217;d like to describe my own experience with perl optimization. There several common way to make you code works more faster. I used perl module Benchmark to make measurements. Rules: 1. If you can use single quotes instead of double quote, do it. In most cases it will be executed more faster because of string [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to describe my own experience with perl optimization. There several common way to make you code works more faster.<br />
<span id="more-671"></span></p>
<p>I used perl module Benchmark to make measurements. Rules:</p>
<p>1. If you can use single quotes instead of double quote, do it. In most cases it will be executed more faster because of string in single quotes is not going to concatenate. </p>
<p>2. Use compiled regexps in case you have loops. It can brings huge performance: </p>
<pre>
use Benchmark;

sub qwe {
    my $re = shift;
    my $line = "wer";
    foreach my $reg (@$re){
        if ( $line =~ /$reg/) {
            my $l=0;
        }
    }
}

my $line = "sdfsdfsdfsdf";
my $ref = ".*";
my @arr = qw(qwe sdf wer); #plaine regexps
my @c_re;
foreach my $p_re (@arr) { # compile it and put in to the @c_re
    my $re = qr/\b$p_re\b/i ;
    push(@c_re,$re);
}

Benchmark::cmpthese(100000, {
    'Compiled' => sub { qwe(\@c_re) },
    'Not_compiled' => sub { qwe(\@arr) },
});</pre>
<p>As result:</p>
<pre>
                 Rate Not_compiled     Compiled
Not_compiled  36232/s           --         -79%
Compiled     169492/s         368%           --</pre>
<p>3. Extract values from string with <em>substr</em> if you can. There are three well knows ways to do such kind of operation: regular expressions, split and substr. Let&#8217;s compare it:</p>
<pre>sub mksplit {
    my ($line) = @_;
    my ($fst,$snd) = split(/-/,$line);
    return($fst,$snd);
}

sub mkregexp {
    my ($line,$re) = @_;
    $line =~ m/$re/;
    return($1,$2);
}

sub mkstr {
    my ($line) = @_;
    my $pos = index($line,'-');
    my $fst = substr($line,0,$pos);
    my $snd = substr($line,$pos+1);
    return($fst,$snd);
}

my $line = "12-34";
my $n_comp_re = '(\d+)-(\d+)';
my $comp_re = qr/\b$n_comp_re\b/i ;

Benchmark::cmpthese(1000000, {
    'Compiled' => sub { mkregexp($line,$comp_re) },
    'Not_compiled' => sub { mkregexp($line,$n_comp_re) },
    'STR' => sub { mkstr($line) },
    'Split' => sub { mksplit($line) },
});

Benchmark::timethese(1000000, {
    'Compiled' => sub { mkregexp($line,$comp_re) },
    'Not_compiled' => sub { mkregexp($line,$n_comp_re) },
    'STR' => sub { mkstr($line) },
    'Split' => sub { mksplit($line) },
});
</pre>
<p>Where <em>compiled</em> and <em>not_compiles</em>  we use when talk about regular expression.</p>
<pre>
                 Rate        Split     Compiled Not_compiled          STR
Split        297619/s           --          -9%         -12%         -25%
Compiled     327869/s          10%           --          -4%         -17%
Not_compiled 340136/s          14%           4%           --         -14%
STR          396825/s          33%          21%          17%           --
Benchmark: timing 1000000 iterations of Compiled, Not_compiled, STR, Split...
  Compiled:  4 wallclock secs ( 3.14 usr +  0.00 sys =  3.14 CPU) @ 318471.34/s (n=1000000)
Not_compiled:  3 wallclock secs ( 2.91 usr +  0.00 sys =  2.91 CPU) @ 343642.61/s (n=1000000)
       STR:  2 wallclock secs ( 2.53 usr +  0.00 sys =  2.53 CPU) @ 395256.92/s (n=1000000)
     Split:  3 wallclock secs ( 3.19 usr +  0.00 sys =  3.19 CPU) @ 313479.62/s (n=1000000)
</pre>
<p>As you can see from output the more faster way to exract values from string is <em>substr</em>, next is split and regular expressions is the most slower. I don&#8217;t know why compiled regexps is more slow than regular one in this case. I guess its because of 1 iteration. </p>
<p>4. Don&#8217;t use sort in hash loops if there is no necessity. The most faster way to through over the hash is <em>keys</em> statement: </p>
<pre>
sub mkeach {
    my $hash = shift;
    my %hash2;
    while ( my($key,$value) = each(%$hash)){
        $hash2{$key} = $value;
    }
    return(\%hash2);
}

sub mkkeys {
    my $hash = shift;
    my %hash2;
    for my $key (keys(%$hash)){
        $hash2{$key} = $hash->{$key};
    }
    return(\%hash2);
}

sub mksort {
    my $hash = shift;
    my %hash2;
    foreach my $key (sort keys %$hash) {
        $hash2{$key} = $hash->{$key};
    }
    return(\%hash2);
}

my %hash = (name => 'name1', surname => 'surname1', address => 'address', var => 'var1', var2 => 'var2');

Benchmark::cmpthese(1000000, {
    'Keys' => sub { mkkeys(\%hash) },
    'Each' => sub { mkeach(\%hash) },
    'Sort' => sub { mksort(\%hash) },
});

Benchmark::timethese(1000000, {
    'Keys' => sub { mkkeys(\%hash) },
    'Each' => sub { mkeach(\%hash) },
    'Sort' => sub { mksort(\%hash) },
});
</pre>
<pre>
        Rate Each Sort Keys
Each 66800/s   --  -3% -14%
Sort 68681/s   3%   -- -11%
Keys 77459/s  16%  13%   --
Benchmark: timing 1000000 iterations of Each, Keys, Sort...
      Each: 16 wallclock secs (14.92 usr +  0.00 sys = 14.92 CPU) @ 67024.13/s (n=1000000)
      Keys: 12 wallclock secs (12.91 usr +  0.00 sys = 12.91 CPU) @ 77459.33/s (n=1000000)
      Sort: 15 wallclock secs (14.62 usr +  0.00 sys = 14.62 CPU) @ 68399.45/s (n=1000000)
</pre>
<p>That&#8217;s all for now, but I&#8217;ll continue to optimize my code so I think there will be an updates soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://andriigrytsenko.net/2010/03/perl-performance-optimization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

