
| Virtual Users And Domains With Postfix, MailScanner, Mailwatch & MySQL On CentOS 5.1 |
| 摘自: www.howtoforge.com 被阅读次数: 32 |
由 yangyi 于 2008-05-07 23:53:22 提供 |
Version 1.0 This document describes how to customize Falko's "Virtual Users And Domains" - setup for CentOS 5.1 so that it works with MailScanner and Mailwatch. The resulting system provides a web interface (Mailwatch) where you can manage quarantined emails, train SpamAssassin, edit the white- and blacklist, view configuration files and the detailed MySQL database status ... This howto is a practical guide without any warranty - it doesn't cover the theoretical backgrounds. There are many ways to set up such a system - this is the way I chose.
1 Preparation Part IOpen http://www.howtoforge.com/virtual-users-and-domains-postfix-courier-mysql-centos5.1 and follow steps 1 - 10.
2 Preparation Part II2.1 Install ClamAVyum -y install clamav clamd unrar
2.2 Language Configurationvi /etc/sysconfig/i18n Change: LANG="en_US.UTF-8" To: LANG="en_US"
2.3 Get MailscannerPlease have a look at http://www.mailscanner.info/downloads.html to find out which is the latest version. When I was writing this howto, it was version 4.66.5-3. cd /tmp/
3 Install Mailscannercd /tmp/MailScanner-4.66.5-3 This will take a while...
4 Mailscanner Configurationmv MailScanner.conf MailScanner.conf.orig Change some parameters so that they look like this: Run As User = postfix mkdir /var/spool/MailScanner/spamassassin/
5 Install SpamassassinThe MailScanner manual recommends to install spamassassin from .tar.gz or via perl shell. Some users reported problems with the .rpm-version. perl -MCPAN -e shell Answer "no" when you're asked if you are ready for manual configuration. Enter the following within the perl shell: o conf prerequisites_policy ask Answer "no" when you're asked if you want to enable the online tests. install Mail::SpamAssassin
6 Postfix Configurationtouch /etc/postfix/header_checks Add the following line: header_checks = regexp:/etc/postfix/header_checks Afterwards stop postfix & sendmail and start ClamAV. chkconfig postfix off 7 Mailwatch7.1 Needed Packageyum -y install php-gd
7.2 Get MailwatchPlease have a look at http://mailwatch.sourceforge.net to find out which is the latest version. When I was writing this howto, it was version 1.04. cd /tmp/
7.3 Mailwatch DatabaseFirst we create and populate the mailwatch database. mysql -p < /tmp/mailwatch-1.0.4/create.sql Next open a MySQL shell. mysql -u root -p Create the MySQL user for the database. GRANT ALL ON mailscanner.* TO mailwatch@localhost IDENTIFIED BY '%sql_user_password%'; After that we have to insert the account data from above into some files. vi /tmp/mailwatch-1.0.4/MailWatch.pm my($db_user) = 'mailwatch'; mv /tmp/mailwatch-1.0.4/MailWatch.pm /usr/lib/MailScanner/MailScanner/CustomFunctions/ vi /var/www/html/mailscanner/conf.php.example define(DB_USER, 'mailwatch'); mv /var/www/html/mailscanner/conf.php.example /var/www/html/mailscanner/conf.php vi /tmp/mailwatch-1.0.4/SQLBlackWhiteList.pm my($db_user) = 'mailwatch'; mv /tmp/mailwatch-1.0.4/SQLBlackWhiteList.pm /usr/lib/MailScanner/MailScanner/CustomFunctions/
7.4 Mailwatch Web AdministratorNow open a MySQL shell with the mailwatch MySQL user. mysql mailscanner -u mailwatch -p Create the web admin account. INSERT INTO users VALUES ('%web_user_username%',md5('%web_user_password%'),'%web_user_name%','A','0','0','0','0','0');
7.5 Mailwatch VHostCreate a vhost like this: <VirtualHost 192.168.0.110:80>
ServerName mailwatch.example.com
ServerAdmin admin@example.com
DocumentRoot /var/www/html/mailscanner/
php_admin_flag short_open_tag On
php_admin_flag safe_mode Off
php_admin_flag register_globals Off
php_admin_flag magic_quotes_gpc On
php_admin_flag magic_quotes_runtime Off
php_admin_flag session.auto_start 0
php_admin_flag allow_url_fopen On
LogLevel warn
ErrorLog logs/mailwatch-error_log
CustomLog logs/mailwatch-access_log combined
</VirtualHost>
Afterwards move the needed files for the webinterface to the right place ... mv mailwatch-1.0.4/mailscanner/ /var/www/html/ ... and change the ownership. chown -R apache:apache /var/www/html/mailscanner/
7.6 Spamassassin Configurationvi /etc/MailScanner/spam.assassin.prefs.conf Change: #bayes_path /etc/MailScanner/bayes/bayes To: bayes_path /var/spool/MailScanner/spamassassin/bayes And modify the directory permissions: chown postfix:apache /var/spool/MailScanner/spamassassin/ /var/spool/MailScanner/spamassassin/bayes_* Test the spamassassin configuration. spamassassin -D -p /etc/MailScanner/spam.assassin.prefs.conf --lint You should see lines like the following in the output: dbg: config: using "/etc/MailScanner/spam.assassin.prefs.conf" for user prefs file
7.7 GeoIP BugfixIn order that the geoip database update in the Mailwatch webinterface will work we have to fix a little bug. vi /var/www/html/mailscanner/geoip_update.php Change: dbquery("LOAD DATA INFILE '".$base.'/'.$file2."' INTO TABLE geoip_country FIELDS TERMINATED BY ',' ENCLOSED BY '\"'"); To: dbquery("LOAD DATA LOCAL INFILE '".$base.'/'.$file2."' INTO TABLE geoip_country FIELDS TERMINATED BY ',' ENCLOSED BY '\"'"); 8 Cronjobs8.1 MailScanner Quarantinevi /etc/cron.daily/clean.quarantine Make sure that it's disabled - the corresponding line should look like this: $disabled = 1;
8.2 Mailwatch Quarantinevi /tmp/mailwatch-1.0.4/tools/db_clean.php Change the first line that it looks like this: #!/usr/bin/php -q cp /tmp/mailwatch-1.0.4/tools/quarantine_maint.php /usr/local/bin/
8.3 Mail Queue WatcherFirst copy the mail queue watcher script. cp /tmp/mailwatch-1.0.4/mailq.php /usr/local/bin/ Afterwards we create a new cronjob. crontab -e Add the following line: 0-59 * * * * /usr/local/bin/mailq.php
9 Quarantine Release FixIn order that a released email is not checked again (it would be quarantined again) we have to add/modify some rules.
9.1 WhiteList SQL DatabaseConnect to phpmyadmin (%server_ip%/phpmyadmin) and log in as mailwatch. Afterwards select the database "mailscanner" and then the table "whitelist". Create a new record: to_address = default
9.2 MailScanner RulesNote that the entries in all lines of the following files have to be separated with tabs! cd /etc/Mail vi filename.rules From: 127.0.0.1 /etc/MailScanner/filename.rules.allowall.conf FromOrTo: default /etc/MailScanner/filename.rules.conf vi filetype.rules From: 127.0.0.1 /etc/MailScanner/filetype.rules.allowall.conf FromOrTo: default /etc/MailScanner/filetype.rules.conf vi filename.rules.allowall.conf allow .* - - vi filetype.rules.allowall.conf allow .* - - vi rules/content.scanning.rules From: 127.0.0.1 no FromOrTo: default yes Now adjust the permissions for the quarantine directory. chown -R postfix:apache /var/spool/MailScanner/quarantine/ Note: The needed MailScanner settings were already included in step 4.
10 Startchkconfig --level 2345 MailScanner on You should see lines like the following in the output: Mar 6 07:33:21 server1 MailScanner[8594]: Config: calling custom init function SQLBlacklist
11 Remaining Configurationhttp://www.howtoforge.com/virtual-users-and-domains-postfix-courier-mysql-centos5.1 from step 14 till the end. Keep in mind that the commands to start, stop or restart postfix have changed! To start MailScanner & Postfix: service MailScanner start To restart MailScanner & Postfix: service MailScanner restart To stop MailScanner & Postfix: service MailScanner stop
12 Mailwatch WebinterfaceNow you can access the mailwatch webinterface via http://mailwatch.example.com. Log in with the username & password that you created in step 7.4 . First you should update the SpamAssassin rule descriptions and the GeoIP database. You'll find both options when you click on the "Tools/Links" button.
13 Links
VMThe attached VM is configured as follows.
Original link: http://www.howtoforge.com/virtua... |



