postfix+courier-imap+maildrop+courier-authlib+extmail+extman

本文属于转载,链接地址为 http://blog.sina.com.cn/harleychen
过程中加入了遇到的一些问题的解决办法。
 
环境:centos5.4,关闭防火墙,关闭selinux。
配置yum
cd /etc/yum.repos.d
mv CentOS-Base.repo  CentOS-Base.repo.save
wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
mv CentOS-Base.repo.5 CentOS-Base.repo
 
设置时间:
yum -y install ntp
ntpdate 210.72.145.44 && clock -w                      ##中国科学院时间服务器ip
 
导入软件包key:
rpm --import /etc/pki/rpm-gpg/RPM*
 
安装php相关组件:
yum -y install php-mcrypt php-mhash libmcrypt libmcrypt-devel libmhash libmhash-devel
 
安装amp:
yum -y install httpd httpd-devel mysql mysql-devel mysql-server php php-xml php-cli php-pdo php-mbstring php-mcrypt php-gd php-common php-devel php-mysql
 
启动服务加入开机启动:
service httpd start                ##此时可能提示修改配置文件的ServerName为相应ip
service mysql start               ##mysqladmin -uroot password 'redhat' 修改密码
chkconfig --level 3 httpd on
chkconfig --level 3 mysqld on
此处可以选择安装phpmyadmin用于方便管理mysql,如果是光盘安装的php,版本是5.1 ,phpmyadmin 只能用2.11.8 系列的, 高版本的需要Php 5.2以上,所以自己选择好对应版本,以及升级。
tar zxvf phpmyadmin-2.11.8.1-all-languages-utf-8-only.tar.gz
mv phpMyAdmin-2.11.8.1-all-languages-utf-8-only /var/www/html/phpmyadmin
cp config.sample.inc.php config.inc.php
具体配置信息略。
 
导入extman后台数据库
tar zxvf extman-0.2.5.tar.gz
cd extman-0.2.5/docs/
mysql -u root -p < extmail.sql  输入密码
mysql -u root -p < init.sql  输入密码
在mysql中查看相关信息
 
通过源码制作rpm包
确保以下文件夹存在
/usr/src/redhat/SPECS
/usr/src/redhat/RPMS
/usr/src/redhat/SOURCES
/usr/src/redhat/BUILD
用rpmbuild生成rpm包的时候需要如下关联关系:
yum -y install postgresql-devel expect libtool-ltdl-devel
 
安装courier-authlib
tar jxvf courier-authlib-0.62.2.tar.bz2
cd courier-authlib-0.62.2
cp courier-authlib.spec /usr/src/redhat/SPECS
cd ..
cp courier-authlib-0.62.2.tar.bz2 /usr/src/redhat/SOURCES
cd /usr/src/redhat/SPECS
rpmbuild -bb courier-authlib.spec (创建rpm 文件)
 
cd /usr/src/redhat/RPMS/i386
rpm -ivh courier-authlib-0.62.2-1.i386.rpm
rpm -ivh courier-authlib-devel-0.62.2-1.i386.rpm
rpm -ivh courier-authlib-mysql-0.62.2-1.i386.rpm
 
配置authlibdaemon
mv /etc/authlib/authdaemonrc /etc/authlib/authdaemonrc.save
vi /etc/authlib/authdaemonrc
输入如下内容:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
daemons=10
authdaemonvar=/var/spool/authdaemon
DEBUG_LOGIN=2
DEFAULTOPTIONS="wbnodsn=1"
LOGGEROPTS=""
 
配置authmysqlrc
mv /etc/authlib/authmysqlrc /etc/authlib/authmysqlrc.save
vi /etc/authlib/authmysqlrc
输入如下内容:
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_PORT 0
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_OPT 0
MYSQL_DATABASE extmail
MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\
CONCAT('/home/data/domains/',homedir), \
CONCAT('/home/data/domains/',maildir), \
quota, \
name \
FROM mailbox \
WHERE username = '$(local_part)@$(domain)'
 
