Install and Configure Nagios - CentOS




Nagios is an open source computer system monitoring, network monitoring and infrastructure monitoring software application. Nagios offers monitoring and alerting services for servers, switches, applications, and services. It alerts the users when things go wrong and alerts them a second time when the problem has been resolved.


Here i am installing and configuring Nagios in CentOS 6.4, 64 bit. Depending upon the versions, make changes in the installation steps. Here in this case both the client and servers are CentOS 6.4, 64 bit.


Server Side Configuration


Server IP: 192.168.1.100
Server Hostname: server.arun.com

Install Nagios


[root@nagios-server ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@nagios-server ~]# yum install nagios nagios-plugins

You can find nagios configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/ after the installation.

Configure Nagios


Create 'nagiosadmin' user

[root@nagios-server ~]# htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Updating password for user nagiosadmin

Now you can access nagios via browser using the following url. You can use 'nagiosadmin' and it's password to login to nagios webpanel.
http://<IP>/nagios


You can find nagios configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/


Change Notification Mail Address

[root@nagios-server ~]# vim /etc/nagios/objects/contacts.cfg
.
.
define contact{
        contact_name             nagiosadmin       ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        }
.
.


Add or Edit Commands for Monitoring

**Commands must be defined before use. We can use a command once it is defined in the commands.cfg file. You cannot use any other commands which is not defined here. Here is the commands which is defined in my server.

[root@nagios-server ~]# egrep -v '^#|^$' /etc/nagios/objects/commands.cfg
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
define command{
command_name notify-service-by-email
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$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
        }
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
        }
define command{
        command_name    check_local_load
        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
        }
define command{
        command_name    check_local_procs
        command_line    $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
        }
define command{
        command_name    check_local_users
        command_line    $USER1$/check_users -w $ARG1$ -c $ARG2$
        }
define command{
command_name check_local_swap
command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$
}
define command{
command_name check_local_mrtgtraf
command_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$
}
define command{
        command_name    check_ftp
        command_line    $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_hpjd
        command_line    $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_snmp
        command_line    $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_http
        command_line    $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
        }
define command{
command_name check_ssh
command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
}
define command{
command_name check_dhcp
command_line $USER1$/check_dhcp $ARG1$
}
define command{
        command_name    check_ping
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
        }
define command{
        command_name    check_pop
        command_line    $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_imap
        command_line    $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
        }
define command{
        command_name    check_smtp
        command_line    $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
        }
