1234e 发表于 2013-6-5 09:18:11

CentOS 6.4 x64 postfix + dovecot + 虚拟用户认证

第一, 首先必须安装 apacachemysqlphp   
CentOS 直接使用 yum 安装
yum -y install httpd httpd-devel mysql php-mysql mysql-server mysql-develmysql-test mysql-connector-odbc64 php pam-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

第二,安装Postfix邮件

tar zxvf postfix-2.10.0.tar.gz
cd postfix-2.10.0
groupadd-g 1200 postdrop
groupadd-g 25 postfix
useradd-u 25 -g 25 -G postdrop -s /sbin/nologin -M postfix
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm'
make install
其间需要配置,我们按照默认方式既可,一直按按回车,既为默认模式安装
输出以下信息:----------------------------------------------------------------------------------------------------------------------------   Warning: you still need to edit myorigin/mydestination/mynetworks   parameter settings in /etc/postfix/main.cf.
   See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html   for information about dialup sites or about sites inside a firewalled   network.
   BTW: Check your /etc/aliases file and be sure to set up aliases   that send mail for root and postmaster to a real person, then run   /usr/bin/newaliases.
-----------------------------------------------------------------------------------------------------------------------------
这里先关闭系统自带的sendmail
chkconfig --level 2345 sendmail off
激活别名功能
newaliases
使用postconf 可查看支持
postconf -m |grep mysql查看是否支持mysql


第三,下面配置postfix
vim /etc/postfix/main.cf
修改 myhostname 为邮件域名
myhostname = mail.11111.com    改成自己的主机名
myorigin = $mydomain
inet_interfaces = all
mynetworks = 127.0.0.0/8
home_mailbox = Maildir/
启动 postfix
postfix start---------------------------------------------------------------------postfix/postfix-script: starting the Postfix mail system----------------------------------------------------------------------




第四,安装配置 dovecot
1. 新建 dovecot 用户
useradd-M -s /sbin/nologin dovecot
编译安装 dovecot
tar zxvf dovecot-1.1.4.tar.gz
cd dovecot-1.1.4
./configure --sysconfdir=/etc/ --with-mysql
make -j 2 && make install

2. 配置 dovecot
cp /etc/dovecot-example.conf/etc/dovecot.conf
vim /etc/dovecot.conf
protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
ssl_disable = yes
mail_location = maildir:~/opt/mailbox/%d/%n/Maildir

3. 启动dovecot(-c指定配置文件)
/usr/local/sbin/dovecot -c /etc/dovecot.conf

ps aux|grep dovecot
lsof -i:110lsof -i:143


第五,添加mysql 虚拟用户支持
tar zxvf extman-1.1.tar.gz
cd extman-1.1/docs/
1.导入数据库
mysql -uroot -p < extmail.sql
mysql -uroot -p < init.sql

2. 拷贝mysql认证配置文件到 postfix 目录
cp mysql_virtual_* /etc/postfix/

3. 建虚拟用户vuser
groupadd -g 1000 vuser
useradd -u 1000 -g 1000 -s /sbin/nologin -M vuser
mkdir /opt/mailbox
chown -R vuser:vuser /opt/mailbox
4. 修改main.cf 配置文件,增加以下内容支持mysql 认证查询
vim /etc/postfix/main.cf


# extmail config herevirtual_mailbox_base = /opt/mailboxvirtual_uid_maps = static:1000virtual_gid_maps = static:1000virtual_transport = virtualvirtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cfvirtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cfvirtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cfvirtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf


第六,搭建extmail
1. 安装依赖包.
tar zxvf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL && make && make install
cd ..

tar zxvf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL && make && make install
cd ..

tar zxvf DBD-mysql-4.020.tar.gz
cd DBD-mysql-4.020
perl Makefile.PL && make && make install
cd ..

2. 安装 extmail
tar zxvf extmail-1.2.tar.gz
cp -r extmail-1.2 /opt/htdocs/extmail
cd /opt/htdocs/extmail/
chown -R postfix:postfix cgi/
cp webmail.cf.default webmail.cf
vim webmail.cf
SYS_CONFIG = /opt/htdocs/extmail/SYS_LANGDIR = /opt/htdocs/extmail/langSYS_TEMPLDIR = /opt/htdocs/extmail/htmlSYS_MAILDIR_BASE = /opt/mailboxSYS_MYSQL_USER = extmailSYS_MYSQL_PASS = extmailSYS_MYSQL_DB = extmailSYS_MYSQL_HOST = localhostSYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sockSYS_G_ABOOK_FILE_PATH = /opt/htdcos/extmail/globabook.cf

