Multiple SSL Certificate install on apache2 server [Ubuntu 12.04]



Multiple SSL Certificate install on apache2 server  [Ubuntu 12.04]
Enable SSL on your webserver
sudo a2enmod ssl
Follow up by restarting Apache.
sudo service apache2 restart
Copy your SSL certificate and key to any location
Eg. Here we copied to /etc/apache2/ssl  
Make sure permission of those files are 400 or 600 [root only read/write]
In   sites/sites-available/<your domains>

vim btlg.com.au
<VirtualHost *:80>
ServerName btlg.com.au 
ServerAlias 
www.btlg.com.au
DocumentRoot /home/bootleg/public_html
</VirtualHost>
<VirtualHost *:443>
ServerName btlg.com.au
ServerAlias 
www.btlg.com.au
DocumentRoot /home/bootleg/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/btlg/281027f6c6f445.crt
SSLCertificateKeyFile /etc/apache2/ssl/btlg/www_btlg_com_au.key 
SSLCertificateChainFile /etc/apache2/ssl/btlg/sf_bundle-g2-g1.crt
</VirtualHost>

vim example.com.au
<VirtualHost *:80>
ServerName btlg.com.au 
ServerAlias
example.com.au
DocumentRoot /home/example.com/public_html
</VirtualHost>
<VirtualHost *:443>
ServerName
example.com.au
ServerAlias www.example.com.au
DocumentRoot /home/example.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/example/281027f6c6f445.crt
SSLCertificateKeyFile /etc/apache2/ssl/example/www_example_com_au.key 
SSLCertificateChainFile /etc/apache2/ssl/btlg/sf_bundle-g2-g1.crt
</VirtualHost>


Restart apache2 and browse to your domain with http or https
#######################################


On Ubuntu 14.04.1 x64 bit
Enable ssl

a2enmod ssl

Generate certificates  for site  example.com
----------------------------------------------------
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/example.com/apache.key -out /etc/apache2/ssl/example.com/apache.crt

**generate certificates for site example.org**
-------------------------------------------------------------
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/example.org/apache.key -out /etc/apache2/ssl/example.org/apache.crt
##Virtual Host Configuration <note:  the vhost file should have .conf extension###

root@server1:/etc/apache2/sites-available# vim  example.com.conf
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName example.org
        DocumentRoot /var/www/html/example.org

</VirtualHost>


<IfModule mod_ssl.c>
<VirtualHost *:443>

        ServerAdmin webmaster@localhost
        ServerName example.org
        DocumentRoot /var/www/html/example.org

        #   SSL Engine Switch:
        #   Enable/Disable SSL for this virtual host.
        SSLEngine on

        SSLCertificateFile /etc/apache2/ssl/example.org/apache.crt
        SSLCertificateKeyFile /etc/apache2/ssl/example.org/apache.key
</VirtualHost>

</IfModule>

#Configure ports

#cat /etc/apache2/ports.conf

NameVirtualHost *:80
NameVirtualHost *:443
Listen 80

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

#Enable sites#
  a2ensite example.com
  a2ensite example.org

Step Four — Activate the SSL Virtual Host

Now that we have configured our SSL-enabled virtual host, we need to enable it.
We can do this by typing:
sudo a2ensite default-ssl.conf
We then need to restart Apache to load our new virtual host file:
sudo service apache2 restart


check process is running




[root@mx12 sshadmin]# crontab -l
*/3 * * * * /opt/checkclam.sh
[root@mx12 sshadmin]# cat /opt/checkclam.sh
#!/bin/bash
if ! pgrep clamd > /dev/null;
then
/etc/init.d/clamd restart > /dev/null;
else
echo "OK `date +%T\ %F`" >> /program.log; #'\ ' is for space use %t for tab
fi


Task: Find out process pid

Simply use ps command as follows:
ps aux | grep {process-name}
For example find out if mysqld process (mysqld pid) is running or not:
$ ps aux | grep mysqld

