为了账号安全,请及时绑定邮箱和手机立即绑定

extmail安装脚本详解

标签:
MySQL


脚本在Linode CentOS 5.6 32位中通过测试,注意将hostname改成你本机名

php和apache使用源码安装,版本:php-5.3.15.tar.gz,httpd-2.2.22.tar.gz,其他使用EMOS_1.5_i386.iso中rpm包。

使用方法:

wget http://blog.linuxeye.com/wp-content/uploads/extmail.zip 

unzip -qo extmail.zip 

cd extmail sh 

sh extmail_install.sh 

文章参考:http://wiki.extmail.org,本文没有安装邮件病毒检查和垃圾邮件过滤

以下是脚本内容:

# by www.linuxeye.com

#1. 安装完系统后,执行初始化脚本地址:http://blog.linuxeye.com/wp-content/uploads/init.sh,开启iptables 25、110端口,设置hostname 

wget http://blog.linuxeye.com/wp-content/uploads/init.sh  #初始化脚本 

sh init.sh 

sed -i 's@COMMIT@-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT \n-A INPUT -p tcp -m state --state NEW -m tcp --dport 110 -j ACCEPT \nCOMMIT@g' /etc/sysconfig/iptables 

service iptables restart 

if [ -z $(grep HOSTNAME  /etc/sysconfig/network) ];then echo 'HOSTNAME=mail.linuxeye.com' >> /etc/sysconfig/network; else  sed -i 's@HOSTNAME.*@HOSTNAME=mail.linuxeye.com@g' /etc/sysconfig/network; fi 

hostname mail.linuxeye.com 

source /etc/profile 

  

#2. 配置yun 

echo '# EMOS-Base.repo 

[EMOS-base] 

name=EMOS-Base 

baseurl=http://mirror.extmail.org/yum/emos/1.5/os/$basearch/ 

gpgcheck=0 

priority=0 

protect=0 

  

[EMOS-update] 

name=EMOS-Updates 

baseurl=http://mirror.extmail.org/yum/emos/1.5/updates/$basearch/ 

gpgcheck=0 

priority=0 

protect=0' > /etc/yum.repos.d/EMOS-Base.repo 

yum clean all 

  

#3. 源码安装apache、php,rpm安装mysql-server 

cd /root 

wget http://blog.linuxeye.com/wp-content/uploads/lamp.zip #lamp源码安装脚本,不用安装mysql 

unzip lamp.zip 

cd lamp 

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel  openldap-clients openldap-servers libxslt-devel libevent-devel ntp  libtool-ltdl bison libtool vim-enhanced gd gd-devel 

if [ -e "/root/lamp" ];then 

echo -e "\e[0;34m start install\e[0m" 

cd /root/lamp/apache 

else 

echo -e "\e[1;31mPlease send lamp directory moved to /root\e[0m" 

exit 1 

fi 

tar xzf pcre-8.31.tar.gz 

cd pcre-8.31 

./configure 

make && make install 

cd ../ 

  

useradd -M -s /sbin/nologin www 

tar xzf httpd-2.2.22.tar.gz 

cd httpd-2.2.22 

./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite=shared --enable-static-support  --with-included-apr --with-mpm=worker 

make && make install 

/bin/cp /usr/local/apache/bin/apachectl  /etc/init.d/httpd 

sed -i '2a # chkconfig: - 85 15' /etc/init.d/httpd 

sed -i '3a # description: Apache is a World Wide Web server. It is used to serve' /etc/init.d/httpd 

chmod 755 /etc/init.d/httpd 

chkconfig --add httpd 

chkconfig httpd on 

cd .. 

yum -y install mysql-server #rpm安装mysql 

service mysqld restart 

mysql -e "grant all privileges on *.* to root@'%' identified by 'admin' with grant option;" 

mysql -e "flush privileges;" 

mysql -e "delete from mysql.user where password='';" 

service mysqld restart 

  

#安装php 

cd /root/lamp/php 

tar xzf libiconv-1.14.tar.gz 

cd libiconv-1.14 

./configure --prefix=/usr/local 

make && make install 

  

cd ../ 

tar xzf libmcrypt-2.5.8.tar.gz 

cd libmcrypt-2.5.8 

./configure 

make && make install 

/sbin/ldconfig 

cd libltdl/ 

./configure --enable-ltdl-install 

make && make install 

cd ../../ 

  

tar xzf mhash-0.9.9.9.tar.gz 

cd mhash-0.9.9.9 

./configure 

make && make install 

cd ../ 

if [ -e "/lib64" ];then 

ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la 

ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so 

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4 

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8 

ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a 

ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la 

ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so 

ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2 

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1 

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config 

else 

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la 

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so 

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 

ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a 

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la 

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so 

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config 

fi 

echo '/usr/lib/mysql/' >> /etc/ld.so.conf 

ldconfig 

