一个简单的基于postfix+extmail+mysql的邮件系统

#!/bin/bash
#赵云,2012年1月29日
#本脚本为初次安装一个邮件服务器,方便快捷,后期的优化自己调试。
#postfix+mysql+extmail+虚拟用户
#运行前,首先配置好系统的yum环境,脚本适用于RedHat AS 5的系统,CentOS一样。
alias cp='cp -i'
unalias cp
     yum install gcc *c++* php php-mysql mysql mysql-devel mysql-server *mysql* openssl-devel dovecot db*-devel gd-*  -y  &>/dev/null
     yum install cyrus-sasl-lib  perl-DBD-MySQL tcl tcl-devel libart_lgpl libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect -y &>/dev/null
     yum install cyrus-sasl cyrus-sasl-devel cyrus-sasl-plain perl  httpd dovecot perl-DBD-MySQL DBD-mysql-* -y  &>/dev/null
     yum remove cyrus-sasl-lib cyrus-sasl -y
#结束不必要的进程
killall dovecot &>/dev/null
killall httpd &>/dev/null
killall postfix & >/dev/null
killall sendmail &>/dev/null
#
service mysqld stop &>/dev/null
rm -rf /var/lib/mysql/*
service mysqld start &>/dev/null
service sendmail stop &>/dev/null
rpm -e postfix &>/dev/null
rpm -e sendmail --nodeps &>/dev/null
tar xzf config.tar.gz
#创建用户
userdel -r postfix
useradd -u 1000 postfix -s /sbin/nolog
groupadd postdrop -g 90
#设置主机名
echo "请输入主机名"
read hostname
#设置邮件域名
echo "请输入邮件域名"
read maildomain
#设置访问域名
echo "要访问的域名"
read domain
#设置主机名
hostname $hostanme
sed -i "s/^HOSTNAME=.*/HOSTNAME=$hostname/" /etc/sysconfig/network

#安装postfix
tar xzf postfix-2.7.3.tar.gz 
cd postfix-2.7.3
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto' &>/dev/null
make &>/dev/null
clear
echo ; echo ; echo ; echo ; echo ; echo
echo "请手动配置,如果不配置,请回车"
sleep 3
make install
newaliases
cd ..
#创建数据库
tar zxf extman-1.1.tar.gz
cd extman-1.1/docs
mysql -u root < extmail.sql
mysql -u root < init.sql
#建立虚拟用户文件
cp mysql_virtual_* /etc/postfix
cd ../../
#修改/etc/postfix/main.cf文件
cp config/main.cf /etc/postfix/main.cf
#配置虚拟用户支持--smtp认证
tar xjf courier-authlib-0.63.0.tar.bz2
cd courier-authlib-0.63.0
./configure  --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmy--with-mysql-libs=/usr/lib/mysql \
 --with-mysql-includes=/usr/include/mysql &>/dev/null && make &>/dev/null && make install &>/dev/null
