2014-08-18 10:19:39
来 源
中存储网
Postfix
准备:关闭firewall和SELinux(略)1.准备:下载以下软件(这里我将包放在/root/mail/和/root/lamp/下了).

第一重天、安装前的准备工作:

[root@junjie ~]# uname –r #查看Linux的环境

2.6.25.19

准备:关闭firewall和SELinux(略)

1.准备:下载以下软件(这里我将包放在/root/mail/和/root/lamp/下了)

httpd-2.2.9.tar.gz

mysql-5.0.95.tar.gz

php-5.4.0.tar.bz2

DBD-mysql-4.020.tar.gz

DBI-1.616.tar.gz

File-Tail-0.99.3.tar.gz

GD-2.46.tar.gz

MailScanner-4.84.3-1.rpm.tar.gz

Unix-Syslog-1.1.tar.gz

courier-authlib-0.62.4.tar.bz2

dovecot-1.1.4.tar.gz

extmail-1.2.tar.gz

extman-1.1.tar.gz

fp-Linux-i686-ws.tar.gz

postfix-2.8.2.tar.gz

rrdtool-1.2.23-3.el5.i386.rpm

rrdtool-perl-1.2.23-3.el5.i386.rpm

squirrelmail-webmail-1.4.22.tar.gz

squirrelmail-webmail-1.4.22.tar.gz

2.#修改ip地址为192.168.101.210,修改dns指向为192.168.101.210