define command{
command_name check_tcp
command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
}
define command{
command_name check_udp
command_line $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
}
define command{
command_name check_nt
command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
}
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$
}
define command{
command_name            check_nrpe
command_line            $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
define command{
command_name process-host-perfdata
command_line /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/log/nagios/host-perfdata.out
}
define command{
command_name process-service-perfdata
command_line /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/log/nagios/service-perfdata.out
}


Add New Client's for Monitoring

I am adding all the client's configuration in a new directory, ie, /etc/nagios/servers . I have to add the new directory in the nagios configuration.

[root@nagios-server ~]# echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfg
Once you have done the above step, all the files with extension .cfg in  /etc/nagios/servers will be loaded with nagios.


Client IP: 192.168.1.101
Client Hostname: client.arun.com

For easy to understand, i am creating the configuration file for 'client.arun.com' as 'client.arun.com.cfg'. Here is a sample configuration template for adding new clients to the nagios server. The following configuration file will monitor FTP, HTTP, POP3, IMAP, SMTP, MYSQL, SSH, PING, Current Load, Current Users, Root Partition, Total Processes, Zombie Processes. You can add new services in this and remove unwanted services.

[root@nagios-server ~]# cat /etc/nagios/servers/client.arun.com.cfg
# First of all client server is to be defined using host defintion.
define host{
use linux-server
host_name client.arun.com
alias client.sudosu.in
address 192.168.1.101
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}

#Once all the host is defined. Then proceed with the monitored services.
define service{
use generic-service
host_name client.arun.com
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}

define service{
use generic-service
host_name client.arun.com
service_description HTTP
check_command check_http
}

define service{
use generic-service
host_name client.arun.com
service_description FTP
check_command check_ftp
}

define service{
use generic-service
host_name client.arun.com
service_description SSH
check_command check_ssh
}

define service{
use generic-service
host_name client.arun.com
service_description SMTP
check_command check_smtp
}

define service{
use generic-service
host_name client.arun.com
service_description POP3
check_command check_pop
}

define service{
use generic-service
host_name client.arun.com
service_description IMAP
check_command check_imap
}

define service{
use generic-service
host_name client.arun.com
service_description MYSQL
check_command check_mysql
}

#nrpe and nagios plugins need not to be installed in the client side for the above services.
#====================================================================
#nrpe and nagios plugins need to install in the client side for the following services.

define service{
    use generic-service
  host_name client.arun.com
  service_description Current Users
    check_command check_nrpe!check_users
}
define service{
    use generic-service
    host_name client.arun.com
    service_description Current Load
    check_command check_nrpe!check_load
}
define service{
    use generic-service
    host_name client.arun.com
    service_description Root Partition
    check_command check_nrpe!check_xvda
}
define service{
    use generic-service
    host_name client.arun.com
    service_description Zombie Processes
    check_command check_nrpe!check_zombie_procs
}
define service{
    use generic-service
    host_name client.arun.com
    service_description Total Processes
    check_command check_nrpe!check_total_procs
}


Once you have made all the above changes, restart nagios and httpd service.

[root@nagios-server ~]# /etc/init.d/httpd restart
[root@nagios-server ~]# /etc/init.d/nagios restart


Client Side Configuration

Install nrpe and Nagios Plugins


**You do not want to do anything in the client server if you want to monitor ssh, smtp, pop3, imap, http, ping, mysql services. ie, do not want to install nrpe and nagios-plugins. You can check the status of these service outside the client server without any additional services. One of the example is 'telnet', it help you to check whether a service is listening in the server or not.

**If you want to monitor process, load, disk usage, swap memory, ie, for all the information which is returned inside the client server. you have to configure the client as follows.


[root@nagios-client ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@nagios-client ~]# yum install nrpe nagios-plugins

You can find nrpe configuration files in /etc/nagios and plugins under /usr/lib64/nagios/plugins/ after the installation.

Here is my sample nrpe.cfg file.

[root@nagios-client ~]# egrep -v '^#|^$' /etc/nagios/nrpe.cfg
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts= 192.168.1.0/24

dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_xvda]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/xvda1
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200


Once you have made all the above changes, restart nrpe service.
[root@nagios-client ~]# /etc/init.d/nrpe restart

cPanel - Install 'memcache' in CentOS


Download and Extract Memcache package

root@server [~]# cd /usr/local/src
root@server [/usr/local/src]# wget http://pecl.php.net/get/memcache-3.0.6.tgz
root@server [/usr/local/src]# tar -xzf memcache-3.0.6.tgz

Compilation and installation

root@server [/usr/local/src]# cd memcache-3.0.6
root@server [/usr/local/src/memcache-3.0.6]# phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626

root@server [/usr/local/src/memcache-3.0.6]# ./configure
root@server [/usr/local/src/memcache-3.0.6]# make
root@server [/usr/local/src/memcache-3.0.6]# make install

Enable memcache in php.ini
root@server [~]# echo "extension=memcache.so" >> /usr/local/lib/php.ini
root@server [~]# /etc/init.d/httpd restart

If 'memcache' is successfully loaded, you will get a result as like follows.

root@server [~]# php -i | grep memcache
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 32768 => 32768
memcache.compress_threshold => 20000 => 20000
memcache.default_port => 11211 => 11211
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.lock_timeout => 15 => 15
memcache.max_failover_attempts => 20 => 20
memcache.protocol => ascii => ascii
memcache.redundancy => 1 => 1
memcache.session_redundancy => 2 => 2

That's it..

Install and Configure Postfix SMTP server with Cyrus-SASL authentication




If you are planning to use mysql for cyrus-sasl authentication, it is better to install PostfixAdmin. It will help us to add new smtp users easily.


