脚本安装dns和postfix

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了脚本安装dns和postfix相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#install dns mail dovecot

read -p "domain name :" domain_name
read -p "hostname:" host_name
read -p "host ip:" host_ip
read -p "Network card path:" eth_path
read -p "postfix package path:" ppp
read -p "dovecot package path:" dpp

for i in {$eth_path,$dpp,$ppp};do
if [ -e $i ];then
echo -e "33[32m $i is at 33[0m"
else
echo -e "33[31m $i not at ! 33[0m"
exit 1
fi
done

if [ -e /dev/sr0 ] ;then
echo "make yum repo and mount CD"
echo "[a]
name=a
baseurl=file:///mnt
enabled=1
gpgcheck=0
" > /etc/yum.repos.d/a.repo
mount /dev/sr0 /mnt
else
echo "CD not at! exit"
exit 1
fi

iptables -F

cat > /etc/sysconfig/network <<EOF
NETWORKING=yes
HOSTNAME=$host_name
EOF

hostname $host_name

for i in {cyrus-sasl-gssapi,cyrus-sasl-devel,cyrus-sasl-plain,cyrus-sasl-lib,cyrus-sasl,make,gcc,gcc-c++,openssl-devel,telnet,pam-devel,bind,bind-chroot};do
if rpm -qa | grep $i >> /dev/null ;then
echo -e "33[32m $i installed 33[0m"
else
yum install -y $i
fi
done

cat > /etc/named.conf <<EOF
options {
listen-on port 53 { $host_ip; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";

};

logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};

zone "$domain_name" IN {
type master;
file "$domain_name.zone";
};

include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
EOF

echo "$TTL 86400
@ IN SOA $domain_name. adim.$domain_name (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
IN NS mail.$domain_name.
IN MX 10 mail.$domain_name.
mail IN A $host_ip" > /var/named/$domain_name.zone

#chown named:named: /var/named/

cat $eth_path | grep "DNS1"
if [ $? -eq 0 ] ;then
sed -i ‘s/^DNS1.*//g‘ $eth_path
echo "DNS1=$host_ip" >> $eth_path
else
echo "DNS1=$host_ip" >> $eth_path
fi

service network restart

service named restart
service network restart
sleep 5
echo -e "33[31m 解析本主机 33[0m"
nslookup $host_name

#################################

echo -e "33[32m ----install mail ----33[0m"
sleep 3
echo -e "33[31m stop old mail 33[0m"
/etc/init.d/postfix stop
chkconfig --level 35 postfix off
gpasswd -a postfix postfix
gpaaswd -a postfix postdrop

tar xf $ppp -C /usr/src/
cd /usr/src/postfix*
make makefiles ‘CCARGS=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I /usr/include/sasl/‘ ‘AUXLIBS=-L/usr/lib64/sasl2 -lsasl2‘

make && make install

if [ -e /etc/postfix/main.cf ] ;then
rm -rf /etc/postfix/main.cf
cat > /etc/postfix/main.cf <<EOF
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
home_mailbox = Maildir/
html_directory = no
inet_interfaces = $host_ip
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
meta_directory = /etc/postfix
mydestination = $myhostname, $mydomain,
mydomain = $domain_name
myhostname = $host_name
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
shlib_directory = no
unknown_local_recipient_reject_code = 550
EOF
else
cat > /etc/postfix/main.cf <<EOF
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
home_mailbox = Maildir/
html_directory = no
inet_interfaces = $host_ip
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq
manpage_directory = /usr/local/man
meta_directory = /etc/postfix
mydestination = $myhostname, $mydomain,
mydomain = $domain_name
myhostname = $host_name
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
setgid_group = postdrop
shlib_directory = no
unknown_local_recipient_reject_code = 550
EOF
echo -e "33[31m the main.cf file not at make it 33[0m"
fi

service postfix start

echo -e "33[31m install complete start postfix 33[0m"

####################################################################

echo -e "33[32m ----install mail ----33[0m"

echo -e "33[31m add user 33[0m"
sleep 3
useradd -M -s /sbin/nologin dovecot
useradd -M -s /sbin/nologin dovenull

tar xf $dpp -C /usr/src/

cd /usr/src/dovecot*

./configure --sysconfdir=/etc/ --with-pam

make && make install

cp doc/dovecot-initd.sh /etc/init.d/dovecot

chmod +x /etc/init.d/dovecot

chkconfig --add dovecot

cp -r /usr/local/share/doc/dovecot/example-config/* /etc/dovecot/

cat > /etc/pam.d/dovecot <<EOF
#%PAM-1.0

auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
EOF

mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.bak
cat > /etc/dovecot/dovecot.conf <<EOF
dict {
#quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
#expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/10-auth.conf
ssl = no
disable_plaintext_auth = no
mail_location = maildir:~/Maildir
!include_try local.conf
EOF

service dovecot restart

以上是关于脚本安装dns和postfix的主要内容,如果未能解决你的问题,请参考以下文章

postfix python发送邮件脚本配置

DNS正向解析脚本以及分析

DNS正向解析脚本以及分析

shell脚本:lnmp等源码安装脚本

linux (二十五)编写自动化脚本安装DNS单机服务主从服务和卸载服务,以及网卡配置

DNS+postfix+dovecot搭建postfix邮箱服务