本文共 5570 字,大约阅读时间需要 18 分钟。
#!/bin/bash
#install dns mail dovecotread -p "domain name :" domain_name
read -p "hostname:" host_nameread -p "host ip:" host_ipread -p "Network card path:" eth_pathread -p "postfix package path:" pppread -p "dovecot package path:" dppfor i in {$eth_path,$dpp,$ppp};do
if [ -e $i ];thenecho -e "\033[32m $i is at \033[0m"elseecho -e "\033[31m $i not at ! \033[0m"exit 1fidoneif [ -e /dev/sr0 ] ;then
echo "make yum repo and mount CD"echo "[a]name=abaseurl=file:///mntenabled=1gpgcheck=0" > /etc/yum.repos.d/a.repomount /dev/sr0 /mntelseecho "CD not at! exit"exit 1fiiptables -F
cat > /etc/sysconfig/network <<EOF
NETWORKING=yesHOSTNAME=$host_nameEOFhostname $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 ;thenecho -e "\033[32m $i installed \033[0m"elseyum install -y $ifidonecat > /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";EOFecho "\$TTL 86400
@ IN SOA $domain_name. adim.$domain_name (0 ; serial1D ; refresh1H ; retry1W ; expire3H ) ; minimumIN 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 ] ;thensed -i 's/^DNS1.*//g' $eth_pathecho "DNS1=$host_ip" >> $eth_pathelseecho "DNS1=$host_ip" >> $eth_pathfiservice network restart
service named restart
service network restartsleep 5echo -e "\033[31m 解析本主机 \033[0m"nslookup $host_name#################################
echo -e "\033[32m ----install mail ----\033[0m"
sleep 3echo -e "\033[31m stop old mail \033[0m"/etc/init.d/postfix stopchkconfig --level 35 postfix offgpasswd -a postfix postfixgpaaswd -a postfix postdroptar 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.cfcat > /etc/postfix/main.cf <<EOFalias_database = hash:/etc/aliasesalias_maps = hash:/etc/aliasescommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixdata_directory = /var/lib/postfixdebug_peer_level = 2debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5home_mailbox = Maildir/html_directory = noinet_interfaces = $host_ipinet_protocols = allmail_owner = postfixmailq_path = /usr/bin/mailqmanpage_directory = /usr/local/manmeta_directory = /etc/postfixmydestination = \$myhostname, \$mydomain,mydomain = $domain_namemyhostname = $host_namemyorigin = \$mydomainnewaliases_path = /usr/bin/newaliasesqueue_directory = /var/spool/postfixreadme_directory = nosample_directory = /etc/postfixsendmail_path = /usr/sbin/sendmailsetgid_group = postdropshlib_directory = nounknown_local_recipient_reject_code = 550EOFelsecat > /etc/postfix/main.cf <<EOFalias_database = hash:/etc/aliasesalias_maps = hash:/etc/aliasescommand_directory = /usr/sbindaemon_directory = /usr/libexec/postfixdata_directory = /var/lib/postfixdebug_peer_level = 2debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5home_mailbox = Maildir/html_directory = noinet_interfaces = $host_ipinet_protocols = allmail_owner = postfixmailq_path = /usr/bin/mailqmanpage_directory = /usr/local/manmeta_directory = /etc/postfixmydestination = \$myhostname, \$mydomain,mydomain = $domain_namemyhostname = $host_namemyorigin = \$mydomainnewaliases_path = /usr/bin/newaliasesqueue_directory = /var/spool/postfixreadme_directory = nosample_directory = /etc/postfixsendmail_path = /usr/sbin/sendmailsetgid_group = postdropshlib_directory = nounknown_local_recipient_reject_code = 550EOFecho -e "\033[31m the main.cf file not at make it \033[0m"fiservice postfix start
echo -e "\033[31m install complete start postfix \033[0m"
####################################################################
echo -e "\033[32m ----install mail ----\033[0m"
echo -e "\033[31m add user \033[0m"
sleep 3useradd -M -s /sbin/nologin dovecotuseradd -M -s /sbin/nologin dovenulltar 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.0auth required pam_nologin.so
auth include system-authaccount include system-authsession include system-authEOFmv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.bak
cat > /etc/dovecot/dovecot.conf <<EOFdict { #quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext#expire = sqlite:/etc/dovecot/dovecot-dict-sql.conf.ext}!include conf.d/10-auth.confssl = nodisable_plaintext_auth = nomail_location = maildir:~/Maildir!include_try local.confEOFservice dovecot restart
转载于:https://blog.51cto.com/13043516/2136962