yum -y install mysql-devel #不然安装php找不到mysql头文件 

tar xzf mcrypt-2.6.8.tar.gz 

cd mcrypt-2.6.8 

/sbin/ldconfig 

./configure 

make && make install 

cd ../ 

tar xzf php-5.3.15.tar.gz 

cd php-5.3.15 

./configure  --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --with-mysqli --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-ftp --enable-zip --enable-soap --disable-debug 

  

make ZEND_EXTRA_LIBS='-liconv' && make install 

cp php.ini-production /usr/local/php/lib/php.ini 

cd ../ 

  

tar xzf memcache-2.2.6.tgz 

cd memcache-2.2.6 

/usr/local/php/bin/phpize 

./configure --with-php-config=/usr/local/php/bin/php-config 

make && make install 

cd ../ 

  

tar xjf eaccelerator-0.9.6.1.tar.bz2 

cd eaccelerator-0.9.6.1 

/usr/local/php/bin/phpize 

./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config 

make && make install 

cd ../ 

  

tar xzf PDO_MYSQL-1.0.2.tgz 

cd PDO_MYSQL-1.0.2 

/usr/local/php/bin/phpize 

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql 

make && make install 

cd ../ 

  

tar xzf ImageMagick-6.6.7-10.tar.gz 

cd ImageMagick-6.6.7-10 

./configure 

make && make install 

cd ../ 

  

tar xzf imagick-2.3.0.tgz 

cd imagick-2.3.0 

/usr/local/php/bin/phpize 

./configure --with-php-config=/usr/local/php/bin/php-config 

make && make install 

cd ../ 

  

#修改php.ini 

mkdir /tmp/eaccelerator 

sed -i 's@expose_php = On@expose_php = Off@g' /usr/local/php/lib/php.ini   #隐藏php版本信息 

sed -i '808a extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626/"' /usr/local/php/lib/php.ini 

sed -i '809a extension = "memcache.so"' /usr/local/php/lib/php.ini 

sed -i '810a extension = "pdo_mysql.so"' /usr/local/php/lib/php.ini 

sed -i '811a extension = "imagick.so"' /usr/local/php/lib/php.ini 

sed -i '134a output_buffering = On' /usr/local/php/lib/php.ini 

sed -i '847a cgi.fix_pathinfo=0' /usr/local/php/lib/php.ini 

sed -i 's@;date.timezone =@date.timezone = Asia/Shanghai@g' /usr/local/php/lib/php.ini 

echo '[eaccelerator] 

zend_extension="/usr/local/php/lib/php/extensions/no-debug-zts-20090626/eaccelerator.so" 

eaccelerator.shm_size="64" 

eaccelerator.cache_dir="/tmp/eaccelerator" 

eaccelerator.enable="1" 

eaccelerator.optimizer="1" 

eaccelerator.check_mtime="1" 

eaccelerator.debug="0" 

eaccelerator.filter="" 

eaccelerator.shm_max="0" 

eaccelerator.shm_ttl="0" 

eaccelerator.shm_prune_period="0" 

eaccelerator.shm_only="0" 

eaccelerator.compress="0" 

eaccelerator.compress_level="9" 

eaccelerator.keys = "disk_only" 

eaccelerator.sessions = "disk_only" 

eaccelerator.content = "disk_only"' >> /usr/local/php/lib/php.ini 

  

#修改apache配置文件 

if [ "$(hostname -i)" == "127.0.0.1" ];then 

echo "OK" 

else 

sed -i "s/127.0.0.1.*$/127.0.0.1       `hostname`  localhost.localdomain localhost/g" /etc/hosts 

fi 

  

sed -i 's/User daemon/User www/g' /usr/local/apache/conf/httpd.conf 

sed -i 's/Group daemon/Group www/g' /usr/local/apache/conf/httpd.conf 

sed -i 's/#ServerName www.example.com:80/ServerName 127.0.0.1:80/g' /usr/local/apache/conf/httpd.conf 

sed -i '288a AddType application/x-httpd-php .php .phtml' /usr/local/apache/conf/httpd.conf 

sed -i '289a AddType application/x-httpd-php-source .phps' /usr/local/apache/conf/httpd.conf 

sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php@g' /usr/local/apache/conf/httpd.conf 

cat >> /usr/local/apache/conf/httpd.conf <<EOF #隐藏apache版本信息 

ServerTokens ProductOnly 

ServerSignature Off 

EOF 

  

#3. 安装配置postfix 

yum -y install postfix  #安装前删除sendmail,初始化脚本中已经删除 

postconf -n > /etc/postfix/main.cf 

  

#编辑main.cf 

echo '# hostname 

mynetworks = 127.0.0.1 

myhostname = mail.linuxeye.com 

mydestination = $mynetworks $myhostname 

  

# banner 

mail_name = Postfix 