[root@junjie ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

NETMASK=255.255.255.0

IPADDR=192.168.101.210

[root@junjie ~]# service network restart

[root@junjie ~]# vim /etc/resolv.conf

nameserver 192.168.101.210

3、安装以下开发所用到的rpm包组:

Development Libraries

Development Tools

Legacy Software Development

X Software Development

#安装方法: yum groupinstall "packge_group_name"

4.构建本地yum服务器(略)

5.安装配置dns服务器:

[root@junjie ~]# yum install -y bind bind-chroot caching-nameserver

[root@junjie ~]# cd /var/named/chroot/etc/

[root@junjie etc]# cp –p named.caching-nameserver.conf named.conf

[root@junjie 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@junjie etc]# vim named.rfc1912.zones

20 zone "junjie.com" IN {

21 type master;

22 file "junjie.com.db";

23 allow-update { none; };

24 };

37 zone "101.168.192.in-addr.arpa" IN {

38 type master;

39 file "192.168.101.db";

40 allow-update { none; };

41 };

[root@junjie etc]# cd ../var/named/

[root@junjie named]# cp -p localhost.zone junjie.com.db

[root@junjie named]# vim junjie.com.db

2 @ IN SOA ns.junjie.com. root (

9 @ IN NS ns.junjie.com.

10 ns IN A 192.168.101.210

11 mail IN A 192.168.101.210

12 pop3 IN CNAME mail

13 smtp IN CNAME mail

14 @ IN MX 10 mail

[root@junjie named]# cp -p named.local 192.168.101.db

[root@junjie named]# vim 192.168.101.db

210 IN PTR mail.junjie.com.

[root@junjie named]# chkconfig named on

[root@junjie named]# service named start

[root@junjie named]# rndc reload

server reload successful

#查看dns解析是否正常

[root@junjie named]# nslookup pop3.junjie.com

[root@junjie named]# nslookup mail.junjie.com

[root@junjie named]# dig -t mx junjie.com

[root@junjie named]# nslookup 192.168.101.210

6.修改主机名称,并重新启动系统,重启后挂载光盘

[root@junjie named]# vim /etc/sysconfig/network

HOSTNAME=mail.junjie.com

[root@junjie named]# init 6

[root@mail ~]# mount /dev/cdrom /mnt/cdrom/

第二重天 LAMP平台结构,源码构建LAMP环境

[root@mail ~]# cd lamp/

[root@mail lamp]# ls

httpd-2.2.9.tar.gz

mysql-5.0.95.tar.gz

php-5.4.0.tar.bz2

2.1安装apache软件:

[root@mail lamp]# tar -zxvf httpd-2.2.9.tar.gz -C /usr/local/src/

[root@mail lamp]#cd /usr/local/src/httpd-2.2.9/

[root@mail httpd-2.2.9]# ./configure

--prefix=/usr/local/apache2 --enable-so --enable-rewrite

[root@mail httpd-2.2.9]# make && make install

#这里我们并没有将Suexec编译进apache中去,提到这个的原因

#是因为后面我们装postfix时候的后台管理extman是通过CGI的

#方式来调用程序的,如果不启用Suexec的话那么就会限制其他

#用户调用CGI程序,但考虑到启用Suexec的风险我们在此

#就不启用它了。

#(启用方式:--enable-suexec –with-suexec-caller=daemon

#–with-suexec-docroot=/usr/local/apache2/htdocs)

#进行相关配置,使apache正常工作

[root@www httpd-2.2.9]# cd /usr/local/apache/

[root@www apache]# ./bin/apachectl start

[root@www apache]# netstat -tupln |grep http

[root@www apache]# vim /etc/profile

55 PATH=$PATH:/usr/local/apache/bin/

[root@www apache]# . /etc/profile

[root@www apache]# echo $PATH

/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:

/root/bin:/usr/local/apache/bin/

#此时可以再任何位置:apachectl start|restart |stop

#配置apache的库文件

[root@www include]# cat /etc/ld.so.conf

[root@www include]# cd /etc/ld.so.conf.d/

[root@www ld.so.conf.d]# vim apache.conf

/usr/local/apache/lib

[root@www ld.so.conf.d]# ldconfig -v |grep apache

/usr/local/apache/lib:

[root@www ld.so.conf.d]#

#查看httpd信息.

[root@www ld.so.conf.d]# netstat -tupln |grep httpd

tcp 0 0 :::80 :::* LISTEN 21263/httpd

2.2安装mysql软件:

[root@mail ld.so.conf.d]# cd /root/lamp/

[root@mail lamp]#useradd -M -s /sbin/nologin mysql

#添加mysql用户,如果安装系统时候已经装过mysql会提示用户已存在,

#建议在安装前先卸载掉系统自带的mysql,卸载完成后必须重启,

#否则新装的mysql会无法启动,提示错误信息3306端口被占有

[root@mail lamp]# tar -zxvf mysql-5.0.95.tar.gz -C /usr/local/src/

[root@mail lamp]# cd /usr/local/src/

[root@mail src]# ll

[root@junjie src]# ln -s mysql-5.0.95/ mysql

[root@junjie src]# ll

[root@junjie src]# cd mysql

[root@mail mysql]# ./configure --prefix=/usr/local/mysql

[root@mail mysql]#make

[root@mail mysql]# 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]# chkconfig --add mysqld

[root@mail mysql-5.0.95]# chkconfig mysqld on

[root@mail mysql-5.0.95]# service mysqld start

#设置系统全局的环境变量PATH值,方便使用mysql数据库命令

[root@mail mysql-5.0.95]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile

2.3安装php软件

[root@mail mysql-5.0.95]# cd /root/lamp/

[root@mail lamp]# ll

total 39640

-rw-r--r-- 1 root root 6396996 Apr 1 10:07 httpd-2.2.9.tar.gz

-rw-r--r-- 1 root root 22693585 Apr 1 10:08 mysql-5.0.95.tar.gz

-rw-r--r-- 1 root root 11439508 Apr 1 10:07 php-5.4.0.tar.bz2

[root@mail lamp]# tar -jxvf php-5.4.0.tar.bz2 -C /usr/local/src/

[root@mail lamp]# 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]# 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

#启动apache,在/usr/local/apache目录下执行指令:bin/apachectl start

[root@mail php-5.4.0]# cd /usr/local/apache2/

[root@mail apache2]# ./bin/apachectl start

[root@mail apache2]# netstat -tupln |grep 80

tcp 0 0 :::80 :::* LISTEN 31981/httpd

2.4测试php是否与apache整合成功

[root@mail apache2]# cd /usr/local/apache2/htdocs/

[root@mail htdocs]# ls

[root@mail htdocs]# mv index.html index.php

[root@mail htdocs]# vim index.php

--xjzhujunjie

--2012/04/10

<?php

phpinfo();

?>

#在浏览器中输入http://192.168.101.210/index.php

#看到下图表示跟apache服务整合成功

[root@mail htdocs]# vim index.php

--xjzhujunjie

--2012/04/10

<?php

$link=mysql_connect('127.0.0.1','root','');

if($link)

echo "scuess";

else

echo "fail";

?>

#在IE浏览器中输入网址http://192.168.101.210/index.php

#看到下图表示跟mysql服务整合成功

[root@mail htdocs]# service mysqld stop

Shutting down MySQL..STOPPING server from pid file /usr/local/mysql/var/mail.junjie.com.pid

120401 11:36:07 mysqld ended [ OK ]

第三重天 安装postfix软件

3.1、卸载sendmailsendmail将占用tcp 25端口,和postfix冲突:

[root@junjie ~]# rpm -e sendmail --nodeps

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 ~]# cd /root/mail/

[root@mail mail]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/postfix-2.8.2/

#安装,安装过程中会出现互动提问,直接选择默认设置即可.若配置中时出现问

#题,检查路径是否正确,或查看日志,和postfix用户是否存在

[root@mail postfix-2.8.2]# make -f Makefile.init makefiles

'CCARGS=-DHAS_MYSQL

-I/usr/local/mysql/include/mysql

-DUSE_SASL_AUTH -I/usr/local/include/sasl'

'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient

-lz -lm -L/usr/local/lib -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;

#若不存在mysql,就不要往下做了,必须重做,知道出现mysql为止

[root@mail postfix-2.8.2]# postconf –m

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.junjie.com

83 mydomain = junjie.com

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.101.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

[root@mail abc]# ll etc/rc.d/init.d/postfix

-rwxr-xr-x 1 root root 2404 Apr 1 13:01 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 ~]# useradd user1