3. 配置httpd 虚拟主机
vim /etc/httpd/conf/httpd.conf
User vuserGroup vuser
<VirtualHost *:80>   ServerAdmin admin@moxian.com   DocumentRoot /var/www/html/extmail/html   ServerName mail.moxian.com   ErrorLog logs/error.log   CustomLog logs/access.log commonScriptAlias /extmail/cgi/ "/var/www/html/extmail/cgi/"   Alias /extmail "/var/www/html/extmail/html/"</VirtualHost>



第七,搭建extman
1. 安装依赖包.
yum install gd-devel -y

tar zxvf GD-2.46.tar.gz
cd GD-2.46
perl Makefile.PL && make && make install
cd ..

tar zxvf File-Tail-0.99.3.tar.gz
cd File-Tail-0.99.3
perl Makefile.PL && make && make install
cd ..

2. 安装图形日志依赖包rrdtool,rrdtool-perl(centos 6.0以上的可用 yum 安装   yum -y install rrdtool rrdtool-perl )
centos默认yum源中没有这两个包,所以需要手动添加yum源来安装这两个包
vim /etc/yum.repos.d/CentOS-Base.repo
---------------------------------------------------------------name=Dag RPM Repository for Red Hat Enterprise Linuxbaseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/daggpgcheck=1gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txtenabled=1-------------------------------------------------------------------
yum install rrdtool rrdtool-perl -y


3. 安装extman
tar zxvf extman-1.1.tar.gz
cp -r extman-1.1 /opt/htdocs/extman
cd /opt/htdocs/extman/
chown -R postfix:postfix cgi/
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman/
chmod -R 777 /tmp/extman/

4. 修改extman配置参数, 让其支持MYSQL 查询
cp webman.cf.default webman.cf
vim webman.cf
SYS_CONFIG = /opt/htdocs/extman/SYS_LANGDIR = /opt/htdocs/extman/langSYS_TEMPLDIR = /opt/htdocs/extman/htmlSYS_MAILDIR_BASE = /opt/mailboxSYS_SESS_DIR = /tmp/extman/SYS_DEFAULT_UID = 1000SYS_DEFAULT_GID = 1000SYS_MYSQL_USER = webmanSYS_MYSQL_PASS = webmanSYS_MYSQL_DB = extmailSYS_MYSQL_HOST = localhostSYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock

5. 修改虚拟主机配置文件,使其支持extman
在上面虚拟机中添加<VirtualHost *:80>   .......   ScriptAlias /extman/cgi "/opt/htdocs/extman/cgi/"   Alias /extman "/opt/htdocs/extman/html/"</VirtualHost>

6. 启动extman 中自带的图形化支持脚本
/opt/htdocs/extman/daemon/cmdserver -d
cp -a /opt/htdocs/extman/addon/mailgraph_ext/ /usr/local/
/opt/htdocs/extman/addon/mailgraph_ext/mailgraph-init start
/opt/htdocs/extman/addon/mailgraph_ext/qmonitor.pl &


第八,虚拟用户发信认证
1. 安装courier-authlib认证软件包
tar jxvf courier-authlib-0.62.4.tar.bz2
cd courier-authlib-0.62.4
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-mysql-libs=/usr/lib64/mysql/ --with-mysql-includes=/usr/include/mysql/
make -j 8 && make install && make install-configure


2. 把courier-authlib链接库添加进系统默认支持库
vim /etc/ld.so.conf.d/courier-authlib.conf
/usr/local/courier-authlib/lib/courier-authlib


3. 编辑authdaemonrc,使其支持mysql认证
cd /usr/local/courier-authlib/etc/authlib/
vim authdaemonrc
authmodulelist="authmysql"authmodulelistorig="authmysql"

chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/


4. 编辑authmysqlrc设置和mysql的连接参数.
cd /usr/local/courier-authlib/etc/authlib/
vim authmysqlrc
MYSQL_SERVER            localhostMYSQL_USERNAME          extmailMYSQL_PASSWORD          extmailMYSQL_SOCKET            /var/lib/mysql/mysql.sockMYSQL_PORT            3306MYSQL_DATABASE          extmailMYSQL_USER_TABLE      mailboxMYSQL_CRYPT_PWFIELD   passwordMYSQL_UID_FIELD         1000MYSQL_GID_FIELD         1000MYSQL_LOGIN_FIELD       usernameMYSQL_HOME_FIELD      concat('/opt/mailbox/',homedir)MYSQL_NAME_FIELD      nameMYSQL_MAILDIR_FIELD   concat('/opt/mailbox/',maildir)