smtpd_banner = $myhostname ESMTP $mail_name 

  

# response immediately 

smtpd_error_sleep_time = 0s 

  

# Message and return code control 

message_size_limit = 15360000 

mailbox_size_limit = 1024000000 

show_user_unknown_table_name = no 

alias_maps = hash:/etc/aliases 

  

# Queue lifetime control 

bounce_queue_lifetime = 1d 

maximal_queue_lifetime = 1d' >> /etc/postfix/main.cf 

  

chkconfig postfix on  #postfix开机自启 

  

#4. 安装Courier-imap 

yum -y install courier-imap 

sed -i 's/^IMAPDSTART=.*/IMAPDSTART=NO/g' /usr/lib/courier-imap/etc/imapd 

sed -i 's/^IMAPDSSLSTART=.*/IMAPDSSLSTART=NO/g' /usr/lib/courier-imap/etc/imapd-ssl 

service courier-imap start 

  

#5. 安装配置courier-authlib 

yum -y install courier-authlib 

yum -y install courier-authlib-mysql 

  

#编辑 /etc/authlib/authmysqlrc 

cat > /etc/authlib/authmysqlrc << EOF 

MYSQL_SERVER            localhost 

MYSQL_USERNAME          extmail 

MYSQL_PASSWORD          extmail 

MYSQL_SOCKET            /var/lib/mysql/mysql.sock 

MYSQL_PORT              3306 

MYSQL_OPT               0 

MYSQL_DATABASE          extmail 

MYSQL_USER_TABLE        mailbox 

MYSQL_CRYPT_PWFIELD     password 

MYSQL_UID_FIELD         uidnumber 

MYSQL_GID_FIELD         gidnumber 

MYSQL_LOGIN_FIELD       username 

MYSQL_HOME_FIELD        homedir 

MYSQL_NAME_FIELD        name 

MYSQL_MAILDIR_FIELD     maildir 

MYSQL_QUOTA_FIELD       quota 

MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,CONCAT('/home/domains/',homedir),CONCAT('/home/domains/',maildir),quota,name FROM mailbox WHERE username = '\$(local_part)@\$(domain)' 

EOF 

  

#修改authdaemonrc文件 

sed -i 's/authmodulelist=.*$/authmodulelist="authmysql"/g' /etc/authlib/authdaemonrc 

sed -i 's/authmodulelistorig=.*$/authmodulelistorig="authmysql"/g' /etc/authlib/authdaemonrc 

  

#修改authdaemon socket目录权限,如果该目录权限不正确修改,maildrop及postfix等将无法正确获取用户的信息及密码认证 

chmod 755 /var/spool/authdaemon/ 

service courier-authlib start 

  

#6. 安装cyrus-sasl 

rpm -e cyrus-sasl --nodeps 

yum -y install cyrus-sasl 

cat >> /etc/postfix/main.cf << EOF 

# 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 sender login matching config 

smtpd_sender_restrictions = permit_mynetworks,reject_sender_login_mismatch,reject_authenticated_sender_login_mismatch,reject_unauthenticated_sender_login_mismatch 

  

smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_maps.cf,mysql:/etc/postfix/mysql_virtual_alias_maps.cf 

  

# SMTP AUTH config here 

broken_sasl_auth_clients = yes 

smtpd_sasl_auth_enable = yes 

smtpd_sasl_local_domain = \$myhostname 

smtpd_sasl_security_options = noanonymous 

EOF 

  

cat > /usr/lib/sasl2/smtpd.conf << EOF 

pwcheck_method: authdaemond 

log_level: 3 

mech_list: PLAIN LOGIN 

authdaemond_path:/var/spool/authdaemon/socket 

EOF 

  

#7. 安装配置maildrop 

yum -y install maildrop 

#配置master.cf 为了使Postfix支持Maildrop,必须修改/etc/postfix/master.cf文件,flags前面有"两个空格" 

echo 'maildrop   unix        -       n        n        -        -        pipe 

flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop}' >> /etc/postfix/master.cf 

  

#测试maildrop对authlib支持,必须出现Courier Authentication Library extension enabled。 

maildrop -v 

  

#8. exmail依赖关系解决和extman验证码图片不显示 

cd /root 

wget http://blog.linuxeye.com/wp-content/uploads/extmail.zip 

unzip -qo extmail.zip 

cd extmail 

#wget http://search.cpan.org/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.021.tar.gz 

tar xzf DBD-mysql-4.021.tar.gz 

cd DBD-mysql-4.021 

perl Makefile.PL 

make && make install 

cd ../ 

  

#wget http://search.cpan.org/CPAN/authors/id/M/MH/MHARNISCH/Unix-Syslog-1.1.tar.gz 

tar xzf Unix-Syslog-1.1.tar.gz 

cd Unix-Syslog-1.1 

perl Makefile.PL 