[root@mail ~]# useradd user2

[root@mail ~]# echo "123" |passwd --stdin user1

[root@mail ~]# echo "123" |passwd --stdin user2

[root@mail ~]# telnet mail.junjie.com 25

Trying 192.168.101.210...

Connected to mail.junjie.com (192.168.101.210).

Escape character is '^]'.

220 mail.junjie.com ESMTP Postfix

ehlo mail.junjie.com

250-mail.junjie.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:user1@junjie.com

250 2.1.0 Ok

rcpt to:user2@junjie.com

250 2.1.5 Ok

data

354 End data with <CR><LF>.<CR><LF>

user1--to--user2

.

250 2.0.0 Ok: queued as 4961D16DE6E

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@junjie.com Tue Apr 10 16:37 13/472

& 1

Message 1:

From user1@junjie.com Tue Apr 10 16:37:23 2012

X-Original-To: user2@junjie.com

Delivered-To: user2@junjie.com

Date: Tue, 10 Apr 2012 16:36:42 +0800 (CST)

From: user1@junjie.com

user1--to--user2

& quit

Saved 1 message in mbox

[user2@mail ~]$

#cat /home/test/Maildir/new/ 按tab键可以看见刚才发的那封邮件,说明SMPT没有问题。

第五重天 Dovecot 邮局软件安装(提供pop3/imap4协议)

5.1安装Dovecot

[root@mail ~]# cd /root/mail/

[root@mail mail]# tar -zxvf dovecot-1.1.4.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/dovecot-1.1.4/

[root@mail dovecot-1.1.4]# groupadd dovecot

[root@mail dovecot-1.1.4]# useradd -M -s /sbin/nologin dovecot

[root@mail dovecot-1.1.4]# ./configure --sysconfdir=/etc --with-mysql && make && 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 ~]# 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

#/usr/local/sbin/dovecot -c /etc/dovecot.conf 启动把这句话写入开机脚本

# pkill -1 dovecot #重新读取dovecot

[root@mail dovecot-1.1.4]# /usr/local/sbin/dovecot -c /etc/dovecot.conf

测试接受服务器dovecot

[root@mail dovecot-1.1.4]# telnet mail.junjie.com 110

Trying 192.168.101.210...

Connected to mail.junjie.com (192.168.101.210).

Escape character is '^]'.

+OK Dovecot ready.

user user2

+OK

pass 123

+OK Logged in.

list

+OK 1 messages:

1 432

.

retr 1

+OK 432 octets

Return-Path: <user1@junjie.com>

X-Original-To: user2@junjie.com

