码迷,mamicode.com
首页 > 其他好文 > 详细

自动化安装postfix

时间:2014-10-13 14:59:20      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:postfix   linux   

#!/bin/bash


setup_select()

{


clear

cat << menu

 ++++++++++++++ LINUX Network service INSTALL MENU ++++++++++++++++++++++

note:all of the need soft must be located in root directory!!!!

         

1. Install Apache

2. Install Mysql

3. Install PHP

4. Install postfix

5. Install dovecot

6. Install squirrelmail

7. Config  cyrus

8. Config maibox & mail size

9. Config virtual mail user---extman

10.Conifg virtual mail user---courier-authlib 

11.Config virtual mail user---post & dove for courier-authlib

12.Install ExtMail

13.Install ExtMan

14.Install MailScanner

15.Install SpamAssassin

16.Install F-Prot

yum.Config yum server

Q. quit

  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

menu

echo -e -n " Please Select [1,2,3.....Q] > "

#read -p "please select [1,2,3,Q] >:"  Select

}

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

amp_setup()

{

           setup_select

           read select

           case $select in               

1)

echo "###############INSTALL Apache################"

sleep 2

Date=`date +%F/%H:%M`

echo "$Date start install apache" >> /tmp/amp.log

tar xzvf /root/httpd-2.2.17.tar.gz -C /usr/src   

cd /usr/src/httpd-2.2.17/

echo "##########configuring.....please wait#########################"

  ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/lib  --enable-auth-digest --enable-cgi  --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs 

echo "############make && make install#############################"

make && make install 

IPADDR=`ifconfig eth0|grep "inet addr"|awk ‘{print $2}‘|cut -d: -f 2`

echo "$IPADDR mail.benet.com" >> /etc/hosts

cp -pf /usr/local/apache2/bin/apachectl /etc/init.d/httpd

chmod 755 /etc/init.d/httpd 

service httpd restart

if [ $? -eq 0 ]

then

Date=`date +%F/%H:%M`

echo "$Date install apache success" >> /tmp/amp.log

fi 

echo "apache install success!!!!"

sleep 4


      amp_setup

              ;;

2)

echo "mysql install,please waite 10 mintues"

sleep 4

Date=`date +%F/%H:%M`

echo "$Date start install mysql" >> /tmp/amp.log

useradd -M -s /sbin/nologin mysql

cd /root

tar zxvf  mysql-5.1.55.tar.gz -C /usr/src 

cd /usr/src/mysql-5.1.55/

./configure --prefix=/usr/local/mysql

make && make install

if [ $? -eq 0 ]

then

Date=`date +%F/%H:%M`

echo  "$Date mysql make && make install success" >> /tmp/amp.log

else

echo "$Date mysql make && make install fault" >> /tmp/amp.log

fi

cp -f support-files/my-medium.cnf /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysqld

chmod a+x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig --level 12345 mysqld on

cd /usr/local/mysql

bin/mysql_install_db --user=mysql

chown -R root.mysql ./

chown -R mysql var

service mysqld restart

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf 

ldconfig

sleep 2

echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile

source /etc/profile

#/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘

if [ $? -eq 0 ]

then

Date=`date +%F/%H:%M`

echo  "$Date the password of root in mysql database is null  " >> /tmp/amp.log

else 

echo "$Date setup password of root in mysql database fault" >> /tmp/amp.log  

fi

            amp_setup

              ;;  

3) 

tar zxf libxml2-2.7.2.tar.gz

cd libxml2-2.7.2

./configure -prefix=/usr/local/libxml

make && make install

cd /root

tar zxf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure && make && make instal

cd /root

tar zxf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9

./configure && make && make install

cd /root

tar zxf mcrypt-2.6.8.tar.gz 

cd mcrypt-2.6.8

./configure --prefix=/usr/local/mcrypt && make && make install 

cd /root

tar zxf zlib-1.2.8.tar.gz

cd zlib-1.2.8

  ./configure --prefix=/usr/local/zlib/

make && make install

cd /root

tar zxf libpng-1.5.19.tar.gz 

cd libpng-1.5.19

./configure --prefix=/usr/local/libpng

make && make install

cd /root

mkdir /usr/local/jpeg8

mkdir /usr/local/jpeg8/bin

mkdir /usr/local/jpeg8/lib 

mkdir /usr/local/jpeg8/include

mkdir -p /usr/local/jpeg8/man/man1

tar zxf jpegsrc.v8.tar.gz   

cd jpeg-

./configure --prefix=/usr/local/jpeg8/ --enable-shared --enable-static

make && make install

cd /root