mysql    28290  1.1  2.7 340496 56812 ?        Sl   Jul31 348:27 /usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-locking --socket=/var/lib/mysql/mysql.sock
 # pidof mysqld

check mysql replication status with bash script

[root@DBASE01 ~]# crontab -l
45 14,21 * * * /root/dbstatus.sh


[root@DBASE01 ~]# cat dbstatus.sh
#!/bin/bash
#/usr/bin/mysql -uroot -p1Lumbini2# -e "show slave status\G;" > /root/status.txt
/usr/bin/mysql  -e "show slave status\G;" > /root/status.txt
i=0
if grep "Slave_IO_Running: Yes" /root/status.txt
then
((i=i+1))
fi
if grep "Slave_SQL_Running: Yes" /root/status.txt
then
((i=i+1))
fi
##########
if [ $i -ne 2 ]
then
 /bin/cat /root/status.txt | mail -s "Mysqlslave replication status for AusIT" alerts@nepallink.net
else
    :              ##colons
fi

Note: make sure the file /root/status.txt have write permission

ICINGA + pnp4nagios installation



Icinga web with pnp4nagios
PNP is an addon for the Nagios Network Monitoring System. PNP provides easy to use, easy to configure RRDTools based performance charts feeded by the performance data output of the Nagios Plugins.


Setting up icinga using repository:-
OS used in this env = CentOS release 6.5 X64bit

1. Install CentOS 6.4 minimal version

2. Prepare your system
# yum groupinstall Development tools
# yum install vim mc
3. Add EPEL and Remi repositories
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm
#wget http://dl.iuscommunity.org/pub/ius/stable/CentOS/6/x86_64/ius-release-1.0-13.ius.centos6.noarch.rpm
#rpm -Uvh ius-release*.rpm
4. Check your repolist[the under lined repos should be present]

5. Installing packages
#yum install php php-cli php-pear php-xmlrpc php-xsl php-pdo php-soap php-gd php-ldap php-mysql
# yum install icinga icinga-gui icinga-doc icinga-idoutils-libdbi-mysql               or    yum install icinga*
# yum install nagios-plugins-all
# yum install mysql-server mysql-client libdbi libdbi-dbd-mysql libdbi-devel icinga-idoutils-libdbi-mysql libdbi-drivers
6. Database setup
 # mysql -u root -p
 mysql> CREATE DATABASE icinga_web;
        GRANT USAGE ON *.* TO 'icinga_web'@'localhost' IDENTIFIED BY 'icinga_web' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0;
        GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX ON icinga_web.* TO 'icinga_web'@'localhost';
        quit;

#echo "CREATE DATABASE icinga; \
GRANT USAGE ON *.* TO 'icinga'@'localhost' \
  IDENTIFIED BY 'icinga' \
  WITH MAX_QUERIES_PER_HOUR 0 \
  MAX_CONNECTIONS_PER_HOUR 0 \
  MAX_UPDATES_PER_HOUR 0; \
GRANT SELECT , INSERT , UPDATE , DELETE, DROP, CREATE VIEW \
  ON icinga.* TO 'icinga'@'localhost'; \
FLUSH PRIVILEGES;" \
| mysql -uroot -p

                               
7. Import the schema
mysql -u root -p   icinga_web < /usr/share/doc/icinga-web-1.7.2/schema/mysql.sql
mysql -u root -p icinga < /usr/share/doc/icinga-idoutils-libdbi-mysql-1.8.4/db/mysql/mysql.sql

chkconfig ido2db on
chkconfig icinga on
chkconfig httpd on
service ido2db start
service icinga start
service httpd start


8. Test classic Web GUI
Set a SHA encrypted administrator password for Basic Authentication
htpasswd -s /etc/icinga/passwd icingaadmin

