Postfix简单企业邮件服务器搭建步骤-入门级

本文讲述在安装了Redhat Enterprice AS 4 U2的PC上,配置一台Postfix邮件服务器的过程。实现虚拟域、虚拟用户、POP3、SMTP

LAMP 配置在此不做配置
涉及的软件
1. Redhat Enterprice AS 4 U5
2. Mysql
系统自带
用于存储虚拟域、虚拟用户等信息。
3. Apache
系统自带
4. PHP
系统自带
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2.安装courier-authlib
 
安装之前添加postfix和maildrop相关的用户&用户组
groupadd postfix
groupadd postdrop
useradd postfix -g postfix -c "Postfix user" -d /dev/null -s /sbin/nologin
groupadd vmail 
useradd vmail -g vmail -d /home/mail
#### 特别提示 1:这个主要是设定邮件管理账号/进程启动帐号. 记住postfix和pstdrop组都中包含用户 
postfix, vmail组中包括vmail用户,你可以通过直接编/etc/group文件,把这些用户加入相关的组。同时 
,请记住这里的vmail的GI--502和UID--501,在下面文章的多处针使用到).

[root@mail~]# mkdir /home/mail
[root@mail~]# chown vmail:vmail /home/mail
[root@mail~]# chmod -R 775 /home/mail
[root@mail~]# cd /usr/src/
[root@usr/src/]# tar jvxf courier-authlib-0.60.2.tar.bz2 
[root@usr/src/]#cd /usr/src/courier-authlib-0.60.2
./configure --prefix=/usr/local/courier-authlib --without-authpam --without-authldap --without-authpwd --without-authshadow --without-authvchkpw --without-authpgsql  --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat  --with-authmysqlrc=/usr/local/courier-authlib/etc/authmysqlrc  --with-authdaemonrc=/usr/local/courier-authlib/etc/authdaemonrc CFLAGS="-march=i686 -O2 -fexpensive-optimizations" CXXFLAGS="-march=i686 -O2 -fexpensive-optimizations" [root@usr/src/courier-authlib-0.60.2]# make
[root@usr/src/courier-authlib-0.60.2]# make install
[root@net-server:/]# cd /usr/local/courier-authlib/etc/
[root@usr/local/courier-authlib/etc]# cp authmysqlrc.dist authmysqlrc
[root@usr/local/courier-authlib/etc]# cp authdaemonrc.dist authdaemonrc
[root@usr/local/courier-authlib/etc]# vi authdaemonrc
authmodulelist="authmysql"               <--使用Mysql用户认证-->
authmodulelistorig="authmysql"           <--使用Mysql用户认证-->
daemons=5                                <--已经存在, 没有就增加-->
authdaemonvar=/var/spool/authdaemon      <--authlib会自己设定好此路径->
DEBUG_LOGIN=0                             <--已经存在, 没有就增加, 2 为详细Debug模式,可以看更详细的日志-->
DEFAULTOPTIONS=""                         <--已经存在, 没有就增加-->
LOGGEROPTS=""                             <--已经存在, 没有就增加-->
[root@usr/local/courier-authlib/etc]# vi authmysqlrc
MYSQL_SERVER  localhost            <--mysql服务器名或IP地址-->
MYSQL_USERNAME  postfix                   <--mysql用户名-->
MYSQL_PASSWORD  postfix                 <--mysql用户名密码-->
MYSQL_SOCKET  /var/lib/mysql/mysql.sock       <--mysql SOCKET,请根据你的实情而定-->
MYSQL_PORT  3306                       <--mysql 端口号,请根据你的实情而定-->
MYSQL_OPT  0
MYSQL_DATABASE  postfix
MYSQL_USER_TABLE  mailbox
MYSQL_CRYPT_PWFIELD  password
MYSQL_UID_FIELD  501                    <--mysql表中, 管理authlib用户的UID.前面我们就用的vmail-->
MYSQL_GID_FIELD  502                    <--mysql表中, 管理authlib用户的GID.前面我们就用的vmail-->
### vmail---->UID:501, GID:502####
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD  concat('/home/mail/',maildir)
MYSQL_NAME_FIELD  name
MYSQL_MAILDIR_FIELD  concat('/home/mail/',maildir)
MYSQL_QUOTA_FIELD  quota
MYSQL_WHERE_CLAUSE active='1'
 注意以上的文字最后不能有空格否则无法连接数据库!!!!