tar zxf freetype-2.4.9.tar.gz 

cd freetype-2.4.9

./configure --prefix=/usr/local/freetype

make && make install

tar zxf libgd-2.1.0.tar.gz 

cd libgd-2.1.0

./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg8/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/

make && make install

echo "+++++++++++++PHP Install+++++++++++++"

sleep 4

Date=`date +%F/%H:%M`

echo "$Date start install php" >> /tmp/amp.log

cd /root

tar zxvf php-5.3.6.tar.gz -C /usr/src  

cd /usr/src/php-5.3.6/

echo "#########php configure ...........###############"

sleep 3

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs  --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml/ -with-png-dir=/usr/local/libpng/  --with-jpeg-dir=/usr/local/jpeg8/  --with-freetype-dir=/usr/local/freetype/ --with-gd --with-zlib-dir=/usr/local/zlib/ --with-mcrypt=/usr/local/mcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all  --enable-sockets 


echo "#########php make && make install################"

sleep 3

make && make install

echo "#######濠电姷鏁搁崕鎴犲緤閽樺褰掑磼閻愯尙鐛ュ┑掳鍊曢幊搴ㄥ几娴h櫣纾兼い鏍ㄧ矤閻斾辜pd.conf###############"

echo "AddType application/x-httpd-php .php" >> /usr/local/apache2/conf/httpd.conf

sed ‘s/DirectoryIndex index.html/DirectoryIndex index.thml index.php/g‘ /usr/local/apache2/conf/httpd.conf > /root/http.conf.new

mv -f /root/http.conf.new /usr/local/apache2/conf/httpd.conf 


/usr/local/apache2/bin/apachectl restart

if [ $? -eq 0 ]

then

Date=`date +%F/%H:%M`

echo "$Date php install success" >> /tmp/amp.log

echo "$Date apache & mysql & php install success" >> /tmp/amp.log

else 

echo "$Date apache & mysql & php install fault" >> /tmp/amp.log  

fi


      amp_setup

               ;; 

4)

echo "+++++++++++++postfix Install+++++++++++++"

         sleep 4

         Date=`date +%F/%H:%M`

         echo "$Date start install postfix" >> /tmp/amp.log

         service sendmail stop &> /dev/null

         chkconfig --level 2345 sendmail off

         groupadd -g 1200 postdrop

         groupadd -g 1000 postfix

         useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix

         cd /root

         tar zxvf postfix-2.4.6.tar.gz -C /usr/src

         gunzip postfix-2.4.6-vda-ng.patch.gz

         cd /usr/src/postfix-2.4.6

         patch -p1 < /root/postfix-2.4.6-vda-ng.patch

         make makefiles  ‘CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl‘ ‘AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2 ‘

         make && make install

         cd /etc/postfix

         postconf -n > main2.cf

         mv -f main.cf main.cf.bak

         mv -f main2.cf main.cf

IPADDR=`ifconfig eth0|grep "inet addr"|awk ‘{print $2}‘|cut -d: -f 2`

cat > main.cf <<EOF

command_directory = /usr/sbin

config_directory = /etc/postfix

daemon_directory = /usr/libexec/postfix

debug_peer_level = 2

html_directory = no

mail_owner = postfix

mailq_path = /usr/bin/mailq

manpage_directory = /usr/local/man

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

unknown_local_recipient_reject_code = 550

inet_interfaces = $IPADDR, 127.0.0.1

myhostname = mail.benet.com

mydomain = benet.com

myorigin = \$mydomain

mydestination = \$mydomain, \$myhostname

home_mailbox = Maildir/

EOF

         groupadd mailusers

         useradd -g mailusers -s /sbin/nologin xiaoqi

         useradd -g mailusers -s /sbin/nologin lisi

         echo "123456" | passwd --stdin xiaoqi   &> /dev/null

         echo "123456" | passwd --stdin lisi     &> /dev/null    

postfix start

         if [ $? -eq 0 ]

          then

          Date=`date +%F/%H:%M`

          echo "$Date postfix install success" >> /tmp/amp.log

         fi

amp_setup

;;

5)

echo "+++++++++++++dovecot Install+++++++++++++"

           sleep 4

           Date=`date +%F/%H:%M`

           echo "$Date start install dovecot" >> /tmp/amp.log

useradd -M -s /sbin/nologin dovecot

tar zxvf /root/dovecot-1.1.4.tar.gz -C /usr/src

cd /usr/src/dovecot-1.1.4

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

make && make install

cp /etc/dovecot-example.conf /etc/dovecot.conf