Install and Configure PostfixAdmin



It is needed to install httpd,mysql and php for PostfixAdmin.

# yum install mysql-server php php-mysql php-imap php-mbstring -y

Once all the above packages were installed, make sure httpd and mysqld services are running.

It is needed to create db, db user for PostfixAdmin. Here i am using the following db details. Change the following details as you prefered.

DB: postfix
DB User: postfix
Password: postfix

The following command will create the DB for postfix. You can also execute these queries directly in the mysql console.

# mysql -e "CREATE DATABASE postfix;"
# mysql -e "CREATE USER postfix@localhost IDENTIFIED BY 'postfix';"
# mysql -e "GRANT ALL PRIVILEGES ON postfix.* TO postfix;"



To download and fix permissions of PostfixAdmin.

# yum install -y subversion
# cd /usr/local/

The following command will download latest PostfixAdmin package. The 'svn' command is available in the package 'subversion' which we have already installed.

# svn co http://svn.code.sf.net/p/postfixadmin/code/trunk postfixadmin
# chmod 777 /usr/local/postfixadmin/templates_c

Edit the postfixadmin configuration file, /usr/local/postfixadmin/config.inc.php and update the following lines as shown below.

 $CONF['configured'] = true;
 $CONF['postfix_admin_url'] = '/postfixadmin';
 $CONF['database_type'] = 'mysqli';
 $CONF['database_host'] = 'localhost';
 $CONF['database_user'] = 'postfix';
 $CONF['database_password'] = 'postfix';
 $CONF['database_name'] = 'postfix';
 $CONF['domain_path'] = 'YES';
 $CONF['domain_in_mailbox'] = 'NO';
 $CONF['encrypt'] = 'cleartext';
 $CONF['emailcheck_resolve_domain] = 'NO';


Once you have done the above changes, you have to create the following entry in httpd.conf to access postfixadmin via browser.

Alias /postfixadmin /usr/local/postfixadmin


Restart httpd service

# /etc/init.d/httpd restart


Now you can access postfixadmin using the following url. Setup the postfixadmin as per the given instructon in there.

http://<IP>/postfixadmin/setup.php

Once the setup is completed successsfully, it is time to install and configure postfix service.


Install and Configure Postfix



There will be a postfix package initiallly in the default installation. Here i am removing it and i am using Postfix-2.9.7. Depending upon the version and architecture, select the postfix version from http://packages.oostergo.net/

To download and install postfix
# rpm -Uvh http://packages.oostergo.net/postfix-2.9/el6/postfix-2.9.7-1.el6.x86_64.rpm

The following commands will made the changes in /etc/postfix/main.cf. We have to setup it initially.

To set postfix's hostname.
# postconf -e "myhostname = mail.sudosu.in"
# postconf -e "mydomain = sudosu.in"

# postconf -e "myorigin = "'$'"mydomain"

inet_interfaces initially set for listening from localhost only. We need to change it to listen on all interfaces.
# postconf -e "inet_interfaces = all"

# postconf -e "inet_protocols = ipv4"

# postconf -e "smtpd_banner = "'$'"myhostname ESMTP"

To limit an email size 10M
# postconf -e "message_size_limit = 10485760"

# postconf -e "mydestination = "'$'"myhostname, localhost."'$'"mydomain, localhost"



Install and Configure Cyrus-SASL 


Install necessary packages.

# yum install cyrus-sasl*



Check if postfix support cyrus authentication. Check if cyrus is listed in the result.

# postconf -a
cyrus
dovecot


Here i am using mysql backend for smtp authentication. Here is cyrus-sasl configuration for smtpd service.

[root@server ~]# cat /etc/sasl2/smtpd.conf
log_level: 7
pwcheck_method: auxprop
auxprop_plugin: sql
sql_engine: mysql
mech_list: PLAIN LOGIN
sql_hostnames: localhost
sql_user: postfix
sql_passwd: postfix
sql_database: postfix
sql_select: SELECT password FROM mailbox WHERE username = '%u@%r'


Postfix configuration for cyrus SMTP-Auth settings

# postconf -e "smtpd_sasl_local_domain = $myhostname"
# postconf -e "broken_sasl_auth_clients = yes"
# postconf -e "smtpd_sasl_type = cyrus"
# postconf -e "smtpd_sasl_auth_enable = yes"
# postconf -e "smtpd_sasl_security_options = noanonymous"
# postconf -e "broken_sasl_auth_clients = yes"
# postconf -e "smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated,  reject_unauth_destination, permit"
# postconf -e "smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination"


**If you have added any more configuration other than discussed in this article, remove those first. Once you verified the configuration discussed here, you can add new configurations.

Once the above onfiguration is completed, restart saslauthd and postfix services.


# /etc/init.d/saslauthd restart
# /etc/init.d/postfix restart

Verify the confiration by using telnet.

Install and Configure Postfix, PostfixAdmin, RoundCubeMail and Dovecot with mysql backend




Install and Configure PostfixAdmin



It is needed to install httpd,mysql and php for PostfixAdmin.

# yum install mysql-server php php-mysql php-imap php-mbstring -y

Once all the above packages were installed, make sure httpd and mysqld services are running.

It is needed to create db, db user for PostfixAdmin. Here i am using the following db details. Change the following details as you prefered.

DB: postfix
DB User: postfix
Password: postfix

The following command will create the DB for postfix. You can also execute these queries directly in the mysql console.

# mysql -e "CREATE DATABASE postfix;"
# mysql -e "CREATE USER postfix@localhost IDENTIFIED BY 'postfix';"
# mysql -e "GRANT ALL PRIVILEGES ON postfix.* TO postfix;"



To download and fix permissions of PostfixAdmin.

# yum install -y subversion
# cd /usr/local/

The following command will download latest PostfixAdmin package. The 'svn' command is available in the package 'subversion' which we have already installed.

# svn co http://svn.code.sf.net/p/postfixadmin/code/trunk postfixadmin
# chmod 777 /usr/local/postfixadmin/templates_c

Edit the postfixadmin configuration file, /usr/local/postfixadmin/config.inc.php and update the following lines as shown below.

 $CONF['configured'] = true;
 $CONF['postfix_admin_url'] = '/postfixadmin';
 $CONF['database_type'] = 'mysqli';
 $CONF['database_host'] = 'localhost';
 $CONF['database_user'] = 'postfix';
 $CONF['database_password'] = 'postfix';
 $CONF['database_name'] = 'postfix';
 $CONF['domain_path'] = 'YES';
 $CONF['domain_in_mailbox'] = 'NO';
 $CONF['encrypt'] = 'cleartext';
 $CONF['emailcheck_resolve_domain] = 'NO';


Once you have done the above changes, you have to create the following entry in httpd.conf to access postfixadmin via browser.

Alias /postfixadmin /usr/local/postfixadmin


Restart httpd service

# /etc/init.d/httpd restart


Now you can access postfixadmin using the following url. Setup the postfixadmin as per the given instructon in there.

http://<IP>/postfixadmin/setup.php

Once the setup is completed successsfully, it is time to install and configure postfix service.


Install and Configure Postfix


There will be a postfix package initiallly in the default installation. Here i am removing it and i am using Postfix-2.9.7. Depending upon the version and architecture, select the postfix version from http://packages.oostergo.net/

To download and install postfix
# rpm -Uvh http://packages.oostergo.net/postfix-2.9/el6/postfix-2.9.7-1.el6.x86_64.rpm

The following commands will made the changes in /etc/postfix/main.cf. We have to setup it initially.

To set postfix's hostname.
# postconf -e "myhostname = mail.sudosu.in"
# postconf -e "mydomain = sudosu.in"

# postconf -e "myorigin = "'$'"mydomain"

inet_interfaces initially set for listening from localhost only. We need to change it to listen on all interfaces.
# postconf -e "inet_interfaces = all"

# postconf -e "inet_protocols = ipv4"

# postconf -e "home_mailbox = Maildir/"

# postconf -e "smtpd_banner = "'$'"myhostname ESMTP"

To limit an email size 10M
# postconf -e "message_size_limit = 10485760"

To limit mailbox 1G
# postconf -e "mailbox_size_limit = 1073741824"

# postconf -e "mydestination = "'$'"myhostname, localhost."'$'"mydomain, localhost"



Create a user 'vmail' for creating virtual users(mail boxes)
# groupadd -g 5000 vmail
# useradd -g vmail -u 5000 vmail -d /home/vmail -m


It is needed to create some configuration files to map the domains and mailboxs from mysql. Here are those configuration files.

# cat /etc/postfix/mysql-domains.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'

# cat /etc/postfix/mysql-users.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = '1'
result_format = %sMaildir/

# cat /etc/postfix/mysql-aliases.cf
hosts = localhost
user = postfix
password = postfix
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'


The above configuration files and 'vmail' user need to map with postfix.

# postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf"
# postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf"
# postconf -e "virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf"
# postconf -e "virtual_mailbox_base = /home/vmail"
# postconf -e "virtual_uid_maps = static:5000"
# postconf -e "virtual_gid_maps = static:5000"

Restart or reload postfix

# postfix reload

or

# /etc/init.d/postfix restart


Install and Configure Dovecot


# yum install dovecot dovecot-mysql -y

Check if postfix support dovecot authentication. Check if dovecot is listed in the result.

# postconf -a
cyrus
dovecot

Postfix configuration for Dovecot SMTP-Auth settings

# postconf -e "smtpd_sasl_local_domain = $myhostname"
# postconf -e "smtpd_sasl_auth_enable = yes"
# postconf -e "broken_sasl_auth_clients = yes"
# postconf -e "smtpd_sasl_type = dovecot"
# postconf -e "smtpd_sasl_path = private/auth"
# postconf -e "smtpd_sasl_security_options = noanonymous"
# postconf -e "smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated,  reject_unauth_destination, permit"
# postconf -e "smtpd_recipient_restrictions =  permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"


Create dovecot-mysql.conf file as follows.

[root@server ~]# cat /etc/dovecot/dovecot-mysql.conf
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=postfix
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u' AND active = '1'


Create dovecot.conf file as follows.

[root@server ~]# cat /etc/dovecot/dovecot.conf

auth_debug = yes
auth_mechanisms = plain login
auth_username_format = %Lu
auth_verbose = yes
mbox_write_locks = fcntl
passdb {
  driver = pam
}
passdb {
  driver = pam
}
passdb {
  args = /etc/dovecot/dovecot-mysql.conf
  driver = sql
}
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0660
    user = postfix
  }
  user = root
}
ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
ssl_key = </etc/pki/dovecot/private/dovecot.pem
userdb {
  driver = passwd
}
userdb {
  driver = passwd
}
userdb {
  args = uid=5000 gid=5000 home=/home/vmail/%d/%n
  driver = static
}


