LSX-blog

Feed Rss

【原创】POSTFIX+LAMP+cyrus-sasl+courier-imap 安装配置

12.27.2011, Linux, by .

一、系统运行环境

ESXI 5.0虚拟出来的CentOS 5.5 X64

安装操作系统只选择开发工具、开发库及基本包

二、软件环境

1、  CentOS5.5 X64 版本

2、  LAMP环境全套软件

3、  postfix-2.8.2.tar.gz

4、  phpMyAdmin-3.4.3.2-all-languages.tar.gz

5、  courier-authlib-0.63.0.tar.bz2

6、  cyrus-sasl-2.1.23.tar.gz

7、  courier-imap-4.9.3.tar.bz2

8、等等

三、准备工作

1、  禁用selinux

Vim /etc/selinux/config

修改成如下所示

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing – SELinux security policy is enforced.

#       permissive – SELinux prints warnings instead of enforcing.

#       disabled – SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted – Only targeted network daemons are protected.

#       strict – Full SELinux protection.

SELINUXTYPE=targeted

2、  卸载部分包

1、  Rpm –qa|grepsendmail卸载查出来的所有包

2、  rpm –qa|grepsasl卸载查出来的所有包

3、创建相关的用户及组

用户名组名作用

Extmailextmail虚拟邮件帐号使用

Postfix        postfixpostfix主程序使用

Postdrop                    postfix setid_group使用

Postdrop是postfix 主配置文件 mail.cf 里标明的, setgid_group=postdrop

四、开始安装

1、  LAMP 环境包

这里我使用我自己组装的一键安装包

2、  安装 courier-authlib

编译参数

./configure –prefix=/usr/local/courier-authlib \

–without-authpam \

–without-authdap \

–without-authshadow \

–without-vchkpw \

–with-authmysql \

–with-mysql-libs=/usr/local/mysql/lib/mysql \

–with-mysql-includes=/usr/local/mysql/include/mysql&& make && make install

配置courier-authlib

[root@mailauthlib]#Cd /usr/local/courier-authlib/etc/authlib

[root@mailauthlib]#cpauthdaemonrc.distauthdaemonrc

[root@mailauthlib]# cpauthmysqlrc.distauthmysqlrc

[root@mailauthlib]# vimauthdaemonrc

Authmodulelist=”authmysql”

Authmodulelistorig=”authmysql”

[root@mailauthlib]# vimauthmysqlrc

修改authmysqlrc内容为以下,其中 502,502 为postfix的UID,GID

MYSQL_SERVER            localhost

MYSQL_USERNAME         extmail

MYSQL_PASSWORD         extmail

MYSQL_SOCKET           /tmp/mysql.sock

MYSQL_PORT             3306

MYSQL_DATABASE         extmail

MYSQL_USER_TABLE       mailbox

MYSQL_CRYPT_PWFIELD     password

MYSQL_UID_FIELD         502

MYSQL_GID_FIELD         502

MYSQL_LOGIN_FIELD       username

MYSQL_HOME_FIELD        concat(‘/var/mailbox/’,homedir)

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD    concat(‘/var/mailbox/’,maildir)

设置开机启动

切换到安装源目录

[root@mailcourier-authlib-0.63.0]#cpcourier-authlib.sysvinitetc/init.d/courier-authlib

[root@mail courier-authlib-0.63.0]# chmod 755 /etc/init.d/courier-authlib

[root@mail courier-authlib-0.63.0]# chkconfig –add courier-authlib

[root@mail courier-authlib-0.63.0]# chkconfig courier-authlib on

3、  安装cyrus-sasl

编译参数

./configure –prefix=/usr/local/sasl2 \

–disable-gssapi \

–disable-anon \

–disable-digest \

–enable-plain \

–enable-login \

–enable-sql \

–with-mysql=/usr/local/mysql \

–with-mysql-includes=/usr/local/mysql/include/mysql \

–with-mysql-libs=/usr/local/mysql/lib/mysql/ \

