lamp+postfix+dovecot+courier-authlib
安装 LAMP
环境
yum -y install openssl-devel ncurses-devel libtermcap-devel libxml2-devel
apache 安装
tar zxf /httpd-2.2.26.tar.gz -C /usr/src/
cd /usr/src/httpd-2.2.26/
./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-cgi --enable-charset-lite --enable-ssl --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/httpd/htdocs
echo $?
make && make install
echo $?
\cp -f /usr/local/httpd/bin/apachectl
sed -i ‘1 a #chkconfig: 35 85 15‘ /etc/init.d/httpd
sed -i ‘2 a #description: Apache is a World Wide Web Server‘ /etc/init.d/httpd
chmod +x /etc/init.d/httpd
chkconfig --add httpd
mysql 安装
tar zxf /mysql-5.15 -C /usr/src/
cd /usr/src/mysql-5.15/
useradd -M -u 49 -s /sbin/nologin mysql
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=gbk,gb2312
make && make install
echo $?
#建立my.cnf配置文件
cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
sed -i ‘s/^skip-locking/#skip-locking/‘ /etc/my.cnf
sed -i ‘/#skip-locking/a skip-external-locking‘ /etc/my.cnf
#mysql执行优化、添加库路径
ln -sf /usr/local/mysql/bin/* /usr/local/bin/
echo "/usr/local/mysql/lib/mysql" > /etc/ld.so.conf.d/mysql-64.conf
ldconfig
#建立 mysqld 服务控制脚本
cp -f /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
cd /usr/local/mysql/bin
mysql_install_db --user=mysql
#调整mysql目录权限
chown -R root:mysql /usr/local/mysql/
chown -R mysql /usr/local/mysql/var/
mysqladmin -uroot -p password 1234567
PHP 安装
tar zxf /php-5.4.24.tar.gz -C /usr/src/
cd /usr/src/php-5.4.24/
./configure --prefix=/usr/local/php --enable-mbstring --enable-sockets --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php
make && make install
echo $?
确认HTTP 对 PHP
awk ‘/^LoadModule/ { print }‘ /usr/local/httpd/conf/httpd.conf
sed -i ‘/DirectoryIndex/s/$/ index.php/‘ /usr/local/httpd/conf/httpd.conf
sed -i ‘/AddHandler allows/i \\tAddType application/x-httpd-php .php‘ /usr/local/httpd/conf/httpd.conf
启动LAMP平台、测试
service mysqld restart
service httpd restart
vim /usr/local/httpd/htdocs/test2.php
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘1234567‘);
if($link) echo "Success !!";
else echo "Failure !!";
mysql_close();
?>
从浏览器访问 http://服务器地址/test2.php,应显示“Success!!”
安装 postfix
service sendmail stop
chkconfig sendmail off
yum -y install db4-devel cyrus-sasl-devel
#运行帐号
groupadd -g 1200 postdrop
groupadd -g 1000 postfix
useradd -M -u 1000 -g 1000 -G 1200 -s /sbin/nologin postfix
#配置编译安装
tar zxf postfix -2.10.2.tar.gz
cd
make makefiles CCARGS=" -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DHAS_MYSQL -I/usr/local/mysql/include/mysql" AUXLIBS=" -L/usr/lib/sasl2 -lsasl2 -L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm"
make && make install
#15次回车
#检查是否支持mysql
postconf -m
#设置开机自动运行
sed -i ‘$ a \/usr\/sbin\/postfix start‘ /etc/rc.local
#安装 dovecot
yum -y install pam-devel
#添加允许帐号
useradd -M -s /sbin/nologin dovecot
useradd -M -s /sbin/nologin dovenull
tar zxf dovecot -2.2.5.tar.gz -C /usr/src
cd /usr/src/dovecot -2.2.5/
./configure --sysconfdir=/etc --with-mysql --with-pam
make && make install
cd doc/
\cp -rpf example-config/* /etc/dovecot/
#禁用ssl加密
#禁用ssl证书
#禁用ssl密钥
sed -i ‘0,/^#ssl/s/yes/no/‘ /etc/dovecot/conf.d/10-ssl.conf
sed -i ‘0,s/^ssl_cert/#ssl_cert/‘ /etc/dovecot/conf.d/10-ssl.conf
sed -i ‘0,/^ssl_cert/s/ssl_cert/#ssl_cert/‘ /etc/dovecot/conf.d/10-ssl.conf
sed -i ‘0,/^ssl_key/s/ssl_key/#ssl_key/‘ /etc/dovecot/conf.d/10-ssl.conf
#建立PAM认证设置
echo "#%PAM-1.0" >/etc/pam.d/dovecot
echo "auth required pam nologin.so" >> /etc/pam.d/dovecot
echo "auth include system-auth" >> /etc/pam.d/dovecot
echo "account include system-auth" >> /etc/pam.d/dovecot
echo "session include system-auth" >> /etc/pam.d/dovecot
#添加dovecot服务
cp dovecot-initd.sh /etc/init.d/dovecot
chmod +x /etc/init.d/dovecot
chkconfig --add dovecot
#安装 courier-authlib
yum -y install libtool-ltdl-devel expect
tar jxf courier-authlib-0.63.0.tar.bz2 -C /usr/src
cd /usr/src/courier-authlib-0.63.0
./configure --prefix=/usr/local/authd --without-stdheaderdir --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql --with-mailuser=postfix --with-mailgroup=postfix --without-authpam --without-authldap --without-authpgsql --without-authcustom --without-authpipe --without-authpwd --without-authshadow
--without-authuserdb #加上可能有问题
make $$make install $$make install-configure
#更新搜索框路径
echo "/usr/local/authd/lib/courier-authlib" > /etc/ld.so.conf.d/courier-authlib.conf
ldconfig
#添加启动脚本
cp /usr/src/courier-authlib-0.63.0/courier-authlib.sysvinit /etc/init.d/authd
chmod +x /etc/init.d/authd
chkconfig --add authd
配置虚拟用户支持
#准备虚拟邮件域、虚拟用户的mysql库
#导入extman提供的两个sql 脚本
tar zxf extman-1.1.tar.gz
service mysqld restart
mysql -u root < docs/extmail.sql
mysql -u root -p1234567 < docs/extmail.sql
mysql -u root -p1234567 < docs/init.sql
#数据库帐号/密码 extmail/extmail webman/extman
#邮箱帐号/密码 [email protected]/extmail
#管理帐号/密码[email protected]/extmail*123*
#创建邮箱仓库
mkdir -p /mxdir/extmail.org/postmaster/Maildir
chown -R postfix:postfix /mxdir/1
#配置posfix支持虚拟用户
cd /usr/src/extman-1.1/docs
cp mysql_virtual_*.cf /etc/postfix/
chown -R :postfix /etc/postfix/mysql_virtual_*.cf
chmod o-r /etc/postfix/mysql_virtual_*.cf
添加虚拟用户支持 启用多邮件域支持
sed -i ‘/# Note:/a inet_interfaces = 192.168.1.254, 127.0.0.1‘ /etc/postfix/main.cf #监听地址
sed -i ‘/other configuration parameters/a myhostname = mail.zongxuan.com‘ /etc/postfix/main.cf #配置主机名
sed -i ‘/^#mydomain/i mydomain = zongxuan.com‘ /etc/postfix/main.cf#配置域名
sed -i ‘s/#home_mailbox = Maildir/home_mailbox = Maildir/‘ /etc/postfix/main.cf
sed -i ‘/the value on the table right-hand side is not used/a mynetworks = 127.0.0.1‘ /etc/postfix/main.cf
sed -i ‘/PARALLEL DELIVERY TO THE SAME DESTINATION/i smtpd_sasl_auth_enable = yes‘ /etc/postfix/main.cf #启用smtp认证
sed -i ‘/smtpd_sasl_auth_enable = yes/a smtpd_sasl_security_options = noanonymous‘ /etc/postfix/main.cf
sed -i ‘/smtpd_sasl_security_options = noanonymous/a smtpd_recipient_restrictions =‘ /etc/postfix/main.cf
sed -i ‘/smtpd_recipient_restrictions =/a permit_mynetworks,‘ /etc/postfix/main.cf
sed -i ‘/permit_mynetworks,/a permit_sasl_authenticated,‘ /etc/postfix/main.cf ***
sed -i ‘/permit_sasl_authenticated/a reject_unauth_destination‘ /etc/postfix/main.cf
#邮箱空间的根目录
echo "######" >> /etc/postfix/main.cf
echo "virtual_mailbox_base = /mxdir" >> /etc/postfix/main.cf
echo "virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf" >> /etc/postfix/main.cf
echo "virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf" >> /etc/postfix/main.cf
echo "virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf" >> /etc/postfix/main.cf
#用户postfix的UID
#组postfix的UID
echo "virtual_uid_maps = static:1000" >> /etc/postfix/main.cf
echo "virtual_gid_maps = static:1000" >> /etc/postfix/main.cf
#启动postfix 服务
postfix start
#配置courier-authlib支持虚拟用户
#设置authdaemonrc认证服务
#确保认证模块仅启用authmysql,根据需要可将DEBUG_LOGIN设为2开启详细调试 生产0
sed -i ‘0,/^authmodulelist/s/authuserdb //‘ /usr/local/authd/etc/authlib/authdaemonrc
sed -i ‘0,/authmodulelistorig=/s/authuserdb //‘ /usr/local/authd/etc/authlib/authdaemonrc
#修改sasl验证方式
echo "pwcheck_method:authdaemond" > /etc/sasl2/smtpd.conf
echo "authdaemond_path:/usr/local/authd/var/spool/authdaemon/socket" >> /etc/sasl2/smtpd.conf
chmod +x /etc/sasl2/smtpd.conf
#配置authmysqlrc数据库连接
sed -i ‘/^MYSQL_SERVER/s/mysql.example.com/localhost/‘ /usr/local/authd/etc/authlib/authmysqlrc #mysql服务器地址
sed -i ‘/^MYSQL_USERNAME/s/admin/extmail/‘ /usr/local/authd/etc/authlib/authmysqlrc#mysql用户名
sed -i ‘/^MYSQL_PASSWORD/s/admin/extmail/‘ /usr/local/authd/etc/authlib/authmysqlrc#mysql连接密码
##sed -i ‘/MYSQL_SOCKET/s/var/tmp/‘ /usr/local/authd/etc/authlib/authmysqlrc#mysqld服务的接口文件
##sed -i ‘/mysql.sock/s/# //‘ /usr/local/authd/etc/authlib/authmysqlrc#mysqld服务的接口文件
sed -i ‘/^MYSQL_SOCKET /var/mysql/mysql.sock/d‘
sed -i ‘/^MYSQL_SOCKET/a MYSQL_SOCKET \/tmp\/mysql.sock‘ /usr/local/authd/etc/authlib/authmysqlrc
sed -i ‘/^MYSQL_DATABASE/s/mysql/extmail/‘ /usr/local/authd/etc/authlib/authmysqlrc#要访问的库
sed -i ‘/^MYSQL_USER_TABLE/s/passwd/mailbox/‘ /usr/local/authd/etc/authlib/authmysqlrc#存放虚拟用户的表
sed -i ‘/^MYSQL_CRYPT_PWFIELD/s/crypt/password/‘ /usr/local/authd/etc/authlib/authmysqlrc#密码字段
sed -i ‘/^MYSQL_UID_FIELD/s/uid/uidnumber/‘ /usr/local/authd/etc/authlib/authmysqlrc#用户UID字段
sed -i ‘/^MYSQL_GID_FIELD/s/gid/gidnumber/‘ /usr/local/authd/etc/authlib/authmysqlrc#组GID字段
sed -i ‘/^MYSQL_LOGIN_FIELD/s/id/username/‘ /usr/local/authd/etc/authlib/authmysqlrc#用户名字段
sed -i "/^MYSQL_HOME_FIELD/s/home/concat(‘\/mxdir\/‘,homedir)/" /usr/local/authd/etc/authlib/authmysqlrc #用户主目录
sed -i "/# MYSQL_MAILDIR_FIELD/s/maildir/concat(‘\/mxdir\/‘,maildir)/" /usr/local/authd/etc/authlib/authmysqlrc#邮箱目录
sed -i ‘/# MYSQL_MAILDIR_FIELD/s/#//‘ /usr/local/authd/etc/authlib/authmysqlrc
#启用authd系统服务
service authd start
#配置dovecot 支持虚拟用户
#修改邮箱路径设置
sed -i ‘/#mail_location /s/=/= maildir:\/mxdir\/%d\/%n\/Maildir/‘ /etc/dovecot/conf.d/10-mail.conf
sed -i ‘s/^#mail_location/mail_location/‘ /etc/dovecot/conf.d/10-mail.conf
#对用户密码启用sql认证文件 查询设置由args指定的独立文件提供
cp /etc/dovecot/conf.d/auth-sql.conf.ext /etc/dovecot/conf.d/10-auth-sql.conf
#设置sql驱动类型及查询语句 使用sql语句从数据库查询用户名密码
sed -i ‘/#driver/a driver = mysql‘ /etc/dovecot/dovecot-sql.conf.ext
sed -i ‘/#connect/a connect =host=localhost dbname=extmail user=extmail password=extmail‘ /etc/dovecot/dovecot-sql.conf.ext
sed -i ‘/#default_pass_scheme/a default_pass_scheme = CRYPT‘ /etc/dovecot/dovecot-sql.conf.ext
sed -i "/#password_query /a SELECT username,password FROM mailbox WHERE username=‘%u‘" /etc/dovecot/dovecot-sql.conf.ext
sed -i "/#password_query/a password_query = SELECT username,password FROM mailbox WHERE username=‘%u‘" /etc/dovecot/dovecot-sql.conf.ext
sed -i "/#user_query/a user_query = SELECT maildir,uidnumber,gidnumber FROM mailbox WHERE username=‘%u‘" /etc/dovecot/dovecot-sql.conf.ext
#重启dovecot服务
service dovecot restart
chown daemon:daemon /usr/local/authd/var/spool/authdaemon/socket
部署extmail 邮箱系统
安装extmail 所要的perl
tar zxf Unix-Syslog-1.1.tar.gz
tar zxf DBI-1.607.tar.gz
tar zxf DBD-mysql-4.011.tar.gz
cd Unix-Syslog-1.1
perl Makefile.PL
make && make install
cd ../DBI-1.607
perl Makefile.PL
make && make install
cd ../DBD-mysql-4.011
perl Makefile.PL
make && make install
#安装extmail邮件系统
tar zxf extmail-1.2.tar.gz
mv extmail-1.2 /usr/local/httpd/htdocs/extmail
chown -R postfix:postfix /usr/local/httpd/htdocs/extmail/cgi/
#建立webmail.cf 配置文件
cp webmail.cf.default webmail.cf
vim webmail.cf
SYS_CONFIG = /usr/local/httpd/htdocs/extmail/
SYS_LANGDIR = /usr/local/httpd/htdocs/extmail/lang
SYS_TEMPLDIR = /usr/local/httpd/htdocs/extmail/html
SYS_MAILDIR_BASE = /mxdir
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
SYS_AUTHLIB_SOCKET = /usr/local/authd/var/spool/authdaemon/socket
SYS_G_ABOOK_FILE_PATH = /usr/local/httpd/htdocs/extmail/globabook.cf
调整httpd服务配置
添加一个虚拟主机mail.zongxuan.com
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName mail.zongxuan.com
DocumentRoot "/usr/local/httpd/htdocs/extmail/html"
ScriptAlias /extmail/cgi /usr/local/httpd/htdocs/extmail/cgi/
Alias /extmail /usr/local/httpd/htdocs/extmail/html/
SuexecUserGroup postfix postfix
</VirtualHost>
vim /usr/local/httpd/conf/httpd.conf
添加 支持php
index.php
打开配置
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
插入一行
CharsetDefault utf8
测试extmail系统
127.0.0.1
用户postmaster 密码extmail extmail.org
部署extman邮件系统管理平台
rpm -ivh rrdtool-1.2.27-4.el5.x86_64.rpm
rpm -ivh rrdtool-perl-1.2.27-4.el5.x86_64.rpm
yum -y install gd-devel
tar zxf GD-2.41.tar.gz
tar zxf File-Tail-0.99.3.tar.gz
cd GD-2.41
perl Makefile.PL
make && make install
cd File-Tail
perl Makefile.PL
make && make install
安装及配置extman管理系统
tar zxf extman-1.1.tar.gz
mv extman-1.1 /usr/local/httpd/htdocs/extman
chown -R postfix:postfix /usr/local/httpd/htdocs/extman/cgi/
cd /usr/local/httpd/htdocs/extman/
cp webman.cf.default webman.cf
vim webman.cf
SYS_CONFIG = /usr/local/httpd/htdocs/extman/
SYS_LANGDIR = /usr/local/httpd/htdocs/extman/lang
SYS_TEMPLDIR = /usr/local/httpd/htdocs/extman/html
SYS_MAILDIR_BASE = /mxdir
SYS_SESS_DIR = /tmp/extman/
SYS_CAPTCHA_ON = 0
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
创建工作目录/tmp/extman
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman
调整httpd服务配置
修改虚拟主机 mail.zongxuan.com 配置 添加对extman/目录的别名设置以便从 http://mail.zongxuan.com/extman/访问
添加
ScriptAlias /extman/cgi /usr/local/httpd/htdocs/extman/cgi/
Alias /extman /usr/local/httpd/htdocs/extman/html/
service httpd restart
启用mailgraph 图形插件
图形化分析邮件通信 /var/log/maillog
extman 源码包带有mailgraph 插件程序 在个别需要部署到/usr/local/下
cp -rf addon/mailgraph_ext/ /usr/local/
cd /usr/local/mailgraph_ext/
cp mailgraph-init /etc/init.d/mailgraphd
chkconfig --add mailgraphd
service mailgraphd start
启动cmdserver进程 提供特权接口
/usr/local/httpd/htdocs/extman/daemon/cmdserver -d
vim /etc/rc.local
/usr/local/httpd/htdocs/extman/daemon/cmdserver -d
访问extman 系统
http://mail.zongxuan.com/extman/
帐号[email protected]
密码extmail*123*
添加域
OK了