make && make install 

cd ../ 

  

#extman验证码图片不显示 

#wget http://packages.sw.be/perl-GD/perl-GD-2.43-1.el5.rf.i386.rpm 

rpm -ivh perl-GD-2.43-1.el5.rf.i386.rpm 

  

#9. 安装配置extmail、extman 

tar xzf extman-1.1.tar.gz 

tar xzf extmail-1.2.tar.gz 

mkdir -p /var/www/extsuite 

mv extmail-1.2 /var/www/extsuite/extmail 

cp /var/www/extsuite/extmail/webmail.cf.default /var/www/extsuite/extmail/webmail.cf 

sed -i 's@^SYS_MYSQL_USER.*@SYS_MYSQL_USER = extmail@g' /var/www/extsuite/extmail/webmail.cf 

sed -i 's@^SYS_MYSQL_PASS.*@SYS_MYSQL_PASS = extmail@g' /var/www/extsuite/extmail/webmail.cf 

#sed -i 's/^SYS_G_ABOOK_FILE_CHARSET.*/SYS_G_ABOOK_FILE_CHARSET = gb2312/g' /var/www/extsuite/extmail/webmail.cf 

#sed -i 's/^SYS_USER_LANG.*/SYS_USER_LANG = zh_CN/g' /var/www/extsuite/extmail/webmail.cf 

  

mv extman-1.1 /var/www/extsuite/extman 

cp /var/www/extsuite/extman/webman.cf.default /var/www/extsuite/extman/webman.cf 

sed -i 's@^SYS_MYSQL_USER.*@SYS_MYSQL_USER = extmail@g' /var/www/extsuite/extman/webman.cf 

sed -i 's@^SYS_MYSQL_PASS.*@SYS_MYSQL_PASS = extmail@g' /var/www/extsuite/extman/webman.cf 

#sed -i 's/^SYS_G_ABOOK_FILE_CHARSET.*/SYS_G_ABOOK_FILE_CHARSET = gb2312/g' /var/www/extsuite/extman/webman.cf 

#sed -i 's/^# SYS_LANG.*/SYS_LANG = zh_CN/g' /var/www/extsuite/extman/webman.cf 

cp /var/www/extsuite/extman/docs/mysql_virtua* /etc/postfix/   #虚拟域和虚拟用户的配置文件 

sed -i 's/TYPE=MyISAM//g' /var/www/extsuite/extman/docs/extmail.sql 

mysql -uroot -padmin < /var/www/extsuite/extman/docs/extmail.sql 

sed -i 's/extmail.org/linuxeye.com/g' /var/www/extsuite/extman/docs/init.sql 

mysql -uroot -padmin < /var/www/extsuite/extman/docs/init.sql 

mysql -uroot -padmin -e "grant all privileges on extmail.* to extmail@localhost identified by 'extmail' with grant option;" 

mysql -uroot -padmin -e "delete from mysql.user where password='';" 

mkdir /tmp/extman 

chown -R vuser:vgroup /tmp/extman 

chown -R vuser.vgroup /var/www 

  

cat >> /etc/postfix/main.cf << EOF 

# extmail config here 

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf 

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf 

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf 

virtual_transport = maildrop: 

EOF 

  

newaliases 

service postfix restart 

  

#10. 配置apache 

sed -i 's@/usr/local/apache/htdocs@/var/www@g' /usr/local/apache/conf/httpd.conf 

sed -i 's/User www/User vuser/g' /usr/local/apache/conf/httpd.conf 

sed -i 's/Group www/Group vgroup/g' /usr/local/apache/conf/httpd.conf 

echo 'Include conf/extra/httpd-vhosts.conf' >> /usr/local/apache/conf/httpd.conf 

  

cat > /usr/local/apache/conf/extra/httpd-vhosts.conf << EOF 

<VirtualHost *:80> 

ServerName mail.linuxeye.com 

DocumentRoot "/var/www/extsuite/extmail/html" 

ErrorLog "/usr/local/apache/logs/mail_error.log" 

CustomLog "/usr/local/apache/logs/mail_access.log" common 

ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi 

<Directory /var/www/extsuite/extman/cgi> 

Options +ExecCGI 

AddHandler cgi-script .cgi 

</Directory> 

  

Alias /extmail /var/www/extsuite/extmail/html 

<Directory /var/www/extsuite/extmail/html> 

Options Indexes FollowSymLinks 

AllowOverride None 

Order allow,deny 

Allow from all 

</Directory> 

ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi 

Alias /extman /var/www/extsuite/extman/html 

</VirtualHost> 

EOF 

  

chown -R vuser.vgroup /tmp/eaccelerator/ 

service httpd restart 

 

©著作权归作者所有:来自51CTO博客作者linuxeye的原创作品,如需转载,请注明出处,否则将追究法律责任

extmail.脚本Shell


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消