sed  -e ‘/ssl_disable =/d‘ -e ‘/protocols =/d‘ -e ‘/disable_plaintext_auth =/d‘ -e ‘/mail_location =/d‘ /etc/dovecot.conf > /tmp/dovecot.conf

mv -f /tmp/dovecot.conf /etc/dovecot.conf

echo "ssl_disable = yes" >> /etc/dovecot.conf

echo "protocols = pop3 imap" >> /etc/dovecot.conf

echo "disable_plaintext_auth = no" >> /etc/dovecot.conf

echo "mail_location = maildir:~/Maildir"  >> /etc/dovecot.conf


cat > /etc/pam.d/dovecot << EOF

auth required pam_nologin.so

auth include system-auth

account include system-auth

session include system-auth

EOF


/usr/local/sbin/dovecot -c /etc/dovecot.conf

if [ $? -eq 0 ]

         then

Date=`date +%F/%H:%M`

echo "$Date dovecot install success" >> /tmp/amp.log

else 

echo "$Date dovecot install fault" >> /tmp/amp.log   

fi

amp_setup

;;

6)

echo "+++++++++++++squirrelmail Install+++++++++++++"

                sleep 4

                Date=`date +%F/%H:%M`

                echo "$Date start install squirrelmail" >> /tmp/amp.log

rm -rf /usr/local/apache2/htdocs/webmail

cd /root

tar jxvf squirrelmail-1.4.13.tar.bz2 -C /usr/local/apache2/htdocs/

cd /usr/local/apache2/htdocs/

mv squirrelmail-1.4.13 webmail

cd webmail/

tar jxvf ~/zh_CN-1.4.13-20071220.tar.bz2

mkdir -p attach data

chown -R daemon:daemon attach/ data/

chmod 730 attach/

cp config/config_default.php  config/config.php

sed -e ‘/squirrelmail_default_language =/d‘ -e ‘/default_charset =/d‘ -e ‘/domain =/d‘ -e ‘/smtpServerAddress =/d‘ -e ‘/smtpServerAddress =/d‘ -e ‘/smtpPort =/d‘ -e ‘/imap_server_type =/d‘ -e ‘/imapPort =/d‘ -e ‘/data_dir =/d‘ -e ‘/attachment_dir =/d‘ config/config.php > config/config.php.new


cat >> config/config.php.new << EOF

\$squirrelmail_default_language = ‘zh_CN‘;

\$default_charset = ‘zh_CN.UTF-8‘;

\$domain = ‘benet.com‘;

\$smtpServerAddress = ‘localhost‘;

\$smtpPort = 25;

\$imap_server_type = ‘dovecot‘;

\$imapPort = 143;

\$data_dir = ‘/usr/local/apache2/htdocs/webmail/data/‘;

\$attachment_dir = ‘/usr/local/apache2/htdocs/webmail/attach/‘;

EOF

mv -f config/config.php.new config/config.php

/usr/local/apache2/bin/apachectl restart


if [ $? -eq 0 ]

      then

      Date=`date +%F/%H:%M`

      echo "$Date squirrelmail install success" >> /tmp/amp.log

      else 

echo "$Date squirrelmail install fault" >> /tmp/amp.log   

fi

amp_setup

;;

yum)

read -p "修改yum本地源指向光碟"

echo "####################################################"

umount /dev/cdrom &> /dev/null

mkdir -p /mnt/rhel5

mount /dev/cdrom /mnt/rhel5

cat > /etc/yum.repos.d/rhel-debuginfo.repo << EOF

[Cluster]

name=Cluster Directory

baseurl=file:///mnt/rhel5/Cluster

enabled=1

gpgcheck=0


[ClusterStorage]

name=ClusterStorage Directory

baseurl=file:///mnt/rhel5/ClusterStorage

enabled=1

gpgcheck=0


[Server]

name=Server Directory

baseurl=file:///mnt/rhel5/Server

enabled=1

gpgcheck=0


[VT]

name=VT Directory

baseurl=file:///mnt/rhel5/VT

enabled=1

gpgcheck=0


EOF

sed -e ‘411s/url/\"\/mnt\/rhel5\/Server\"/g‘ /usr/lib/python2.4/site-packages/yum/yumRepo.py > /tmp/123

mv -f /tmp/123 /usr/lib/python2.4/site-packages/yum/yumRepo.py

;;

  Q|q)  

exit 0

               ;;

*) 

amp_setup

               ;;

 esac

}


start_menu()

{

amp_setup

}

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

start_menu

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


本文出自 “龙爱雪琪” 博客,转载请与作者联系!

自动化安装postfix

标签:postfix   linux   

原文地址:http://dragon123.blog.51cto.com/9152073/1563117

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!