Delivered-To: user2@junjie.com

Received: from mail.junjie.com (mail.junjie.com [192.168.101.210])

by mail.junjie.com (Postfix) with ESMTP id 6FA1116DEF5

for <user2@junjie.com>; Tue, 10 Apr 2012 17:46:37 +0800 (CST)

Message-Id: <20120410094651.6FA1116DEF5@mail.junjie.com>

Date: Tue, 10 Apr 2012 17:46:37 +0800 (CST)

From: user1@junjie.com

11111111111111

.

quit

+OK Logging out.

Connection closed by foreign host.

第六重天 安装Webmail软件

6.1 squirrelmail安装

[root@mail ~]# cd mail/

[root@mail mail]# tar -zxvf squirrelmail-webmail-1.4.22.tar.gz -C /usr/local/apache2/htdocs/

[root@mail mail]# cd /usr/local/apache2/htdocs/

[root@mail htdocs]# mv squirrelmail-webmail-1.4.22/ webmail

6.2 配置webmail

[root@mail htdocs]# cd /usr/local/apache2/htdocs/webmail/

[root@mail webmail]# mkdir -p attach data/

[root@mail webmail]# chown -R daemon:daemon attach/ data/

[root@mail webmail]# chmod 730 attach/

[root@mail webmail]# cp config/config_default.php config/config.php

[root@mail webmail]# vim config/config.php

118 $domain = 'junjie.com';

146 $smtpServerAddress = 'localhost';

151 $smtpPort = 25;

210 $imapPort = 143;

231 $imap_server_type = 'dovecot';

499 $data_dir = '/usr/local/apache2/htdocs/webmail/data/';

517 $attachment_dir = '/usr/local/apache2/htdocs/webmail/attach/';

6.3重启 apache 服务

[root@mail webmail]# /usr/local/apache2/bin/apachectl restart

6.4测试:客户端IE地址栏中输入 http://mail.junjie.com/webmail (前提mail.junjie.com可以被解析,否则用ip)即可看见下图:

到此我们的postfix+webmail已经安装完成,但是为了使我们更好的管理维护邮件服务器的前端与后台接下来我们来安装extmail和extman以便实现我们的需求。

6.5 初始化 extman 软件

6.5.1 数据库脚本

[root@mail ~]# service mysqld restart

Shutting down MySQL.. [ OK ]

Starting MySQL. [ OK ]

[root@mail ~]# cd mail/

[root@mail mail]# tar -zxvf extman-1.1.tar.gz -C /usr/local/src/

[root@mail 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:

#注意这里在5.3版本中汇出错

ERROR 1064 (42000) at line 50: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM COMMENT='Ext/Webman - Admin Accounts'' at line 15

原因:编写数据库的版本比当前安装的版本不相同。

解决:1、用文本编辑器打开extmail.sql;

2、查找/替换,将数据库文件内的所有TYPE=MyISAM修改为ENGINE=MyISAM,保存退出;

3、重新导入extmail.sql即可。

第七重天 配置 Postfix

#查看模块,#postconf -m |grep mysql 返回值有mysql,说明可以支持mysql 数据库的查询表

[root@mail docs]# cd

[root@mail ~]# postconf -m |grep mysql

mysql

7.1 修改配置文件

[root@mail ~]# vim /etc/postfix/main.cf

162-163行需要注释掉

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 ~]# cd mail/

[root@mail mail]# tar -jxvf courier-authlib-0.62.4.tar.bz2 -C /usr/local/src/

