Postfix全功能邮件服务器
第一章 安装前准备工作
postfix所需软件包
httpd-2.2.19.tar.bz2 安装源码包apache
mysql-5.0.95.tar.gz 安装源码包mysql
php-5.4.0.tar.gz2 安装php软件
postfix-2.8.2.tar.gz postfix主程序
dovecot-1.1.4.tar.gz IMAP和POP3邮件服务器软件
squirrelmail-1.4.13.tar.bz2 web界面邮件管理
extman-1.1.tar.gz 邮件后台管理程序
extmail-1.2.tar.gz web界面邮件管理
courier-authlib-0.60.2.tar.bz2 SMTP发信认证
Unix-Syslog-1.1.tar.gz
DBI-1.607.tar.gz
DBD-mysql-4.011.tar.gz 以上三个包为extmail的倚赖包
GD-2.41.tar.gz
File-Tail-0.99.3.tar.gz
rrdtool-1.2.23-3.el5.i386.rpm
rrdtool-perl-1.2.23-3.el5.i386.rpm 以上四个包为extman的倚赖包
配置DNS
[root@localhost ~]# vim /etc/resolv.conf
nameserver 222.88.88.88
nameserver 192.168.2.100
search localdomain
[root@localhost ~]# yum install bind bind-chroot caching-nameserver
[root@localhost ~]# cd /var/named/chroot/etc/
[root@localhost etc]# cp -p named.caching-nameserver.conf named.conf
[root@localhost etc]# vim named.conf
15 listen-on port 53 { any; };
27 allow-query { any; };
28 allow-query-cache { any; };
37 match-clients { any; };
38 match-destinations { any; };
[root@localhost etc]# vim named.rfc1912.zones
21 zone "a.org" IN {
22 type master;
23 file "a.org.db";
24 allow-update { none; };
25 };
26 zone "2.168.192.in-addr.arpa" IN {
27 type master;
28 file "192.168.2.db";
29 allow-update { none; };
30 };
[root@localhost etc]# cd ../var/named/
[root@localhost named]# cp -p localhost.zone a.org.db
[root@localhost named]# vim a.org.db
1 $TTL 86400
2 @ IN SOA ns.a.org. root (
3 42 ; serial (d. adams)
4 3H ; refresh
5 15M ; retry
6 1W ; expiry
7 1D ) ; minimum
8
9 @ IN NS ns.a.org.
10 ns IN A 192.168.2.100
11 mail IN A 192.168.2.100
12 pop3 IN CNAME mail
13 smtp IN CNAME mail
14 @ IN MX 10 mail
[root@localhost named]# cp -p named.local 192.168.2.db
[root@localhost named]# vim 192.168.2.db
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
100 IN PTR mail.a.org.
[root@localhost named]# chkconfig named on
[root@localhost named]# service named start
Starting named: [ OK ]
[root@localhost named]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=mail.a.org
[root@localhost named]# vim /etc/hosts
127.0.0.1 mail.a.org localhost.localdomain localhost
[root@localhost named]# init 6
[root@mail ~]# dig -t mx a.org
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t mx a.org
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20756
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;a.org. IN MX
;; ANSWER SECTION:
a.org. 86400 IN MX 10 mail.a.org.
;; AUTHORITY SECTION:
a.org. 86400 IN NS ns.a.org.
;; ADDITIONAL SECTION:
mail.a.org. 86400 IN A 192.168.2.100
ns.a.org. 86400 IN A 192.168.2.100
;; Query time: 4 msec
;; SERVER: 192.168.2.100#53(192.168.2.100)
;; WHEN: Mon Apr 9 15:08:17 2012
;; MSG SIZE rcvd: 93
第二章 LAMP平台结构
2.1 安装apache
[root@mail ~]# yum -y install *gcc* openssl-devel
[root@mail ~]# tar -jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/httpd-2.2.19/
[root@mail httpd-2.2.19]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --enable-auth-digest --enable-cgi --with-ssl=/usr/lib --enable-ssl --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache2/htdocs
[root@mail httpd-2.2.19]# make
[root@mail httpd-2.2.19]# make install
[root@mail httpd-2.2.19]# cd /usr/local/apache2/bin/
[root@mail bin]# vim apachectl
#!/bin/sh
# chkconfig: 35 85 15
# description: Apache is a World Wide Web Server
[root@mail bin]# cp apachectl /etc/init.d/apache
[root@mail bin]# chkconfig --add apache
[root@mail bin]# chkconfig apache on
[root@mail bin]# service apache start
[root@mail bin]# netstat -tupln |grep httpd
tcp 0 0 :::80 :::* LISTEN 26754/httpd
2.2安装mysql
[root@mail ~]# tar -zxvf mysql-5.0.95.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/mysql-5.0.95/
[root@mail mysql-5.0.95]# useradd -M -s /sbin/nologin mysql
添加mysql用户,如果安装系统时候已经装过mysql会提示用户已存在,建议在安装前先卸载掉系统自带的mysql,卸载完成后必须重启,否则新装的mysql会无法启动,提示错误信息3306端口被占有
[root@mail mysql-5.0.95]# yum -y install libtermcap-devel
[root@mail mysql-5.0.95]# ./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql
[root@mail mysql-5.0.95]# make
[root@mail mysql-5.0.95]# make install
安装完成
配置mysql复制主配置文件
[root@mail mysql-5.0.95]# cp support-files/my-medium.cnf /etc/my.cnf
初始化
[root@mail mysql-5.0.95]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@mail mysql-5.0.95]# chown -R root:mysql /usr/local/mysql/
[root@mail mysql-5.0.95]# chown -R mysql /usr/local/mysql/var/
添加库文件路径
[root@mail mysql-5.0.95]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/mysql/
[root@mail mysql-5.0.95]# ldconfig -v |grep mysql
/usr/local/mysql/lib/mysql:
libmysqlclient.so.15 -> libmysqlclient.so.15.0.0
后台安全启动(如果显示启动并且卡住不动按回车
[root@mail mysql-5.0.95]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
复制启动脚本
[root@mail mysql-5.0.95]# cp support-files/mysql.server /etc/init.d/mysqld
[root@mail mysql-5.0.95]#chmod +x /etc/init.d/mysqld
[root@mail mysql-5.0.95]#ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@mail mysql-5.0.95]# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/
赋予脚本执行权限
[root@mail mysql-5.0.95]# chkconfig mysqld on
[root@mail mysql-5.0.95]# service mysqld start
Starting MySQL [ OK ]
[root@mail mysql-5.0.95]# netstat -tupln |grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 23971/mysqld
[root@mail mysql-5.0.95]# ps -e |grep mysqld
23945 pts/1 00:00:00 mysqld_safe
23971 pts/1 00:00:00 mysqld
设置系统全局的环境变量PATH值,方便使用mysql数据库命令
[root@mail mysql-5.0.95]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
2.3安装php软件
[root@mail ~]# tar -zxvf php-5.4.0.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/php-5.4.0/
[root@mail php-5.4.0]# ./configure --prefix=/usr/local/php5 --enable-mbstring --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5
[root@mail php-5.4.0]# make
[root@mail php-5.4.0]# make install
复制配置文件
[root@mail php-5.4.0]# cp php.ini-production /usr/local/php5/php.ini
修改apache服务的主配置文件使其支持php
[root@mail php-5.4.0]# vim /usr/local/apache2/conf/httpd.conf
53 LoadModule php5_module modules/libphp5.so
确认53行的存在,如果没有就重新编译php
添加这行记录,在这行添加关于php格式首页
167 DirectoryIndex index.php index.html
310 AddType application/x-httpd-php .php
2.4测试php是否与apache整合成功
[root@mail php-5.4.0]# cd /usr/local/apache2/htdocs/
[root@mail htdocs]# mv index.html index.php
[root@mail htdocs]# vim index.php
<?php
phpinfo();
?>
[root@mail htdocs]# service apache stop
[root@mail htdocs]# service apache start
在浏览器中输入http://192.168.2.100/index.php 看到下图表示跟mysql服务整合成功
[root@mail htdocs]# vim index.php
<?php
$link=mysql_connect('127.0.0.1','root','');
if($link)
echo "scuess";
else
echo "fail";
?>
在浏览器中输入http://192.168.2.100/index.php 看到下图表示跟mysql服务整合成功
[root@mail htdocs]# service mysqld stop
Shutting down MySQL... [ OK ]
第三章 安装postfix
3.1关闭系统自带的sendmail服务
[root@mail ~]# service sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
[root@mail ~]# chkconfig sendmail off
3.2编译安装postfix软件
[root@mail ~]# groupadd -g 1200 postdrop
[root@mail ~]# groupadd -g 1000 postfix
[root@mail ~]# useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/
安装,安装过程中会出现互动提问,直接选择默认设置
[root@mail ~]# cd /usr/local/src/postfix-2.8.2/
[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2'
[root@mail postfix-2.8.2]# make
[root@mail postfix-2.8.2]# make install
生成别名二进制文件,这个步骤如果忽略,会造成postfix效率降低
[root@mail postfix-2.8.2]# newaliases
查看postfix支持的模块是否有mysql
[root@mail postfix-2.8.2]# postconf -m |grep mysql
mysql
第四章 配置postfix
进行一些基本配置,测试启动postfix进行发信
[root@mail postfix-2.8.2]# cp /etc/postfix/main.cf /etc/postfix/main.cf.bak
[root@mail postfix-2.8.2]# vim /etc/postfix/main.cf
76 myhostname = mail.a.org
83 mydomain = a.org
99 myorigin = $mydomain
113 inet_interfaces = all
162 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
163 mail.$mydomain, www.$mydomain, ftp.$mydomain
260 mynetworks = 192.168.2.0/24, 127.0.0.0/8
说明
myorigin 参数用来指明发件人所在的域名
mydestination参数指定postfix接收邮件时收件人的域名,即您的postfix系统要接收到哪个域名的邮件;
myhostname 参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain参数指定您的域名,默认情况下,postfix将myhostname的第一部分删除而作为mydomain的值;
mynetworks 参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,如果是本地网络用户则允许其访问;
inet_interfaces 参数指定postfix系统监听的网络接口;
注意:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当作参数值的一部分来使用;
3、每修改参数及其值后执行 postfix reload 即可令其生效;但若修改了inet_interfaces,则需重新启动postfix;
4、如果一个参数的值有多个,可以将它们放在不同的行中,只需要在其后的每个行前多置一个空格即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
检查配置启动postfix
[root@mail postfix-2.8.2]# postfix start
postfix/postfix-script: starting the Postfix mail system
[root@mail postfix-2.8.2]# postfix check
[root@mail postfix-2.8.2]# service postfix restart
postfix: unrecognized service
制作postfix启动控制文件
#没有启动文件的启动postfix方法如下:
#/usr/local/postfix/sbin/postfix start
[root@mail postfix-2.8.2]# mkdir /tmp/abc
[root@mail postfix-2.8.2]# cd /tmp/abc/
[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./
[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio -id
16333 blocks
[root@mail abc]# ll etc/rc.d/init.d/postfix
-rwxr-xr-x 1 root root 2404 Apr 13 07:51 etc/rc.d/init.d/postfix
[root@mail abc]# cp etc/rc.d/init.d/postfix /etc/rc.d/init.d/
[root@mail abc]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@mail abc]# chkconfig --add postfix
[root@mail abc]# chkconfig postfix on
[root@mail abc]# chkconfig --list postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
连接postfix,验证服务启动状况,测试是否可以发信:
[root@mail abc]# cd
[root@mail ~]# useradd user1
[root@mail ~]# useradd user2
[root@mail ~]# echo "123" |passwd --stdin user1
Changing password for user user1.
passwd: all authentication tokens updated successfully.
[root@mail ~]# echo "123" |passwd --stdin user2
Changing password for user user2.
passwd: all authentication tokens updated successfully.
[root@mail ~]# telnet mail.a.org 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.a.org ESMTP Postfix
ehlo mail.a.org
250-mail.a.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:user1@a.org
250 2.1.0 Ok
rcpt to:user2@a.org
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
user1-to-user2
.
250 2.0.0 Ok: queued as 308C8CF785
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@mail ~]# su - user2
[user2@mail ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user2": 1 message 1 new
>N 1 user1@a.org Fri Apr 13 08:03 13/412
& 1
Message 1:
From user1@a.org Fri Apr 13 08:03:56 2012
X-Original-To: user2@a.org
Delivered-To: user2@a.org
Date: Fri, 13 Apr 2012 08:03:09 +0800 (CST)
From: user1@a.org
user1-to-user2
& quit
Saved 1 message in mbox
第五章 Dovecot软件安装(提供pop3/imap4协议)
5.1安装dovecot
[root@mail ~]# tar -zxvf dovecot-1.1.4.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/dovecot-1.1.4/
[root@mail dovecot-1.1.4]# useradd -M -s /sbin/nologin dovecot
[root@mail dovecot-1.1.4]# ./configure --sysconfdir=/etc --with-mysql
[root@mail dovecot-1.1.4]# make
[root@mail dovecot-1.1.4]# make install
5.2安装完成,配置
[root@mail dovecot-1.1.4]# cp /etc/dovecot-example.conf /etc/dovecot.conf
[root@mail dovecot-1.1.4]# vim /etc/dovecot.conf
23 protocols = pop3 imap
47 disable_plaintext_auth = no
87 ssl_disable = yes
208 mail_location = maildir:~/Maildir
[root@mail dovecot-1.1.4]# vim /etc/postfix/main.cf
415 home_mailbox = Maildir/
[root@mail dovecot-1.1.4]# vim /etc/pam.d/dovecot
auth required pam_nologin.so
auth include system-auth
account include system-auth
session include system-auth
[root@mail dovecot-1.1.4]# /usr/local/sbin/dovecot -c /etc/dovecot.conf
[root@mail dovecot-1.1.4]# echo "/usr/local/sbin/dovecot -c /etc/dovecot.conf" >> /etc/rc.local
[root@mail dovecot-1.1.4]# pkill -1 dovecot
[root@mail dovecot-1.1.4]# netstat -tupln |grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 1187/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 1187/dovecot
测试接受服务器dovecot
[root@mail dovecot-1.1.4]# telnet 127.0.0.1 110
Trying 127.0.0.1...
Connected to mail.a.org (127.0.0.1).
Escape character is '^]'.
+OK Dovecot ready.
user user2
+OK
pass 123
+OK Logged in.
list
+OK 2 messages:
1 380
2 374
.
retr 1
+OK 380 octets
Return-Path: <user1@a.org>
X-Original-To: user2@a.org
Delivered-To: user2@a.org
Received: from mail.a.org (mail.a.org [127.0.0.1])
by mail.a.org (Postfix) with ESMTP id 7E142CF76B
for <user2@a.org>; Fri, 13 Apr 2012 08:43:30 +0800 (CST)
Message-Id: <20120413004345.7E142CF76B@mail.a.org>
Date: Fri, 13 Apr 2012 08:43:30 +0800 (CST)
From: user1@a.org
11111111111
aa
.
quit
+OK Logging out.
Connection closed by foreign host.
第六章 安装webmail软件
6.1squirrelmail安装
[root@mail dovecot-1.1.4]# cd
[root@mail ~]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz -C /usr/local/apache2/htdocs/
[root@mail htdocs]# mv squirrelmail-webmail-1.4.22/ webmail
6.2配置webmail
[root@mail webmail]# cp config/config_default.php config/config.php
[root@mail webmail]# vim config/config.php
118 $domain = 'a.org';
146 $smtpServerAddress = 'localhost';
151 $smtpPort = 25;
210 $imapPort = 143;
231 $imap_server_type = 'dovecot';
499 $data_dir = '/usr/local/apache2/htdocs/webmail/data/';
517 $p_w_upload_dir = '/usr/local/apache2/htdocs/webmail/attach/';
6.3重启apache服务
[root@mail webmail]# service apache stop
[root@mail webmail]# service apache start
6.4测试:
客户端IE地址栏中输入 http://mail.a.org/webmail (前提mail.a.org可以被解析,否则用ip)
即可看见下图:
到此我们的postfix+webmail已经安装完成,但是为了使我们更好的管理维护邮件服务器的前端与后台接下来我们来安装extmail和extman以便实现我们的需求。
6.5初始化extman
6.5.1数据库脚本
[root@mail webmail]# service mysqld restart
Shutting down MySQL. [ OK ]
Starting MySQL. [ OK ]
[root@mail webmail]# cd
[root@mail ~]# tar -zxvf extman-1.1.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/extman-1.1/docs/
6.5.2脚本导入数据库的时候会询问密码,默认情况root用户密码为空
[root@mail docs]# mysql -u root -p < extmail.sql
Enter password:
[root@mail docs]# mysql -u root -p < init.sql
Enter password:
第七章 配置postfix
数据库的查询表
[root@mail ~]# postconf -m |grep mysql
mysql
修改配置文件
[root@mail ~]# vim /etc/postfix/main.cf
改行需要注释掉
162 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
163 # mail.$mydomain, www.$mydomain, ftp.$mydomain
652 virtual_mailbox_base = /mailbox
653 virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
654 virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
655 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
656 virtual_uid_maps = static:1000
657 virtual_gid_maps = static:1000
658 virtual_transport = virtual
[root@mail ~]# cd /usr/local/src/extman-1.1/docs/
[root@mail docs]# cp mysql_virtual_* /etc/postfix/
第八章 虚拟用户设置smtp发信认证
8.1软件安装
确认系统中的rpm格式的mysql软件被卸载
[root@mail docs]# rpm -qa |grep mysql
[root@mail docs]# cd
[root@mail ~]# tar -jxvf courier-authlib-0.62.4.tar.bz2 -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/courier-authlib-0.62.4/
[root@mail courier-authlib-0.62.4]# ./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-includes=/usr/local/mysql/include/mysql
[root@mail courier-authlib-0.62.4]# make
[root@mail courier-authlib-0.62.4]# make install
[root@mail courier-authlib-0.62.4]# make install-configure
8.2添加courier-authlib库文件路径
[root@mail courier-authlib-0.62.4]# vim /etc/ld.so.conf.d/courier-authlib.conf
/usr/local/courier-authlib/lib/courier-authlib
[root@mail courier-authlib-0.62.4]# ldconfig -v |grep courier-authlib
/usr/local/courier-authlib/lib/courier-authlib:
8.3修改authdaemonrc主配置文件
[root@mail courier-authlib-0.62.4]# cd /usr/local/courier-authlib/etc/authlib/
[root@mail authlib]# cp authdaemonrc authdaemonrc.bak
[root@mail authlib]# vim authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
[root@mail authlib]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
8.4修改authmysqlrc文件
[root@mail authlib]# cd /usr/local/courier-authlib/etc/authlib/
[root@mail authlib]# cp authmysqlrc authmysqlrc.bak
[root@mail authlib]# vim authmysqlrc
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /tmp/mysql.sock
56 MYSQL_PORT 3306
68 MYSQL_DATABASE extmail
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
113 MYSQL_UID_FIELD uidnumber
119 MYSQL_GID_FIELD gidnumber
128 MYSQL_LOGIN_FIELD username
133 MYSQL_HOME_FIELD concat('/mailbox/',homedir)
139 MYSQL_NAME_FIELD name
150 MYSQL_MAILDIR_FIELD concat('/mailbox/',maildir)
8.5复制courier-authlib脚本,并启动courier-authlib服务
[root@mail authlib]# cd /usr/local/src/courier-authlib-0.62.4/
[root@mail courier-authlib-0.62.4]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@mail courier-authlib-0.62.4]#cd
[root@mail ~]# chmod 755 /etc/init.d/courier-authlib
[root@mail ~]# chkconfig --add courier-authlib
[root@mail ~]# chkconfig --level 2345 courier-authlib on
[root@mail ~]# chkconfig --list courier-authlib
courier-authlib 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@mail ~]# service courier-authlib start
Starting Courier authentication services: authdaemond
第九章 修改cyrus sasl设置
添加如下文件
[root@mail ~]# vim /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
mech_list:PLAIN LOGIN
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socke
第十章 修改dovecot配置
10.1修改dovecot
[root@mail ~]# vim /etc/dovecot.conf
208 mail_location = maildir:/mailbox/%d/%n/Maildir
790 auth default {
795 mechanisms = plain
828 # passdb pam {
857 # }
899 passdb sql {
901 args = /etc/dovecot-mysql.conf
902 }
962 userdb sql {
964 args = /etc/dovecot-mysql.conf
965 }
打开一行,postfix的配置文件也要该
[root@mail ~]# vim /etc/postfix/main.cf
415 home_mailbox = Maildir/
10.2建立数据查询配置文件
手动产生/etc/dovecot-mysql.conf文件
[root@mail ~]# vim /etc/dovecot-mysql.conf
1 ver = mysql
2 connect = host=localhost dbname=extmail user=extmail password=extmail
3 default_pass_scheme = CRYPT
4 password_query = SELECT username AS user,password AS password FROM m ailbox W HERE username = ‘%u’
5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FRO M mailbo x WHERE username = ‘%u’
第十一章 建立虚拟用户
11.1建立邮箱目录并调整权限
[root@mail ~]# mkdir -p /mailbox/extmail.org/postmaster/Maildir
[root@mail ~]# cd /mailbox/extmail.org/postmaster/Maildir/
[root@mail Maildir]# chown -R postfix:postfix /mailbox/
启动服务
[root@mail Maildir]# dovecot
Fatal: Dovecot is already running with PID 1187 (read from /usr/local/var/run/dovecot/master.pid)
[root@mail Maildir]# /usr/local/sbin/dovecot -c /etc/dovecot.conf
Fatal: Dovecot is already running with PID 1187 (read from /usr/local/var/run/dovecot/master.pid)
11.2虚拟用户测试
确认authlib服务
[root@mail Maildir]# /usr/local/courier-authlib/sbin/authtest -s login postmaster@extmail.org extmail
Authentication succeeded.
Authenticated: postmaster@extmail.org (uid 1000, gid 1000)
Home Directory: /mailbox/extmail.org/postmaster
Maildir: /mailbox/extmail.org/postmaster/Maildir/
Quota: (none)
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
第十二章 extmail平台
基于Perl 语言开发的中文Webmail管理平台
套件:ExtMail --Web 界面的邮件操作
Extman –Web 界面的邮件系统管理
12.1平台安装
3个依赖包
[root@mail ~]# tar -zxvf Unix-Syslog-1.1.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/Unix-Syslog-1.1/
[root@mail Unix-Syslog-1.1]# perl Makefile.PL && make && make install
[root@mail ~]# tar -zxvf DBI-1.616.tar.gz -C /usr/local/src/
[root@mail DBI-1.616]# perl Makefile.PL
[root@mail DBI-1.616]# make
[root@mail DBI-1.616]# make install
[root@mail ~]# tar -zxvf DBD-mysql-4.020.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/DBD-mysql-4.020/
[root@mail DBD-mysql-4.020]# perl Makefile.PL
[root@mail DBD-mysql-4.020]# make
[root@mail DBD-mysql-4.020]# make install
注意以上三个包在编译安装过程可能会提示 警告信息 隐式函数 计算出的变量值未被使用等,只要没有error信息就一切ok
安装extmail
[root@mail DBD-mysql-4.020]# cd
[root@mail ~]# tar -zxvf extmail-1.2.tar.gz -C /usr/local/apache2/htdocs/
[root@mail ~]# cd /usr/local/apache2/htdocs/
[root@mail htdocs]# mv extmail-1.2/ extmail
[root@mail htdocs]# cd extmail/
[root@mail extmail]# chown -R postfix:postfix cgi/
[root@mail extmail]# cp webmail.cf.default webmail.cf
12.2修改配置文件
[root@mail extmail]# vim webmail.cf
2 SYS_CONFIG = /usr/local/apache2/htdocs/extmail/
5 SYS_LANGDIR = /usr/local/apache2/htdocs/extmail/lang
127 SYS_MAILDIR_BASE = /mailbox
139 SYS_MYSQL_USER = extmail
140 SYS_MYSQL_PASS = extmail
141 SYS_MYSQL_DB = extmail
142 SYS_MYSQL_HOST = localhost
143 SYS_MYSQL_SOCKET = /tmp/mysql.sock
12.3修改apache服务添加虚拟主机
[root@mail extmail]# vim /usr/local/apache2/conf/httpd.conf
66 User postfix
67 Group postfix
412 NameVirtualHost *:80
413 <VirtualHost *:80>
414 ServerName mail.a.org
415 DocumentRoot /usr/local/apache2/htdocs/extmail/html/
416 ScriptAlias /extmail/cgi/ "/usr/local/apache2/htdocs/extmail/cgi/"
417 Alias /extmail "/usr/local/apache2/htdocs/extmail/html/"
418 </VirtualHost>
重启apache
[root@mail extmail]# service apache stop
[root@mail extmail]# service apache start
12.4 Extmail无法访问问题原因
到这一步很多网上的文档都会说这时候只要在客户端访问 http://mail.a.org 就可以看到ExtMail的登录界面,但是经过我很多次实践改动配置得到的结果都是访问页面不存在404的错误提示页面,一度我曾认为可能是我之前编译的那三个倚赖包有问题,或者是我的PHP有问题,以及cgi权限问题都想到但是结果依然是404页面不存在,但是我可以很正常的看到访问http://mail.a.org时候页面确实是跳转到了http://mail.a.org /extmail/cgi/index.cgi这个目录,而且我这个目录中文件确实存在,没有任何问题,经过我多次尝试终于找到原因如果要成功的访问到这个页面就必须把Extman装上,并且在apache配置文件中写入extman的路径这样我终于如愿以偿的看到了期望已久的ExtMail的登录界面。
下面我们开始安装Extman
第十三章 extman平台
13.1安装包
4个依赖包
[root@mail extmail]# cd
[root@mail ~]# tar -zxvf GD-2.46.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/GD-2.46/
[root@mail GD-2.46]# perl Makefile.PL && make && make install
[root@mail ~]# tar -zxvf File-Tail-0.99.3.tar.gz -C /usr/local/src/
[root@mail ~]# cd /usr/local/src/File-Tail-0.99.3/
[root@mail File-Tail-0.99.3]# perl Makefile.PL && make && make install
[root@mail ~]# rpm -ivh rrdtool-1.2.23-3.el5.i386.rpm
[root@mail ~]# rpm -ivh rrdtool-perl-1.2.23-3.el5.i386.rpm
Extmail套件
[root@mail ~]# tar -zxvf extman-1.1.tar.gz -C /usr/local/apache2/htdocs/
[root@mail ~]# cd /usr/local/apache2/htdocs/
[root@mail htdocs]# mv extman-1.1/ extman
[root@mail htdocs]# cd extman/
[root@mail extman]# chown -R postfix:postfix cgi/
[root@mail extman]# mkdir /tmp/extman
[root@mail extman]# chown -R postfix:postfix /tmp/extman/
13.2修改配置文件
[root@mail extman]# cp webman.cf.default webman.cf
[root@mail extman]# vim webman.cf
2 SYS_CONFIG = /usr/local/apache2/htdocs/extman/
5 SYS_LANGDIR = /usr/local/apache2/htdocs/extman/lang
8 SYS_TEMPLDIR = /usr/local/apache2/htdocs/extman/html
12 SYS_MAILDIR_BASE = /mailbox
127 SYS_MYSQL_USER = webman
128 SYS_MYSQL_PASS = webman
129 SYS_MYSQL_DB = extmail
130 SYS_MYSQL_HOST = localhost
131 SYS_MYSQL_SOCKET = /tmp/mysql.sock
13.3调整apache主配置文件。添加extman相关目录别名
[root@mail extman]# vim /usr/local/apache2/conf/httpd.conf
412 NameVirtualHost *:80
413 <VirtualHost *:80>
414 ServerName mail.a.org
415 DocumentRoot /usr/local/apache2/htdocs/extmail/html/
416 ScriptAlias /extmail/cgi/ "/usr/local/apache2/htdocs/extmail/cgi/"
417 Alias /extmail "/usr/local/apache2/htdocs/extmail/html/"
418 ScriptAlias /extman/cgi "/usr/local/apache2/htdocs/extman/cgi/"
419 Alias /extman "/usr/local/apache2/htdocs/extman/html/"
420 </VirtualHost>
[root@mail extman]# service apache stop
[root@mail extman]# service apache start
13.4在客户端访问
http://mail.a.org就可以看到extmail登录界面了
http://mail.a.org/extman 就可以看到extman界面了
默认管理员帐号:root@extmail.org
默认密码:extmail*123*
如果无法登录禁用校验码,将1改为0
# [root@mail extman]# vim /usr/local/apache2/htdocs/extman/webman.cf
#21 SYS_CAPTCHA_ON = 1
第十四章 设置邮件系统的图形化日志信息
[root@mail ~]# ln -sf /usr/local/apache2/htdocs/extman/addon/mailgraph_ext/mailgraph-init /usr/sbin/
[root@mail ~]# cp -a /usr/local/apache2/htdocs/extman/addon/mailgraph_ext/ /usr/local/
[root@mail ~]# mailgraph-init start
Starting mail statistics grapher: mailgraph_ext
Starting queue statistics grapher: qmonitor
[root@mail ~]# qmonitor.pl start &
[1] 3209
[root@mail ~]# echo "/usr/sbin/qmoonitor.pl start" >> /etc/rc.d/rc.local
[root@mail ~]# echo "/usr/sbin/mailgraph-init start" >> /etc/rc.d/rc.local
第十五章 垃圾邮件过滤
15.1根据客户端的主机名/地址池过滤邮件
[root@mail ~]# vim /etc/postfix/main.cf
546 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
[root@mail ~]# vim /etc/postfix/access
447 192.168.3 REJECT
448 192.168.3.1 OK
449 192.168.3.2 OK
[root@mail ~]# postmap /etc/postfix/access
15.2根据客户机HELO信息中的主机名地址过滤邮件
[root@mail ~]# vim /etc/postfix/main.cf
547 smtpd_helo_required = yes
548 smtpd_helo_restrictions = reject_invalid_hostname
[root@mail ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system
15.3根据发件人的地址过滤邮件
[root@mail ~]# vim /etc/postfix/main.cf
549 smtpd_sender_login_maps =mysql:/etc/postfix/mysql_virtual_sender_maps.cf,mysql:/etc/postfix/m ysql_virtual_alias_maps.cf
550 smtpd_sender_restrictions =permit_mynetworks,reject_sender_login-mismatch,reject_non_fqdn_sen der,reject_unknown_sender_domain,check_sender_access hash:/etc/postfix/sender_access
[root@mail ~]# vim /etc/postfix/sender_access
1 ads@xxxx.com REJECT
2 marketing@ REJECT
3 fake.aptech.com REJECT
[root@mail ~]# postmap /etc/postfix/sender_access
15.4根据收件人的地址过滤邮件
[root@mail ~]# vim /etc/postfix/main.cf
551smtpd_recipient_restrictions =permit_mynetworks,permit_sasl_authenticated,reject_unauth_desti nation,reject_non_fqdn_ recipient,reject_unknown_recipient_domain
为了便于管理,您可以编辑脚本,将服务脚本添加到相关目录即可。限于篇幅,笔者略去操作步骤。
[root@mail ~]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
15.5基于邮件内容的过滤
15.1安装并配置mailscanner扫描工具
1.安装mailscanner扫描调度工具
[root@mail ~]# tar -zxvf MailScanner-4.84.3-1.rpm.tar.gz
[root@mail ~]# cd MailScanner-4.84.3-1
[root@mail MailScanner-4.84.3-1]# ./install.sh
2.修改配置文件Mailscanner
[root@mail ~]# vim /etc/MailScanner/MailScanner.conf
131 Run As User = postfix
136 Run As Group = postfix
165 Incoming Queue Dir = /var/spool/postfix/hold
169 Outgoing Queue Dir = /var/spool/postfix/incoming
2231 Required SpamAssassin Score = 7
2237 High SpamAssassin Score = 10
2437 Spam Actions = deliver header "X-Spam-Status: Yes"
2499 High Scoring Spam Actions = delete forward spam@extmail.org
3.配置postfix支持调用mailscanner
[root@mail ~]# vim /etc/postfix/main.cf
520 header_checks = regexp:/etc/postfix/header_checks
[root@mail ~]# vim /etc/postfix/header_checks
497 /^Received:/HOLD
4.调整邮件过滤列表的目录属主,属组,并启动mailscanner服务程序
[root@mail ~]# chown -R postfix.postfix /var/spool/MailScanner/incoming
[root@mail ~]# chown -R postfix.postfix /var/spool/MailScanner/quarantine
[root@mail ~]# service MailScanner start
Starting MailScanner daemons:
incoming postfix: [ OK ]
outgoing postfix: [ OK ]
MailScanner: [ OK ]
[root@mail ~]# chkconfig --level 35 MailScanner on
15.5.2.安装并配置SpamAssassin垃圾邮件过滤器
1.安装并配置SpamAssassin垃圾邮件过滤器
[root@mail Server]# yum list |grep spamassassin
This system is not registered with RHN.
RHN support will be disabled.
spamassassin.i386 3.2.5-1.el5 rhel-server
[root@mail Server]# yum -y install spamassassin
2.修改配置文件local.cf
(位于“/etc/mail/spamassassin/local.cf”,一般不需要进行任何修改,保
持默认设置即可)
3.启动SpamAssassin服务
[root@mail Server]# service spamassassin start
Starting spamd: [ OK ]
[root@mail Server]# chkconfig --level 35 spamassassin on
15.5.3安装并配置F-Port病毒查杀软件
1.安装F-Port软件包安装过程中出现提示是按回车键接受默认设置
[root@mail Server]# cd
[root@mail ~]# tar -zxvf fp-Linux-i686-ws.tar.gz -C /opt/
[root@mail ~]# cd /opt/f-prot/
[root@mail f-prot]# ./install-f-prot.pl
2.升级F-Port 病毒库(服务器要能够访问Internet 互联网)
升级需要连接initernet网卡,您可以编辑eth0:0将它的地址修改成您可以上网的网址,这样,您所使用的源地址不变,只需要将dns修改即可。
[root@mail ~]# cd /opt/f-prot/
[root@mail f-prot]# /opt/f-prot/fpupdate
[root@mail f-prot]# crontab -e
添加 00 8 * * * /opt/f-prot/fpupdate
[root@mail f-prot]# service crond start
[root@mail f-prot]# chkconfig --level 35 crond on
15.6测试
15.6.1测试反病毒能力
病毒测试数据:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
15.6.2测试反垃圾能力
垃圾邮件测试数据:
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
第十六章extman后台管理设置
16.1首页概况
登录进去首页显示系统管理员列表
16.2添加用户
基础设置 设置用户名,后面可选用户所在的域。
用户的磁盘限额、网络磁盘限额以及过期日期是否激活等(默认磁盘、网络磁盘限额为5M)
设置完基本信息保存修改会提示密码错误,所有要设置密码之后才可以保存修改。
16.2.1密码设置
设置密码,密码找回问题以及是否禁止用户修改密码
16.3添加别名
可以添加别名,别名所在的域,设置多个目标地址 提示 目标地址每行只能写一个并激活
16.4添加域
基础设置 设置域名、域名描述、最大用户、最大别名、最大限额、最大网络磁盘限额、传输方式、还有是否允许自由注册(如果勾上这个选项的话,在ExtMail登录页面下面有一个免费注册邮箱就可以注册,如果不勾的话注册免费邮箱时候就会提示域名不提供注册服务!)是否激活域名、最后是域名过期日期。
模版设置
设置域名新账户默认限额、网络磁盘限额、新账户默认生命周期以及新账户默认开启的服务
16.5添加管理员
管理员名称,通用名,过期日期是否激活等。同普通用户一样设置密码才能保存修改
16.5.1密码相关设置
同普通用户一样也是 设置密码、找回密码问题与答案是否禁止用户修改密码等
16.6群发邮件
按照提示说明可以设置群邮件的群发,可用于通知类型的邮件
16.7图像日志
在这里可以查看各类日志分析邮件服务器是否正常
17.2偏好设置
这里可以设置个人的信息包括姓名,密码以及密码问题等