`
ryan.liu
  • 浏览: 133946 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Postfix安装脚本

阅读更多

以下脚本在CentOS 5 上通过

 

#!/bin/bash

# 切换到root开始安装
su -
mkdir /data/Downloads/
chmod -R 777 /data/Downloads/
cd /data/Downloads/


wget http://postfix.it-austria.net/releases/official/postfix-2.7.1.tar.gz
wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.23.tar.gz
wget ftp://ftp.andrew.cmu.edu/pub/cyrus/cyrus-imapd-2.3.16.tar.gz
wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz



#创建用户
useradd -M -s /bin/false -p* postfix
groupadd postdrop


# 安装
tar xzf openssl-1.0.0a.tar.gz
cd openssl-1.0.0a
./config --prefix=/usr/local/openssl-1.0.0a  shared threads  # -fPIC for 64 bit OS
make
make install
ln -s /usr/local/openssl-1.0.0a /usr/local/openssl


tar xzf cyrus-sasl-2.1.23.tar.gz
cd cyrus-sasl-2.1.23
./configure --prefix=/usr/local/postfix/cyrus-sasl-2.1.23 \
        --enable-login --enable-ntlm
make && make install
cd ..


tar xzf cyrus-imapd-2.3.16.tar.gz
cd cyrus-imapd-2.3.16
./configure --prefix=/usr/local/postfix/cyrus-imapd-2.3.16 --with-lock=fcntl \
        --with-sasl=/usr/local/postfix/cyrus-sasl-2.1.23 \
        --with-openssl=/usr/local/openssl
make && make install
cd ..


tar xzf postfix-2.7.1.tar.gz
cd postfix-2.7.1
make makefiles --always-make CCARGS='-I/usr/local/postfix/cyrus-sasl-2.1.23/include/sasl -I/usr/local/openssl/include -DDEF_CONFIG_DIR=\"/usr/local/postfix/etc\" -DFD_SETSIZE=2048 -DUSE_CYRUS_SASL -DUSE_TLS' \
        AUXLIBS='-L/usr/local/postfix/cyrus-sasl-2.1.23/lib/sasl2 -L/usr/local/openssl/lib -L/usr/local/openssl/lib64 -lsasl2 -lssl -lcrypto'
make
make install
#安装过程中需要回答问题,下面三个问题,请使用右边的回答,其他直接按回车用默认值
#  [/usr/bin/mailq]   /usr/bin/mailq.postfix
#  [/usr/bin/newaliases]   /usr/bin/newaliases.postfix
#  [/usr/sbin/sendmail]   /usr/sbin/sendmail.postfix
cd ..



# 添加以下内容到main.cf echo [BELOW TEXT] >> /usr/local/postfix/etc/main.cf
local_recipient_maps =
#请将所有的mail.example.com和example.com替换为您的MX域名
###############postfix#################################
myhostname = mail.example.com
myorigin = example.com
mydomain = example.com
append_dot_mydomain = no
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mynetworks = 192.168.1.0/24, 10.0.0.0/24, 127.0.0.0/8
mynetworks = 127.0.0.1  #只接收本机的本地邮件
#body_checks = regexp:/usr/local/postfix/etc/body_checks  #用于从邮件中提取信息记录到postfix日志

############################CYRUS-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
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 $myhostname ESMTP,Warning: Version not Available!


# echo [BELOW TEXT] > /usr/local/postfix/etc/smtpd.conf
echo "pwcheck_method: saslauthd" >> /usr/local/postfix/etc/smtpd.conf
echo "mech_list: PLAIN LOGIN" >> /usr/local/postfix/etc/smtpd.conf

# echo [BELOW TEXT] >> /usr/local/postfix/etc/body_checks
/\/account\/([a-z_]+)\/veri/  WARN "$1"
/verify=3D([0-9a-f]+)/  WARN "$1"




# 设置
rm -f /usr/sbin/sendmail
ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
rm -f /etc/alternatives/mta
ln -s /usr/sbin/sendmail.postfix /etc/alternatives/mta

rm -f /usr/sbin/saslauthd
ln -s /usr/local/postfix/cyrus-sasl-2.1.23/sbin/saslauthd /usr/sbin/saslauthd
rm -rf /etc/postfix
ln -s /usr/local/postfix/etc /etc/postfix

# 启动
/etc/rc.d/init.d/sendmail stop
chkconfig sendmail off
chkconfig --list sendmail
chkconfig saslauthd on
chkconfig --list saslauthd
/etc/rc.d/init.d/saslauthd start
postfix start

# 测试,收件人为who@where.com
telnet localhost 25
EHLO mail.example.com
MAIL FROM:admin@example.com
RCPT TO:who@where.com NOTIFY=success,failure
DATA
subject:Mail test!
This is just a mail test!!!
.


#从日志中统计退回、拒收、超时失败的邮件
#grep "status=bounced" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'
#grep "status=deferred" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'
#grep "status=expired" /var/log/maillog | gawk 'match($0,/to=<(.*)>/){print substr($0,RSTART+4,RLENGTH-5)}'


 
分享到:
评论
1 楼 ryan.liu 2014-09-24  
Postfix 2.11 Under CentOS 6

yum install -y db4-devel cyrus-sasl-devel cyrus-imapd-devel
make makefiles --always-make CCARGS='-DDEF_CONFIG_DIR=\"/etc/postfix\" -DFD_SETSIZE=2048 -DUSE_CYRUS_SASL -DUSE_TLS' AUXLIBS='-lsasl2 -lssl -lcrypto'
make install

相关推荐

Global site tag (gtag.js) - Google Analytics