一、安装前的准备工作及说明
所需的源码包:courier-authlib-0.63.1.20111230.tar、extmail-1.2.tar、extman-1.1.tar、postfix-2.8.2.tar、Unix-Syslog-1.1.tar(源码包均来自互联网,如有需要可自行下载)
linux
运行平台企业版5.4,ip地址192.168.101.222,域名为abc.com
1、搭建DNS 服务器:
[root@Eleven ~]# mkdir /mnt/cdrom
[root@Eleven ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
编辑yum
[root@Eleven ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[root@Eleven ~]# cd /mnt/cdrom/Server/
[root@Eleven Server]# yum install bind bind-chroot caching-nameserver –y
[root@Eleven Server]# cd /var/named/chroot/etc/
[root@Eleven etc]# cp -p named.caching-nameserver.conf named.conf
[root@Eleven etc]# vim named.conf
(红色为修改的内容)
修改区域声明文件
[root@Eleven etc]# vim named.rfc1912.zones
生成数据库
[root@Eleven etc]# cd ../var/named/
[root@Eleven named]# cp -p localhost.zone abc.com.db
[root@Eleven named]# vim abc.com.db
修改为如下内容:
修改vim /etc/resolv.conf
修改主机名:
vim /etc/sysconfig/network
重启系统:init 6
[root@mail ~]# service named start
Starting named: [ OK ]
[root@mail ~]# chkconfig named on
DNS
安装完成
2、安装所需的rpm包,这包括以下这些:
[root@mail ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@mail ~]# yum install -y httpd mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect
3、关闭sendmail,并将它的随系统自动启动功能关闭:
[root@mail ~]#service sendmail stop
[root@mail ~]#chkconfig sendmail off
4、安装以下开发所用到的rpm包组:
Development Libraries
Development Tools
Legacy Software Development
X Software Development
先使用指令yum grouplist 查看,如没安装可用指令:yum groupinstall "packge_group_name"
5、启动mysql数据库,并给mysql的root用户设置密码:
[root@mail ~]# service mysqld start
[root@mail ~]# chkconfig mysqld on
设置新密码为“redhat”,因为没有老密码,所以在需输入老密码的时候直接回车即可。
[root@mail ~]# mysqladmin -u root password 'redhat'
也可以
---------------------------------
授权本地用户
SET PASSWORD FOR root@'localhost'=PASSWORD('redhat');
SET PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat');
FLUSH PRIVILEGES; #
使修改生效
-------------------------------
授权远程用户
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat';
FLUSH PRIVILEGES;
二、安装配置postfix
[root@mail ~]# groupadd -g 2525 postfix
[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[root@mail ~]# groupadd -g 2526 postdrop
[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop
[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/postfix-2.8.2/
[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
[root@mail postfix-2.8.2]# make && make install
在此过程中遇见要选择的选项,直接按回车即可。
[root@mail postfix-2.8.2]# postconf –m
[root@mail postfix-2.8.2]# newaliases #
生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cf
说明:
myorigin
参数用来指明发件人所在的域名;
mydestination
参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname
参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain
参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
mynetworks
参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
编辑postfix的启动脚本
[root@mail ~]# mkdir zhu
[root@mail ~]# cd zhu
[root@mail zhu]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./
[root@mail zhu]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
[root@mail zhu]# cd etc/
[root@mail etc]# cd rc.d/
[root@mail rc.d]# cd init.d/
[root@mail init.d]# cp postfix /etc/init.d
至此可以使用指令:service postfix start 来启动postfix
[root@mail init.d]# service postfix start
Starting postfix: [ OK ]
将其加入开机自启动
[root@mail init.d]# chkconfig --add postfix
[root@mail init.d]# chkconfig postfix on
连接postfix,验正服务启动状况:
建一用户user1
[root@mail ~]# useradd user1
[root@mail ~]# echo "123" |passwd --stdin user1
[root@mail ~]# telnet mail.abc.com 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.abc.com ESMTP Postfix
EHLO mail.abc.com
250-mail.abc.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with .
11111111111111111
.
250 2.0.0 Ok: queued as 45F632482A8
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]# su - user1
[user1@mail ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N 1 [email protected] Tue Feb 7 22:45 13/437
& 1
Message 1:
From [email protected] Tue Feb 7 22:45:37 2012
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Tue, 7 Feb 2012 22:45:18 +0800 (CST)
From: [email protected]
11111111111111111
& quit
Saved 1 message in mbox
[user1@mail ~]$ eixt
[root@mail ~]#
三、为postfix开启基于cyrus-sasl的认证功能
[root@mail ~]# vim /etc/postfix/main.cf
增加以下内容:
############################CYRUS-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
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!
[root@mail sasl2]# vim /usr/lib/sasl2/smtpd.conf
增加如下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
启动sasl,并将其设为开机自启动
[root@mail sasl2]# service saslauthd start
Starting saslauthd: [ OK ]
[root@mail sasl2]# chkconfig saslauthd on
重启postfix
[root@mail sasl2]# service postfix restart
[root@mail ~]# telnet mail.abc.com 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 Welcome to our mail.abc.com ESMTP,Warning: Version not Available!
EHLO mail.abc.com
250-mail.abc.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN #
已出现验证机制
250-AUTH=PLAIN LOGIN #
已出现验证机制
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
四、安装Courier authentication library
[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/src/
[root@mail ~]# cd /usr/src/courier-authlib-0.63.1.20111230/
[root@mail courier-authlib-0.63.1.20111230]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include
[root@mail courier-authlib-0.63.1.20111230]# make && make install
[root@mail ~]#chmod 755 /usr/local/courier-authlib/var/spool/authdaemon
[root@mail ~]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@mail ~]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
修改文件/etc/authdaemonrc
[root@mail ~]# vim /etc/authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
[root@mail ~]# vim /etc/authmysqlrc
修改的内容:
MYSQL_SERVER localhost
MYSQL_PORT 3306
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_DATABASE extmail
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD '2525'
MYSQL_GID_FIELD '2525'
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir)
[root@mail ~]# cd /usr/src/courier-authlib-0.63.1.20111230/
[root@mail courier-authlib-0.63.1.20111230]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail ~]#chmod 755 /etc/init.d/courier-authlib
[root@mail ~]# chkconfig --add courier-authlib
[root@mail ~]# chkconfig --level 2345 courier-authlib on
[root@mail ~]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
[root@mail ~]# ldconfig –v
[root@mail ~]# service courier-authlib start
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
[root@mail ~]# mkdir -pv /var/mailbox
mkdir: created directory `/var/mailbox'
[root@mail ~]# chown -R postfix /var/mailbox
接下来重新配置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
五、让postfix支持虚拟域和虚拟用户
1、
[root@mail ~]# vim /etc/postfix/main.cf
添加如下内容;
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
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:2525
virtual_gid_maps = static:2525
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
##########################QUOTA Settings########################
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 Tidy your mailbox and try again later.
virtual_overquota_bounce = yes
2、使用extman源码目录下docs目录中的extmail.sql和init.sql建立数据库:
[root@mail ~]# tar -zxvf extman-1.1.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/extman-1.1/docs/
[root@mail docs]# mysql -u root -p
Enter password:
[root@mail docs]# mysql -u root -p
Enter password:
密码为“redhat”
mysql -u root -p
进行验证
[root@mail docs]# cp mysql* /etc/postfix/
3、授予用户extmail访问extmail数据库的权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql>FLUSH PRIVILEGES;
让设置的内容生效
具体操作:
[root@mail docs]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
重启postfix
[root@mail docs]# service postfix restart
六、配置dovecot
[root@mail ~]# vim /etc/dovecot.conf
增加一行:
mail_location = maildir:/var/mailbox/%d/%n/Maildir
注释掉796、829、897、904行、
打开870、872、874行,修改872行:
打开931、933、934行,修改933行:
[root@mail ~]# vim /etc/postfix/main.cf
编辑新文件dovecot-mysql.conf
[root@mail ~]# vim /etc/dovecot-mysql.conf
添加如下内容:
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
启动dovecot
[root@mail ~]# service dovecot start
[root@mail ~]# chkconfig dovecot on
七、安装Extmail-1.2 (先安装httpd)
1、安装
[root@mail ~]# tar -zxvf extmail-1.2.tar.gz -C /usr/src/
[root@mail ~]# mkdir -pv /var/www/extsuite
[root@mail ~]# cd /usr/src/
[root@mail src]# mv extmail-1.2 /var/www/extsuite/extmail
[root@mail src]# cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf
2、修改主配置文件
[root@mail src]# vim /var/www/extsuite/extmail/webmail.cf
SYS_USER_LANG = en_US
语言选项,可改作:
SYS_USER_LANG = zh_CN
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
SYS_MYSQL_USER = db_user
SYS_MYSQL_PASS = db_pass
以上两句句用来设置连接数据库服务器所使用用户名、密码和邮件服务器用到的数据库,这里修改为:
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_AUTHLIB_SOCKET = /var/spool/authdaemon/socket
此句用来指明authdaemo socket文件的位置,这里修改为:
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
3、apache相关配置
由于extmail要进行本地邮件的投递操作,故必须将运行apache服务器用户的身份修改为您的邮件投递代理的用户;本例中打开了apache服务器的suexec功能,故使用以下方法来实现虚拟主机运行身份的指定。此例中的MDA为postfix自带,因此将指定为postfix用户:
编辑apache配置文件
[root@mail ~]# vim /etc/httpd/conf/httpd.conf
如果您没有打开apache服务器的suexec功能,也可以使用以下方法解决:
User postfix
Group postfix
在最后添加如下内容:
ServerName mail.abc.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
修改 cgi执行文件属主为apache运行身份用户:
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/
4、依赖关系的解决
extmail
将会用到perl的Unix::syslogd功能,您可以去http://search.cpan.org搜索下载原码包进行安装
[root@mail ~]# tar -zxvf Unix-Syslog-1.1.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/Unix-Syslog-1.1/
[root@mail Unix-Syslog-1.1]# perl Makefile.PL
[root@mail Unix-Syslog-1.1]# make && make install
启动apache
[root@mail Unix-Syslog-1.1]# service httpd start
[root@mail Unix-Syslog-1.1]# chkconfig httpd on
八、
安装Extman-1.1
1、安装及基本配置
[root@mail ~]# tar -zxvf extman-1.1.tar.gz -C /usr/src/
[root@mail ~]# cd /usr/src/
[root@mail src]# mv extman-1.1 /var/www/extsuite/extman
[root@mail ~]# cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf
[root@mail ~]# vim /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /home/domains
此处即为您在前文所设置的用户邮件的存放目录,可改作:
SYS_MAILDIR_BASE = /var/mailbox
修改
SYS_CAPTCHA_ON = 1
为
SYS_CAPTCHA_ON = 0
修改cgi目录的属主:
[root@mail ~]# chown -R postfix.postfix /var/www/extsuite/extman/cgi/
在apache的主配置文件中Extmail的虚拟主机部分,添加如下两行:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
创建其运行时所需的临时目录,并修改其相应的权限:
[root@mail ~]# mkdir -pv /tmp/extman
[root@mail ~]# chown postfix.postfix /tmp/extman
[root@mail ~]#
编辑/etc/postfix/main.cf
注释掉165、166行
重启apache服务
测试:
在浏览器中输入http://mail.abc.com/extmail
已成功
选择管理即可登入extman进行后台管理了。默认管理帐号为:[email protected] 密码为:extmail*123*
注册新用户
此时已可以正常接收发送邮件了
至此我们已经搭建好最基本的电子邮件服务器了。