Once the above settings has been completed, restart postfix and dovecot and verify the installation using telnet.

# /etc/init.d/dovecot restart
# /etc/init.d/postfix restart



Install and Configure RoundCubeMail


Download RoundCubeMail code

You can install latest roudcube using git.

# yum install git -y

# cd /usr/local
# git clone git://github.com/roundcube/roundcubemail.git

You can find a directory named 'roundcubemail' after the above step.

Install Necessary Packages

Install the following packages for the working if roundcube.

# yum install httpd php php-common php-json php-xml php-mbstring php-imap php-pear php-mysql mysql mysql-server

You have to add the following entries in the httpd.conf to access roundcube via browser.

Alias /roundcube /usr/local/roundcubemail

Restart httpd service.

# /etc/init.d/httpd restart


Necessary DataBase setup

Here i am using the following details for the DB setup. You can change it as you like.

DB: roundcubemail
DB User: roundcubemail
Password: roundcube_pass

# mysql -e "CREATE DATABASE roundcubemail;"
# mysql -e "GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost IDENTIFIED BY 'roundcube_pass';"
# mysql roundcubemail < /usr/local/roundcubemail/SQL/mysql.initial.sql


You can now access roundcube using the following url. You have to follow the instruction to complete the installation.

http://<IP>/roundcube/installer/