[root@mail 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

install-configure #生成默认配置文件authmysqlrc 和 authdaemonrc

[root@mail courier-authlib-0.62.4]# make && make install && 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

[root@mail ~]# ps -aux |grep courier-authlib

第九重天 修改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 WHERE username = ‘%u’

5 user_query = SELECT maildir, uidnumber AS uid, gidnumber AS gid FRO M mailbox 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 29275 (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 29275 (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 Maildir]# cd /root/mail/

[root@mail mail]# ll

[root@mail mail]# tar -zxf Unix-Syslog-1.1.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/Unix-Syslog-1.1/

[root@mail Unix-Syslog-1.1]# perl Makefile.PL && make && make install

[root@mail Unix-Syslog-1.1]# cd /root/mail/

[root@mail mail]# ll

[root@mail mail]# tar -zxf DBI-1.616.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/DBI-1.616/

[root@mail DBI-1.616]# perl Makefile.PL && make && make install

[root@mail DBI-1.616]# cd /root/mail/

[root@mail mail]# ll

[root@mail mail]# tar -zxf DBD-mysql-4.020.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/DBD-mysql-4.020/

[root@mail DBD-mysql-4.020]# perl Makefile.PL && make && make install

#注意以上三个包在编译安装过程可能会提示 警告信息 隐式函数 计算出的变量值未被使用等,只要没有error信息就一切ok

安装ExtMail

[root@mail DBD-mysql-4.020]# cd /root/mail/

[root@mail mail]# ll

[root@mail mail]# tar -zxf extmail-1.2.tar.gz -C /usr/local/apache2/htdocs/

[root@mail mail]# cd /usr/local/apache2/htdocs/

[root@mail htdocs]# ll

[root@mail htdocs]# mv extmail-1.2 extmail

[root@mail htdocs]# cd extmail/

[root@mail extmail]# chown -R postfix:postfix cgi/

[root@mail extmail]# ll

[root@mail extmail]# cp webmail.cf.default webmail.cf

[root@mail extmail]# ll

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

8 SYS_TEMPLDIR = /usr/local/apache2/htdocs/extmail/html

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.junjie.com

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>

#这里由于前面我们并没有启用Suexec 所以我们没有在虚拟主机中添加 SuexecUerGroup postfix postfix

#重启apache

[root@mail extmail]# /usr/local/apache2/bin/apachectl restart

12.4 Extmail无法访问问题原因

到这一步很多网上的文档都会说这时候只要在客户端访问 http://mail.junjie.com 就可以看到ExtMail的登录界面,但是经过我很多次实践改动配置得到的结果都是访问页面不存在404的错误提示页面,一度我曾认为可能是我之前编译的那三个倚赖包有问题,或者是我的PHP有问题,以及cgi权限问题都想到但是结果依然是404页面不存在,但是我可以很正常的看到访问http://mail.junjie.com时候页面确实是跳转到了http://mail.junjie.com/extmail/cgi/index.cgi这个目录,而且我这个目录中文件确实存在,没有任何问题,经过我多次尝试终于找到原因如果要成功的访问到这个页面就必须把Extman装上,并且在apache配置文件中写入extman的路径这样我终于如愿以偿的看到了期望已久的ExtMail的登录界面。

下面我们开始安装Extman

第十三重天 Extman平台

13.1 安装包

4个倚赖包

[root@mail extmail]# cd /root/mail/

[root@mail mail]# tar -zxf GD-2.46.tar.gz -C /usr/local/src/

[root@mail mail]# cd /usr/local/src/GD-2.46/

[root@mail GD-2.46]# perl Makefile.PL && make && make install

[root@mail GD-2.46]# cd /root/mail/

[root@mail mail]# tar -zxf File-Tail-0.99.3.tar.gz -C /usr/local/src/

[root@mail 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 File-Tail-0.99.3]# cd /root/mail/

[root@mail mail]# rpm -ivh rrdtool-1.2.23-3.el5.i386.rpm

[root@mail mail]# rpm -ivh rrdtool-perl-1.2.23-3.el5.i386.rpm

Extman 套件

[root@mail mail]# tar -zxf extman-1.1.tar.gz -C /usr/local/apache2/htdocs/

[root@mail mail]# cd /usr/local/apache2/htdocs/

[root@mail htdocs]# ll

[root@mail htdocs]# mv extman-1.1 extman

[root@mail htdocs]# ll

[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]# ll

[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.junjie.com

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]# /usr/local/apache2/bin/apachectl restart

13.4 现在在客户端访问

http://mail.junjie.com 就可以看见ExtMail的登录界面了。在客户端访问

http://mail.junjie.com/extman 就可以看见Extman后台管理登录界面了

默认管理员账户:root@extmail.org

默认密码:extmail*123*

#如无法登录禁用校验码,将1改为0

#[root@mail ~]# vim /usr/local/apache2/htdocs/extman/webman.cf

#21 SYS_CAPTCHA_ON = 1

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。