–with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket && make && make install

配置cyrus-sasl

创建运行时需要的目录

[root@mail cyrus-sasl-2.1.23]# mkdir /var/state/saslauthd–p

[root@mail cyrus-sasl-2.1.23]# vim /usr/local/sasl2/lib/sasl2/smtpd.conf

添加如下内容

pwcheck_method: saslauthd

mech_list: PLAIN LOGIN

添加启动项

echo “/usr/local/sasl2/sbin/saslauthd -a shadow pam”>>/etc/rc.local

为下一步安装创建环境

echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf

echo “/usr/local/sasl2/lib” >> /etc/ld.so.conf

echo “/usr/local/sasl2/lib/sasl2” >> /etc/ld.so.conf

ln -s /usr/local/sasl2/lib/sasl2/ /usr/lib

ldconfig

4、  安装postfix

编译参数

make -f Makefile makefiles \

‘CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql \

-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/local/sasl2/include/sasl’ \

‘AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/local/sasl2/lib -lsasl2’

Make

Make install

 

install_root: [/]

Please specify a directory for scratch files while installing Postfix. You

must have write permission in this directory.

tempdir: [/root/postfix-2.8.2] /tmp

Please specify the final destination directory for installed Postfix

configuration files.

config_directory: [/etc/postfix] /etc/postfix

Please specify the final destination directory for installed Postfix

administrative commands. This directory should be in the command search

path of adminstrative users.

command_directory: [/usr/sbin] /usr/local/postfix/sbin

Please specify the final destination directory for installed Postfix

daemon programs. This directory should not be in the command search path

of any users.

daemon_directory: [/usr/libexec/postfix] /usr/local/postfix/libexec

 

Please specify the final destination directory for Postfix-writable

data files such as caches or random numbers. This directory should not

be shared with non-Postfix software.

data_directory: [/var/lib/postfix] /usr/local/postfix/lib

Please specify the destination directory for the Postfix HTML

files. Specify “no” if you do not want to install these files.

html_directory: [no]

Please specify the owner of the Postfix queue. Specify an account with

numerical user ID and group ID values that are not used by any other

accounts on the system.

mail_owner: [postfix]

Please specify the final destination pathname for the installed Postfix

mailq command. This is the Sendmail-compatible mail queue listing command.

mailq_path: [/usr/bin/mailq]

Please specify the destination directory for the Postfix on-line manual

pages. You can no longer specify “no” here.

manpage_directory: [/usr/local/man] /usr/local/postfix/man

Please specify the final destination pathname for the installed Postfix

newaliases command. This is the Sendmail-compatible command to build

alias databases for the Postfix local delivery agent.

newaliases_path: [/usr/bin/newaliases]

Please specify the final destination directory for Postfix queues.

queue_directory: [/var/spool/postfix]

Please specify the destination directory for the Postfix README

files. Specify “no” if you do not want to install these files.

readme_directory: [no]

Please specify the final destination pathname for the installed Postfix

sendmail command. This is the Sendmail-compatible mail posting interface.

sendmail_path: [/usr/sbin/sendmail]

配置postfix

[root@mail ~]# newaliases

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

修改内容如下

myhostname = mail.test.com  //主机名

mydomain = test.com               //域名

myorigin = $myhostname

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost

mynetworks = 192.168.189.0/24, 127.0.0.0/8

设置自启动

echo “/usr/local/postfix/sbin/postfix start”>>/etc/rc.local

为postfix开启sasl 认证

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

添加以下内容

############################CYRUS-SASL############################

broken_sasl_auth_clients = yes

smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_sasl_security_options = noanonymous

smtpd_sasl_application_name = smtpd

smtpd_banner = Welcome to our $myhostname ESMTP,Warning: Version not Available!

####################################################################

重新载入配置文件

[root@mail ~]# /usr/local/postfix/sbin/postfix reload

测试

[root@mail lib]# telnet localhost 25

Trying 127.0.0.1…

