RHEL5上安装邮件系统Postfix+dovecot+MailScanner+spamassassin+f-prot+PostfixAdmin+SquirrelMail
作者:LEO [url]http://zqli.cublog.cn/[/url]
概要:
本文讲述在安装了RHEL5上,配置一台Postfix邮件服务器的过程。实现虚拟域、虚拟用户、POP3、POP3S、SMTP、SMTPS、IMAP、IMAPS、防毒、防SPAM、网页邮件功能。
涉及的软件
1. Red Hat Enterprise Linux Server release 5 (Tikanga)
2. MySQL
系统自带
用于存储虚拟域、虚拟用户等信息。
3. Apache
系统自带
运行网页邮件SquirrelMail和PostfixAdmin时使用。
4. PHP
系统自带
运行网页邮件SquirrelMail和PostfixAdmin时使用。
5. Cyrus-sasl
系统自带
实现带验证的SMTP时使用。
6. Courier authentication library
从 [url]http://download.chinaunix.net/[/url]下载
实现带验证的SMTP时使用。
7. Postfix
从 [url]http://www.postfix.org[/url] 下载
一个MTA,虽然RHEL 4 自带Postfix,但因为其不支持SSL及Mysql,所以我们需要自行编译。
8. PostfixAdmin
从 [url]http://www.postfixadmin.com/[/url] 下载
虚拟域、虚拟用户等信息是放在Mysql内的,安装PostfixAdmin后,就可以用浏览器管理这些信息。
9. SquirrelMail
系统自带或从 [url]http://www.squirrelmail.org/download.php[/url]下载
一个基于IMAP的Webmail客户端。
10. Dovecot
系统自带
提供POP3,POP3S,IMAP,IMAPS功能。
11. F-prot
从 [url]http://www.f-prot.com[/url] 下载,Linux workstation 版个人使用是免费的
提供杀毒功能,据说速度和病毒库比开源的Clamav好。
12. SpamAssassin
系统自带
提供过滤垃圾邮件功能。
13. MailScanner
从 [url]http://www.mailscanner.info/[/url] 下载
Postfix 是使用MailScanner 调用f-prot 与SpamAssassin,或者其它调用方法效率更好,但MailScanner配置比较直观。
作者:LEO [url]http://zqli.cublog.cn/[/url]
配置过程
1. 基本软件安装
默认方式安装RHEL5,不选中任何类型服务器(如WEB服务器,开发服务器,虚拟服务器等),安装上文中提及“系统自带”的软件。
下载其它需要的软件。
安装MySQL
[root@rhel5 Server]# rpm -ivh mysql-5.0.22-2.1.i386.rpm
[root@rhel5 Server]# rpm -ivh mysql-server-5.0.22-2.1.i386.rpm
[root@rhel5 Server]# chkconfig mysqld on
安装Apache
[root@rhel5 Server]# rpm -ivh httpd-2.2.3-6.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh httpd-manual-2.2.3-6.el5.i386.rpm
[root@rhel5 Server]# chkconfig httpd on
安装PHP
[root@rhel5 Server]# rpm -ivh php-common-5.1.6-5.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh php-pdo-5.1.6-5.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh php-mysql-5.1.6-5.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh php-cli-5.1.6-5.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh php-5.1.6-5.el5.i386.rpm
安装Cyrus-sasl
[root@rhel5 Server]# rpm �Civh cyrus-sasl-2.1.22-4.i386.rpm
安装squirrelmail
[root@rhel5 Server]# rpm -ivh squirrelmail-1.4.8-4.el5.noarch.rpm
安装dovecot
[root@rhel5 Server]# rpm -ivh dovecot-1.0-1.2.rc15.el5.i386.rpm
安装spamassassin
[root@rhel5 Server]# rpm -ivh perl-IO-Zlib-1.04-4.2.1.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Archive-Tar-1.30-1.fc6.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Digest-SHA1-2.11-1.2.1.i386.rpm
[root@rhel5 Server]# rpm -ivh perl-Socket6-0.19-3.fc6.i386.rpm
[root@rhel5 Server]# rpm -ivh perl-IO-Socket-INET6-2.51-2.fc6.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Net-SSLeay-1.30-4.fc6.i386.rpm
[root@rhel5 Server]# rpm -ivh perl-IO-Socket-SSL-1.01-1.fc6.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Digest-HMAC-1.01-15.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Net-IP-1.25-2.fc6.noarch.rpm
[root@rhel5 Server]# rpm -ivh perl-Net-DNS-0.59-1.fc6.i386.rpm
[root@rhel5 Server]# rpm -ivh spamassassin-3.1.7-4.el5.i386.rpm
[root@rhel5 ~]# tar xvf postfixadmin-2.1.0.gz
[root@rhel5 ~]# mv postfixadmin-2.1.0 /var/www/html/pa
[root@rhel5 ~]# service mysqld start
[root@rhel5 ~]# mysql -uroot < /var/www/html/pa/DATABASE_MYSQL.TXT
[root@rhel5 ~]# cp /var/www/html/pa/config.inc.php.sample /var/www/html/pa/config.inc.php
打开浏览器访问 [url]http://IP/pa[/url],然后按提示增加两个虚拟域名mailidc.cn 和 zqli.com,增加两个虚拟用户
[email protected],
[email protected]
[root@rhel5 ~]# vi /etc/httpd/conf/httpd.conf
加入以下内容,加强安全性,要不每个人不经认证都可以用postfixadmin
<Directory "/var/www/html/pa" >
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride None
AuthType Basic
authname Private
authuserfile /var/phpaccess/leo
require valid-user
Order allow,deny
Allow from all
</Directory>
注意/var/phpaccess/leo是我的密码文件名
[root@rhel5 ~]# mkdir /var/phpaccess
[root@rhel5 ~]# touch /var/phpaccess/leo
[root@rhel5 ~]# cd /var/phpaccess/
[root@rhel5 phpaccess]# htpasswd -c leo leo #添加用户leo
New password:
Re-type new password:
Adding password for user leo
然后我们就可以打开网页浏览器来访问了
[url]http://ip/pa[/url]
至此postfixadmin配置完毕。在这里我推荐对mysql比较了解的人更改默认的postfix连接密码:默认数据名为postfix,用户名密码都是postfix。我们下面的配置还是用回默认的用户名和密码。
作者:LEO [url]http://zqli.cublog.cn/[/url]
安装postfix所依赖的包
[root@rhel5 Server]# rpm -ivh db4-devel-4.3.29-9.fc6.i386.rpm
[root@rhel5 Server]# rpm -ivh e2fsprogs-devel-1.39-8.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh krb5-devel-1.5-17.i386.rpm
[root@rhel5 Server]# rpm -ivh zlib-devel-1.2.3-3.i386.rpm
[root@rhel5 Server]# rpm -ivh openssl-devel-0.9.8b-8.3.el5.i386.rpm
[root@rhel5 Server]# rpm -ivh mysql-devel-5.0.22-2.1.i386.rpm
[root@rhel5 Server]# rpm -ivh cyrus-sasl-devel-2.1.22-4.i386.rpm
编译、配置Postfix
先删除sendmail
[root@rhel5 ~]# rpm -e sendmail �Cnodeps
[root@rhel5 ~]# groupadd postfix
[root@rhel5 ~]# groupadd postdrop
[root@rhel5 ~]# useradd postfix -g postfix -c "Postfix user" -d /dev/null -s /sbin/nologin
[root@rhel5 ~]# tar zxvf postfix-2.4.3.tar.gz
[root@rhel5 postfix-2.4.3]# make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_TLS -DUSE_CYRUS_SASL -DUSE_SASL_AUTH -I/usr/include/sasl' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib -lssl -lcrypto -lsasl2'
[root@rhel5 postfix-2.4.3]# make
[root@rhel5 postfix-2.4.3]# make install
注:“make install”命令后的所有问题都直接敲回车键即可。
编辑/etc/postfix/main.cf 为以下内容
#=====================BASE=========================
myhostname = mail.mailidc.cn
mydomain = mailidc.cn
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 192.168.1.0/24 127.0.0.0/8
inet_interfaces = all
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /var/spool/mail
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:501
virtual_gid_maps = static:502
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
#====================QUOTA========================
message_size_limit = 14336000
virtual_mailbox_limit = 20971520
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the user's maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes
#====================SASL========================
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "Version not Available"
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
编辑/etc/postfix/mysql_virtual_alias_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
编辑/etc/postfix/mysql_virtual_domains_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
编辑/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
编辑/etc/postfix/mysql_virtual_mailbox_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
配置SMTP 认证
编辑 /usr/lib/sasl2/smtpd.conf 为以下内容
pwcheck_method: authdaemond
log_level: 3
mech_list: plain login
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
安装Courier authentication library
[root@rhel5 ~]# tar jxvf courier-authlib-0.58.tar.bz2
[root@rhel5 ~]# cd courier-authlib-0.58
[root@rhel5 courier-authlib-0.58]# ./configure --prefix=/usr/local/courier-authlib --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/usr/local/courier-authlib/etc/authmysqlrc --with-authdaemonrc=/usr/local/courier-authlib/etc/authdaemonrc CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations"
[root@rhel5 courier-authlib-0.58]# make
[root@rhel5 courier-authlib-0.58]# make install
[root@rhel5 courier-authlib-0.58]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
[root@rhel5 courier-authlib-0.58]# cp /usr/local/courier-authlib/etc/authdaemonrc.dist /usr/local/courier-authlib/etc/authdaemonrc
修改/usr/local/courier-authlib/etc/authdaemonrc 文件
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
编辑/usr/local/courier-authlib/etc/authmysqlrc 为以下内容,其中501,502 为postfix 用户的UID和GID。
MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE postfix
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD '501'
MYSQL_GID_FIELD '502'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/var/spool/mail/',maildir)
MYSQL_MAILDIR_FIELD concat('/var/spool/mail/',maildir)
MYSQL_NAME_FIELD name
[root@rhel5 courier-authlib-0.58]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@rhel5 courier-authlib-0.58]# chkconfig --level 35 courier-authlib on
[root@rhel5 courier-authlib-0.58]# chmod 755 /etc/init.d/courier-authlib
[root@rhel5 courier-authlib-0.58]# service courier-authlib start
此时你已经拥有一台带验证的SMTP 服务器,用Outlook 、Foxmail测试一下吧,用户名采用
[email protected] 形式。到了这一步,可以正常地发信了。
作者:LEO [url]http://zqli.cublog.cn/[/url]
增加SSL功能,配置SMTPS服务
在/etc/postfix/main.cf 增加以下内容
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/ssl/smtpd.pem
smtpd_tls_cert_file = /etc/ssl/smtpd.pem
smtpd_tls_CAfile = /etc/ssl/smtpd.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
生成证书
# mkdir /etc/ssl
# cd /etc/ssl
# openssl req -new -x509 -nodes -out smtpd.pem -keyout smtpd.pem -days 3650
重新启动postfix
# postfix reload
这时SMTPS功能应该能正常工作了。有能力测试的网友们请验证一下这功能。
配置Dovecot,增加IMAP,IMAPS,POP3,POP3S功能
由于Dovecot 是系统自带的,配置两个文件,再生成证书就可以了。
编辑 /etc/dovecot.conf 为以下内容
base_dir = /var/run/dovecot/
protocols = imap imaps pop3 pop3s
listen = *
ssl_disable = no
ssl_cert_file = /etc/pki/dovecot/certs/dovecot.pem
ssl_key_file = /etc/pki/dovecot/private/dovecot.pem
login_dir = /var/run/dovecot/login
default_mail_env = maildir:/var/spool/mail/%u/
auth default {
mechanisms = plain login digest-md5 cram-md5
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb sql {
args = /etc/dovecot-mysql.conf
}
}
first_valid_uid = 501
编辑 /etc/dovecot-mysql.conf 为以下内容
driver = mysql
connect = host=/var/lib/mysql/mysql.sock dbname=postfix user=postfix password=postfix
default_pass_scheme = CRYPT
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 501 AS uid, 502 AS gid FROM mailbox WHERE username = '%u'
生成证书
[root@rhel5 ssl]# mkdir /etc/ssl/certs
[root@rhel5 ssl]# mkdir /etc/ssl/private
[root@rhel5 ssl]# cd /usr/share/doc/dovecot-1.0/examples
[root@rhel5 examples]# sh mkcert.sh
启动Dovecot 服务
[root@rhel5 ~]# chown postfix /var/spool/mail/
# service dovecot start
# chkconfig --level 35 dovecot on
顺利的话,此时SMTP、SMTPS、POP3、POP3S已经配置完成。
作者:LEO [url]http://zqli.cublog.cn/[/url]