学习extmail搭建的博友想必一定对Linux以及extmail有一定的了解,所以那些原理性的内容我就不准备那么详细了,直接来实战环节。
一、准备系统环境
上传软件包到系统中
[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media groupinstall "Server Platform Development"
[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media groupinstall "Development tools"
[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media remove postfix
[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media install httpd mysql mysql-server mysql-devel openssl-devel dovecot perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgp-devel libtool-ltdl-ltdl-devel expect
[root@localhost ~]# service mysqld start//启动MySQL
[root@localhost ~]# mysqladmin -u root -p password 'inferr'//配置MySQL密码
Enter password: //初始数据库时无密码,此处直接回车
[root@localhost ~]#
二、安装Postfix
安装系统的时候系统已安装过Postfix 而我这儿的Postfix的源码安装的,所以需要将系统安装的RPM包Postfix删除掉,再来安装。不过删除之前复制一下它的服务控制脚本,这样等我们安装完源码包的Postfix后就不用编写脚本了。
[root@localhost ~]# rpm -qa |grep postfix
postfix-2.6.6-2.2.el6_1.i686 //确定是否安装
[root@localhost ~]#
[root@localhost ~]# cp /etc/init.d/postfix /etc/init.d/postfix.bak
[root@localhost ~]# yum --disablerepo=\* --enablerepo=c6-media remove postfix
由于之前安装过Postfix的原因,它所形成的用户以及组都是存在的。必须删除掉,再来配置源码的Postfix
[root@localhost extmail]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/ //释放源码包
[root@localhost extmail]# id postfix
uid=89(postfix) gid=89(postfix) groups=89(postfix),12(mail)
[root@localhost extmail]#
[root@localhost extmail]# userdel -r postfix//删除用户
userdel: /var/spool/postfix not owned by postfix, not removing //Postfix这个目录没有被删掉,这个可以不做理会,影响不大。
[root@localhost extmail]#
[root@localhost extmail]# groupdel postfix //删除组
[root@localhost extmail]# groupadd -g 2525 -r postfix //添加一个ID为2525的系统组
[root@localhost extmail]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
[root@localhost extmail]# groupdel postdrop //删除系统创建的postdrop组
[root@localhost extmail]# groupadd -g 2526 postdrop
[root@localhost extmail]# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop //添加一个ID为2526没有家目录且不可登录的用户名为postdrop的用户
确定结果
[root@localhost extmail]# id postfix
uid=2525(postfix) gid=2525(postfix) groups=2525(postfix)
[root@localhost extmail]# id postdrop
uid=2526(postdrop) gid=2526(postdrop) groups=2526(postdrop)
[root@localhost extmail]#
进入释放后的目录,编译Postfix.
[root@localhost extmail]# cd /usr/local/src/postfix-2.8.2/
[root@localhost 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' //产生Makefile文件
[root@localhost postfix-2.8.2]#make && make install
make install 的时候它会询问你一些文件的安装目录,如下。不过大部分安装目录路径采用默认的都行了,只用修改一个临时目录的路径.
Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to other
machines.
install_root: [/]
Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/usr/local/src/postfix-2.8.2] /tmp
Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix]
编译完成之后执行newaliases
恢复之前保留的Postfix启动脚本
[root@localhost postfix-2.8.2]# mv /etc/init.d/postfix.bak /etc/init.d/postfix
由于/var/lib/postfix这个目录的所有者还是系统的,因此需要修改一下。
[root@localhost postfix-2.8.2]# ll -d /var/lib/postfix/
drwx------. 2 89 root 4096 Dec 2 2011 /var/lib/postfix/
[root@localhost postfix-2.8.2]#
[root@localhost postfix-2.8.2]# chown -R postfix /var/lib/postfix/
同时也将/var/spool/postfix/目录下的public、private目录的所有者修改一下。
[root@localhost postfix-2.8.2]# ll /var/spool/postfix/
[root@localhost postfix-2.8.2]# chown -R postfix /var/spool/postfix/public/
[root@localhost postfix-2.8.2]# chown -R postfix /var/spool/postfix/private/
启动Postfix
[root@localhost postfix-2.8.2]# chkconfig --add postfix //加入开机服务
[root@localhost postfix-2.8.2]# chkconfig postfix on //设置开机启动
修改主机名,方便实验。为使名称能立即生效,可以从终端从新登陆一次,如果这样还不行的话就只好重启主机了。
[root@localhost postfix-2.8.2]# vim /etc/sysconfig/network
安装测试时需要工具
[root@test ~]# yum --disablerepo=\* --enablerepo=c6-media install perl-CGI perl-CGI-Session
[root@test ~]# yum --disablerepo=\* --enablerepo=c6-media install telnet
配置Postfix
[root@test ~]# vim /etc/postfix/main.cf
75 myhostname = test.com //配置主机名
83 mydomain = sina.com //配置默认管理域
99 myorigin = $mydomain //指定起源域
161 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain //启用mydestination
260 mynetworks = 127.0.0.0/8 //配置管理网段
[root@test ~]# service postfix restart
安装配置完成之后添加一个用户可以小小测试一下.
[root@test ~]# useradd abc
经过小小的测试,说明搭建的邮件系统还是可以正常工作的。
三、安装配置身份验证所需的Syrus-SASL.
[root@test ~]# rpm -qa |grep cyrus-sasl
cyrus-sasl-plain-2.1.23-13.el6_3.1.i686
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686
cyrus-sasl-lib-2.1.23-13.el6_3.1.i686
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686
cyrus-sasl-2.1.23-13.el6_3.1.i686 //cyrus-sasl主程序已经装过
[root@test ~]#
开启基于cyrus-sasl的认证功能
[root@test ~]# cd /usr/local/lib
[root@test lib]# mkdir sasl2
[root@test lib]# cd sasl2/
[root@test sasl2]# vim smtpd.conf
编辑Postfix的配置文件,插入下列内容
[root@test sasl2]# vim /etc/postfix/main.cf
############################CYRUS-SASL############################
broken_sasl_auth_clients = yessmtpd_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@test sasl2]# service postfix restart
[root@test sasl2]# service saslauthd start
[root@test sasl2]# chkconfig --add saslauthd
[root@test sasl2]# chkconfig saslauthd on
四、编译安装courier-authlib
[root@test extmail]# tar -jxvf courier-authlib-0.63.0.tar.bz2 -C /usr/local/src/
[root@test extmail]# cd /usr/local/src/courier-authlib-0.63.0/
[root@test courier-authlib-0.63.0]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc/ --with-authmysql --with-mysql-libs=/usr/lib/mysql/ --with-mysql-include=/usr/include/mysql/ --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc
[root@test courier-authlib-0.63.0]# make && make install
进入安装目录
[root@test courier-authlib-0.63.0]# cd /usr/local/courier-authlib/
指定courier-authlib的库文件路径
[root@test courier-authlib]# vim /etc/ld.so.conf.d/courier-authlib.conf
刷新并确定结果
[root@test courier-authlib]# ldconfig
[root@test courier-authlib]# ldconfig -pv |grep courier
处理头文件路径
[root@test courier-authlib]# ln -s /usr/local/courier-authlib/include/ /usr/include/courier-authlib
拷贝服务控制脚本
[root@test courier-authlib]# cp /usr/local/src/courier-authlib-0.63.0/courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@test courier-authlib]# chmod a+x /etc/init.d/courier-authlib //赋予可执行权限
修改服务运行目录权限
[root@test courier-authlib]# chmod 755 var/spool/authdaemon/
拷贝启动服务需要的两个文件并编辑相关配置
[root@test courier-authlib]# cp /etc/authmysqlrc.dist /etc/authmysqlrc
[root@test courier-authlib]# cp /etc/authdaemonrc.dist /etc/authdaemonrc
[root@test courier-authlib]# vim /etc/authdaemonrc
[root@test courier-authlib]# vim /etc/authmysqlrc
编辑完成后启动服务,服务可以成功启动,但是查看监听端口的时候并没有端口处于监听模式下。而socket文件确实存在,说明服务已经启动。
[root@test courier-authlib]# service courier-authlib star
[root@test courier-authlib]# netstat -tupln |grep -i cour
[root@test courier-authlib]# chkconfig --add courier-authlib //加入开机启动队列
[root@test courier-authlib]# chkconfig courier-authlib on //设为开机启动
结合Cyrus-sasl与Courier-authlib
创建基目录并修改所有者
[root@test courier-authlib]# mkdir /var/mailbox
[root@test courier-authlib]# chown -R postfix /var/mailbox/
配置SMTP认证
[root@test courier-authlib]# vim /usr/local/lib/sasl2/smtpd.conf
再来编辑Postfix的配置文件,支持虚拟域和虚拟用户。插入内容
[root@test courier-authlib]# vim /etc/postfix/main.cf
########################Virtual Mailbox Settings########################
virtual_mailbox_base = /var/mailbox
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cfvirtual_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 = yesvirtual_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 Tidyyour mailbox and try again later.
virtual_overquota_bounce = yes
重启服务
[root@test courier-authlib]# service courier-authlib restart
[root@test courier-authlib]# service saslauthd restart
导入表格数据
[root@test courier-authlib]# cd /root/extmail/
[root@test extmail]# tar -zxv extman-1.1.tar.gz
[root@test extmail]# cd extman-1.1/docs/
[root@test docs]# mysql -u root -p -p <extmail.sql //数据库
Enter password: //输入密码
[root@test docs]# mysql -u root -p -p <init.sql //初始化数据
Enter password: //输入数据库密码
[root@test docs]#
[root@test docs]# cp mysql_virtual_* /etc/postfix/ //拷贝MySQL虚拟文件
进入数据库确认结果
[root@test docs]# mysql -u root -p
Enter password: //输入数据库密码
授予用户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; //刷新权限
五、 配置dovecot
[root@test ~]# vim /etc/dovecot/conf.d/10-mail.conf
配置MySQL搜索路径
[root@test ~]# vim /etc/dovecot/conf.d/auth-sql.conf.ext
创建搜索文件
[root@test ~]# vim /etc/dovecot/dovecot-sql.conf
启动dovecot
[root@test ~]# service dovecot start
[root@test ~]# chkconfig --add dovecot
[root@test ~]# chkconfig dovecot on
六、安装extmail
[root@test ~]# mkdir /var/www/extsuite
[root@test ~]# tar -zxvf /root/extmail/extmail-1.2.tar.gz -C /var/www/extsuite/
[root@test ~]# mv /root/extmail/extman-1.1 /var/www/extsuite/
[root@test ~]# cp /var/www/extsuite/extman-1.1/ /var/www/extsuite/extman
[root@test ~]# cp /var/www/extsuite/extmail-1.2/ /var/www/extsuite/extmail
[root@test ~]# cd /var/www/extsuite/extmail/
[root@test extmail]# cp webmail.cf.default webmail.cf
[root@test extmail]# vim webmail.cf
修改cgi目录的所有者以及所属组
[root@test extmail]# chown -R postfix:postfix /var/www/extsuite/extmail/cgi/
Apache调用cgi
[root@test extmail]# vim /etc/httpd/conf/httpd.conf
[root@test extman]# service httpd restart
七、安装Uinx-Syslog
[root@test ~]# cd extmail/
[root@test extmail]# tar -zxvf Unix-Syslog-0.100.tar.gz -C /usr/local/src/
[root@test extmail]# cd /usr/local/src/Unix-Syslog-0.100/
[root@test Unix-Syslog-0.100]# perl Makefile.PL
[root@test Unix-Syslog-0.100]# make && make install
八、安装配置extman
[root@test Unix-Syslog-0.100]# cd /var/www/extsuite/extman/
[root@test extman]# cp webman.cf.default webman.cf
[root@test extman]# vim webman.cf
修改Postfix的配置文件并重新启动服务
[root@test extman]# vim /etc/postfix/main.cf
[root@test extman]# service postfix restart
修改Apache的配置文件
[root@test extman]# vim /etc/httpd/conf/httpd.conf
创建extman的临时目录
[root@test extman]# mkdir /tmp/extman
[root@test extman]# chown postfix:postfix /tmp/extman/
测试时,如果邮件发送不出去的话再编辑/etc/postfix/main.cf文件,把160行注释掉。
[root@test extman]# vim /etc/postfix/main.cf