postfix邮件服务器搭建02-安装篇
本文接着上文的环境,进行postfix邮件发信端和dovecot邮件收信端的部署,之后部署基于浏览器的extmail图形管理端,使管理员可以通过网页对邮件虚拟用户进行管理,对邮件服务器进行管控
1.postfix邮件发信端部署
1.1.清理会引起冲突的软件sendmail,如果是关闭相关软件设计操作过多,不推荐
rpm -qa postfix sendmail
rpm -e --nodeps postfix sendmail
# 清除之前的邮件账号信息
userdel postfix groupdel postdrop cat /etc/passwd|grep post* cat /etc/gshadow|grep post*
1.2.创建postfix邮件用户和组
groupadd -g 2525 postfix useradd -g postfix -u 2525 -s /sbin/nologin -M postfix groupadd -g 2526 postdrop useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop cat /etc/passwd|grep post* cat /etc/gshadow|grep post*
# 新建虚拟用户邮箱目录,并将其权限赋予postfix用户:
mkdir -p /var/mailbox chown -R postfix /var/mailbox
1.3.源码编译安装postfix-3.2.3
cd /server/tools wget ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/official/postfix-3.2.3.tar.gz tar -zxf postfix-3.2.3.tar.gz cd postfix-3.2.3
# 配置参数
make makefiles \ 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -I/usr/include/openssl' \ 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
# 编译安装
make make install
# 执行完之后会进入设置相关目录的交互界面,基本按照默认配置即可。
install_root: [/] tempdir: [/server/tools/postfix-3.2.3] config_directory: [/etc/postfix] command_directory: [/usr/sbin] daemon_directory: [/usr/libexec/postfix] data_directory: [/var/lib/postfix] html_directory: [no] /usr/local/postfix/html mail_owner: [postfix] mailq_path: [/usr/bin/mailq] manpage_directory: [/usr/local/man] newaliases_path: [/usr/bin/newaliases] queue_directory: [/var/spool/postfix] readme_directory: [no] /usr/local/postfix/readme sendmail_path: [/usr/sbin/sendmail] setgid_group: [postdrop] shlib_directory: [no] /usr/local/postfix/share-library meta_directory: [/etc/postfix]
1.4.更新别名数据文件/etc/aliases.db,这个步骤如果忽略,会造成postfix效率极低
/usr/bin/newaliases ll /etc/aliases.db
# 注意:
1).安装过程如果报错,需要删除目录重新安装
2).本文采用yum安装Mysql和sasl2,如果使用源码安装这两个软件,需要修改编译时CCARGS和AUXLIBS选项。
使用源码安装的mysql和cyrus-sasl,使用以下编译参数:
make makefiles \ 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl -DUSE_TLS -I/usr/include/openssl' \ 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lrt -lm -L/usr/local/sasl2/lib -lsasl2 -lssl -lcrypto'
3).在执行make install的时有如下的提示:
/usr/libexec/ld-elf.so.1: Shared object "libmysqlclient.so.12" not found
是因为mysql的lib库没找到,需要告诉postfix应该到哪里去找libmysqlclient.so.12。
使用ldconfig可以解决,例如:
echo /usr/local/mysql/lib/mysql >> /etc/ld.so.conf ldconfig
4).make install的交互配置最好使用默认,如果修改根目录则目录结构会乱掉
5).如果/etc/aliases文件不存在,可以用如下命令创建:
echo postfix: root >> /etc/aliases
1.5.修改相关目录的权限否则,postfix无法正常运行(必须使用以下顺序授权)
cd /server/tools chown -R postfix.postfix /var/lib/postfix/ chown -R postfix.postfix /var/spool/postfix/private chown -R postfix.postfix /var/spool/postfix/public chown -R root /var/spool/postfix/pid/ chgrp -R postdrop /var/spool/postfix/public chgrp -R postdrop /var/spool/postfix/maildrop/ chown root /var/spool/postfix
# 查看修改完的结果:
ll /var/lib/postfix/ -d ll /var/lib/postfix/ ll /var/spool/postfix/ -d ll /var/spool/postfix/
# 查看postfix相关程序文件
ll /usr/sbin/post* ll /usr/libexec/postfix/ ll /var/spool/postfix/ ll /var/spool/postfix/private/ ll /var/spool/postfix/incoming/
1.6.修改配置文件,启动postfix
vim /etc/postfix/main.cf
# 修改并确认以下配置,改成自己对应的就好
myhostname = mail.zuiyoujie.com mydomain = zuiyoujie.com myorigin = $mydomain inet_interfaces = 127.0.0.1, (外网地址)(或着写all) mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain mynetworks = 127.0.0.0/8
# 参数说明:
myhostname 指定运行postfix邮件系统的主机的主机名(用 FQDN 的方式来写),默认情况下,其值被设定为本地机器名;
mydomain 指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
myorigin 指明发件人所在的域名;邮件标头上面的 mail from 的那个地址
inet_interfaces 指定系统监听的网络接口;
mydestination 指定接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
mynetworks 指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
# 注意:
1)在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2)任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3)每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4)如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
# 为postfix提供SysV服务管理脚本/etc/rc.d/init.d/postfix
vim /etc/init.d/postfix
# 以下是管理脚本具体内容:
#!/bin/bash # postfix Postfix Mail Transfer Agent # chkconfig: 2345 80 30 # description: Postfix is a Mail Transport Agent, which is the program \ # that moves mail from one machine to another. # processname: master # pidfile: /var/spool/postfix/pid/master.pid # main-config: /etc/postfix/main.cf # master-config: /etc/postfix/master.cf # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ $NETWORKING = "no" ] && exit 3 [ -x /usr/sbin/postfix ] || exit 4 [ -d /etc/postfix ] || exit 5 [ -d /var/spool/postfix ] || exit 6 RETVAL=0 prog="postfix" # Start daemons. start() { echo -n $"Starting postfix: " /usr/bin/newaliases >/dev/null 2>&1 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start" RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix echo return $RETVAL } # Stop daemons. stop() { echo -n $"Shutting down postfix: " /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop" RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix echo return $RETVAL } reload() { echo -n $"Reloading postfix: " /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload" RETVAL=$? echo return $RETVAL } restart() { stop start } abort() { /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort" return $? } flush() { /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush" return $? } check() { /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check" return $? } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; abort) abort ;; flush) flush ;; check) check ;; status) status master ;; condrestart) [ -f /var/lock/subsys/postfix ] && restart || : ;; *) echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}" exit 1 esac exit $?
# 添加为系统服务,并设置开机自启动
chmod 755 /etc/init.d/postfix chkconfig --add postfix chkconfig postfix on chkconfig --list postfix
# postfix启动管理脚本测试
service postfix start
service postfix stop
# postfix常用的管理命令
/usr/sbin/postfix start /usr/sbin/postfix reload /usr/sbin/postfix check
1.7.测试postfix是否可以正常发送邮件
yum install telnet -y
telnet 127.0.0.1 25
# 实例如下:
[root@mail tools]# telnet 127.0.0.1 25 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 220 Welcome to our mail.zuiyoujie.com ESMTP! helo mail.zuiyoujie.com 250 mail.zuiyoujie.com mail from:root@zuiyoujie.com 250 2.1.0 Ok rcpt to:zhaoshuai@zuiyoujie.com 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> from: root testmail <root@zuiyoujie.com> to:zhaoshuai@zuiyoujie.com subject:first test mail This is a test mail from root. . 250 2.0.0 Ok: queued as 329F5180712 quit 221 2.0.0 Bye Connection closed by foreign host. [root@mail tools]# mailq -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 329F5180712* 433 Mon Oct 16 17:46:55 root@zuiyoujie.com zhaoshuai@zuiyoujie.com -- 0 Kbytes in 1 Request.
# 使用以下命令可以查看邮件内容
postcat -q [Queue ID]
# 实例如下:
[root@mail ~]# postcat -q 329F5180712 *** ENVELOPE RECORDS deferred/3/329F5180712 *** message_size: 362 690 1 0 362 0 message_arrival_time: Mon Oct 16 18:39:02 2017 create_time: Mon Oct 16 18:39:22 2017 named_attribute: log_ident=329F5180712 named_attribute: rewrite_context=local sender: root@zuiyoujie.com named_attribute: log_client_name=localhost named_attribute: log_client_address=127.0.0.1 named_attribute: log_client_port=35432 named_attribute: log_message_origin=localhost[127.0.0.1] named_attribute: log_helo_name=mail.zuiyoujie.com named_attribute: log_protocol_name=SMTP named_attribute: client_name=localhost named_attribute: reverse_client_name=localhost named_attribute: client_address=127.0.0.1 named_attribute: client_port=35432 named_attribute: server_address=127.0.0.1 named_attribute: server_port=25 named_attribute: helo_name=mail.zuiyoujie.com named_attribute: protocol_name=SMTP named_attribute: client_address_type=2 named_attribute: dsn_orig_rcpt=rfc822;zhaoshuai@zuiyoujie.com original_recipient: zhaoshuai@zuiyoujie.com recipient: zhaoshuai@zuiyoujie.com *** MESSAGE CONTENTS deferred/3/329F5180712 *** Received: from mail.zuiyoujie.com (localhost [127.0.0.1]) by mail.zuiyoujie.com (Postfix) with SMTP id 329F5180712 for <zhaoshuai@zuiyoujie.com>; Mon, 16 Oct 2017 18:39:02 +0800 (CST) from: root testmail <root@zuiyoujie.com> to:zhaoshuai@zuiyoujie.com Message-Id: <20171016103922.329F5180712@mail.zuiyoujie.com> Date: Mon, 16 Oct 2017 18:39:02 +0800 (CST) *** HEADER EXTRACTED deferred/3/329F5180712 *** *** MESSAGE FILE END deferred/3/329F5180712 ***
# 可以看出邮件服务器已经可以发送邮件,不过由于接收邮件的服务没有配好邮件还收不到,如果想看收发效果,可以将收件人改为自己的qq邮箱等进行测试。
# 接下来进行配置,启用smtp用户认证,使用courier-authlib通过数据库对虚拟用户进行管理
2.安装配置Courier authentication library
# courier-authlib是Courier组件中的认证库,它是courier组件中一个独立的子项目,用于为Courier的其它组件提供认证服务,是由一位美籍俄罗斯人的杰作。其认证功能通常包括验正登录时的帐号和密码、获取一个帐号相关的家目录或邮件目录等信息、改变帐号的密码等。而其认证的实现方式也包括基于PAM对/etc/passwd和/etc/shadow进行认证,基于GDBM或DB进行认证,基于LDAP/MySQL/PostgreSQL进行认证等。因此,courier-authlib也常用来与courier之外的其它邮件组件(如postfix)整合为其提供认证服务。
cd /server/tools wget http://jaist.dl.sourceforge.net/project/courier/authlib/0.66.1/courier-authlib-0.66.1.tar.bz2 tar -xf courier-authlib-0.66.1.tar.bz2 cd courier-authlib-0.66.1
# 配置参数
./configure \ --prefix=/usr/local/courier-authlib \ --sysconfdir=/etc \ --with-redhat \ --with-mailuser=postfix \ --with-mailgroup=postfix \ --with-authmysql=yes \ --with-authmysqlrc=/etc/authmysqlrc \ --with-authdaemonrc=/etc/authdaemonrc \ --with-mysql-libs=/usr/lib64/mysql \ --with-mysql-includes=/usr/include/mysql \ --without-authpam \ --without-authpgsql \ --without-authvchkpw \ --without-authshadow
# 编译安装
make make install
make install-configure
# 创建认证配置文件
chmod 755 -R /usr/local/courier-authlib/var/spool/authdaemon cp /etc/authmysqlrc.dist /etc/authmysqlrc cp /etc/authdaemonrc.dist /etc/authdaemonrc ll /etc/authmysqlrc ll /etc/authdaemonrc
# 编辑/etc/authdaemonrc文件,确保使用mysql认证模块
vim /etc/authdaemonrc
# 修改并确认以下配置
authmodulelist="authpwd authmysql" authmodulelistorig="authpwd authmysql" daemons=10
# 编辑/etc/authmysqlrc文件,让courier能够正确的读取MySQL中的认证信息
vim /etc/authmysqlrc
# 修改并确认以下配置
MYSQL_SERVER localhost MYSQL_USERNAME extmail # 数据库用户名 MYSQL_PASSWORD extmail # 数据库密码 MYSQL_SOCKET /var/lib/mysql/mysql.sock MYSQL_PORT 3306 # mysql监听的端口 MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password # 92行,crypt改为password DEFAULT_DOMAIN mail.zuiyoujie.com # 105行,默认邮件域 MYSQL_UID_FIELD '2525' MYSQL_GID_FIELD '2525' MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD concat('/var/mailbox/',homedir) # 133行,home修改 MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD concat('/var/mailbox/',maildir) # 150行,maildir修改
# 将courier-authlib配置为系统服务
cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib chmod 755 /etc/init.d/courier-authlib chkconfig --add courier-authlib chkconfig --list courier-authlib
# 将courier-authlib 的库目录添加到库搜索文件中
echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf ldconfig -v
# 启动 courier-authlib 服务
service courier-authlib start
# 由于是socket的方式,所以没有端口,可以验证进程是否启动
ps -ef | grep courier pstree | grep authdaemond ll /usr/local/courier-authlib/var/spool/authdaemon/socket
# 查看postfix是否支持cyrus-sasl认证功能
cd /server/tools/ /usr/sbin/postconf -a
# 出现以下内容表示可以使用sasl认证
[root@mail tools]# /usr/sbin/postconf -a
cyrus
dovecot
# 设置postfix使用的sasl配置文件smtpd,让sasl知道该怎么从MySQL中读取认证信息,该文件需要手工创建,sasl密码验证机制为authdaemond
# 新建smtp认证文件,添加以下4行内容:
vim /etc/sasl2/smtpd.conf
pwcheck_method: authdaemond log_level: 3 mech_list:PLAIN LOGIN authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
# 关于sasl2的认证文件smtpd.conf的位置,可以有以下3个,需要注意
/etc/sasl2/smtpd.conf /usr/lib64/sasl2/smtpd.conf /etc/postfix/sasl2/smtpd.conf
# 配置postfix支持sasl邮箱安全认证
vim /etc/postfix/main.cf
# 添加以下内容
###### CYRUS-SASL ###### broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_path = /etc/sasl2 smtpd_sasl_security_options = noanonymous smtpd_banner = Welcome to our $myhostname ESMTP! smtpd_sender_restrictions = permit_mynetworks,reject_sender_login_mismatch,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_invalid_hostname,reject_authenticated_sender_login_mismatch,reject_unauthenticated_sender_login_mismatch,check_sender_access hash:/etc/postfix/access smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_sender_domain,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_maps.cf,mysql:/etc/postfix/mysql_virtual_alias_maps.cf
/usr/sbin/postfix check
/usr/sbin/postfix reload
3.安装配置dovecot
yum install dovecot dovecot-mysql
# 修改dovecot主配置文件
vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp # 启用
listen = *
# 修改auth认证配置文件
vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no auth_mechanisms = plain login !include auth-system.conf.ext
# 修改10-mail.conf配置文件
vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
# 配置数据库认证相关文件
cd /etc/dovecot/conf.d/ cp auth-sql.conf.ext auth-sql.conf vim /etc/dovecot/conf.d/auth-sql.conf
# 第9行和第21行改为以下内容(去掉passdb和userdb的ext后缀)
args = /etc/dovecot/dovecot-sql.conf
# 手工创建dovecot-sql.conf文件
vim /etc/dovecot/dovecot-sql.conf
driver = mysql connect = host=localhost dbname=extmail user=extmail password=extmail default_pass_scheme = CRYPT password_query = SELECT username AS user,password AS password FROM mailbox WHERE username = '%u' user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FROM mailbox WHERE username = '%u'
# 启动dovecot邮件接收端
chkconfig dovecot on chkconfig --list dovecot service dovecot start
4.安装extmail
cd /server/tools tar -xf extmail-1.2.tar.gz mkdir -p /var/www/extsuite mv extmail-1.2 /var/www/extsuite/extmail chown -R postfix.postfix /var/www/extsuite/extmail ll /var/www/extsuite/extmail
# 修改配置文件
cd /var/www/extsuite/extmail/ cp webmail.cf.default webmail.cf vim /var/www/extsuite/extmail/webmail.cf
SYS_USER_LANG = zh_CN # 77行,语言选项 SYS_MESSAGE_SIZE_LIMIT = 52428800 # 105行,用户可以发送的邮件大小默认5M SYS_MIN_PASS_LEN = 8 # 107行,最短密码长度 SYS_MAILDIR_BASE = /var/mailbox # 127行,前文所设置的用户邮件的存放目录 SYS_MYSQL_USER = extmail # 140行,连接数据库服务器所使用用户名 SYS_MYSQL_PASS = extmail # 141行,密码和邮件服务器用到的数据库 SYS_MYSQL_HOST = localhost # 143行,数据库服务器主机名 SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock SYS_MYSQL_TABLE = mailbox # 147行,以下配置用来指定验证用户登录所用到的表,以及用户名、域名和用户密码分别对应的表中列的名称,默认即可 SYS_MYSQL_ATTR_USERNAME = username SYS_MYSQL_ATTR_DOMAIN = domain SYS_MYSQL_ATTR_PASSWD = password # 198行,指定之前安装的authdaemo socket文件的位置 SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
# 创建extmail临时目录
mkdir -p /tmp/extmail/upload chown -R postfix.postfix /tmp/extmail/ ll /tmp ll /tmp/extmail/
5.安装extman
cd /server/tools/ tar -xf extman-1.1.tar.gz mv extman-1.1 /var/www/extsuite/extman chown -R postfix.postfix /var/www/extsuite/extman ll /var/www/extsuite/extman
# 修改配置文件
cd /var/www/extsuite/extman/ cp webman.cf.default webman.cf vim /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /var/mailbox # 12行,设置的用户邮件的存放目录 SYS_SESS_DIR = /tmp/extman/ # 此两处后面设定的ID号需更改为前而创建的postfix用户和postfix组的id号,本文使用的 SYS_DEFAULT_UID = 2525 # 98行 SYS_DEFAULT_GID = 2525 # 101行 SYS_MYSQL_USER = extmail # 127行 SYS_MYSQL_PASS = extmail # 128行 SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock # 132行 # 132行,指定验证管理员登录所用到的表,及相关参数,默认即可 SYS_MYSQL_TABLE = manager SYS_MYSQL_ATTR_USERNAME = username SYS_MYSQL_ATTR_PASSWD = password
# 创建extman临时目录,用于session等数据文件
mkdir /tmp/extman chown -R postfix.postfix /tmp/extman/ ll /tmp
# 修改cgi目录的属主,便于网页访问
chown -R postfix.postfix /var/www/extsuite/extmail/cgi/ chown -R postfix.postfix /var/www/extsuite/extman/cgi/ ll /var/www/extsuite/extmail/cgi/ ll /var/www/extsuite/extman/cgi/
# 复制5个虚拟用户数据库配置文件到postfix目录
cd /var/www/extsuite/extman/docs/ cp mysql_virtual_* /etc/postfix/ ll /etc/postfix/mysql_virtual_*
# 初始化extmail数据库(空密码)
mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql
mysql -u root -p < /var/www/extsuite/extman/docs/init.sql
# 据库授权
mysql -uroot -p
grant all privileges on extmail.* to extmail@localhost identified by 'extmail'; grant all privileges on extmail.* to extmail@127.0.0.1 identified by 'extmail'; flush privileges; delete from mysql.user where user=' '; delete from mysql.user where host='mail.zuiyoujie.com'; select user,host from mysql.user;
# 编辑/etc/postfix/main.cf,让postfix支持虚拟域和虚拟用户
vim /etc/postfix/main.cf
####### Virtual Mailbox Settings ####### virtual_uid_maps = static:2525 virtual_gid_maps = static:2525 virtual_transport = virtual message_size_limit = 60336000 virtual_mailbox_base = /var/mailbox virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_limit = mysql:/etc/postfix/mysql_virtual_limit_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf virtual_alias_domains = smtpd_client_connection_count_limit = 50 smtpd_client_connection_rate_limit = 50
# 重新载入配置文件
/usr/sbin/postfix check
/usr/sbin/postfix reload
6.配置Mailgraph_ext,使用Extman的图形日志
# 配置启动图形工具
cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext/ /usr/local/mailgraph_ext/mailgraph-init start /var/www/extsuite/extman/daemon/cmdserver -daemon
# 配置开机自启动
echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >> /etc/rc.d/rc.local
7.配置Apache,使用浏览器进行虚拟用户管理
vim /etc/httpd/conf/httpd.conf
# 修改并确认以下配置
LoadModule suexec_module modules/mod_suexec.so # 198行,将suexec插件注释掉,否则配置比较麻烦 User postfix # 242行,修改http运行用户postfix Group postfix # 243行,修改http运行组为postfix ServerName mail.zuiyoujie.com # 276行,修改监听域名 # DocumentRoot "/var/www/html" # 292行,将之注释掉,启用虚拟主机
# 配置虚拟主机
vim /etc/httpd/conf.d/extmail.conf
<VirtualHost *:80> ServerName mail.zuiyoujie.com DocumentRoot /var/www/extsuite/extmail/html/ ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi Alias /extmail /var/www/extsuite/extmail/html ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi Alias /extman /var/www/extsuite/extman/html </VirtualHost>
# 启动Apache
service httpd start
chkconfig httpd on
chkconfig --list httpd
# 接下来就可以登录http://mail.zuiyoujie.com,选择管理即可登入extman进行后台管理了
# 默认的管理员用户密码
root@extmail.org extmail*123*
至此postfix邮箱服务器的收发件,用户安全认证就已经配置完成,可以集中管理邮件虚拟用户
8.常用邮件日志分析
# 动态跟踪日志变化
tail -f /var/log/maillog
# 取指定类型的日志
egrep '(reject|warning|error|fatal|panic):' /var/log/maillog
# 查看postfix成功接收到邮件:(交货到邮件目录)
cat /var/log/maillog |grep "delivered to maildir" cat /var/log/maillog |grep "delivered to maildir" | egrep -o "(\w+)([@]{1}\w+[.]{1,})(\w+)"
# 取指定日期,指定类型日志:
cat /var/log/maillog | grep "^Oct\ 17" | egrep "reject|warning|error|fatal|panic" | less
# 取指定日期,指定类型日志:
cat /var/log/maillog | grep "^Oct\ 17" | egrep "reject|warning|error|fatal|panic" | less
9.postfix中的命令行工具
mailq 对邮件队列文件进行列表。表中的每一个条目包含有以下信息:队列文件ID、邮件的大小、到达的时间、发件人、收件人和投递延迟的原因(如果投递有延迟的话)。该命令主要是与showq后台程序通信来获取队列文件的相关信息。该命令无参数。
newaliases 该工具进行别名数据库的初始化。如果没有指定数据库的类型,则使用系统默认的数据库类型(在linux下为hash)。该命令可以不带参数执行。
postcat 打印邮件队列文件的内容。后面接要显示的队列文件名,可以带一个-v的参数进行冗余显示。
postmap 建立postfix查询数据库。在linux下可以直接跟上原始文件而不带任何参数来建立该数据库。
postconf -d 打印配置参数的缺省值。
postconf -m 列出所有支持的查询表类型。
postconf -n 查看postfix生效的配置
完毕,呵呵呵
本文版权归作者和博客园共有,如果感觉有用可以随意打赏,感谢支持,欢迎转载