Virtual Multiserver Environment With Dedicated Web & MySQL, Email & DNS Servers On Debian Squeeze With ISPConfig 3 - Page 2

Want to support HowtoForge? Become a subscriber!
 
Submitted by MaddinXx (Contact Author) (Forums) on Mon, 2012-05-21 15:33. ::

5 Creating The Virtual Servers

We now will use the OVZ Web Panel to create our virtual servers. Log into the panel and add your IPs under IP Addresses. Then, click on localhost and OS Templates.

We now have to download a template for our virtual servers. We do so by clicking Install New OS Template -> Contributed and select debian-6.0-amd64-minimal.

Now go back to localhost and click Create virtual server. Fill in the fields as below:

  • Server ID (VEID): a number (I would choose the last part of you IP, so 2 for the first)
  • OS Template: already selected the right
  • Server Template: unlimited
  • IP Address: 192.168.1.2
  • Host Name: web.example.tld
  • DNS Server: 8.8.4.4 8.8.8.8 (which are Google's DNS)
  • leave the rest as it is and assign Disk Space, RAM and CPU like you want...

Repeat this step for all you virtual servers (finally 4 times: Web, Mail, 2x DNS).

 

5.1 Preparing The virtual servers

You should now login to every single virtual server and run these commands:

apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade
apt-get -y install nano wget ntp ntpdate

which will upgrade them to latest version and install some missing packages.

 

6 Installing The Dedicated Servers

6.1 Installing The Web/DB Server

Edit the hosts file and add the IP addresses and hostnames for all servers. The hostnames and IP addresses have to be adjusted to match your setup.

nano /etc/hosts

127.0.0.1 localhost
192.168.1.2 web.example.tld
192.168.1.3 mail.example.tld
192.168.1.4 ns1.example.tld
192.168.1.5 ns2.example.tld

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Set the hostname of the server:

echo web.example.tld > /etc/hostname
/etc/init.d/hostname.sh start

Install the MySQL server. A MySQL server instance is necessary on every server as ISPConfig uses it to sync the configuration between the servers.

apt-get -y install mysql-client mysql-server

Enter the new password for MySQL when requested by the installer.

We want MySQL to listen on all interfaces on the master server, not just localhost, therefore we edit /etc/mysql/my.cnf and comment out the line bind-address = 127.0.0.1:

nano /etc/mysql/my.cnf

[...]

# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1

[...]

Then restart MySQL:

/etc/init.d/mysql restart

Now install Apache2, PHP5, phpMyAdmin, FCGI, suExec, Pear, and mcrypt as follows:

apt-get -y install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt php5-imagick imagemagick libapache2-mod-suphp libopenssl-ruby libapache2-mod-ruby sudo zip wget

You will see the following question:

Web server to reconfigure automatically: <-- apache2

Then run the following command to enable the Apache modules suexec, rewrite, ssl, actions, headers, expires and include:

a2enmod suexec rewrite ssl actions include ruby dav_fs dav auth_digest headers expires

PureFTPd can be installed with the following command:

apt-get -y install pure-ftpd-common pure-ftpd-mysql

Edit the file /etc/default/pure-ftpd-common...

vi /etc/default/pure-ftpd-common

... and make sure virtualchroot is set VIRTUALCHROOT=true:

[...]
VIRTUALCHROOT=true
[...]

Now we configure PureFTPd to allow FTP and TLS sessions. FTP is a very insecure protocol because all passwords and all data are transferred in clear text. By using TLS, the whole communication can be encrypted, thus making FTP much more secure.

If you want to allow FTP and TLS sessions, run

echo 1 > /etc/pure-ftpd/conf/TLS

In order to use TLS, we must create an SSL certificate. I create it in /etc/ssl/private/, therefore I create that directory first:

mkdir -p /etc/ssl/private/

Afterwards, we can generate the SSL certificate as follows:

openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem

Country Name (2 letter code) [AU]: <-- Enter your Country Name (e.g., "DE").
State or Province Name (full name) [Some-State]:
<-- Enter your State or Province Name.
Locality Name (eg, city) []:
<-- Enter your City.
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
<-- Enter your Organization Name (e.g., the name of your company).
Organizational Unit Name (eg, section) []:
<-- Enter your Organizational Unit Name (e.g. "IT Department").
Common Name (eg, YOUR name) []:
<-- Enter the Fully Qualified Domain Name of the system (e.g. "web.example.tld").
Email Address []:
<-- Enter your Email Address.

Change the permissions of the SSL certificate:

chmod 600 /etc/ssl/private/pure-ftpd.pem

Install vlogger, webalizer, and awstats:

apt-get -y install vlogger webalizer awstats

Open /etc/cron.d/awstats afterwards...

vi /etc/cron.d/awstats

... and comment out both cron jobs in that file:

#*/10 * * * * www-data [ -x /usr/share/awstats/tools/update.sh ] && /usr/share/awstats/tools/update.sh

# Generate static reports:
#10 03 * * * www-data [ -x /usr/share/awstats/tools/buildstatic.sh ] && /usr/share/awstats/tools/buildstatic.sh

Install Jailkit: Jailkit is needed only if you want to chroot SSH users. It can be installed as follows (important: Jailkit must be installed before ISPConfig - it cannot be installed afterwards!):

apt-get -y install build-essential autoconf automake1.9 libtool flex bison debhelper

cd /tmp
wget http://olivier.sessink.nl/jailkit/jailkit-2.14.tar.gz
tar xvfz jailkit-2.14.tar.gz
cd jailkit-2.14
./debian/rules binary
cd ..
dpkg -i jailkit_2.14-1_*.deb
rm -rf jailkit-2.14*

Install fail2ban: This is optional but recommended, because the ISPConfig monitor tries to show the log:

apt-get install fail2ban

To make fail2ban monitor PureFTPd, create the file /etc/fail2ban/jail.local:

vi /etc/fail2ban/jail.local

[pureftpd]

enabled  = true
port     = ftp
filter   = pureftpd
logpath  = /var/log/syslog
maxretry = 3

Then create the following filter file:

vi /etc/fail2ban/filter.d/pureftpd.conf

[Definition]
failregex = .*pure-ftpd: \(.*@<HOST>\) \[WARNING\] Authentication failed for user.*
ignoreregex =

Restart fail2ban afterwards:

/etc/init.d/fail2ban restart

Next we will install ISPConfig 3. To get the download URL of the latest ISPConfig 3 stable release, please visit the ISPConfig website: http://www.ispconfig.org/ispconfig-3/download/

This server is the master server in our setup which runs the ISPConfig control panel interface. To allow the other MySQL instances to connect to the MySQL database on this node during installation, we have to add MySQL root user records in the master database for every slave server hostname and IP address. The easiest way to do this is to use the web based phpmyadmin administration tool that we installed already. Open the URL http://192.168.1.2/phpmyadmin in a web browser, log in as MySQL root user and execute these MySQL queries:

CREATE USER 'root'@'192.168.1.3' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.1.3' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER 'root'@'192.168.1.4' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.1.4' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER 'root'@'192.168.1.5' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'192.168.1.5' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER 'root'@'mail.example.tld' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'mail.example.tld' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER 'root'@'ns1.example.tld' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'ns1.example.tld' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

CREATE USER 'root'@'ns2.example.tld' IDENTIFIED BY 'myrootpassword';
GRANT ALL PRIVILEGES ON * . * TO 'root'@'ns2.example.tld' IDENTIFIED BY 'myrootpassword' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

In the above sql commands, replace the IP adresses (192.168.1.3 - 192.168.1.5) with the IP addresses of your servers and replace mail.example.tld, ns1.example.tld and ns2.example.tld with the hostnames of your servers and myrootpassword with the desired root password.

Click on the reload permissions button or restart MySQL. Then close phpmyadmin.

Go back to the shell of web.example.tld and download the latest ISPConfig 3 stable release:

cd /tmp
wget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz
tar xfz ISPConfig-3-stable.tar.gz
cd ispconfig3_install/install/

Then start the install script:

php -q install.php

Select language (en,de) [en]:<-- en
Installation mode (standard,expert) [standard]:<-- expert
Full qualified hostname (FQDN) of the server, eg server2.domain.tld [web.example.tld]:<-- web.example.tld
MySQL server hostname [localhost]:<-- localhost
MySQL root username [root]:<-- root
MySQL root password []:<-- Enter your MySQL root password here
MySQL database to create [dbispconfig]:<-- dbispconfig
MySQL charset [utf8]:<-- utf8
Shall this server join an existing ISPConfig multiserver setup (y,n) [n]:<-- n
Configure Mail (y,n) [y]:<-- n
Configure Jailkit (y,n) [y]:<-- y
Configure FTP Server (y,n) [y]:<-- y
Configure DNS Server (y,n) [y]:<-- n
Configure Apache Server (y,n) [y]:<-- y
Configure Firewall Server (y,n) [y]:<--n
Install ISPConfig Web-Interface (y,n) [y]:<--y
ISPConfig Port [8080]:<-- 8080
Enable SSL for the ISPConfig web interface (y,n) [y]:
<-- y
Country Name (2 letter code) [AU]: <-- ENTER
State or Province Name (full name) [Some-State]: <-- ENTER
Locality Name (eg, city) []: <-- ENTER
Organization Name (eg, company) [Internet Widgits Pty Ltd]: <-- ENTER
Organizational Unit Name (eg, section) []: <-- ENTER
Common Name (eg, YOUR name) []: <-- ENTER
Email Address []: <-- ENTER
A challenge password []: <-- ENTER
An optional company name []:
<-- ENTER

Clean up the install directories:

cd /tmp
rm -rf /tmp/ispconfig3_install/install
rm -f /tmp/ISPConfig-3-stable.tar.gz

 

6.2 Installing The Mail Server

Edit the hosts file and add the IP addresses and hostnames for all servers. The hostnames and IP addresses have to be adjusted to match your setup.

nano /etc/hosts

127.0.0.1 localhost
192.168.1.2 web.example.tld
192.168.1.3 mail.example.tld
192.168.1.4 ns1.example.tld
192.168.1.5 ns2.example.tld

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Set the hostname of the server:

echo mail.example.tld > /etc/hostname
echo mail.example.tld > /etc/mailname
/etc/init.d/hostname.sh start

Install postfix, dovecot and MySQL with one single command:

apt-get -y install postfix postfix-mysql postfix-doc mysql-client mysql-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d

Enter the new password for mysql when requested by the installer and answer the next questions as decsribed below:

General type of configuration? <-- Internet site
Mail name?
<-- mail.example.tld

To install amavisd-new, SpamAssassin, and ClamAV, we run:

apt-get -y install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl

If you want to use mailinglists on your server, then install mailman. This step is optional. mailman requires a apache webserver, so if you dont want to run a apache instance on your mailserver, then dont install mailman.

apt-get -y install mailman

The apt installer for mailman will ask you then to select the languages for the mailing list. Enable all languages that you want to use for mailman. Next create the "mailman" mailinglist.

newlist mailman

and enter the email address and new password for the mailinglist administrator. Thats the last step of the mailman install. The next command to install php has to be executed on every server, independently if you installed mailman or not.

Then install install the commandline version of PHP to be able to run PHP-based shell scripts for ISPConfig:

apt-get -y install php5-cli php5-mysql php5-mcrypt mcrypt

Install fail2ban: This is optional but recommended, because the ISPConfig monitor tries to show the log:

apt-get install fail2ban

To make fail2ban monitor PureFTPd and Dovecot, create the file /etc/fail2ban/jail.local:

vi /etc/fail2ban/jail.local

[dovecot-pop3imap]

enabled = true
filter = dovecot-pop3imap
action = iptables-multiport[name=dovecot-pop3imap, port="pop3,pop3s,imap,imaps", protocol=tcp]
logpath = /var/log/mail.log
maxretry = 5

Then create the following filter file:

vi /etc/fail2ban/filter.d/dovecot-pop3imap.conf

[Definition]
failregex = (?: pop3-login|imap-login): .*(?:Authentication failure|Aborted login \(auth failed|Aborted login \(tried to use disabled|Disconnected \(auth failed|Aborted login \(\d+ authentication attempts).*rip=(?P<host>\S*),.*
ignoreregex =

Restart fail2ban afterwards:

/etc/init.d/fail2ban restart

Now I will install ISPConfig 3 on this server. To get the download URL of the latest ISPConfig 3 stable release, please visit the ISPConfig website: http://www.ispconfig.org/ispconfig-3/download/

Download the latest ISPConfig 3 stable release:

cd /tmp
wget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz
tar xfz ISPConfig-3-stable.tar.gz
cd ispconfig3_install/install/

Then start the install script:

php -q install.php

Select language (en,de) [en]:<-- en
Installation mode (standard,expert) [standard]:<-- expert
Full qualified hostname (FQDN) of the server, eg server1.domain.tld [mail.example.tld]:<-- mail.example.tld
MySQL server hostname [localhost]:<-- localhost
MySQL root username [root]:<-- root
MySQL root password []:<-- Enter your MySQL root password here
MySQL database to create [dbispconfig]:<-- dbispconfig
MySQL charset [utf8]:<-- utf8
Shall this server join an existing ISPConfig multiserver setup (y,n) [n]:<-- y
MySQL master server hostname []:<-- web.example.tld
MySQL master server root username [root]:<-- root
MySQL master server root password []:<-- Enter the root password of the master server here
MySQL master server database name [dbispconfig]:<-- dbispconfig
Configure Mail (y,n) [y]:<-- y

Country Name (2 letter code) [AU]:<-- DE (Enter the ISO country code where you live here)
State or Province Name (full name) [Some-State]:<-- Niedersachsen (Enter the state where you live here)
Locality Name (eg, city) []:<-- Lueneburg (Enter the city here)
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<-- ENTER
Organizational Unit Name (eg, section) []:<-- ENTER
Common Name (eg, YOUR name) []:<-- ENTER
Email Address []:<-- ENTER

Configure Jailkit (y,n) [y]:<-- n
Configure FTP Server (y,n) [y]:<-- n
Configure DNS Server (y,n) [y]:<-- n
Configure Apache Server (y,n) [y]:<-- n
Configure Firewall Server (y,n) [y]:<--n
Install ISPConfig Web-Interface (y,n) [y]:<--n

Run...

rm -f /var/www/ispconfig

... to remove the ISPConfig interface link in the /var/www directory.

Clean up the install directories:

rm -rf /tmp/ispconfig3_install/install
rm -f /tmp/ISPConfig-3-stable.tar.gz


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.