Friday, January 13, 2012

chrony


 chrony uses ntp protocol. It designed to get even more accurate time in linux environment. Chrony can also run in any machines that do not have any internet connections or internet connection is very slow such as dial up connections. So, the reference of accurate time can be any clock with high accuracy, but we should able to read the clock and give it to program. In addition and most importantly, it is also capable of calculating the inaccuracy of the hardware clock, and based on that, adjust the hardware clock at boot time. chrony consists of two parts: chronyd daemon and a user interface chronyc.

The following shows that how I installed and configured chrony in my host machine:

yum install chrony      #To install chrony daemon in my host machine
service ntpd stop  
#I should stop ntpd daemon because they don't work together. I figured out this in /var/log/messages.

Then I configured the chrony configuration file, which is /etc/chrony.conf. I just show important lines:

    vi /etc/chrony.conf
    server 0.fedora.pool.ntp.org     #these are the time servers that I get time through
    server 1.fedora.pool.ntp.org     #internet connection
    server 2.fedora.pool.ntp.org
    # Allow client access from local network.
    allow 192.168.2/24
    keyfile /etc/chrony.keys    #key file  path
    # Specify the key used as password for chronyc.
    commandkey 1
    logdir /var/log/chrony   # logging directory  path
    log measurements statistics tracking  #enable statistics logs

Then, I enabled the commented line in the /etc/chrony.keys file.
1 a_key
Finally, I started my chrony daemon by:
service chronyd start

I typed 'chronyc <command>' to monitor the operation of chronyd. The monitoring commands are:
    sources
    sourcestats
    tracking
The followings are the output of running these commands: 
 [root@f13 ~]# chronyc tracking
Reference ID    : 69.20.226.105 (2.fedora.pool.ntp.org)
Stratum         : 3
Ref time (UTC)  : Sun Jan 8 20:10:33 2012
System time     : 0.448538870 seconds fast of NTP time
Frequency       : 0.000 ppm fast
Residual freq   : -9891.555 ppm
Skew            : 1000000.000 ppm
Root delay      : 0.108197 seconds
Root dispersion : 22.964180 seconds

[root@f13 ~]# chronyc sourcestats
210 Number of sources = 3
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
================================================================
0.fedora.pool.ntp.org       3   3   129   -576.006     194193   +541ms    34ms
1.fedora.pool.ntp.org       3   3   130  -7632.297    1479518    +10ms   125ms
2.fedora.pool.ntp.org       3   3   131  -9891.555     296739    -21us    10ms

[root@f13 ~]# chronyc sources
210 Number of sources = 3
MS Name/IP address           Stratum Poll LastRx Last sample
================================================================
^+ 0.fedora.pool.ntp.org         3    6     13   +167ms[ -288ms] +/-  542ms
^* 1.fedora.pool.ntp.org         2    6     10    -83ms[ -538ms] +/-  115ms
^+ 2.fedora.pool.ntp.org         2    6      8    -89ms[  -89ms] +/-  191ms

 
Now, it is the time to configure the guest machine. The processes are the same as host, but the only difference is that I changed the server address to my host in /etc/chrony.conf.

vi /etc/chrony.conf
server 192.168.2.5     #this is the ip address of my host
Also, there is no need to define client access for local network. So, you can comment that statement. The following is the status of the guest machine:

