二、安装配置postfix
#创建postfix用户
groupadd -g2525 postfix #大于一千最好 -g
useradd -gpostfix -u 2525 -s /sbin/nologin -M postfix
groupadd -g 2526 postdrop
useradd -gpostdrop -u 2526 -s /bin/false -M postdrop
假设准备阶段的软件包都存放在/mnt/postfix里
tar zxvfpostfix-2.6.5.tar.gz
cdpostfix-2.6.5
make makefiles'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL-I/usr/include/sasl -DUSE_TLS ''AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 -lssl -lcrypto'
#gcc的编译选项;mysql头文件;支持sasl认证;cyrus_sasl的头文件;mysql的客户端;指明auxlibs的位置
make
make install
安装过程中会出现一些提示除了tempdir:改为/tmp,其他使用默认项,直接直接回车
install_root: [/] /
tempdir:[/usr/local/src/ postfix-2.6.5] /tmp
config_directory:[/etc/postfix] /etc/postfix
daemon_directory:[/usr/libexec/postfix]
command_directory:[/usr/sbin]
queue_directory:[/var/spool/postfix]
sendmail_path:[/usr/sbin/sendmail]
newaliases_path:[/usr/bin/newaliases]
mailq_path:[/usr/bin/mailq]
mail_owner: [postfix]
setgid_group:[postdrop]
html_directory: [no] /var/www/postfix_html
manpages:[/usr/local/man]
readme_directory: [no]
安装后会由警告,不用理会
newaliases # 生成别名二进制文件,可有可无,反正以后也要打
2.进行一些基本配置,测试启动postfix并进行发信
vi /etc/postfix/main.cf
修改以下几项为您需要的配置
myhostname = mail.dean.com
myorigin = dean.com
mydomain = dean.com
mydestination = $myhostname, localhost.$mydomain,localhost, $mydomain
mynetworks = 192.1680.0/24, 127.0.0.1/8
说明:
myorigin参数用来指明发件人所在的域名;
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
启动postfix
/usr/sbin/postfix start
#手动创建启动脚本
vim /etc/init.d/postfix
#!/bin/bash . /etc/rc.d/init.d/functions . /etc/sysconfig/network [ ${NETWORKING} = "no" ] && exit 0 [ -x /usr/sbin/postfix ] || exit 0 [ -d /etc/postfix ] || exit 0 [ -d /var/spool/postfix ] || exit 0 RETVAL=0 prog="postfix" start() { # Startdaemons. echo -n{1}quot;Starting postfix: " /usr/bin/newaliases >/dev/null 2>&1 /usr/sbin/postfixstart 2>/dev/null 1>&2 && success || failure {1}quot;$progstart" RETVAL=$? [ $RETVAL-eq 0 ] && touch /var/lock/subsys/postfix echo return$RETVAL } stop() { # Stopdaemons. echo -n{1}quot;Shutting down postfix: " /usr/sbin/postfixstop 2>/dev/null 1>&2 && success || failure {1}quot;$progstop" RETVAL=$? [ $RETVAL-eq 0 ] && rm -f /var/lock/subsys/postfix echo return$RETVAL } reload() { echo -n{1}quot;Reloading postfix: " /usr/sbin/postfixreload 2>/dev/null 1>&2 && success || failure {1}quot;$progreload" RETVAL=$? echo return$RETVAL } abort() { /usr/sbin/postfixabort 2>/dev/null 1>&2 && success || failure {1}quot;$progabort" return $? } flush() { /usr/sbin/postfixflush 2>/dev/null 1>&2 && success || failure {1}quot;$progflush" return $? } check() { /usr/sbin/postfixcheck 2>/dev/null 1>&2 && success || failure {1}quot;$progcheck" return $? } restart() { stop start } # See how we were called. 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{1}quot;Usage: $0{start|stop|restart|reload|abort|flush|check|status|condrestart}" exit 1 esac exit $?
-------------------------------------------------------------------------------------------
# 别忘了给执行权限
chmod +x /etc/init.d/postfix
chkconfig --add postfix # 这步可能加不,不用管它
连接postfix,验正服务启动状况:
[root@station71 postfix]# telnet 192.168.0.71 25
Trying 192.168.0.71...
Connected to station71.RedHat_hu.com (192.168.0.71).
Escape character is '^]'.
220 mail.evo.com ESMTP Postfix
ehlo mail.evo.com
250-mail.evo.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:root@evo.com
250 2.1.0 Ok
rcpt to:root@evo.com
250 2.1.5 Ok
data
354 End data with<CR><LF>.<CR><LF>
subject:test
test 123...
.
250 2.0.0 Ok: queued as 7AAD51B803D
quit
221 2.0.0 Bye
Connection closed by foreign host.
You have mail in /var/spool/mail/root
[root@station71 postfix]# mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1root@evo.com Sun Aug 1420:03 15/481 "test"
#测试成功
三、为postfix开启基于cyrus-sasl的认证功能
使用以下命令验正postfix是否支持cyrus风格的sasl认证,如果您的输出为以下结果,则是支持的:
/usr/sbin/postconf -a
cyrus
dovecot
vi /etc/postfix/main.cf
添加以下内容:
############################CYRUS-SASL############################ broken_sasl_auth_clients = yes #定义是否允许突破sasl认证 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 #拒绝xxxxxxxxx smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous smtpd_sasl_application_name = smtpd smtpd_banner = Welcome to our $myhostnameESMTP,Warning: Version has been hidden! #欢迎信息且隐藏版本号
vi /usr/lib/sasl2/smtpd.conf
添加如下内容:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
让postfix重新加载配置文件
/usr/sbin/postfix reload
service postfix restart
[root@station71 postfix]# telnet 192.168.0.32
Trying 192.168.0.32.
Connected to station71.redhat_hu.com (192.168.0.32
Escape character is '^]'.
220 Welcome to our mail.evo.com ESMTP,Warning: Versionhas been hidden.
ehlo mail.evo.com
250-mail.evo.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN #有以上两行说明CYRUS-SASL认证添加成功
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
#测试