make install-configure &>/dev/null
cp courier-authlib.sysvinit /etc/init.d/courier-authlib
cd ..
#修改主配置,authdaemonrc 文件
dir=/usr/local/courier-authlib/etc/authlib
sed -i '27cauthmodulelist="authmysql"' $dir/authdaemonrc
sed -i '34cauthmodulelistorig="authmysql"' $dir/authdaemonrc
#修改数据库配置,authmysqlrc 文件
sed -i '26cMYSQL_SERVER  127.0.0.1' $dir/authmysqlrc
sed -i '27cMYSQL_USERNAME  extmail' $dir/authmysqlrc
sed -i '28cMYSQL_PASSWORD  extmail' $dir/authmysqlrc
sed -i '49c#MYSQL_SOCKET /tmp/mysql.sock' $dir/authmysqlrc
sed -i '68cMYSQL_DATABASE extmail' $dir/authmysqlrc
sed -i '83cMYSQL_USER_TABLE mailbox' $dir/authmysqlrc
sed -i '133cMYSQL_HOME_FIELD concat('/mailbox/',homedir)' $dir/authmysqlrc
sed -i '150cMYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)' $dir/authmysqlrc
#通过authdaemond进行认证
echo 'pwcheck_method: authdaemond' > /usr/lib/sasl2/smtpd.conf
echo 'authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket/'>>/usr/lib/sasl2/smtpd.conf
chmod -R 755  /usr/local/courier-authlib/var/spool/authdaemon
echo "/usr/local/courier-authlib/lib/courier-authlib " >> /etc/ld.so.conf
ldconfig &>/dev/null
chmod 755 /etc/init.d/courier-authlib
chkconfig --add courier-authlib
chkconfig mysqld on
chkconfig courier-authlib on
service   courier-authlib   start
#配置虚拟用户支持
cp config/dovecot.conf /etc/dovecot.conf
#配置数据查询文件
cp config/dovecot-mysql.conf /etc/dovecot-mysql.conf
#建立邮箱目录,并调整权限
rm -rf /mailbox
mkdir -p /mailbox/extmail.org/postmaster/Maildir
chown -R postfix:postfix /mailbox
#安装Extmail
tar xzf Unix-Syslog-1.1.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL &>/dev/null
make &>/dev/null ; make install &>/dev/null
cd ..
tar xzf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL &>/dev/null
make &>/dev/null ; make install &>/dev/null
cd ..
#安装extmail  程序套件
tar xzf extmail-1.2.tar.gz
rm -rf /var/www/extmail
mv extmail-1.2 /var/www/extmail
cp config/webmail.cf /var/www/extmail/webmail.cf
cp config/httpd.conf /etc/httpd/conf/httpd.conf
#重新启动dovecot服务
service dovecot restart
#邮箱账号:postmaster           密码:extmail  域名:extmail.org
#部署Extman Web 管理界面
tar xzf GD-2.46.tar.gz
cd GD-2.46
perl Makefile.PL &>/dev/null; make &>/dev/null ; make install &>/dev/null
cd ..
tar xzf File-Tail-0.99.3.tar.gz
cd File-Tail-0.99.3
perl Makefile.PL &>/dev/null; make &>/dev/null ; make install &>/dev/null
cd ..
    rpm -ivh rrdtool-1.2.27-3.el5.i386.rpm &>/dev/null
    rpm -ivh rrdtool-perl-1.2.27-3.el5.i386.rpm  &>/dev/null
 
tar xzf extman-1.1.tar.gz
rm -rf /var/www/html/extman
mv extman-1.1 /var/www/html/extman
chown -R postfix:postfix /var/www/html/extman/
chown -R postfix:postfix /var/www/html/extman/cgi/
cp config/webman.cf /var/www/html/extman/webman.cf
mkdir /var/extman &>/dev/null
chmod 777 /var/extman
rm -rf /usr/local/mailgraph_ext
mkdir /usr/local/mailgraph_ext
cp /var/www/html/extman/addon/mailgraph_ext/mailgraph_ext.pl  /usr/local/mailgraph_ext/
cp /var/www/html/extman/addon/mailgraph_ext/qmonitor.pl  /usr/local/mailgraph_ext/
/var/www/html/extman/addon/mailgraph_ext/mailgraph-init start
sed -i "993c<VirtualHost $domain>" /etc/httpd/conf/httpd.conf
sed -i "994cServerName $domain" /etc/httpd/conf/httpd.conf
sed -i "69cmyhostname = $hostname" /etc/postfix/main.cf
sed -i "s/^mydomain.*/mydomain = $maildomain/g" /etc/postfix/main.cf
service httpd restart
/var/www/html/extman/daemon/cmdserver -d &>/dev/null
#在浏览器中访问 http://服务器地址/extman/
#管理账号: [email protected]            密码:extmail*123*
#添加开机启动服务
cp config/postfix /etc/init.d/
chkconfig --add postfix
service postfix restart &>/dev/null
chkconfig dovecot on
chkconfig httpd on
chkconfig postfix on
#删除临时文件
rm -rf DBI-1.616
rm -rf Unix-Syslog-1.1
rm -rf postfix-2.7.3
rm -rf File-Tail-0.99.3
rm -rf courier-authlib-0.63.0
rm -rf GD-2.46
rm -rf config
echo ; echo ; echo ; echo ; echo ; echo
echo "
安装完成,请使用浏览器打开 http://服务器域名/extman/
管理账号: [email protected]            密码:extmail*123*
默认密码在完成安装后自行修改。
用户邮箱登录http://服务器域名
默认邮箱账号:postmaster           密码:extmail  域名:extmail.org "
echo ; echo ; echo ; echo ; echo ; echo
 
 
这个是脚本的内容,可下载安装包,我都打包好了。
下载地址:  http://down.51cto.com/data/323527 
减压后,由一个install.sh的文件,用本脚本内容替换掉,按提示执行安装。

你可能感兴趣的:(mysql,数据库,postfix,邮件系统,ExtMail)