启动courier-authlib
[root@mail]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail~]#chmod 755 /etc/rc.d/init.d/courier-authlib
[root@mail~]# service courier-authlib start
[root@mail~]#chkconfig --add courier-authlib
[root@mail~]#chkconfig --level 35  courier-authlib on
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
配置认证cyrus-sasl版本2(编译安装)
cyrus-sasl-2.1.22.tar.gz

./configure  -prefix=/usr/local/cyrus-sasl --enable-plain --enable-cram --enable-digest --enable-login --enable-sql --disable
-anon --disable-ntlm --disable-gssapi --disable-krb4 --disable-otp --disable-srp --disable-srp-setpass --with-authdaemond=/usr/local
/courier-authlib/var/spool/authdaemon/socket --with-mysql=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql/ --with-mysql-libs
=/usr/lib/mysql
make
make install
新版本很旧版本做链接:
ln -s /usr/local/cyrus-sasl/lib/sasl2/lib  /usr/lib/sasl2/
ln -s /usr/local/cyrus-sasl/lib/sasl2/lib  /usr/lib/sasl/lib
vi /usr/local/cyrus-sasl/lib/sasl2/smtpd.conf 
vi /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
设置自启动:
chkconfig –- level  35  saslauthd on
service saslauthd start
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装postfix  postfix-2.5.1-1.mysql.sasl2.vda.rhel4.i386.rpm  #此版本支持mysql sasl2 免去编译的麻烦#
rpm -ivh postfix-2.5.1-1.mysql.sasl2.vda.rhel4.i386.rpm

生成别名二进制文件,这个步骤如果忽略,会造成postfix效率极低
newaliases
相关配置文件
编辑/etc/postfix/main.cf 为以下内容
#=====================BASE=========================
myhostname = mail.epanel.cn
mydomain = epanel.cn
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain  注意 如果测试出错,删除!
mynetworks = 192.168.1.0/24 127.0.0.0/8
inet_interfaces = all
#=====================Vritual Mailbox settings=========================
virtual_mailbox_base = /home/mail
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:501
virtual_gid_maps = static:502
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1
#====================QUOTA========================
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 try again later.
virtual_overquota_bounce = yes
#====================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,permit
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname   注意 如果测试出错,删除!
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "Version not Available"
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
#====================ANTI-SPAM========================#
smtpd_recipient_restrictions = 
  permit_sasl_authenticated
  permit_mynetworks
  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
  check_sender_access hash:/etc/postfix/rbl_pass
  reject_rbl_client cblplus.anti-spam.org.cn=127.0.8.6
  
  permit
#====================WHITELIST========================#  
  check_sender_access hash:/etc/postfix/rbl_pass
 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
编辑/etc/postfix/mysql_virtual_alias_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = AND active = '1'
编辑/etc/postfix/mysql_virtual_domains_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
additional_conditions = AND active = '1'
编辑/etc/postfix/mysql_virtual_mailbox_limit_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
additional_conditions = AND active = '1'
编辑/etc/postfix/mysql_virtual_mailbox_maps.cf 为以下内容
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = AND active = '1'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
配置Dovecot,增加IMAP,,POP3,功能
由于Dovecot 是系统自带的,配置两个文件,
编辑 /etc/dovecot.conf 为以下内容
base_dir = /var/run/dovecot/
protocols = imap imaps pop3 pop3s
imap_listen = [::]
pop3_listen = [::]
login_dir = /var/run/dovecot-login
login = imap
login = pop3
mbox_locks = fcntl
auth = default
auth_mechanisms = plain
auth_userdb = passwd
auth_user = root
log_path = /var/log/dovecot.log
default_mail_env = maildir:/home/mail/%u
auth_userdb = mysql /etc/dovecot-mysql.conf
auth_passdb = mysql /etc/dovecot-mysql.conf
first_valid_uid = 501
编辑 /etc/dovecot-mysql.conf 为以下内容
db_host = localhost   《----数据库主机名称----》
db_port = 3306
db_unix_socket = /var/lib/mysql/mysql.sock
db = postfix
db_user = postfix
db_passwd = postfix
db_client_flags = 0
default_pass_scheme = PLAIN-MD5
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir, 501 AS uid, 502 AS gid FROM mailbox WHERE username = '%u'
 
启动Dovecot 服务
[root@mail~]# service dovecot start
[root@mail~]# chkconfig --level 35 dovecot on
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

     本文转自andylhz 51CTO博客,原文链接:http://blog.51cto.com/andylhz2009/252014,如需转载请自行联系原作者
上一篇:慎重决定!从自建服务器到选择阿里云


下一篇:对memcached使用的总结和使用场景