Connected to mail.jjhh.com (127.0.0.1).

Escape character is ‘^]’.

220 Welcome to our mail.jjhh.com Mail System!

ehlo mail.jjhh.com

250-mail.jjhh.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH LOGIN PLAIN                //成功标示

250-AUTH=LOGIN PLAIN                //成功标示

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

配置虚拟域

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

添加如下内容

########################Virtual Mailbox Settings########################

virtual_mailbox_base = /var/mailbox

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

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

virtual_alias_domains =

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

virtual_uid_maps = static:502       //为postfix UID

virtual_gid_maps = static:502                      //GID

virtual_transport = virtual

maildrop_destination_recipient_limit = 1

maildrop_destination_concurrency_limit = 1

##########################QUOTA Settings########################

message_size_limit = 14336000

virtual_mailbox_limit = 20971520

virtual_create_maildirsize = yes

virtual_mailbox_extended = yes

virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf

virtual_mailbox_limit_override = yes

virtual_maildir_limit_message = Sorry, the user’s maildir has overdrawn his diskspace quota, please Tidy your mailbox and try again later.

virtual_overquota_bounce = yes

################################################################

vim /etc/postfix/mysql_virtual_alias_maps.cf

user = extmail

password = extmail

hosts = localhost

dbname = extmail

table = alias

select_field = goto

where_field = address

 

vim /etc/postfix/mysql_virtual_domains_maps.cf

user = extmail

password = extmail

hosts = localhost

dbname = extmail

table = domain

select_field = description

where_field = domain

 

vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf

user = extmail

password = extmail

hosts = localhost

dbname = extmail

table = mailbox

select_field = quota

where_field = username

 

vim /etc/postfix/mysql_virtual_mailbox_maps.cf

user = extmail

password = extmail

hosts = localhost

dbname = extmail

table = mailbox

select_field = maildir

where_field = username

5、  安装Courier-IMAP

编译参数

./configure –prefix=/usr/local/courier-imap \

–enable-unicode \

–disable-root-check \

–with-trashquota \

–without-ipv6 \

CPPFLAGS=’-I/usr/local/courier-authlib/include’ \

LDFLAGS=’-L/usr/local/courier-authlib/lib/courier-authlib’ \

COURIERAUTHCONFIG=’/usr/local/courier-authlib/bin/courierauthconfig’

make&&make install

配置

切换到程序配置目录

Cd /usr/local/courier-imap/etc

[root@mail etc]# cp imapd.dist imapd

[root@mail etc]# cp imapd-ssl.dist imapd-ssl

[root@mail etc]# cp pop3d.dist pop3d

[root@mail etc]# cp pop3d-ssl.dist pop3d-ssl

[root@mail etc]# vim pop3d   //打开配置文件

修改如下

POP3DSTART=NO 改成YES

如果你想打开IMAP 验证只需修改imapd 文件即可

开机启动

切换到源码目录

我是在/root 目录的所以直接cd ~/courier-imap-4.9.3/

[root@mail courier-imap-4.9.3]# cp courier-imap.sysvinit /etc/init.d/courier-imapd

[root@mail courier-imap-4.9.3]# chmod 755 /etc/init.d/courier-imapd

[root@mail courier-imap-4.9.3]# chkconfig –add courier-imapd

[root@mail courier-imap-4.9.3]# chkconfig courier-imapd on

[root@mail courier-imap-4.9.3]# service courier-imapd start

Starting Courier-IMAP server: pop3

启动成功

6、  新建邮件目录及附加新配置

[root@mail ~]# mkdir /var/mailbox -p

[root@mail ~]# chown -R postfix /var/mailbox/

重新编辑smtpd.conf

[root@mail ~]# vim /usr/local/sasl2/lib/sasl2/smtpd.conf

修改成如下内容

pwcheck_method:authdaemond

log_level:3

mech_list:PLAIN LOGIN

authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

7、  安装插件

DBI 及 unix-syslog

Unix-syslog安装