Once the installation completed, http://<IP>/roundcube allow you to login to the mail accounts.


Reference:
http://www.server-world.info/en/

Plesk (Linux) showing 500 internal server error


There may be a lot of reasons for the internal server error in plesk. Here in my case the situation is as follows.

FIrst of all i stopped 'psa' service and then i started again.

[root@plesk ~]# /etc/init.d/psa stop

[root@plesk ~]# /etc/init.d/psa start
Starting psa... done
Starting xinetd service... done
Starting named service... done
Starting mysqld service... done
Starting postgresql service... not installed
Starting psa-spamassassin service... done
Plesk: Starting Mail Server... already started
Starting psa... done
Starting drwebd service... failed

drwebd service failed here. Then i check the plesk service's error log and found the following entries.

====================================================
[root@plesk ~]# tail -f /var/log/sw-cp-server/error_log

2013-07-16 12:42:23: (connections.c.1737) SSL (error): 5 -1 0 Success
2013-07-16 12:42:23: (connections.c.1737) SSL (error): 5 -1 0 Success
Cannot find config item ["global/SERVERsocket==:8443", ".php", 0]
2013-07-16 12:42:24: (mod_fastcgi.c.1000) the fastcgi-backend /usr/bin/sw-engine-cgi -c /usr/local/psa/admin/conf/php.ini -d auto_prepend_file=auth.php3 -u psaadm failed to start:
2013-07-16 12:42:24: (mod_fastcgi.c.1004) child exited with status 1 /usr/bin/sw-engine-cgi -c /usr/local/psa/admin/conf/php.ini -d auto_prepend_file=auth.php3 -u psaadm
2013-07-16 12:42:24: (mod_fastcgi.c.1007) if you try do run PHP as FastCGI backend make sure you use the FastCGI enabled version.
You can find out if it is the right one by executing 'php -v' and it should display '(cgi-fcgi)' in the output, NOT (cgi) NOR (cli)
For more information check http://www.lighttpd.net/documentation/fastcgi.html#preparing-php-as-a-fastcgi-program
2013-07-16 12:42:24: (mod_fastcgi.c.1012) If this is PHP on Gentoo add fastcgi to the USE flags
2013-07-16 12:42:24: (mod_fastcgi.c.1105) [ERROR]: spawning fcgi failed.
=======================================================