Icinga- Web
Test New Web GUI
Open the URL https://ICINGA_SERVER_IP/icinga-web and login with user “root” and password “password”
Set the Timezone
Proper time setting is required to make the scheduled check commands work.
Set the variable TIMEZONE to your timezone, e.g. "Europe/Berlin"
export TIMEZONE="Europe/Berlin"
sed -i "s|^[ ;]*date.timezone *=.*|date.timezone='$TIMEZONE'|" /etc/php.ini
Example 2
ln -s /usr/share/zoneinfo/Canada/Central /etc/localtime
[root@VM156 ~]# date
Mon Sep 22 03:29:14 CDT 2014
[]#vim /etc/php.ini
 [Date]                  #line number 943
date.timezone = "Canada/Central"                      ##line number 946
Install pnp4nagios
Install the required packages:
# yum install rrdtool rrdtool-devel rrdtool-perl openssl-devel gcc php-rrdtool php-gd php php-pdo php-common perl-Time-HiRes
# yum install wget
Download pnp4nagios source
# wget -c 
http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.21.tar.gz
# tar -xvzf pnp4nagios-0.6.21.tar.gz
# cd pnpnagios-0.6.21
Compile and install pnp4nagios for Icinga user:
# ./configure --with-nagios-user=icinga --with-nagios-group=icinga
# make all
# make install
# make install-webconf
# make install-config
# make install-init

Configure pnp4nagios for Icinga Core:
# vim /etc/icinga/icinga.cfg
................
#process_performance_data=0
process_performance_data=1
.................
broker_module=/usr/local/pnp4nagios/lib/npcdmod.o config_file=/usr/local/pnp4nagios/etc/npcd.cfg
..................

Add new command for check configuration files of the Icinga:
# alias icicheck='/usr/bin/icinga -v /etc/icinga/icinga.cfg'
Integration Icinga htpasswd file in pnp4nagios:
# vim /etc/httpd/conf.d/pnp4nagios.conf    [check the highlighted values]
AuthName "Nagios Access"                   #line number 12
AuthType Basic
AuthUserFile /etc/icinga/passwd

Restart following services:
# service httpd restart
# /etc/init.d/npcd start && chkconfig npcd on
# icicheck
# /etc/init.d/icinga restart
Please check correct installation of pnp4nagios.
Go to web http://<server name>/pnp4nagios/
If you see in the end web page following "Your environment passed all requirements." so you must remove or rename the /usr/local/pnp4nagios/share/install.php file
# mv /usr/local/pnp4nagios/share/install.php /usr/local/pnp4nagios/share/install.php.testfile
Configure main config file of the pnp4nagios:
# cd /usr/local/pnp4nagios/etc/
# mv rra.cfg-sample rra.cfg
# vim npcd.cfg

user = icinga
group = icinga
log_type = file
log_level = -1
load_threshold = 10.0

After that check icinga configuration
# icicheck
Total Warnings: 0
Total Errors: 0
# vim config.php
# Link back to Nagios or Thruk
#
$conf['nagios_base'] = "/icinga/cgi-bin";

Please, overwrite all settings for perfdata:
# vim /etc/icinga/icinga.cfg
#host_perfdata_file=/tmp/host-perfdata
#service_perfdata_file=/tmp/service-perfdata
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
#host_perfdata_file_template=[HOSTPERFDATA]\t$TIMET$\t$HOSTNAME$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$
#service_perfdata_file_template=[SERVICEPERFDATA]\t$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$
host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$
#host_perfdata_file_mode=a
#service_perfdata_file_mode=a
host_perfdata_file_mode=a
service_perfdata_file_mode=a
#host_perfdata_file_processing_interval=0
#service_perfdata_file_processing_interval=0
host_perfdata_file_processing_interval=30
service_perfdata_file_processing_interval=30
#host_perfdata_file_processing_command=process-host-perfdata-file
#service_perfdata_file_processing_command=process-service-perfdata-file
host_perfdata_file_processing_command=process-host-perfdata-file
service_perfdata_file_processing_command=process-service-perfdata-file