[root@mail ~]# tar zxvf Unix-Syslog-1.1.tar.gz

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

[root@mail ~]# perl Makefile.PL

[root@mail Unix-Syslog-1.1]# make && make install

DBI 我采用RPM 包所以需要如下包

MySQL-shared-compat-5.1.57-1.rhel5.x86_64.rpm

perl-DBD-MySQL-3.0007-2.el5.x86_64.rpm

perl-DBI-1.52-2.el5.x86_64.rpm

安装

Rpm –ivh *.rpm

Preparing…           ########################################### [100%]

1:perl-DBI           ########################################### [ 33%]

2:MySQL-shared-compat ########################################## [ 67%]

3:perl-DBD-MySQL   ########################################### [100%]

8、  安装Extmail与Extman

创建相关目录

Mkdir /data/www/mail–p

Cd /data/www/mail

[root@mail mail]# tar zxf ~/extmail-1.2.tar.gz

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

[root@mail extmail-1.2]# cp -r html/default/ ./

[root@mail extmail-1.2]# cp -r html/images/ ./

[root@mail extmail-1.2]# cp -r html/plugins/ ./

[root@mail extmail-1.2]# cp html/index.html ../

这里面这个index.html 是在mail 目录下记住因为我们虚拟主机要解析到/data/www/mail 下面,所以mail目录下的是extmail 的index.html

然后把extmail-1.2 重命名为extmail

修改webmail.cf

# sys_config, the config file and webmail programe root

SYS_CONFIG = /data/www/mail/extmail/

# sys_langdir, the i18n dir

SYS_LANGDIR = /data/www/mail/extmail/lang

# sys_templdir, the template dir

SYS_TEMPLDIR = /data/www/mail/extmail/html

SYS_USER_LANG = zh_US

SYS_MAILDIR_BASE = /var/domains

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/courier-authlib/var/spool/authdaemon/socket

[root@mail www]# tar zxvf ~/extman-1.1.tar.gz

把解压出来的extman-1.1 目录重命名为extman

[root@mail mail]# cd extman

[root@mail extman]# cp webman.cf.default webman.cf

[root@mail extman]# cp -r html/default/ ./

[root@mail extman]# cp -r html/images/ ./

[root@mail extman]# cp -r html/plugins/ ./

[root@mail extman]# cp html/index.html ./

配置extman

[root@mail extman]# vim webman.cf

# sys_config, the config file and webman programe root

SYS_CONFIG = /data/www/mail/extman/

# sys_langdir, the i18n dir

SYS_LANGDIR = /data/www/mail/extman/lang

# sys_templdir, the template dir

SYS_TEMPLDIR = /data/www/mail/extman/html

# maildir_base, the base dir of user maildir, use absolute path

# if not set.

SYS_MAILDIR_BASE = /var/mailbox/

SYS_MYSQL_SOCKET = /tmp/mysql.sock

创建依赖目录

Mkdir /tmp/extman

导入数据库

[root@mail data]# cd /data/www/mail/extman/docs/

[root@mail docs]# /usr/local/mysql/bin/mysql -p<extmail.sql

Enter password:

[root@mail docs]# /usr/local/mysql/bin/mysql -p<init.sql

Enter password:

[root@mail docs]#

设置APACHE

切换到/DATA目录执行如下命令

[root@mail data]# chown postfix.postfix www/ -R

配置APACHE

更改如下

<IfModule dir_module>

DirectoryIndex index.html index.php index.cgi

</IfModule>

在这个<IfModule mime_module>模块里添加如下:

AddHandler cgi-script .cgi

添加虚拟主机

<VirtualHost *:80>

<Directory “/data/www/mail/extmail/cgi”>

Options Indexes FollowSymLinks +ExecCGI

AllowOverride None

Order allow,deny

Allow from all

</Directory>

<Directory “/data/www/mail/extman/cgi”>

Options Indexes FollowSymLinks +ExecCGI

AllowOverride None

Order allow,deny