Fix:

I checked the available diskspace in each disk using 'df -h' command and i found that the disk mounted /tmp directory is full and there is not enough space to create temporary files to run plesk.

I found some files as shown below using the entire space.

[root@plesk ~]# ls -la /tmp
-rw-------   1 psaadm sw-cp-server      200000 Jul 16 11:17 dumpAkwhRE.tar
-rw-------   1 psaadm sw-cp-server   4096 Jul 16 11:18 dumpY2sRjw.tar


I removed one of the 'dump' using more space and restarted the psa service again. Now the plesk service working without any error.

Xen Migration in between SolusVM Nodes




Step1: @Source Node


First of all login to the source Node.

Let you want to migrate the the VM, vm123.
Check the lvm partitions assigned for the VM, vm123. There will be a primary partitions, vm123_img and swap partition vm123_swap. You can check the details to these partitions using the following commands.

Note down the size of the VM and it's swap memory.


[root@source ~]# lvdisplay /dev/VolGroup00/vm123_img
--- Logical volume ---
LV Name /dev/VolGroup00/vm123_img
VG Name VolGroup00
LV UUID mmp1Jl-JhWN-FCzd-Gyqe-A8pF-LlvG-nfrpVx
LV Write Access read/write
LV Status available
# open 1
LV Size 20.00 GB
Current LE 640
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:10


[root@source ~]# lvdisplay /dev/VolGroup00/vm123_swap
--- Logical volume ---
LV Name /dev/VolGroup00/vm123_swap
VG Name VolGroup00
LV UUID hnZ0PL-k4y1-r3V3-2mVn-d8cK-gMGq-8JW3v1
LV Write Access read/write
LV Status available
# open 1
LV Size 512.00 MB
Current LE 16
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:11