启动authlib服务
service courier-authlib start
chmod 777 /var/spool/authdaemon
chkconfig --level 3 courier-authlib on
 
安装courier-imap
yum -y install fam-devel openldap-servers
这里要注意不能用root身份生成rpm包
useradd quan
passwd quan
su - quan
mkdir -p rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
vi ~/.rpmmacros
%_topdir /home/quan/rpm
 
tar zxvf courier-imap-4.4.1.tar.bz2
cp courier-imap-4.4.1.tar.bz2 ~/rpm/SOURCES
cd courier-imap-4.4.1
cp courier-imap.spec ~/rpm/SPECS
cd ~/rpm/SPECS
vi courier-imap.spec
将以下内容:
%if %suse_version
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel %([ %{suse_version} -gt 819 ] && echo /usr/include/fam.h)
%else
BuildPreReq: rpm >= 4.0.2 sed /usr/include/fam.h openldap-devel openldap-servers
%endif
修改为:
%if %suse_version
BuildPreReq: rpm >= 3.0.5 /usr/bin/sed openldap2 openldap2-devel
%else
BuildPreReq: rpm >= 4.0.2 sed openldap-devel openldap-servers
%endif
开始创建rpm包
rpmbuild -bb courier-imap.spec
退出quan用户:exit
安装courier-imap包
rpm -ivh /home/quan/rpm/RPMS/i386/courier-imap-4.4.1-1.i386.rpm
启动服务
service courier-imap start
chkconfig --level 3 courier-imap on
 
cyrus-sasl采用系统自带的2.1.22版本
确保有以下包的存在
rpm -ihv cyrus-sasl-lib-2.1.22-8.i386.rpm
rpm -ihv cyrus-sasl-2.1.22-8.i386.rpm
rpm -ihv cyrus-sasl-plain-2.1.22-8.i386.rpm
rpm -ivh cyrus-sasl-devel-2.1.22-8.i386.rpm
 
vi /usr/lib/sasl2/smtpd.conf
pwcheck_method:authdaemond
log_level:3
mech_list:PLAIN LOGIN
authdaemond_path:/var/spool/authdaemon/socket
 
安装postfix
wget http://ftp.wl0.org/official/2.5/SRPMS/postfix-2.5.4-2.src.rpm
和上面一样制作rpm 包
这里编辑下 postfix.spec 文件,修改下面对应内容,修改好后为:
%define distribution rhel-5.0
%define with_mysql_redhat 1
%define with_sasl 2
%define with_vda 1
生成rpm 包,并安装,安装方法和上面一样,在RPMS 文件夹里面你可以找到postfix 的rpm 包。
切换系统默认的MTA
alternatives --config mta (选择2,postfix)
rpm �Ce sendmail
cd /usr/sbin/
mv sendmail sendmail.bak
newaliases
ln -s sendmail.postfix sendmail
 
配置Postfix
cd /etc/postfix
mv main.cf main.cf.backup
vi main.cf
输入下面内容:
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
unknown_local_recipient_reject_code = 550
debug_peer_level = 2
debugger_command =
       PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
       ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = /usr/share/doc/postfix-2.5.2-documentation/html
manpage_directory = /usr/share/man
sample_directory = /etc/postfix
readme_directory = /usr/share/doc/postfix-2.5.2-documentation/readme
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
myhostname = quan.mail
mydomain = quanmail.com
mydestination = $myhostname
smtpd_banner = quanmail.com ESMTP Mail System
message_size_limit = 14680064
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_base = /home/data/domains
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf
virtual_transport = maildrop:
maildrop_destination_recipient_limit = 1
#sasl
smtpd_sasl_auth_enable = yes
smtpd_sasl2_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination,reject_unauth_pipelining,
reject_invalid_hostname
 
