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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:
本文讲述在安装了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 ,如需转载请自行联系原作者
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
3月前
|
网络协议 Shell Windows
搭建rtmp流媒体服务器的步骤
网络上很多问文章介绍使用ffmpeg推送和拉流,经常遗漏安装rtsp-simple-server的步骤,执行推流命令:
181 0
|
3天前
|
运维 数据安全/隐私保护 数据库管理
企业实战项目之服务器用户权限集中管理
企业实战项目之服务器用户权限集中管理
|
2月前
|
运维
软件开发常见流程之下载安装宝塔,一台服务器安装一次,多台就重复这个步骤
软件开发常见流程之下载安装宝塔,一台服务器安装一次,多台就重复这个步骤
|
4月前
|
弹性计算 运维 监控
【阿里云弹性计算】从物理机到阿里云ECS:企业IT架构转型升级之路
【5月更文挑战第29天】随着云计算兴起,企业正转向阿里云ECS以应对传统物理机的挑战。本文详述了这一转型过程,包括现状评估、迁移计划制定、测试环境搭建、应用数据迁移及后期监控优化。转型升级可提升资源利用率,降低运维成本,加快业务响应,并增强数据安全。示例代码展示了使用阿里云Python SDK创建ECS实例的过程。
178 1
|
4月前
|
网络协议
阿里云服务器搭建DNS解析服务步骤
在阿里云搭建DNS解析服务,首先注册阿里云账号并购买适合的云服务器。获取服务器公网IP后,配置服务器并安装DNS软件如Bind9。接着设置DNS解析,包括定义顶级和子域名的指向。最后,通过ping测试或浏览器访问验证DNS解析功能是否正常。
251 5
|
4月前
|
弹性计算 监控 负载均衡
【阿里云弹性计算】ECS实例迁移实战:无缝迁移到阿里云的步骤与技巧
【5月更文挑战第22天】阿里云ECS实例迁移实战详解,涵盖无缝迁移步骤与技巧:选择合适迁移方案,如VPC或使用阿里云工具;创建目标环境,数据迁移及配置同步;测试验证功能正常,流量切换;选择低峰期,保证数据一致,实时监控,提升迁移成功率。本文为云平台迁移提供实用指南。
116 2
|
4月前
|
存储 监控 安全
云服务器如何最好安全,企业如何保障云机主的安全使用
云服务器作为数据存储和处理的中心,承载着大量敏感信息。一旦云服务器受到攻击或数据泄露,将可能导致严重的经济损失、声誉损害甚至法律纠纷。因此,加强云服务器安全防护至关重要。
|
4月前
|
存储 监控 安全
如何利用服务器为个人和企业提供定制服务?
【5月更文挑战第4天】如何利用服务器为个人和企业提供定制服务?
46 11
|
4月前
|
安全 Linux 数据库
windows服务器 cwRsyncServer 搭建步骤
windows服务器 cwRsyncServer 搭建步骤
435 0
windows服务器 cwRsyncServer 搭建步骤
|
4月前
|
监控 测试技术
【亮剑】理解CPU负载对服务器稳定性的重要性,并提供了诊断和解决CPU负载过高问题的步骤
【4月更文挑战第30天】本文阐述了理解CPU负载对服务器稳定性的重要性,并提供了诊断和解决CPU负载过高问题的步骤:1) 使用监控工具分析CPU使用率和系统负载;2) 深入排查运行队列、进程占用、系统调用和硬件状态;3) 根据排查结果进行代码优化、调整进程优先级或限制CPU使用率,必要时升级硬件。建议建立监控体系,定期性能测试,并持续优化以保证服务器高效运行。
139 1
下一篇
云函数