1.安装apache
yum -y install gcc gcc-c++ pcre-devel make libxml2-devel
tar zxvf httpd-2.4.4.tar.gz -C /usr/src
cd /usr/src/httpd-2.4.4/
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-cgi --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache/htdocs --with-include-apr --enable-mods-shared=most
make && make install
2.安装mysql
略
3.安装php
tar zxvf php-5.3.13.tar.gz -C /usr/src
cd /usr/src/php-5.3.13
./configure --prefix=/usr/local/php --enable-mbstring --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc
cp php.ini-production /usr/local/php/etc/php.ini
4.配置apache支持php
vi /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
DirectoryIndex index.php index.html
5.安装postfix
userdel postfix
groupdel postfix
groupadd -g 1200 postdrop
groupadd -g 1000 postfix
userdel -M -u 1000 -g postfix -G postdrop -s /sbin/nologin
yum -y install cyrus-sasl-devel db*-devel
vi /etc/ld.so.conf
/usr/loca/mysql/lib //添加这一行
ldconfig
tar zxvf postfix-2.10.0.tar.gz -C /usr/src
cd /usr/src/postfix-2.10.0/
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/ -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2'
make
make install //运行后会要求输入安装路径,直接默认就行
6.配置postfix
cd /etc/postfix
postconf -n > main2.cf
mv main.cf main.cf.bak
mv main2.cf main.cf
vi main.cf //添加如下项
inet_interfaces = 192.168.10.6,127.0.0.1
myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
mydestination = $mydomain, $myhostname
home_mailbox = Maildir/
#mydestination //文件中原来的这一行加#号注释掉
7.配置dovecot
yum -y install pam-devel
useradd -M -s /sbin/nologin dovecot
tar zxvf dovecot-2.2.1.tar.gz -C /usr/src/
cd /usr/src/dovecot/
./configure --with-mysql --with-pam -sysconfdir=/etc
make
make install
cp -rf /usr/local/share/doc/dovecot/example-config/* /etc/dovecto/
vi /etc/dovecot/dovecot.conf
listen = *
cd /etc/dovecot
vi conf.d/10-auth.conf
disable_plaintext_auth = no
vi conf.d/10-ssl.conf
ssl = no
ssl_cert 和 ssl_key 两行加#号注释掉
vi conf.d/10-mail.conf
mail_location = maildir:~/Maildir
vi /etc/pam.d/dovecot
auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
useradd -M -s /sbin/nologin dovenull
7.配置SMTP认证
vi /usr/lib/sasl2/smtpd.conf
pwcheck_method:saslauthd
service saslauthd start
chkconfig --level 35 saslauthd on
vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.1,192.168.10.6
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
8.启动postfix、dovecot
postfix做到这已经可以支持用系统用户来收发邮件了...
chmod postfix /var/lib/postfix/master.lock
postfix check
postfix start
dovecot
9.配置postfix支持虚拟用户,首先建立用户数据库
tar zxvf extman-1.1.tar.gz -C /usr/src/
cd /usr/src/extman-1.1/docs/
mysql -u root -p < extmail.sql (这一步如果出现错误,参照其它postfix相关资料)
mysql -u root -p < init.sql
10.修改postfix配置
vi /etc/postfix/main.cf
#mydestination = $mydomain, $myhostname //注释掉这一行
virtual_mailbox_base = /mailbox
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
cp /usr/src/extman-1.1/docs/mysql_virtual_* /etc/postfix/
11.为虚拟用户配置SMTP认证
yum -y install libtool libtool-devel libtool-ltdl-devel sqlite-devel
useradd courier
tar jxvf courier-authlib-0.65.0.tar.bz2 -C /usr/src/
cd /usr/src/courier-authlib-0.65.0/
./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib --with-mysql-includes=/usr/local/mysql/include --with-mailuser=courier --with-mailgroup=courier
make
make install
make install-configure
vi /etc/ld.so.conf
/usr/local/courier-authlib/lib/courier-authlib
ldconfig
cd /usr/local/courier-authlib/etc/authlib/
cp authdaemonrc.dist authdaemonrc
vi authdaemonrc
authmodulelist="authmysql"
authmodulelistorig="authmysql"
chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
cp authmysqlrc.dist authmysql
vi authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME extmail
MYSQL_PASSWORD extmail
MYSQL_SOCKET /tmp/mysql.sock
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 concat('/mailbox/',homedir)
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)
cp /usr/src/courier-authlib-0.65.0/courier-authlib.sysvinit /etc/init.d/courier-authlib
chmod 755 /etc/rc.d/init.d/courier-authlib
chkconfig --level 35 courier-authlib on
service courier-authlib start
vi /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
authdaemond_path: /usr/local/courier-authlib/var/spool/authdaemon/socket
12.配置dovecot支持虚拟用户
vi /etc/dovecot/conf.d/10-auth.conf
#!include auth-system.conf.ext
!include auth-sql.conf.ext
vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/mailbox/%d/%n/Maildir
vi /etc/dovecot/dovecot.sql.conf.ext
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = select username as user, password as password from mailbox where username = '%u'
user_query = select maildir, uidnumber as uid, gidnumber as gid from mailbox where username = '%u'
13.安装extmail
yum -y install perl-devel gd-devel
tar zxvf extmail-1.2.tar.gz -C /usr/src/
/usr/src/extmail-1.2/tools/pkg-stats.sh //执行这条命令后会列出需要安装的软件包,使用下面的perl命令将没有的安装包安装即可
perl -MCPAN -e shell
>install 安装包的名字
>exit
mv /usr/src/extmail-1.2/ /usr/local/apache/htdocs/extmail
cd /usr/local/apache/htdocs/extmail
chown -R postfix:postfix cgi
cp webmail.cf.default webmail.cf
vi webmail.cf
SYS_CONFIG = /usr/local/apache/htdocs/extmail
SYS_LANGDIR = /usr/local/apache/htdocs/extmail/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extmail/html
SYS_MAILDIR_BASE = /mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
vi /usr/local/apache/conf/httpd.conf
#LoadModule suexec_module ......
#LoadModule cgi_module ...... //去掉这两行前面的#
ServerName mail.test.com:80
#DocumentRoot ...... //这行前面加#
#Include conf/extra/httpd-vhosts.conf //去掉这行前面的#
mkdir -p /mailbox/extmail.org/postmaster/Maildir/
chown -R postfix:postfix /mailbox
vi /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /usr/local/apache/htdocs/extmail/html
ServerName mail.test.com
ScriptAlias /extmail/cgi/ /usr/local/apache/htdocs/extmail/cgi/
Alias /extmail /usr/local/apache/htdocs/extmail/html
ScriptAlias /extman/cgi/ /usr/local/apache/htdocs/extman/cgi/
Alias /extman /usr/local/apache/htdocs/extman/html
SuexecUserGroup postfix postfix
</VirtualHost>
14.安装extman
yum -y install rrdtool rrdtool-perl
perl -MCPAN -e shell
install File::Tail
install Time::HiRes
exit
mv /usr/src/extman-1.1 /usr/local/apache/htdocs/extman
cd /usr/local/apache/htdocs/extman
chown -R postfix:postfix cgi
mkdir /tmp/extman
chown -R postfix:postfix /tmp/extman
cp webman.cf.default webman.cf
vi webman.cf
SYS_CONFIG = /usr/local/apache/htdocs/extman/
SYS_LANGDIR = /usr/local/apache/htdocs/extman/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extman/html
SYS_MAILDIR_BASE = /mailbox
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
15.配置邮件系统的图形化日志信息
perl -MCPAN -e shell
install Carp
install Symbol
install Time::Local
install Getopt::Long
exit
mkdir /usr/local/mailgraph_ext
cp /usr/local/apache/htdocs/extman/addon/mailgraph_ext/* /usr/local/mailgraph_ext/
/usr/local/mailgraph_ext/mailgraph-init start
/usr/local/apache/htdocs/extman/daemon/cmdserver -d
16.重新加载所有服务
service mysqld restart
/usr/local/apache/bin/apachectl restart
postfix reload
doveadm reload
17.登录
前台:http://mail.test.com
默认账户:postmaster 密码:extmail
后台:http://mail.test.com/extman
默认管理员账户:root@extmail.org 密码:extmail*123*
注意事项:
(1) 配置本机指向正确的DNS服务器,并在DNS服务器上添加对应的MX记录和A记录
(2)上面的perl和rrdtool都是用yum安装的,如果使用源码安装,参考下面的步骤
tar jxvf perl-5.16.3.tar.bz2 -C /usr/src
cd /usr/src/perl-5.16.3/
./Configure -des -Dprefix=/usr/local/perl
make
make test
make install
mv /usr/bin/perl /usr/bin/perl.bak
ln -s /usr/local/perl/bin/perl /usr/bin/perl
tar xvf rrdtool.tar.tar -C /usr/src
./configure --prefix=/usr/local/rrdtool
make
make install
cd /usr/local/perl/lib/site_perl/5.16.3/i686-linux/
ln -s /usr/local/rrdtool/lib/perl/5.16.3/i686-linux/RRDs.pm ./
ln -s /usr/local/rrdtool/lib/perl/5.16.3/i686-linux/auto/RRDs/RRDs.so ./
perl -MCPAN -e shell
>install 安装上文中所有需要的安装包