复制 extman/docs 目录下所有 .cf 文件到/etc/postfix
cp /usr/local/src/extman-0.2.5/docs/mysql_virtual_* . /etc/postfix
因为配置文件的用户、密码与刚开始导入extmail 数据库时一样,所以不用修改。
启动postfix
service postfix start
chkconfig --level 3 postfix on
 
安装maildrop
安装关联组件
yum -y install pcre-devel
wget http://nchc.dl.sourceforge.net/sourceforge/courier/maildrop-2.0.4.tar.bz2
cp maildrop-2.0.4.tar.bz2 /usr/src/redhat/SOURCES
tar xjfv  maildrop-2.0.4.tar.bz2
cd cp maildrop-2.0.4
cp maildrop.spec /usr/src/redhat/SPECS
编辑maildrop.spec
vi maildrop.spec
将下面:
BuildRequires: /usr/include/fam.h gdbm-devel pcre-devel
改为:
BuildRequires: gdbm-devel pcre-devel
把下面:
%configure --with-devel --enable-userdb --enable-maildirquota \
--enable-syslog=1 --enable-trusted-users='root mail daemon postmaster qmaild mmdf' \
--enable-restrict-trusted=0 \
--enable-sendmail=/usr/sbin/sendmail
改为:
%configure --with-devel --enable-userdb --enable-maildirquota \
--enable-syslog=1 --enable-trusted-users='root mail daemon postmaster qmaild mmdf' \
--enable-restrict-trusted=0 --enable-sendmail=/usr/sbin/sendmail \
--enable-authlib
 
安装生成的rpm包
 
