shell script自动搭建简单的mail服务器(postfix+dovecot)
2013-03-04 17:22
429 查看
#!/bin/bash
#
#Shell name:config_mail.sh
#
#Program:
# config mail server by this shell script
#
#Author:perofu
#
#Mail: perofu.com@gmail.com
#
#History:
# 2012/10/14
#
#NOTE:
#
#Please check some right strings in your /etc/postfix/main.cf and
#/etc/dovecot/dovecot.conf to change it in this shell script,
#
#Not in below part
######################################################
# /etc/postfix/main.cf
######################################################
#
# #myhostname = host.domain.tld
# #mydomain = domain.tld
# #myorigin = $myhostname
# #myorigin = $mydomain
# #inet_interfaces = all
# inet_interfaces = localhost
# mydestination = $myhostname, localhost.$mydomain, localhost
# #mynetworks = 168.100.189.0/28, 127.0.0.0/8
# #relay_domains = $mydestination
#
######################################################
# /etc/dovecot/dovecot.conf
######################################################
#
# #protocols = imap pop3 lmtp
#
######################################################
#If you have any opinions please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
SHELL_NAME=$(basename $0)
PC=/etc/postfix/main.cf #postfix configuer
DC=/etc/dovecot/dovecot.conf #dovecot configuer
if [ $UID -ne 0 ]
then
echo "Run as root"
exit 1
fi
if [ "$#" -ne "0" ]
then
if [ "$#" -ne "3" ]
then
echo "Usage:"
echo "A ./${SHELL_NAME}"
echo "B ./${SHELL_NAME} hostname domain_name subnet"
echo
exit 77
else
hn=$1
dm=$2
sn=$3
fi
else
read -p "Please input your host name like [mail.example.com] " hn
read -p "Please input your domain name like [example.com] " dm
read -p "Please input your subnet like [10.0.0.0/24] " sn
fi
#install postfix and dovecot
yum install postfix* dovecot* -y &> /dev/null
cp $PC $PC.bak #backup
cp $DC $DC.bak
#check some right strings in your /etc/postfix/main.cf and write in there
grep "#myhostname = host.domain.tld" $PC |sed -i "s/#myhostname = host.domain.tld/myhostname = ${hn}/" $PC
grep "#mydomain = domain.tld" $PC |sed -i "s/#mydomain = domain.tld/mydomain = ${dm}/" $PC
grep "#myorigin = \$myhostname" $PC |sed -i "s/#myorigin = \$myhostname/myorigin = \$myhostname/" $PC
grep "#myorigin = \$mydomain" $PC |sed -i "s/#myorigin = \$mydomain/myorigin = \$mydomain/" $PC
grep "#inet_interfaces = all" $PC |sed -i "s/#inet_interfaces = all/inet_interfaces = all/" $PC
grep "inet_interfaces = localhost" $PC |sed -i "s/inet_interfaces = localhost/#inet_interfaces = localhost/" $PC
grep "#mynetworks = 168.100.189.0/28, 127.0.0.0/8" $PC |sed -i "s%#mynetworks = 168.100.189.0\/28, 127.0.0.0\/8%#mynetworks = ${sn}, 127.0.0.0\/8%" $PC
grep "#relay_domains = \$mydestination" $PC |sed -i "s/#relay_domains = \$mydestination/relay_domains = \$mydestination/" $PC
grep "^mydestination = $myhostname, localhost.$mydomain, localhost" /etc/postfix/main.cf |sed -i "s/^mydestination = \$myhostname, localhost.\$mydomain, localhost/mydestination = \$myhostname, \$mydomain/" /etc/postfix/main.cf
#check some right strings in your /etc/dovecot/dovecot.conf and write in there
grep "#protocols = imap pop3 lmtp" $DC |sed -i "s/#protocols = imap pop3 lmtp/protocols = imap pop3 lmtp/" $DC
#check sendmail server and stop it
if [ -e /usr/sbin/sendmail.sendmail ]
then
/etc/init.d/sendmail stop &> /dev/null
chkconfig sendmail off
yes 2 | alternatives --config mta &> /dev/null
/etc/init.d/postfix restart &> /dev/null
chkconfig postfix on
/etc/init.d/dovecot restart &> /dev/null
chkconfig dovecot on
else
/etc/init.d/postfix restart &> /dev/null
chkconfig postfix on
#MTA
yes 1 | alternatives --config mta &> /dev/null
/etc/init.d/dovecot restart &> /dev/null
chkconfig dovecot on
fi
echo "Enjoin mail-server"
grep "^mydestination = $myhostname, localhost.$mydomain, localhost" /etc/postfix/main.cf |sed -i "s/^mydestination = \$myhostname, localhost.\$mydomain, localhost/mydestination = \$myhostname, \$mydomain/" /etc/postfix/main.cf
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144586
#
#Shell name:config_mail.sh
#
#Program:
# config mail server by this shell script
#
#Author:perofu
#
#Mail: perofu.com@gmail.com
#
#History:
# 2012/10/14
#
#NOTE:
#
#Please check some right strings in your /etc/postfix/main.cf and
#/etc/dovecot/dovecot.conf to change it in this shell script,
#
#Not in below part
######################################################
# /etc/postfix/main.cf
######################################################
#
# #myhostname = host.domain.tld
# #mydomain = domain.tld
# #myorigin = $myhostname
# #myorigin = $mydomain
# #inet_interfaces = all
# inet_interfaces = localhost
# mydestination = $myhostname, localhost.$mydomain, localhost
# #mynetworks = 168.100.189.0/28, 127.0.0.0/8
# #relay_domains = $mydestination
#
######################################################
# /etc/dovecot/dovecot.conf
######################################################
#
# #protocols = imap pop3 lmtp
#
######################################################
#If you have any opinions please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
SHELL_NAME=$(basename $0)
PC=/etc/postfix/main.cf #postfix configuer
DC=/etc/dovecot/dovecot.conf #dovecot configuer
if [ $UID -ne 0 ]
then
echo "Run as root"
exit 1
fi
if [ "$#" -ne "0" ]
then
if [ "$#" -ne "3" ]
then
echo "Usage:"
echo "A ./${SHELL_NAME}"
echo "B ./${SHELL_NAME} hostname domain_name subnet"
echo
exit 77
else
hn=$1
dm=$2
sn=$3
fi
else
read -p "Please input your host name like [mail.example.com] " hn
read -p "Please input your domain name like [example.com] " dm
read -p "Please input your subnet like [10.0.0.0/24] " sn
fi
#install postfix and dovecot
yum install postfix* dovecot* -y &> /dev/null
cp $PC $PC.bak #backup
cp $DC $DC.bak
#check some right strings in your /etc/postfix/main.cf and write in there
grep "#myhostname = host.domain.tld" $PC |sed -i "s/#myhostname = host.domain.tld/myhostname = ${hn}/" $PC
grep "#mydomain = domain.tld" $PC |sed -i "s/#mydomain = domain.tld/mydomain = ${dm}/" $PC
grep "#myorigin = \$myhostname" $PC |sed -i "s/#myorigin = \$myhostname/myorigin = \$myhostname/" $PC
grep "#myorigin = \$mydomain" $PC |sed -i "s/#myorigin = \$mydomain/myorigin = \$mydomain/" $PC
grep "#inet_interfaces = all" $PC |sed -i "s/#inet_interfaces = all/inet_interfaces = all/" $PC
grep "inet_interfaces = localhost" $PC |sed -i "s/inet_interfaces = localhost/#inet_interfaces = localhost/" $PC
grep "#mynetworks = 168.100.189.0/28, 127.0.0.0/8" $PC |sed -i "s%#mynetworks = 168.100.189.0\/28, 127.0.0.0\/8%#mynetworks = ${sn}, 127.0.0.0\/8%" $PC
grep "#relay_domains = \$mydestination" $PC |sed -i "s/#relay_domains = \$mydestination/relay_domains = \$mydestination/" $PC
grep "^mydestination = $myhostname, localhost.$mydomain, localhost" /etc/postfix/main.cf |sed -i "s/^mydestination = \$myhostname, localhost.\$mydomain, localhost/mydestination = \$myhostname, \$mydomain/" /etc/postfix/main.cf
#check some right strings in your /etc/dovecot/dovecot.conf and write in there
grep "#protocols = imap pop3 lmtp" $DC |sed -i "s/#protocols = imap pop3 lmtp/protocols = imap pop3 lmtp/" $DC
#check sendmail server and stop it
if [ -e /usr/sbin/sendmail.sendmail ]
then
/etc/init.d/sendmail stop &> /dev/null
chkconfig sendmail off
yes 2 | alternatives --config mta &> /dev/null
/etc/init.d/postfix restart &> /dev/null
chkconfig postfix on
/etc/init.d/dovecot restart &> /dev/null
chkconfig dovecot on
else
/etc/init.d/postfix restart &> /dev/null
chkconfig postfix on
#MTA
yes 1 | alternatives --config mta &> /dev/null
/etc/init.d/dovecot restart &> /dev/null
chkconfig dovecot on
fi
echo "Enjoin mail-server"
grep "^mydestination = $myhostname, localhost.$mydomain, localhost" /etc/postfix/main.cf |sed -i "s/^mydestination = \$myhostname, localhost.\$mydomain, localhost/mydestination = \$myhostname, \$mydomain/" /etc/postfix/main.cf
本文出自 “无咎” 博客,请务必保留此出处http://perofu.blog.51cto.com/6061242/1144586
相关文章推荐
- shell script自动搭建简单的pxe服务器
- 邮件系统服务器搭建记录(三)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 邮件系统服务器搭建记录(四)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- Postfix + dovecot 搭建Mail服务器
- 邮件系统服务器搭建记录(二)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 邮件系统服务器搭建记录(五)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- 邮件系统服务器搭建记录(一)(Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+MySQL)
- shell script自动搭建简单的nfs服务器
- shell script自动搭建简单的cacti监控
- 简单邮件服务器postfix+dovecot搭建
- shell script自动搭建简单的yum
- CentOS 搭建Postfix+Dovecot简单邮件系统
- Ubuntu 14.04搭建邮箱服务器(Postfix, Dovecot)
- shell script自动搭建简单的双机ssh认证
- postfix+dovecot+squrrelmail邮件服务器的搭建 推荐
- 利用postfix+mutt+dovecot 搭建邮件的收发服务器
- Linux与云计算——第二阶段Linux服务器架设 第九章:Mail电子邮件服务器架设—postfix和Dovecot
- postfix 邮件服务(搭建简单的邮件服务器)
- shell script自动搭建简单的mysql主从(replication)