After that check icinga configuration
# icicheck
Total Warnings: 0
Total Errors: 0
Either edit or append. A sample is provided within /usr/local/pnp4nagios/etc/misccommands.cfg:
# cp /usr/local/pnp4nagios/etc/misccommands.cfg-sample /etc/icinga/misccommands.cfg
# vi /etc/icinga/misccommands.cfg
and uncomment following strings
define command {
command_name process-service-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$
}
define command {
command_name process-host-perfdata-file
command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$
}
After that check icinga configuration
# icicheck
Total Warnings: 0
Total Errors: 0
# /etc/init.d/httpd restart
# /etc/init.d/icinga reload
Check for perfdata
# ls -la /usr/local/pnp4nagios/var/perfdata/localhost
In this directory you must see files: .rrd+.xml
Useful tools
Clear web cache
#/usr/bin/icinga-web-clearcache

Reference:-
https://wiki.icinga.org/display/howtos/Setting+up+Icinga+Web+on+RHEL

zpanel virtual domains

step 1 : create the subdomain in the control panel domain > sub-domain create ( then restart Apache server )
SSH command : sudo service apache2 restart

step 2: go to DNS manager , create record under A , for webmail ( you should wait for this to activate … luckily couple of hours https://www.whatsmydns.net use this site to check the reach)
step 3 : edit your virtual hosts ,

SSH Command : vi /etc/zpanel/configs/apache/httpd-vhosts.conf

# DOMAIN: webmail.my-domain.com
<virtualhost *:80>
ServerName webmail.my-domain.com
ServerAlias webmail.my-domain.com
ServerAdmin zadmin@localhost
DocumentRoot "/etc/zpanel/panel/etc/apps/webmail"
 
</virtualhost>
 
# END DOMAIN: webmail.my-domain.com


now restart Apache again. 
 

pro ftp apache virtual host

Well, we decided to consider this question on example of proftpd. I could not  say that this is very useful FTP sever, but its configuration syntax is very apache-like, so it is very easy to undertsand how system works and configure it. My post regarding configuration of Apache virtual hosts could be useful for understanding of concepts.
Fisrt of all we assume that:
  • proftpd is running
  • webspace (folder with web site) is already created
  • assume that we adding webpace /srv/www/vhosts/itvictories to proftpd
Main config of proftpd is /etc/proftpd.conf. Syntax is like in Apache's config and we now just have to declare new virtual host for proftpd. It also could be done in main config file, as well as in one, which is connected with include directive.
First of all you have to create to entities:
  • user, which will be responcible for webspace and will have ftp access to its folder
  • group, which will contain all ftp users
It could be done with standard linux commands, but please pay attention to creation of a new user:
useradd ftp-vhost-itvictories -s /bin/false

passwd useradd

groupadd ftp-users
Option "-s /bin/false" in useradd command will disable remote login (with shell) capability for user. Aftewards, open file /etc/group with your favourite editor and edit user ftp-vhost-itvictories to group ftp-users
Group creation is not mandatory at all, but help you to structurize your infrastracture.
Somehow grant write permissions to created user. E.g. in a following way:
chown -R ftp-vhost-itvictories /srv/www/vhosts/itvictories

chmod -R u+w /srv/www/vhosts/itvictories
Now we came to point to declare virtual host in /etc/proftpd.conf or some included file. Add below section to your config:
<VirtualHost itvictories.com>
DefaultRoot /srv/www/vhosts/itvictories
<Limit LOGIN>
Order allow,deny
AllowUser ftp-vhost-itvictories
DenyAll
</Limit>
</VirtualHost>
This will grant permissions for use ftp-vhost-itvictories to access directory /srv/www/vhosts/itvictories in chrooted mode. So user will be unable to reach any other directory at the server.
Now restart your proftpd and your webspace will be available over ftp.