#!/bin/bash #mail install #system version:centos 6.5 #auther:vfastlinux
#set hostname #hostname mail.vfast.com #bash
#sed -i '/HOSTNAME=/c\HOSTNAME=mail.vfast.com' /etc/sysconfig/network hostname=$HOSTNAME #add user #/usr/sbin/groupadd -g 1000 vgroup #/usr/sbin/useradd -g 1000 -u 1000 -M -s /bin/false vuser
#install rely on #yum -y install ntsysv ntp telnet wget rsync vixie-cron logwatch perl-Unix-Syslog perl-Net-Daemon perl-PlRPC perl-DBI perl-DBD-MySQL freetype-demos freetype-devel libart_lgpl-devel libpng libpng-devel perl-Time-HiRes perl-Time-HiRes-Value perl-File-Tail perl-libwww-perl perl-HTMLParser perl-HTML-Tagset perl-IO-stringy perl-IO-Multiplex perl-MailTools perl-TimeDate perlConvert-ASN1 perl-Convert-BinHex perl-MIME-tools perl-FCGI perl-GD rrdtool rrdtool-perl aprdevel apr-docs apr-util-devel apr-util-docs giflib libgdiplus mono-core dbus-sharp dbus-sharp-devel dbus-glib-devel dbh dbh-devel pcre pcre-devel httpd httpd-devel httpd-manual mysql mysql-devel mysql-server cyrus-sasl cyrus-sasl-plain bind bind-chroot amavisd-new clamd clamav clamav-db spamassassin bison bzip2-devel expect fam-devel flex freetype-devel gcc gcc-c++ gdbm-devel libcclient-devel libjpeg-devel libmcrypt libmcrypt-devel libpng-devel libxslt-devel make rpm-build mod_ssl php php-gd php-mysql php-mbstring php-mcrypt phpmyadmin perl-Mon perl-Authen-PAM perl-Filter perl-Net_SSLeay.pm perl-Convert-BER perl-URI perl-XML-SAX perl-Crypt-Blowfish perl-Crypt-CBC perl-Date-Calc ncurses-devel net-snmp-devel libtool openssl openssl-devel opensslperl pam-devel pkgconfig postgresql-devel zlib-devel libtool-ltdl-devel
#Powered up httpd mysqld #chkconfig httpd on #chkconfig mysqld on
#install postfix #yum -y install postfix
#change configuration #postconf -n > /etc/postfix/main2.cf #mv /etc/postfix/main.cf /etc/postfix/main.cf.old #mv /etc/postfix/main2.cf /etc/postfix/main.cf
#echo "$hostname">>/etc/postfix/main.cf #sed -i '/inet_interfaces/c\inet_interfaces = all' /etc/postfix/main.cf #sed -i '/mydestination =/c\mydestination = $mynetworks $myhostname' /etc/postfix/main.cf #echo "mynetworks = 127.0.0.1">>/etc/postfix/main.cf #echo "myhostname = mail.vfast.com">>/etc/postfix/main.cf
#echo "# banner">>/etc/postfix/main.cf #echo "mail_name = Postfix - by extmail.org">>/etc/postfix/main.cf #echo "smtpd_banner = $myhostname ESMTP $mail_name">>/etc/postfix/main.cf
#echo "# response immediately">>/etc/postfix/main.cf #echo "smtpd_error_sleep_time = 0s">>/etc/postfix/main.cf #echo "unknown_local_recipient_reject_code = 450">>/etc/postfix/main.cf
#echo "# extmail config here">>/etc/postfix/main.cf #echo "virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf">>/etc/postfix/main.cf #echo "virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf">>/etc/postfix/main.cf #echo "virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf">>/etc/postfix/main.cf #echo "virtual_transport = maildrop:">>/etc/postfix/main.cf #echo "maildrop_destination_recipient_limit = 1" >>/etc/postfix/main.cf
#install courier-authlib #tar xf /opt/courier-authlib-0.62.4.tar.bz2 -C /usr/src #cd /usr/src/courier-authlib-0.62.4 #./configure --prefix=/usr/local/courier-authlib
#--without-stdheaderdir
#--without-authuserdb
#--without-authpam
#--without-authldap
#--without-authpwd
#--without-authshadow
#--without-authvchkpw
#--without-authpgsql
#--without-authcustom
#--with-authmysql
#--with-redhat #[ $? -eq 0 ] &&make #[ $? -eq 0 ]&&make install #[ $? -eq 0 ]&&make install-configure #echo "/usr/local/courier-authlib/lib/courier-authlib " >> /etc/ld.so.conf #ldconfig #ldconfig -v #[ $? -eq 0 ]&& echo "ok" #cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib #chmod 755 /etc/rc.d/init.d/courier-authlib #chkconfig --add courier-authlib #chkconfig courier-authlib on #chmod 755 /usr/local/courier-authlib/var/spool/authdaemon #mv /usr/local/courier-authlib/etc/authlib/authmysqlrc /usr/local/courier-authlib/etc/authlib/authmysqlrc.bak
#touch /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_SERVER localhost" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_USERNAME extmail" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_PASSWORD extmail" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_SOCKET /var/lib/mysql/mysql.sock" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_PORT 3306" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_OPT 0" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_DATABASE extmail" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_USER_TABLE mailbox" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_CRYPT_PWFIELD password" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_UID_FIELD uidnumber" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_GID_FIELD gidnumber" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_LOGIN_FIELD username" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_HOME_FIELD homedir" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_NAME_FIELD name" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_MAILDIR_FIELD maildir" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_QUOTA_FIELD quota" >> /usr/local/courier-authlib/etc/authlib/authmysqlrc #echo "MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber, \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " CONCAT('/home/domains/',homedir), \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " CONCAT('/home/domains/',maildir), \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " quota, \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " name, \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " CONCAT("disableimap=",disableimap,",disablepop3=", \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " disablepop3,",disablewebmail=",disablewebmail, \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " ",disablesmtpd=",disablesmtpd,",disablesmtp=", \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " disablesmtp,",disablenetdisk=",disablenetdisk, \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " ",netdiskquota=",netdiskquota) \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " FROM mailbox \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " WHERE username = '$(local_part)@$(domain)' \" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc #echo " DEFAULT_DOMAIN vfast.com" >>/usr/local/courier-authlib/etc/authlib/authmysqlrc
#start courier-authlib #/etc/init.d/courier-authlib start #[ $? -eq 0 ]&&echo "courier-authlib start successful" #ln -s /usr/local/courier-authlib/bin/courierauthconfig /usr/bin/courierauthconfig
#邮件投递代理,直观的讲就是把收到的邮件转发到用户的邮箱目录 #install maildrop #cd /opt #tar xf maildrop-2.2.0.tar.bz2 -C /usr/src #cd /usr/src/maildrop-2.2.0 #./configure
#--enable-sendmail=/usr/sbin/sendmail
#--enable-trusted-users='root vuser'
#--enable-syslog=1
#--enable-maildirquota
#--enable-maildrop-uid=1000
#--enable-maildrop-gid=1000
#--with-trashquota
#--with-dirsync #make #make install #maildrop -v #[ $? -eq 0 ]&&echo "maildrop install successful"
#需要修改/etc/postfix/master.cf #maildrop unix - n n - - pipe
flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}
#maildrop install error #configure: error: pcre.h not found - install PCRE from www.pcre.org #install pcre-devel 执行 ./configure successful
#make error
#main.C:320: error: ‘auth_getuserinfo’ was not declared in this scope #cp /usr/local/courier-authlib/include/* /usr/include/ 执行这个命令之后可以正常make
#install courier-unicode #tar xf /opt/courier-unicode-2.0.tar.bz2 -C /usr/src #cd /usr/src/courier-unicode-2.0 #./configure #make #make install #[ $? -eq 0 ]&&echo -e "\033[32m courier-unicode install successful \033[0m"
#提供Pop3及IMAP服务 ##install courier-imap #tar xf /opt/courier-imap-4.10.0.tar.bz2 -C /usr/src #cd /usr/src/courier-imap-4.10.0 #./configure
#--prefix=/usr/local/courier-imap
#--with-redhat
#--enable-unicode
#--disable-root-check
#--with-trashquota
#--without-ipv6 COURIERAUTHCONFIG='/usr/local/courier-authlib/bin/courierauthconfig' #[ $? -eq 0 ]&&make #[ $? -eq 0 ]&&make install
#cp /usr/local/courier-imap/etc/imapd.dist /usr/local/courier-imap/etc/imapd #cp /usr/local/courier-imap/etc/imapd-ssl.dist /usr/local/courier-imap/etc/imapd-ssl #cp /usr/local/courier-imap/etc/pop3d.dist /usr/local/courier-imap/etc/pop3d #cp /usr/local/courier-imap/etc/pop3d-ssl.dist /usr/local/courier-imap/etc/pop3d-ssl #cp /usr/src/courier-imap-4.10.0/packaging/systemd/courier-imap.sysvinit /etc/rc.d/init.d/courier-imapd #chmod 755 /etc/rc.d/init.d/courier-imapd #chkconfig --add courier-imapd #[ $? -eq 0 ]&&echo -e "\033[32m courier-imap install successful \033[0m"
#change pop #sed -i '/POP3DSTART=/c\POP3DSTART=YES' /usr/local/courier-imap/etc/pop3d #sed -i '/MAXDAEMONS=/c\MAXDAEMONS=512' /usr/local/courier-imap/etc/pop3d #sed -i '/MAXPERIP=/c\MAXPERIP=4' /usr/local/courier-imap/etc/pop3d
#提供webmail前端服务功能 #install extmail #[ ! -f /var/www/extsuite ]&&mkdir /var/www/extsuite #tar xf /opt/extmail-1.0.4.tar.gz -C /usr/src #cp -r /usr/src/extmail-1.0.4 /var/www/extsuite/extmail #cd /var/www/extsuite/extmail #cp webmail.cf.default webmail.cf #chown -R vuser:vgroup /var/www/extsuite/extmail/cgi
#sed -i "s#SYS_MYSQL_USER = db_user#SYS_MYSQL_USER = extmail#g" /var/www/extsuite/extmail/webmail.cf #sed -i "s#SYS_MYSQL_PASS = db_pass#SYS_MYSQL_PASS = extmail#g" /var/www/extsuite/extmail/webmail.cf #sed -i "s#SYS_SHOW_SIGNUP = 1#SYS_SHOW_SIGNUP = 0#g" /var/www/extsuite/extmail/webmail.cf #sed -i "s#SYS_MESSAGE_SIZE_LIMIT = 5242880#SYS_MESSAGE_SIZE_LIMIT = 52428800#g" /var/www/extsuite/extmail/webmail.cf #[ $? -eq 0 ]&&echo -e "\033[32m extmail install successful \033[0m" #cd -
####### #提供extman后台管理功能 #install extmain #tar xf /opt/extman-1.0.0.tar.gz -C /usr/src #cp -r /usr/src/extman-1.0.0 /var/www/extsuite/extman #chown -R vuser:vgroup /var/www/extsuite/extman/cgi/ #mkdir /var/www/extsuite/extman/tmp #chown -R vuser:vgroup /var/www/extsuite/extman/tmp
#sed -i "s#SYS_SESS_DIR = /tmp/extman/#SYS_SESS_DIR = /var/www/extsuite/extman/tmp/#g" /var/www/extsuite/extman/webman.cf #[ $? -eq 0 ]&&echo -e "\033[32m extman install successful \033[0m"
#import mysql data #mysql -uroot -p < /var/www/extsuite/extman/docs/extmail.sql #mysql -uroot -p < /var/www/extsuite/extman/docs/init.sql
##create administrator dir #cd /var/www/extsuite/extman/tools #./maildirmake.pl /home/domains/vfast.com/postmaster/Maildir #chown -R vuser:vgroup /home/domains #cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext/ #echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.d/rc.local #echo "/usr/local/mailgraph_ext/qmonitor-init start" >> /etc/rc.d/rc.local
#启动报错 #Can't locate RRDs.pm in @INC #需要安装 perl-rrdtool
#Can't locate File/Tail.pm in @INC #需要安装File-Tail
######### #install slockd #tar xf /opt/slockd-0.08.tar.gz -C /usr/src #cp -r /usr/src/slockd-0.08 /usr/local/slockd #echo "/usr/local/slockd/slockd-init start" >> /etc/rc.d/rc.local #[ $? -eq 0 ]&&echo -e "\033[32m slockd install successful \033[0m"
#change cofnig file #sed -i 's#AddDefaultCharset UTF-8##AddDefaultCharset UTF-8#g' /etc/httpd/conf/httpd.conf
#touch /etc/httpd/conf.d/vhost_extmail.conf #echo "# VirtualHost for ExtMail Solution" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "<VirtualHost *:80>" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "ServerName $hostname" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "DocumentRoot /var/www/extsuite/extmail/html/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "LoadModule fastcgi_module modules/mod_fastcgi.so" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "<Ifmodule mod_fastcgi.c>" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "FastCgiExternalServer /usr/bin/dispatch.fcgi -host 127.0.0.1:10030" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "<Ifmodule>" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "Alias /extmail/cgi/ /usr/bin/dispatch.fcgi/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "<Location "/extmail/cgi">" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "SetHandler fastcgi-script" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "</Location>" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "#ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "Alias /extmail /var/www/extsuite/extmail/html/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "Alias /extman /var/www/extsuite/extman/html/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "Alias /phpmyadmin /var/www/extsuite/phpmyadmin/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "Alias /phpldapadmin /var/www/extsuite/phpldapadmin/htdocs/" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "# Suexec config" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "SuexecUserGroup vuser vgroup" >>/etc/httpd/conf.d/vhost_extmail.conf #echo "</VirtualHost>" >>/etc/httpd/conf.d/vhost_extmail.conf
#install fastcgi module #tar xf File-Tail-0.99.3.tar.gz -C /usr/src #cd /usr/src/File-Tail-0.99.3 #perl Makefile.PL #make #make install
#rpm -ivh /opt/perl-FCGI-0.68-1.el6.rf.x86_64.rpm
#tar xf /opt/mod_fastcgi-2.4.7-0910052141.tar.bz2 -C /usr/src #cd /usr/src/mod_fastcgi-2.4.7-0910052141 #ln -s /usr/lib64/httpd/build /etc/httpd/build #cp Makefile.AP2 Makefile #make top_dir=/etc/httpd install #echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.d/rc.local #/var/www/extsuite/extmail/dispatch-init start
ERROR: opening '/var/lib/mailgraph.rrd': No such file or directory 看一下/var/lib下是否有对应的包
#extman 验证码看不到 安装perl-GD
Unix::Syslog not found, please install it first! (in cleanup) Undefined subroutine &Ext::Logger::do_closelog called at /var/www/extsuite/extmail/libs/Ext/Logger.pm line 86. 安装perl-Unix-Syslog
修改extman默认的用户 /var/www/extsuite/extman/html/default/index.html中的<input name=username value=root@mail.vip1.315i.com class=login_input>
Can't open /var/www/extsuite/extman/tmp//sid_8489f2869ab25e38ff809b112cafe4ca, Permission denied 修改目录权限为777
修改extmail的pop3和smtp /var/www/extsuite/extmail/html/default/index.html <span id="dmy" style="color:#666;line-height:20px;"> <%hint_pop3_setting%><br /> POP3 <b>:</b> pop3.mail.extmail.org<br /> SMTP <b>:</b> smtp.mail.extmail.org<br /> </span>
修改extmail默认模板参考 http://blog.51cto.com/mcmvp/1275069
extman 无法创建用户目录,将http的用户和组修改为vuser/vgroup 之后正常了
#配置认证 yum -y install cyrus-sasl
编辑/etc/postfix/main.cf 增加如下内容
smtpd related config
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname,
SMTP AUTH config here
broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous
编辑/etc/sasl2/smtpd.conf pwcheck_method: authdaemond log_level: 3 mech_list: PLAIN LOGIN authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket ~
存盘退出后,重新启动postfix: /etc/init.d/postfix restart
#安装过滤和病毒库 tar xf amavisd-new-2.4.0.tar.gz -C /usr/src mkdir /var/amavis mkdir /var/amavis/tmp /var/amavis/var /var/amavis/db /var/amavis/home chown -R amavis:amavis /var/amavis chmod -R 750 /var/amavis cd /usr/src/amavisd-new-2.4.0/ cp amavisd /usr/local/sbin/ chown root /usr/local/sbin/amavisd chmod 755 /usr/local/sbin/amavisd cp amavisd.conf /etc/ chown root /etc/amavisd.conf chmod 644 /etc/amavisd.conf
需要更改的参数 $max_servers = 10; $sa_spam_subject_tag = '[SPAM] '; $mydomain = 'mail.extmail.org'; $myhostname = 'mail.extmail.org'; @local_domains_maps = qw(.); $sa_tag2_level_deflt = 5.0; $sa_kill_level_deflt = 5.0; $sa_spam_modifies_subj = 0; # don't modify subject $remove_existing_x_scanned_headers= 1; # remove existing headers $remove_existing_spam_headers = 1; 上述$mydomain参数与$myhostname参数相同,主要是为了方便之后的病毒/垃圾汇报邮件发给系统管理员时,能投递到本地的别名里,再转交到虚拟域的特定用户
参考了这一篇,看到我整理2天才整理好,记录一下以后好用 https://www.xiaohui.com/dev/server/20071020-extmail-solution-howto-for-linux.htm