Virtual Hosting Howto With Virtualmin On CentOS 5.1 Virtual Hosting Howto With Virtualmin On CentOS 5.1 Version 1.0.1 Author: Andrew Colin Kissa <andrew [at] topdog [dot] za [dot] net> Last edited 14/04/2008 Introduction This tutorial shows how to set up a CentOS 5.x server to offer all services needed by virtual web hosters. These include web hosting, smtp server with (SM TP-AUTH and TLS, SPF, DKIM, Domainkeys), DNS, FTP, MySQL, POP3/IMAP, Firewall, Webalizer for stats. I will use the following software: Database Server: MySQL 5.0.22 Mail Server: Postfix 2.3.3 NS Server: BIND9 9.3.3 Web Server: Apache 2.2.3 /PHP 5.1.6 FTP Server: Vsftpd 2.0.5 POP3/IM AP server: Dovecot 1.0 Webalizer: for site statistics 2.01_10 Virtualmin: Control panel OS Installation Requirements To install the system you will need CentOS 5.1 Install media A good internet connection Install The Base System NOTE Some stages of the installation are not described here in interest of keeping the howto short, The grub configuration stages are left out for instance. Boot from the DVD or CD media and at the boot prompt type linux text. Skip the media test. Select your language: Select keyboard layout: Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all 1 of 29 1/31/2009 2:54 AM
29
Embed
Virtual Hosting Howto With Virtual Min on CentOS 5.1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Virtual Hosting Howto With Virtualmin On CentOS 5.1
Virtual Hosting Howto With Virtualmin On CentOS 5.1
Version 1.0.1Author: Andrew Colin Kissa <andrew [at] topdog [dot] za [dot] net>Last edited 14/04/2008
Introduction
This tutorial shows how to set up a CentOS 5.x server to offer all services needed by virtual web hosters. These include web hosting, smtp server with (SMTP-AUTH and TLS, SPF,DKIM, Domainkeys), DNS, FTP, MySQL, POP3/IMAP, Firewall, Webalizer for stats.
I will use the following software:
Database Server: MySQL 5.0.22Mail Server: Postfix 2.3.3NS Server: BIND9 9.3.3Web Server: Apache 2.2.3 /PHP 5.1.6FTP Server: Vsftpd 2.0.5POP3/IMAP server: Dovecot 1.0Webalizer: for site statistics 2.01_10Virtualmin: Control panel
OS Installation
Requirements
To install the system you will need
CentOS 5.1 Install mediaA good internet connection
Install The Base System
NOTE Some stages of the installation are not described here in interest of keeping the howto short, The grub configuration stages are left out for instance.
Boot from the DVD or CD media and at the boot prompt type linux text.Skip the media test.Select your language:
Select keyboard layout:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
1 of 29 1/31/2009 2:54 AM
Configure your network, I will be using dhcp if you do not have dhcp you can use static entries.
Select Yes to initialize drive:
Select custom layout for partitioning type:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
2 of 29 1/31/2009 2:54 AM
Create partitions:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
3 of 29 1/31/2009 2:54 AM
Configure networking:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
4 of 29 1/31/2009 2:54 AM
Set IP address and netmask:
Set gateway and dns servers:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
5 of 29 1/31/2009 2:54 AM
Set the hostname:
Set the timezone:
Set the root password:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
6 of 29 1/31/2009 2:54 AM
Select server group and select customize software selection:
Package groups select as follows:DNS name server
bind-chroot
Editorsvim-enhanced
FTP serverMail server
dovecotspamassassinpostfix
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
7 of 29 1/31/2009 2:54 AM
Mysql Databasemysql-server
Web servermod_sslwebalizerphpphp-pearhttp-suexecphp-mysql
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
8 of 29 1/31/2009 2:54 AM
Start the installation:
File system is formatted:
The installation will run:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
Virtual Hosting Howto With Virtualmin On CentOS 5.1 - Page 2
Services To Disable
To enhance security and free system resources on the system we need to disable any services that are not required. You can run this script to do this for you.
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
10 of 29 1/31/2009 2:54 AM
yum-updatesd
Basics
We need to fix a few issues to prepare the system for configuration.
Install updates
yum upgrade
Switch the mta to postfix
alternatives --config mta
There are 2 programs which provide 'mta'.Selection Command-----------------------------------------------1 /usr/sbin/sendmail.postfix*+ 2 /usr/sbin/sendmail.sendmailEnter to keep the current selection[+], or type selection number: 1
Verify the rpm (should say OK or else download again):
rpm --checksig webmin-1.390-1.noarch.rpm
Install the rpm:
rpm -Uvh webmin-1.390-1.noarch.rpm
Initial Webmin Config
We need to secure webmin by editing /etc/webmin/miniserv.conf and make the following changes:
Using SSL only:
ssl=1
Change the port to 443 and bind to the second nic only:
port=443bind=192.168.1.6
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
11 of 29 1/31/2009 2:54 AM
Disable UDP broadcasts:
#listen=10000
Change host lockout on login failures to 3 :
blockhost_failures=3
Increase host lockout timeout to 120:
blockhost_time=120
Change user lockout on login failures to 3:
blockuser_failures=3
Change user lockout timeout to 120:
blockuser_time=120
Change the realm to something else:
realm=cpanel
Log logins to utmp:
utmp=1
Install the webmin Tiger theme:
Login to webmin via https://192.168.1.5:10000 using root and your password.Go to webmin ? Configuration ? webmin themes.Select From ftp or http URL and enter http://www.stress-free.co.nz/files/theme-stressfree.tar.gzClick install theme.Click "return to list themes".Select StressFree as the Current theme then click change.
Install php-pear module:
Go to webmin ? webmin configuration ? webmin modules.Select Third party module from and enter http://www.webmin.com/download/modules/php-pear.wbm.gz.Click install module.
Install virtualmin:
Go to webmin ? webmin configuration ? webmin modules.Select install from ftp or http URL and enter http://download.webmin.com/download/virtualmin/virtual-server-3.51.gpl.wbm.gzClick install module.
Remove unwanted modules Go to webmin ? webmin configuration ? delete and select the following:
ADSL clientBacula backup systemCD BurnerCVS ServerCluster change passwordsCluster copy filesCluster cron jobsCluster shell commandsCluster software packagesCluster usermin serversCluster users and groupsCluster webmin serversCommand shellConfiguration engineCustom commandsDHCP serverFetchmail mail retrievalFile managerFrox ftp proxyHTTP TunnelHeartbeat monitorIPsec VPNJabber IM serverLDAP serverLogical volume managementMajordomo list managerNFS exportsNIS client and serverOpenSLP serverPPP dialin serverPPP dialup clientPPTP vpn server
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
12 of 29 1/31/2009 2:54 AM
PPTP vpn clientPostgresql database serverPrinter adminProFTPD serverQMAIL mail serverSMART drive statusSSH / Telnet loginSSL tunnelsSAMBA windows file sharingScheduled commandsSendmail mail serverShoreline firewallSquid analysis report generatorSquid proxy serverVoicemail serverWU-FTP serverIdmapd server
NOTE: If you are using a different architecture check on https://rpmrepo.org/RPMforge/Using for the correct rpmDisable the repo (such that base packages not overwritten) edit /etc/yum.d/rpmforge.repo and set the following option:
The adding of accounts and domains with be configured through virtualmin although it can be done manually as well. The setup is designed to be resource friendly so should beable to run on machines that are not over spec'ed so enabling the resources to be put to better use. To make it resource friendly we are not using external databases to storevirtual user information like most other how-to's do as well as using milters for spam and virus checking as opposed to running amavisd-new.
The Basics
To begin with we will configure the basics such as the hostname, mail origin, networks, hash maps spool directory. All these configuration options should be added to/etc/postfix/main.cf unless stated. Sample configuration files are available for download at the end of this page.
We will use the much improved maildir format as opposed to the default mbox format:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
14 of 29 1/31/2009 2:54 AM
home_mailbox = Maildir/
SASL
To perform SMTP authentication we will be using SASL, however we will not use the Cyrus SASL as that requires us to run the saslauthd daemon, we will instead use dovecotsasl since we will be running dovecot for IMAP and POP3 thus killing 2 birds with one stone.
We need TLS to ensure that the plain text passwords are not transmitted over the wire during SMTP authentication, servers that support TLS are also able to communicatewith this server over a secured connection.
Instructions on creating your server certificate signed by cacert.org are can be found here.
For your spam classification using spamassassin and virus scanning using clamav we will be using postfix's milter interface instead of using the resource intensive amavisd-newdaemon. This is a very efficient way of doing it as we don't even have to run clamd the clamav milter does the scanning itself.
We will use the maildir format as opposed to the default mbox format.
mail_location = maildir:~/Maildir
Authentication & SASL
Configure dovecot to use LOGIN and PLAIN as the authentication mechanisims as many MS clients are unable to use encrypted authentication mechanisms. We also setup theSASL socket to enable postfix to authenticate SMTP connections using dovecot.
Some MS imap clients in the outlook family have issues with both thier IMAP and POP3 implementations so we need to accommodate them by setting up these work arounds:
The imap server is configured to run on port 10143 such that port 143 is handled by the imap proxy server that will improve performance for your webmail by cachingconnections to the imap server. The listen option under protocol sets this up.
imapproxy was written to compensate for webmail clients that are unable to maintain persistent connections to an IMAP server. Most webmail clients need to log in to an IMAPserver for nearly every single transaction. This behaviour can cause tragic performance problems on the IMAP server. imapproxy tries to deal with this problem by leavingserver connections open for a short time after a webmail client logs out. When the webmail client connects again, imapproxy will determine if there's a cached connectionavailable and reuse it if possible. - according to the imapproxy website.
Configuration
Make the following changes in the file /etc/imapproxy.conf:
server_hostname 127.0.0.1cache_size 3072
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
Bind will be set up chrooted to improve security we will also use views to prevent abuse of the dns server.
Basic Configuration
The basic configuration disables by default, recursive queries and zone transfers. We also obscure the version of BIND we are running such that we are not hit by zero dayvulnerabilities from script kiddies.
Ensure that this is set in the file /etc/sysconfig/named (it's usually set by the bind-chroot package):
ROOTDIR=/var/named/chroot
Point Server
Let the machine use this server for dns resolution edit /etc/resolv.conf and prepend:
nameserver 127.0.0.1
Sample files
named.conf/etc/sysconfig/named
Vsftpd Setup
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
18 of 29 1/31/2009 2:54 AM
Introduction
We will use vsftpd as our ftp server. This has a better track record as opposed to the proftpd & wuftpd servers.
Basic Setting
Our basic setup disables anonymous users, and enables local system users to connect to the ftp server.
anonymous_enable=NOlocal_enable=YESwrite_enable=YESlocal_umask=022anon_upload_enable=NOanon_mkdir_write_enable=NOdirmessage_enable=YESxferlog_enable=YESconnect_from_port_20=YESxferlog_file=/var/log/vsftpd.logxferlog_std_format=YESftpd_banner=Welcome to example.com serverpam_service_name=vsftpdtcp_wrappers=YES
Chroot
All users will be chrooted to their home directories (except usernames in the /etc/vsftpd/chroot_list file) meaning the cannot break out and see other users files.
We will be storing the image hashes in a mysql database to improve on performance such that images that we have already scanned do not get scanned again as OCR is aresource intense activity.
Create MySQL Database
The sql script creates the database and tables and adds a user fuzzyocr with the password fuzzyocr:
mysql -p < /usr/local/src/devel/FuzzyOcr.mysql
Change the password:
mysqladmin -u fuzzyocr -p fuzzyocr password
Basic Settings
Edit /etc/mail/spamassassin/FuzzyOCR.cf and set the basic options:
Apache has to be configured to listed to one address for port 443 as webmin will be using the same port. Edit /etc/httpd/conf.d/ssl:
Listen 192,168.1.6:443
Enable Gzip Compression
We setup gzip compression via the mod_deflate module to improve web server performance and to cut down on bandwidth usage by compressing responses to the client.
As we will be providing webmail for all domains that are created on the system we need to setup a catch all virtualhost that can display roundcube when ever a user accesseshttp://webmail.domainname. Edit /etc/httpd/conf/httpd.conf and append:
Virtual Hosting Howto With Virtualmin On CentOS 5.1 - Page 6
Configure Virtualmin
Introduction
Virtualmin is a powerful and flexible hosting control panel that integrates with webmin. We will be using it to provide the virtual hosting functions such as creation of domains,accounts and maintaining configurations on the system.
Start Services
You need to start up services that are required to be able to configure virtualmin. Start the following services:
service named startservice spamassassin startservice spamass-milter startservice clamav-milter startservice postfix startservice dovecot startservice imapproxy startservice httpd start
Initial Settings
MySQL
Webmin needs to be able to communicate with mysql since we have set a password for mysql we need to set that up in webmin, go to servers ? mysql and enter thisinformation:
Configure Features
You need to enable the features and plugins that we want to use. On login this is the screen that you will see.
Enable the following features and saveHome directoryAdministration userMail for domainBIND DNS domainApache websiteWebalizer reportingLog file rotationMysql databaseWebmin user
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
24 of 29 1/31/2009 2:54 AM
Configure Server Templates
Server template are used to customize the services and to create packages for different hosting account types.
Apache Template
You can make changes to the way apache virtual hosts are created by editing this template, The defaults however will do for purposes of this howto.
Domain Owner Template
This template is used to configure various server limits such as number of mailboxes,aliases,databases,virtual servers and other options like bandwidth limits, admin abilities. Forthis howto we will use the default values.
Home Directory Template
This template allows you to set a skel directory to hold setting for new users for this howto we will use the defaults.
Administration User
This template lets you set the quota for the virtual server and the admin user for this howto we will use the default quota 1GB.
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
25 of 29 1/31/2009 2:54 AM
Mail For Domain Template
This template sets various mail related options, we will modify the email message sent on server creation to have the content below:
The following virtual server has been set up successfully :Domain name: ${DOM}Hosting server: ${HOSTNAME}${IF-VIRT}Virtual IP address: ${IP}${ENDIF-VIRT}Administration login: ${USER}Administration password: ${PASS}${IF-WEBMIN}Administration URL: ${WEBMIN_PROTO}://www.${DOM}:${WEBMIN_PORT}/${ENDIF-WEBMIN}${IF-WEB}Website: http://www.${DOM}/${IF-WEBALIZER}Webalizer log reporting: Enabled${ELSE-WEBALIZER}Webalizer log reporting: Disabled${ENDIF-WEBALIZER}${ENDIF-WEB}${IF-MAIL}Email domain: ${DOM}SMTP server: mail.${DOM}POP3 server: mail.${DOM}Webmail: webmail.${DOM}${ENDIF-MAIL}${IF-DNS}DNS domain: ${DOM}Nameserver: ${HOSTNAME}${ENDIF-DNS}${IF-MYSQL}MySQL database: ${DB}MySQL login: ${MYSQL_USER}MySQL password: ${PASS}${ENDIF-MYSQL}${IF-POSTGRES}PostgreSQL database: ${DB}PostgreSQL login: ${USER}PostgreSQL password: ${PASS}${ENDIF-POSTGRES}
We will leave the other options as the defaults.
BIND DNS Domain Template
This template is used to customize the zones that will be created by virtualmin. The changes to be made are adding a spf record, add the following records to auto generated textbox (replace ns1.home.topdog-software.com. with your slave server):
@ IN NS ns1.home.topdog-software.com. ;slaveadmin IN A 192.168.1.6 ;virtualminwebmail IN A 192.168.1.5 ;webmail
In the directives text box add the following with the IP address of your slave server such that the slave is allowed to do zone transfers.
allow-transfer { 192.168.1.2; };
MySQL Database Template
Contains options on creation of databases by virtualmin, for the howto we will use the defaults.
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
26 of 29 1/31/2009 2:54 AM
Webmin Login Template
Contains option on creation of new users by virtualmin, for the howto we will use the defaults.
Create Virtual Server
Finally we have a working virtual server system, lets create our first virtual server. Go to servers ? virtualmin virtual servers and click add new virtual server, owned by newuser.
Fill in the require fields and click create.
Add a mail user to the domain. click on the domain name, then click edit mail and FTP users, then add user and fill in the information.
Testing
Postfix
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
27 of 29 1/31/2009 2:54 AM
Test SMTP
telnet 192.168.1.5 25Connected to localhost.Escape character is '^]'.220 tds mail clusterhelo me250 hosting1mail from:[email protected] 2.1.0 Okrcpt: [email protected] 2.1.0 OkDATA354 End data with <CR><LF>.<CR><LF>
telnet 192.168.1.5 25Trying 192.168.1.5...Connected to localhost.Escape character is '^]'.220 tds mail clusterehlo me250-hosting1250-PIPELINING250-SIZE 10240000250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
telnet 192.168.1.5 143* OK Dovecot ready.01 login andrew.example password01 OK User logged in01 list "" "*"
* LIST (\HasNoChildren) "." "Trash"* LIST (\HasNoChildren) "." "Drafts"* LIST (\HasNoChildren) "." "Junk"* LIST (\HasNoChildren) "." "Sent"
* LIST (\HasNoChildren) "." "INBOX"01 OK List completed.01 logout* BYE LOGOUT received01 OK Completed
BIND
dig example.com @127.0.0.1
Virtual Hosting Howto With Virtualmin On CentOS 5.1 http://www.howtoforge.com/book/print/3208/1/all
28 of 29 1/31/2009 2:54 AM
Clamav-milter
We are using the test virus from www.eicar.org.
telnet 192.168.1.5 25Connected to localhost.Escape character is '^]'.220 tds mail clusterhelo me250 hosting1mail from:[email protected] 2.1.0 Okrcpt: [email protected] 2.1.0 OkDATA354 End data with <CR><LF>.<CR><LF>
Take a lot at your /var/log/maillog you should see something like this:
73BC87C4E4: milter-reject: END-OF-MESSAGE from localhost[127.0.0.1]:5.7.1 virus Eicar-Test-Signature detected by ClamAV - http://www.clamav.net; from=<[email protected]> to=<[email protected]> proto=SMTP helo=<me>
Spamass-milter
We are using the test message from http://spamassassin.apache.org/gtube/.
telnet 192.168.1.5 25Connected to localhost.Escape character is '^]'.220 tds mail clusterhelo me250 hosting1mail from:[email protected] 2.1.0 Okrcpt: [email protected] 2.1.0 OkDATA354 End data with <CR><LF>.<CR><LF>
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X.550 5.7.1 Blocked by SpamAssassinquit221 2.0.0 Bye
You will see this in your log files:
spamd: result: Y 1002 - AWL,GTUBE,MISSING_SUBJECT,TVD_SPACE_RATIO,UNPARSEABLE_RELAY scantime=0.5,size=723,user=root,uid=99,required_score=5.0,