添加虚似用户及创建目录
groupadd -g 1000 vgroup
useradd -g 1000 �Cu 1000 �Cs /sbin/nologin �Cd /dev/null vuser
配置master.cf 文件
vi /etc/postfix/master.cf
在最后面加入下面内容:
maildrop unix - n n - - pipe
flags=DRhu user=vuser argv=/usr/bin/maildrop -d ${user}@${nexthop} ${recipient} ${user} ${extension} ${nexthop}
创建邮件存储目录
mkdir -p /home/data/domains/extmail.org/postmaster
maildirmake /home/data/domains/extmail.org/postmaster/Maildir
chown -R vuser:vgroup /home/data/domains/
####### 上面的extmail.org 默认extmail 使用这个域名,之后你可以通过extman 修改掉。
测试maildrop
[root@localhost ~]# echo "test" | maildrop -V 10 -d [email protected]
maildrop: authlib: groupid=1000
maildrop: authlib: userid=1000
maildrop: authlib: [email protected], home=/home/data/domains/extmail.org/postmaster, mail=/home/data/domains/extmail.org/postmaster/Maildir/
maildrop: Changing to /home/data/domains/extmail.org/postmaster
Message start at 0 bytes, envelope [email protected]
maildrop: Attempting .mailfilter
maildrop: Delivery complete.
出现上以信息说明authlib,maildrop 工作正常
测试pop3
[root@localhost ~]# telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user [email protected]
+OK Password required.
pass extmail
+OK logged in.
List
+OK POP3 clients that break here, they violate STD53.
1 6
. ############# 这里退出是用符号 点 。
retr 1
+OK 6 octets follow.
test
.
quit
+OK Bye-bye.
Connection closed by foreign host.
测试postfix
[root@localhost ~]# perl -MMIME::Base64 -e 'print encode_base64("postmaster\@extmail.org");'
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
[root@localhost ~]# perl -MMIME::Base64 -e 'print encode_base64("extmail");'
ZXh0bWFpbA==
[root@localhost ~]# service postfix restart (重启一下)
[root@localhost ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 quan.mail ESMTP Mail System
ehlo test.com
250-mail.quanmail.com
250-PIPELINING
250-SIZE 14680064
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
ZXh0bWFpbA==
235 2.7.0 Authentication successful
quit
221 2.0.0 Bye
Connection closed by foreign host
安装extman/extmail
A、配置apache
修改/etc/httpd/conf/httpd.conf,设置虚拟账户为vuser:group 将下面的选项改为:
user vuser
group vgroup
[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# vim extmail.conf
输入下面的内容:
Alias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman /var/www/extsuite/extman/html/
<Location "/extman/cgi">
SetHandler cgi-script
Options +ExecCGI
</Location>
# config for ExtMail
Alias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html/
<Location "/extmail/cgi">
SetHandler cgi-script
Options +ExecCGI
</Location>
[root@localhost ~]# mkdir /var/www/extsuite
[root@localhost ~]# tar zxf extmail-1.0.5.tar.gz
[root@localhost ~]# cp -r extmail-1.0.5 /var/www/extsuite/extmail
[root@localhost ~]# cp -r extman-0.2.5 /var/www/extsuite/extman
配置extmail 参数
[root@localhost ~]# cd /var/www/extsuite/extmail/
[root@localhost extmail]# cp webmail.cf.default webmail.cf
修改webmail.cf 下面的选项
SYS_SESS_DIR = /tmp/extmail
SYS_MAILDIR_BASE = /home/data/domains
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
配置extman 参数
[root@localhost extmail]# cd /var/www/extsuite/extman/
修改webman.cf 下面的选项为邮件目录:
SYS_MAILDIR_BASE = /home/data/domains
创建session 目录
[root@localhost extman]# mkdir /tmp/{extman,extmail}
[root@localhost extman]# chown vuser:vgroup /tmp/ext*
配置后台日志分析工具
[root@localhost addon]# cd /var/www/extsuite/extman/addon/
[root@localhost addon]# cp -r mailgraph_ext /usr/local/
将下面的内容加入/etc/rc.local
/usr/local/mailgraph_ext/mailgraph-init start
/usr/local/mailgraph_ext/qmonitor-init start
安装所依懒的软件包
[root@localhost mailgraph_ext]# yum -y install rrdtool perl-rrdtool perl-GD perl-File-Tail
启动后台进程
[root@localhost mailgraph_ext]# /usr/local/mailgraph_ext/qmonitor-init start
Starting queue statistics grapher: qmonitor
[root@localhost mailgraph_ext]# /usr/local/mailgraph_ext/mailgraph-init start
Starting mail statistics grapher: mailgraph_ext
访问extmail/extman
打开浏览器,输入http://your_ip_address/extmail 注意:your_ip_address 为你实际的ip
第一个测试用户为:postmaster 密码:extmail 域:extmail
打开浏览器,输入http://your_ip_address/extman
用户为:[email protected] 密码为:extmail*123*
注意:进入系统后要修改密码及找回密码的提示问题、答案。
安装slockd
slockd 是一个基于策略的垃圾邮件软件,很多用户反映使用后,反垃圾效果非常明显,但是有部分用户由于对该软件的使用,特性不了解,而产生了很多麻烦。
所在在此建议,如果你对该软件不了解,或者系统里的垃圾邮件少,可以暂时不安装。
[root@localhost ~]# tar zxf slockd-0.2beta1.tar.gz
[root@localhost ~]# cp -r slockd-0.2beta1 /usr/local/slockd
[root@localhost ~]# cd /usr/local/slockd
将下面的内容加入/etc/rc.local
/usr/local/slockd/slockd-init start
修改/etc/postfix/main.cf 将原先的内容:
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
改为:
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname,
check_policy_service inet:127.0.0.1:10030
重载postfix 配置文件
[root@localhost slockd]# service postfix reload
这里注意下,apache 改变运行id 后,php session 功能将会出现问题,因为session 的存储目录权限没有跟着改变为新的,所以phpmyadmin 等就会提示错误。
只要执行下面的命令即可解决问题。
[root@localhost slockd]# chown -R vuser:vgroup /var/lib/php/session/
 

你可能感兴趣的:(postfix,休闲,ExtMail,extman,maildrop)