Allow from all

</Directory>

ServerAdmin webmaster@dummy-host.example.com

DocumentRoot “/data/www/mail”

ServerName mail.test.com

ErrorLog “logs/mail.test.com-error_log”

CustomLog “logs/mail.test.com-access_log” common

</VirtualHost>

9、  附属功能

下面加入启动项

/data/www/mail/extman/daemon/cmdserver -d  提供系统信息

验证码依赖的包

因为验证码这个问题需要很多包,所以这里用YUM 安装

Yum –y install perl-GD*

yum –y install libart_lgpl-devel

yum –y install pango-devel* cairo-devel

也可以在webmail.cf 中关闭验证码功能

SYS_CAPTCHA_ON = 0

图形日志功能

这个需要安装

[root@mail ~]# tar zxvf rrdtool-1.4.5.tar.gz

./configure –enable-perl-site-install && make && make install

这时图形日志不会报错但图片还是出不来

安装File-Tail-0.99.3.tar.gz

tar zxvf File-Tail-0.99.3.tar.gz

perl Makefile.PL && make && make install

安装好上面这个插件,操作下面步骤

Mailgraph_ext 这个文件夹是从

[root@mail addon]# cp -r /data/www/mail/extman/addon/mailgraph_ext/ /usr/local/

复制出来的

运行并添加启动项

/usr/local/mailgraph_ext/mailgraph-init start  图形报表

10、              测试运行情况

登陆后台

用户名默认

密码为extmail*123* 这是系统默认的登陆后记得修改

 

接下来删除默认域名,建立自己的域名测试发信收信功能

详细的测试我就不说了,就到此吧

文章所涉及的地方,有些还是可以优化的,文章不是太详细不过知识分享而已,做个参照吧

文章所涉及的附近我会一并发布出去,以下是下载链接地址

 

http://115.com/file/c240l9a9#

postfix.zip

【原创】POSTFIX+LAMP+cyrus-sasl+courier-imap 安装配置 有 110 条回应

  1. I was recommended this blog via my cousin. I am no
    longer sure whether this submit is written via him as no one else realize such
    exact approximately my trouble. You’re incredible! Thank
    you!

    回复
  2. Hi there! This is my first visit to your blog! We are a group of volunteers
    and starting a new project in a community in the same niche.
    Your blog provided us valuable information to work on.
    You have done a outstanding job!

    回复
  3. Excellent goods from you, man. I’ve understand your stuff previous to and
    you’re just too wonderful. I actually like what you’ve acquired
    here, certainly like what you’re stating and the way in which you say it.
    You make it enjoyable and you still care for to keep
    it sensible. I cant wait to read far more from you.
    This is really a great site.

    回复
  4. Howdy just wanted to give you a quick heads
    up. The text in your article seem to be running off the screen in Firefox.
    I’m not sure if this is a formatting issue or
    something to do with web browser compatibility but I thought I’d post to let you
    know. The design and style look great though! Hope you
    get the issue fixed soon. Cheers

    回复
  5. It’s really very complex in this busy life to listen news on Television, therefore I simply use internet for
    that reason, and obtain the latest information.

    回复
  6. Hi there, I would like to subscribe for this weblog to get hottest
    updates, therefore where can i do it please help out.

    回复
  7. Great blog here! Also your site loads up fast! What web host
    are you using? Can I get your affiliate link to your host?
    I wish my website loaded up as quickly as yours lol

    回复
  8. I have read some just right stuff here. Definitely price
    bookmarking for revisiting. I wonder how a lot
    attempt you put to create this kind of magnificent informative web site.

    回复
  9. I’m not sure where you’re getting your information, but great topic.
    I needs to spend some time learning much more or understanding more.
    Thanks for fantastic information I was looking for this info for my mission.

    回复
  10. Truly no matter if someone doesn’t be aware of afterward its up
    to other visitors that they will help, so here it happens.

    回复

发表评论

电子邮件地址不会被公开。 必填项已用*标注