5. 将脚本文件添加进默认环境变量中,并添加开机启动程序
cp /opt/software/courier-authlib-0.62.4/courier-authlib.sysvinit /usr/local/bin/courier-authlib
chmod 755/usr/local/bin/courier-authlib
courier-authlib start


6. 新建smtpd.conf文件,使postfix支持认证。
vim /usr/lib64/sasl2/smtpd.conf
----------------------------------------------------------------------------pwcheck_method: authdaemondmech_list:PLAIN LOGINauthdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket-----------------------------------------------------------------------------
cp -a /usr/local/courier-authlib/sbin/authtest /usr/local/sbin/



第九,虚拟用户收信认证
1. 编辑dovecot.conf 文件 打开mysql认证,关闭默认pam认证
vim /etc/dovecot.conf--------------------------------------------------------------------------------------------------
protocols = imap imaps pop3 pop3s  <---默认没有打开pop3,需要手动添加disable_plaintext_auth = no       <------允许plain认证ssl_disable = yes<------禁用ssl加密mail_location = maildir:~/opt/mailbox/%d/%n/Maildirmechanisms = plain#passdb pam {<--默认是打开的,需要注释掉#}passdb sql {       args = /etc/dovecot-mysql.conf   } userdb sql {       args = /etc/dovecot-mysql.conf    }
---------------------------------------------------------------------------------------------------

2. 创建dovecot-mysql.conf,设置和mysql连接及查询参数
vim /etc/dovecot-mysql.conf
-----------------------------------------------------------------------------------------------------------------driver = mysqlconnect=host=localhostdbname=extmailuser=extmailpassword=extmaildefault_pass_scheme=CRYPTpassword_query=SELECTusernameASuser,passwordASpasswordFROMmailboxWHEREusername= '%u'user_query=SELECTmaildir,uidnumberASuid,gidnumberASgidFROMmailboxWHEREusername='%u'--------------------------------------------------------------------------------------------------------------------


3. 重启 dovecot
pkill dovecot
dovecot -c /etc/dovecot.conf



第十,虚拟用户SASL身份认证
1. 重新编译 postfix
postfix stop
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl-DUSE_TLS ' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2   -lssl -lcrypto'
make -j 8
2. 升级postfix(升级)
make upgrade
重新启动 postfix
postfix start
postconf-a查看是否支持 cyrus

3. 修改main.cf配置文件,配置sasl认证参数
vim /etc/postfix/main.cf
在最后面增加 sasl认证
#sasl认证smtpd_sasl_auth_enable = yesbroken_sasl_auth_clients = yessmtpd_sasl_security_options = noanonymoussmtpd_recipient_restrictions =       permit_mynetworks,       permit_sasl_authenticated,       reject_non_fqdn_hostname,       reject_unknown_sender_domain,       reject_non_fqdn_sender,       reject_non_fqdn_recipient,       reject_unauth_destination,       reject_unauth_pipelining,       reject_invalid_hostnamesmtpd_sender_login_maps =       mysql:/etc/postfix/mysql_virtual_sender_maps.cf,       mysql:/etc/postfix/mysql_virtual_alias_maps.cf

















错误 1
Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).BEGIN failed--compilation aborted.
yum -y install perl-CPAN

然后
perl -MCPAN -eshell
出现cpan>
输入
install CGI

xinxuaw231 发表于 2013-6-5 17:58:40

恋爱就是无数个饭局,结婚就是一个饭局。

lanxi256 发表于 2013-6-5 23:35:17

人生不能像做菜、把所有的料都准备好才下锅!

我是条汉子 发表于 2013-6-6 06:19:35

丑,但是丑的特别,也就是特别的丑!

wendu 发表于 2013-6-6 07:33:13

路过,学习下

榕叶 发表于 2013-6-6 08:48:49

比我有才的都没我帅,比我帅的都没我有才!

zxcvb12 发表于 2013-6-6 09:00:02

写的真的很不错
页: [1]
查看完整版本: CentOS 6.4 x64 postfix + dovecot + 虚拟用户认证