加载中…
正文 字体大小:

postfix+dovecot+postfixadmin+mysql架设邮件服务器

(2010-03-25 13:20:03)
标签:

postfix

分类: IT

 

1、 安装apache(nginx)+php+mysql(不再介绍)

2、 如果有需要请架设bind服务器

3、  安装postfix+dovecot+postfixadmin+mysql
需要安装以下软件:postfix(一款MTA),postfixadmin(管理邮局帐号),cyrus-sasl(安全认证软件),dovecot(一款安全pop软件)
(1)添加mysql用户

#/opt/app/mysql/bin/mysql –u root –proot

mysql>create database postfix;

mysql>grant all privileges on postfix.* to postfix@localhost identified by 'postfix';
mysql>flush privileges;

(2)安装postfixadmin
#tar -zvxf postfixadmin-2.6.5.tar.gz
#mv postfixadmin-2.6.5 /opt/case/mail/postfixadmin
#cd /opt/case/mail/postfixadmin
#cp config.inc.php config.inc.php.bak
#vim config.inc.php

$CONF['configured'] = true;
$CONF['default_language'] = 'cn';           ###让postfixadmin 支持中文

$CONF['database_type'] = 'mysql';

$CONF['database_host'] = 'localhost';

$CONF['database_user'] = 'postfix';

$CONF['database_password'] = 'postfix';

$CONF['database_name'] = 'postfix';
$CONF['domain_in_mailbox'] = 'NO';         ###If you don't want to have the domain in your mailbox set this to 'NO'.
$CONF['encrypt'] = 'md5';
(3)配置apache访问postfixadmin
#vim /opt/app/apache/conf/httpd.conf
<VirtualHost *:80>
DocumentRoot /opt/case/mail/postfixadmin
<Directory " /opt/case/mail/postfixadmin">
  Options FollowSymLinks
  DirectoryIndex index.php index.html index.htm
  AllowOverride None
  AuthType Basic                        ###可以不用
  authname Private                      ###可以不用
  authuserfile /var/run/admin           ###可以不用
  require valid-user                    ###可以不用
  Order allow,deny
  Allow from all
</Directory>
</VirtualHost>
(4)生成认证文件(如果在配置apache时没有启用AuthType Basic,本部骤省略。)
#/opt/app/apache/bin/htpasswd -c /var/run/admin admin      

###其中/var/run/admin为文件名,最后的admin为用户名
ew password:
Re-type new password:
Adding password for user admin
###输入两次密码后生成用户admin
(5)运行安装向导前需要安装php的imap扩展
先安装依赖包,否则会报错
#yum -y install openssl openssl-devel pam pam-devel
#wget ftp://ftp.cac.washington.edu/mail/imap.tar.Z
#tar -zvxf imap.tar.z
#cd imap-2007e
#make lr5 PASSWDTYPE=std SSLTYPE=unix.nopwd IP6=4
#echo "set disable-plaintext nil" > /etc/c-client.cf
#mkdir /usr/local/imap-2007e
#mkdir /usr/local/imap-2007e/include/
#mkdir /usr/local/imap-2007e/lib/
#chmod -R 077 /usr/local/imap-2007e
#cp imapd/imapd /usr/sbin/
#cp c-client/*.h /usr/local/imap-2007e/include/
#cp c-client/*.c /usr/local/imap-2007e/lib/
#cp c-client/c-client.a /usr/local/imap-2007e/lib/libc-client.a
#cd /usr/local/src/php-5.2.12/ext/imap
#/opt/app/php/bin/phpize
#./configure --with-php-config=/opt/app/php/bin/php-config --with-imap-ssl --with-imap=/usr/local/imap-2007e
#make && make install
(6)编辑php.ini

改magic_quotes_gpc = Off

加入 extension = "imap.so"
重启apache
打开http://mail.qihang001.com/setup.php就可以开始postfixadmin的安装了,安装完后可以进行添加域和用户的操作
注:如装了php5-imap还是提示无imap,则直接改掉setup.php里的变为if ( $f_imap_open == 0)  跳过检查
设置setup密码

打开postfixadmin配置文件config.inc.php,找到$CONF['setup_password'] =‘changme’这一行,把值改为刚才setup生成的加密密码,如

“84ab1a59d0a50933fffb7cf2c3483ac9:65a5b14ab41e35c53c85f6806eb1182765ecf866”

输入管理员的邮箱 和密码点击 Add Admin 按扭

(7)安装cyrus-sasl
#tar -zvxf cyrus-sasl-2.1.23.tar.gz
#cd cyrus-sasl-2.1.23
#./configure --enable-login --enable-sql --with-mysql=/opt/app/mysql/
#make && make install
#ln -s /usr/local/lib/sasl2 /usr/lib/sasl2
(8)停用sendmail
#service sendmail stop
#chkconfig --level 345 sendmail off
#mv /usr/bin/newaliases /usr/bin/newaliases.orig
#mv /usr/bin/mailq /usr/bin/mailq.orig
#mv /usr/sbin/sendmail /usr/sbin/sendmail.orig

(9)安装postfix
#groupadd -g 12345 postfix
#useradd -u 12345 -g postfix -s /sbin/nologin -d /dev/null postfix
#groupadd -g 54321 postdrop
#tar -zvxf postfix-2.6.5.tar.gz
#cd postfix-2.6.5
# make -f Makefile.init makefiles \