[root@vm01 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address           Stratum Poll LastRx Last sample
===============================================================
^~ 192.168.2.5                  16    6     43    -51ms[  -51ms] +/- 1500ms

[root@vm01 ~]# chronyc sourcesstatus
210 Number of sources = 1
MS Name/IP address           Stratum Poll LastRx Last sample
================================================================
^* 192.168.2.5                   3    6     19    +50ms[  +52ms] +/-  226ms

[root@vm01 ~]# chronyc tracking
Reference ID    : 192.168.2.5 (192.168.2.5)
Stratum         : 4
Ref time (UTC)  : Sun Jan 8 22:45:16 2012
System time     : 0.000000354 seconds slow of NTP time
Frequency       : 35.881 ppm slow
Residual freq   : -0.413 ppm
Skew            : 23.131 ppm
Root delay      : 0.062902 seconds
Root dispersion : 0.146990 seconds

 
Accuracy
Advantages
Disadvantage
Chrony is very accurate and if you look at to the output of chronyc command above, you will see that the accuracy is      microsecond.

Chrony supports intermittent internet connections (like a modem). Chrony also keeps track of the computers internal clock error compared to the NTP time to correct the time when the computer isn't connected to the internet (which is also handy even with a continuously connection).
In my opinion, the only major drawback is that chrony is not as widely tested as ntpd and there could be serious bugs   hidden. I found some security issues in pervious versions of chrony on internet.

 

Sunday, December 25, 2011

Setup and Configure Sendmail Server

Hello Everyone,
After verifying connectivity, DNS, and telnet to smtp, it is right time to configure your Sendmail server. To enable masquerading and binding your domain for sendmail, you should change the sendmail configuration file which is located in /etc/mail/sendmail.mc. Open this file with vi and change the following lines:
change:
LOCAL_DOMAIN(`localhost.localdomain')dnl     to     LOCAL_DOMAIN(khosro.org)dnl
dnl MASQUERADE_AS(`mydomain.com')dnl      to   MASQUERADE_AS(khosro.org)dnl
dnl FEATURE(masquerade_envelope)dnl            to   FEATURE(masquerade_envelope)dnl
dnl FEATURE(masquerade_entire_domain)   to FEATURE(masquerade_entire_domain)dnl
dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl   to MASQUERADE_DOMAIN(khosro.org)dnl

Replace khosro.org with your domain name.
Now, you should run the following command in order to take effect your change in configuration file. You should use m4 command like this:
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Now, restart your sendmail with this command:    service sendmail restart
If everything is fine, you should able to send an email. Create a file and put some text on this file. Name this file to message_file. Run this command in order to send an email to your friend.

mail -v -s "Test from Khosro" root@mymachine.khosro.org < message_file

Change mymachine.khosro.org to your machine name and domain name. Use mail command to check the inbox and verify your email that you already sent it.  
Please leave your comments or questions. I will try to answer as soon as possible.
Thanks,
Khosro Taraghi

Exporting all Email Accounts from Zimbra Server for Microsoft Transporter Suite

Hello Everyone,

In order to move all email accounts and data from IMAP or POP3 Zimbra Server in Linux box machine to Exchange Server 2007, we need to create a .CSV file with the following columns:
  • SourceIdentity: The e-mail account that the user has in the IMAP/POP3 Server
  • SourceServer: The name or IP of the IMAP/POP3 Server
  • SourceLoginID: the account user name used to connect on the IMAP/POP3 server
  • SourcePassword: the user’s password
  • TargetIdentity: the Exchange Server 2007 identity will receive the data from the previous IMAP/POP3 Server settings  
To make life easier, I made a script that export all users from Zimbra to a CSV file. 
Here is the script:

#!/bin/bash
clear
echo "Processing account, please wait.............................."
USERS=`su - zimbra -c 'zmprov -l gaa'`
#Assume that domain name is test.com
exchange="@test.com"
echo "SourceIdentity,SourceServer,SourceLoginID,SourcePassword,TargetIdentity" > export_users.csv
for ACCOUNT in $USERS
 do
  SourceIdentity=`echo $ACCOUNT`
  #Assume that domain name is xyz.com for Linux box and Zimbra
  SourceServer=`echo "xyz.com"`
  SourceLoginID=`echo $ACCOUNT | awk -F@ '{print $1}'`
  SourcePassword=`echo "P@ssw0rd"`
  TargetIdentity=`echo -n $ACCOUNT | awk -F@ '{print $1}'`
  TargetIdentity=${TargetIdentity}${exchange}
  if [ $SourceLoginID == "admin" ] || [ $SourceLoginID == "spam" ] || [ $SourceLoginID == "ham" ] || [ $SourceLoginID == "virus-quarantine" ]
  then
   echo "Skipping system account, $ACCOUNT..."
  else
   echo "$SourceIdentity,$SourceServer,$SourceLoginID,$SourcePassword,$TargetIdentity" >> export_users.csv
  fi
 done



Now, we can use this CSV file in Microsoft Transporter Suite to import users to Exchange 2007.
Hope enjoy using this script. Please leave your comments or questions. I will try to answer as soon as possible.
Thanks,
Khosro Taraghi

Wednesday, November 23, 2011

Apache Module mod_vhost_alias


Hello everybody,
mod_vhost_alias provides for dynamically configured mass virtual hosting. According to Apache website, http://httpd.apache.org/docs/2.0/mod/mod_vhost_alias.html, this module creates dynamically configured virtual hosts, by allowing the IP address and/or the Host: header of the HTTP request to be used as part of the pathname to determine what files to serve. This allows for easy use of a huge number of virtual hosts with similar configurations.

The following explanation shows how to configure apache with this module. Then, I wrote a script to automate creation of mass virtual hosting.

  • Untar the installation file of apache and change your directory to apache directory
  • Run this command: ./configure –prefix=$HOME/apache –enable-modules=mod_vhost_alias
  • make
  • make install

Here is the script:

#!/bin/bash
clear
echo "******************************************************"
echo "This is a script for making multiple virtual hosts."
echo "Scripted by: Khosro Taraghi"
echo "Modified date: Nov-23-2011"
echo "******************************************************"
echo ""
echo ""
reset_server=0
end_of_script=""
while ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
do
echo -n "Press y to continue or press n to exit (y/n): "
read end_of_script
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!!"
fi
done
if [ "$end_of_script" == "y" ]
then
echo -n "Please enter the path to your Server Root (Absolute path): "
read sroot
sroot=$(echo $sroot | sed 's/\/$//')
while ([ ! -d "$sroot" ])
do
echo -n "Directory $sroot does not exist!! Please try again: "
read sroot
sroot=$(echo $sroot | sed 's/\/$//')
done
echo -n "Please enter the path to your Document Root (Absolute path): "
read droot
droot=$(echo $droot | sed 's/\/$//')
while ([ ! -d "$droot" ])
do
echo -n "Directory $droot does not exist!! Please try again: "
read droot
droot=$(echo $droot | sed 's/\/$//')
done
sed -i 's/^#.*NameVirtualHost/NameVirtualHost/' $sroot/conf/httpd.conf
fi
while [ "$end_of_script" != "n" ]
do
echo -n "Please enter the name of your Server Name (for example, www.example.com): "
read sname
echo "<VirtualHost *:80>" >> $sroot/conf/httpd.conf
echo "ServerAdmin khosro@example.com" >> $sroot/conf/httpd.conf
mkdir -p $droot/$sname
echo "VirtualDocumentRoot \"$droot/%0\"" >> $sroot/conf/httpd.conf
echo "DirectoryIndex index.html" >> $sroot/conf/httpd.conf
echo "ServerName $sname" >> $sroot/conf/httpd.conf
echo "ErrorLog logs/$sname-error_log" >> $sroot/conf/httpd.conf
echo "CustomLog logs/$sname-access_log common" >> $sroot/conf/httpd.conf
alias_vhost=""
while ([ "$alias_vhost" != "n" ] && [ "$alias_vhost" != "y" ])
do
echo -n "Do you want to add an alias to another virtual host (y/n): "
read alias_vhost
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!! Enter y for yes or n for no!"
fi
done
if [ "$alias_vhost" == "y" ]
then
echo -n "Please enter the name of Server Name that you want to make an alias to $sname, (for example, www.example2.com) : "
read alias_name
echo "AliasMatch ^/(.*)$ $droot/$alias_name/index.html" >> $sroot/conf/httpd.conf
fi
redirect=""
while ([ "$redirect" != "n" ] && [ "$redirect" != "y" ])
do
echo -n "Do you want to make a redirect to another virtual host (y/n): "
read redirect
if ([ "$redirect" != "n" ] && [ "$redirect" != "y" ])
then
echo "The input is incorrect!!! Enter y for yes or n for no!"
fi
done
if [ "$redirect" == "y" ]
then
echo -n "Please enter the name of Server Name that you want to make a Redirect to $sname, (for example, www.example2.com) : "
read redirect_name
echo "RedirectMatch permanent ^/$ http://$redirect_name" >> $sroot/conf/httpd.conf
fi
echo "</VirtualHost>" >> $sroot/conf/httpd.conf
echo "<html><title>$sname</title>This is a webpage that belongs to $sname.</html>" >> $droot/$sname/index.html
echo ""
echo "The Virtual Host <$sname> was added successfully."
echo "Press any key to continue..."
read
echo "127.0.0.1 $sname" >> /etc/hosts
service NetworkManager restart
clear
reset_server=1
end_of_script=""
while ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
do
echo -n "Press y to continue or press n to exit (y/n): "
read end_of_script
if ([ "$end_of_script" != "n" ] && [ "$end_of_script" != "y" ])
then
echo "The input is incorrect!!!"
fi
done
done
if [ $reset_server -eq 1 ]
then
sed -i '/combined/s/^LogFormat "/LogFormat "%V /' $sroot/conf/httpd.conf
sed -i '/common/s/^LogFormat "/LogFormat "%V /' $sroot/conf/httpd.conf
$sroot/bin/apachectl stop 1>/dev/null
$sroot/bin/apachectl start 1>/dev/null
fi


Regards,
Khosro Taraghi

Thursday, September 29, 2011

How To Install And Run Webalizer From Source Code And How To Configure Apache For Webalizer

Hello Everybody,
Today, I will explain, briefly, how to install and run Webalizer and how to configure apache for webalizer at the same machine box. First download the source code from following address: http://www.webalizer.org/download.html (Download .tgz file). Then go to the location of this file (.tgz)and run following commands:

1. yum install gcc libpng libpng-devel gd gd-devel zlib zlib-devel
2. tar xvzf webalizer-2.23-05-src.tgz
3. cd webalizer-2.23-05
4. ./configure --prefix=/webalizer ------> Here you can specify the destination of installation. You change to somewhere else.
5. make
6. make install
7. cp /webalizer/etc/webalizer.conf.sample /webalizer/etc/webalizer.conf ----> Change to your path if you already changed it.
8. vi /webalizer/etc/webalizer.conf ------>  Uncomment and change the following lines(don't forget to change the path to your path):
    LogFile        /apa2/logs/access_log
    OutputDir      /apa2/usage
    HistoryName     /webalizer/webalizer.hist
    Incremental     yes
    IncrementalName /webalizer/webalizer.current
    Quiet           yes
    FoldSeqErr      yes
    HideURL         *.gif
    HideURL         *.GIF
    HideURL         *.jpg
    HideURL         *.JPG
    HideURL         *.png

    HideURL         *.PNG
    HideURL         *.ra


9. mkdir /apa2/usage   ------> change the /apa2 to the location of your Server root.
10. vi /apa2/conf/httpd.conf ------> change the path to the location of your httpd.conf
11. Add the following lines to your httpd.conf ------> change the /apa2 to the location of your Server root.

    <IfModule mod_alias.c>

      Alias /usage/ "/apa2/usage/"
          <Directory "/apa2/usage">
          Options None
          AllowOverride None
          Order deny,allow
          Deny from all
          Allow from 127.0.0.1
          </Directory>

    </IfModule>


12. Restart apache:  ------> change the /apa2 to the location of your Server root.
    
    /apa2/bin/apachectl restart

13. To run Webalizer manually, to generate reports, use the following command:

    /webalizer/bin/webalizer   ------> Change /webalizer/ to the location of your Webalizer. For example, if you installed Webalizer in /abc, just change it to /abc/bin/webalizer

Now, whenever you want to get the new report, you should do the step 13 manually. To run this command automatically, use cron job.

14. To see the result, open the browser and enter the following url:

     http://127.0.0.1/usage/

Now, you should see the result on the browser. For any question, please leave a comment. I will try to answer as soon as possible.

Regards,
Khosro Taraghi

Saturday, September 24, 2011

How To Start sshd Service in CYGWIN

Hello All,

Today, I want to explain that how you can start the sshd service in cygwin. First, You should download the installation file from www.cygwin.com for windows. During the installation, you must expand the Admin folder and select cygrunsrv. Also, you must expand Net and select openssh. After installation, open cygwin shell, and run the following commands:
  1. ssh-host-config -y     --------> This command will create necessary configuration files.
  2. cygrunsrv -S sshd     --------> This command will run the sshd service. This is equal to "service sshd start" command.
Now your sshd service is ready. Try by doing ssh to somewhere or someone ssh to you.
Don't forget to configure your firewall in Windows.

Regards,
Khosro Taraghi