Here vm123_img is a size of 20.00 GB and vm123_swap is a size of 512.00 MB.


Step2: @Source Node (Creating and mounting necessary LVs and creating Backup )

Create a logical volume to create and mount the backup. Give an additional 5GB space for the backup logical volume. Here in this case it is 25G after adding 5G space.

[root@source ~]# lvcreate -n vm123_backup --size 25G /dev/VolGroup00
[root@source ~]# mkfs.ext3 /dev/VolGroup00/vm123_backup
[root@source ~]# mkdir -p /home/xen/vm123_backup
[root@source ~]# mount /dev/VolGroup00/vm123_backup /home/xen/vm123_backup

It is need to shutdown the VM to create the backup.
[root@source ~]# xm shutdown vm123

Create backup of the logical voulume which mounted the vm123 using dd command.

[root@source ~]# dd if=/dev/VolGroup00/vm123_img of=/home/xen/vm123_backup/vm123_backup.img

Verify if the backup is in the location.

[root@source ~]# ls -lh /home/xen/vm123_backup


Step3: @Destination Node (Creating and Mounting necessary LVs)

In the destination it is needed to create 3 logical volumes. One for the backup, one for the vm itself and one for the swap memory. Here also backup LV is given additioanl 5G space. Compare the swap memory with the source server before creating swap memory.

[root@destination ~]# lvcreate -n vm123_backup --size 25G /dev/VolGroup00
[root@destination ~]# lvcreate -n vm123_img --size 20G /dev/VolGroup00
[root@destination ~]# lvcreate -n vm342_swap --size 512M /dev/VolGroup00

Make swap LV available for the swap space.

[root@destination ~]# mkswap /dev/VolGroup00/vm123_swap

Backup LV is creating and Mounting.

[root@destination ~]# mkfs.ext3 /dev/VolGroup00/vm123_backup
[root@destination ~]# mkdir -p /home/xen/vm123_backup
[root@destination ~]# mount /dev/VolGroup00/vm123_backup /home/xen/vm123_backup



Step4: @Source Node (Transferring backup)

[root@source ~]# scp -P 22 -C /home/xen/vm123_backup/vm123_backup.img root@<Destiantion server IP>:/home/xen/vm123_backup/


Step5: @Destination (Restoring)

[root@destination ~]# dd if=/home/xen/vm123_backup/vm123_backup.img of=/dev/VolGroup00/vm123_img


Now it is time to login to SolusVM Master Node.

Step 5: @SolusVM Master Node (To map the VM with new Hardware Node)

[root@SolusVM-Master ~]# /scripts/vm-migrate <VM ID> <New HN ID>


***Once you have done the above step, Reboot the VM via SolusVM cotrol panel. Just 'Boot' the server will not start the VM. You must click the 'Reboot' option.


Step6: @Destination node (new node). (Remove backups)

[root@destination ~]# umount /home/xen/vm179_backup
[root@destination ~]# lvremove /dev/VolGroup00/vm179_backup


Step7: @Source node (old node) Finally if migrated server is working fine, remove backups.

[root@source ~]# umount /home/vm179_backup
[root@source ~]# lvremove /dev/VolGroup00/vm179_backup
[root@source ~]# lvremove /dev/VolGroup00/vm179_img
[root@source ~]# lvremove /dev/VolGroup00/vm179_swap


That's it..

Create BCC of incoming and outgoing mails without knowing the users - MDaemon




MDaemon has a 'Content Filtre' feature which will help you to filtre the emails sending/receinving through MDaemon server. The following screen shots will help you to find this feature.

1. Open MDaemon,
    Security >> Content Filtre


2. You can find a sectip to Add Rules in there. Click the option, 'New Rule'.



3. You can select the condition in the left column and select Approproate actions in the right column.



4. The selected rules and conditions will be shown in the bottom section. You an select the underlined blue line section in the bottom section to add the values to the rules.
Here i have selected the 'To Header' filter. The given screen shot will help you to find more options.



5. Once the values are given click 'Add' and then Ok. You can now verify the settings by sending test mails.



That's it....