'CCARGS=-DHAS_MYSQL -I/opt/app/mysql/include/mysql -DUSE_SASL_AUTH -DDEF_SERVER_SASL_TYPE="dovecot"' \

'AUXLIBS=-L/opt/app/mysql/lib/mysql -lmysqlclient -lz -lm'
#make && make install

注:如果提示bin/postconf: error while loading shared libraries: libmysqlclient.so.15: cannot open shared object file: No such file or directory错误,则解决方法如下:

#echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf

#ldconfig

然后再重新make install,ok,postfix安装好了。
然后下一步下一步默认就可以

(10)配置postfix

①、设置main.cf

#cd /etc/postfix

#mv main.cf main.cf .bak

#vim main.cf

command_directory = /usr/sbin

config_directory = /etc/postfix

daemon_directory = /usr/libexec/postfix

data_directory = /var/lib/postfix

debug_peer_level = 2

html_directory = no

inet_interfaces = all

mail_owner = postfix

mailbox_size_limit = 209715200      ###容量大小

mailq_path = /usr/bin/mailq

manpage_directory = /usr/local/man

message_size_limit = 52428800       ###限制附件大小

mydomain = qihang001.com            ###域名

myhostname = mail.qihang001.com     ###主机名

mynetworks = 0.0.0.0/0              ###配置这一项使用用户可在任意地发送邮件

mynetworks_style = subnet

myorigin = $mydomain

newaliases_path = /usr/bin/newaliases

queue_directory = /var/spool/postfix

readme_directory = no

sample_directory = /etc/postfix

sendmail_path = /usr/sbin/sendmail

setgid_group = postdrop

###配置使用dovecot的sql认证

 

smtpd_banner = $myhostname ESMTP

smtpd_recipient_restrictions = permit_mynetworks, reject_invalid_hostname, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_non_fqdn_recipi

ent, reject_unknown_recipient_domain, reject_unauth_pipelining, reject_unauth_destination

###上面这个smtpd_recipient_restrictions后面的项目每个逗号后都要有一个空格,否则会有问题

 

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain =

smtpd_sasl_path = /var/run/dovecot/auth-client      ###路径要与dovecot一样

smtpd_sasl_security_options = noanonymous

smtpd_sasl_type = dovecot                       ###定义安装方式 dovecot

unknown_local_recipient_reject_code = 550

 

###虚拟用户设定

virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_gid_maps = static:12345

virtual_mailbox_base = /data/mailbox/           ###虚拟用户目录

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_limit = 209715200

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_transport = virtual

virtual_uid_maps = static:12345

②、创建mysql通信文件

# vim /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

#vim /etc/postfix/mysql_virtual_domains_maps.cf

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain

#vim /etc/postfix/mysql_virtual_mailbox_maps.cf

user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#postfix start                      ###启动postfix
(11)安装配置dovecot
#mkdir -p /data/mailbox
#chown -R postfix.postfix /data/mailbox
#useradd -d /dev/null -s /sbin/nologin dovecot
#tar zxf dovecot-1.2.9.tar.gz
#cd dovecot-1.2.9
#./configure --prefix=/opt/app/dovecot --sysconfdir=/etc/dovecot --with-sql --with-sql-drivers --with-mysql \

CPPFLAGS=-I/opt/app/mysql/include/mysql LDFLAGS=-L/opt/app/mysql/lib/mysql
#make && make install
vim /etc/dovecot/dovecot.conf
protocols=pop3 pop3s

listen=*

disable_plaintext_auth = no

ssl= no

auth_debug = yes

log_path = /var/log/pop3.log

mail_location =maildir:/data/mailbox/%u

pop3_uidl_format=%08Xu%08Xv

mail_uid = 12345

mail_gid = 12345

first_valid_uid = 12345

auth default {

    mechanisms = PLAIN LOGIN

    passdb sql {

        args = /etc/dovecot/dovecot-sql.conf

    }

    userdb sql {

        args = /etc/dovecot/dovecot-sql.conf

    }

    socket listen {

        client {

            path = /var/run/dovecot/auth-client                    

###这里对应 postfix  smtpd_sasl_path 

            mode = 0660

            user = postfix

            group = postfix

        }

    }

}


#vim /etc/dovecot/dovecot-sql.conf
driver = mysql

connect = host=localhost dbname=postfix user=postfix password=postfix

default_pass_scheme = MD5  

###这里修改为 MD5 是为了与 postfixadmin 想符合,不然验证不过去总提示密码错误!

password_query = SELECT password FROM mailbox WHERE username = '%u'

user_query = SELECT maildir, 12345 as uid, 12345 as gid FROM mailbox WHERE username = '%u'

# /opt/app/dovecot/sbin/dovecot     ###启动dovecot
4、运行测试
(1)打开浏览器输入:http://mail.qihang001.com

输入我们刚刚建立的管理账号和密码,登录

(2)登录后,点域名清单——>新建域,如图

 

(3)点虚拟用户清单——>新建邮箱,如图

 

(4)再添加一个用户

(5)用outlook进行测试

注:中途遇到什么问题,多看看dovecot,postfix 日志,和mysql 日志

阅读 评论 收藏 转载 喜欢 打印举报
已投稿到:
  • 评论加载中,请稍候...
发评论

       

    验证码: 请点击后输入验证码 收听验证码

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 不良信息反馈 电话:4006900000 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有