HREL5.0+LAMP+postfix+mysql+postfixadmin+dovecot

                                  本文是在RHEL5.0上完成的实验
  在查看了众多文章后,自己的邮件系统终于出炉呢..一路艰辛的走过,再次原与大家分享一下安装经验

准备工作,
# service iptables stop
确保/etc/sysconfig/saslauthd 中 MECH = shadow
确保/etc/sysconfig/selinux 中 SELINUX=disabled

-1.安装LAMP环境

LAMP就是Linux+Apache+MySql+PHP搭建的动态网站环境,是目前互联网上非常流行的一个网页服务组合。
网上有很多教程搭建LAMP环境,基本上都是编译安装的,其实对新手来说只需要了解LAMP环境的一些特性,RMP安装相对来说容易上手点,只需要安装几个光盘上的安装包就可以顺利完成LAMP的搭建。
安装Apache

    [root@linux-a ~]# rpm -ivh /media/Server/httpd-2.2.3-6.el5.i386.rpm
    warning: /media/Server/httpd-2.2.3-6.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    error: Failed dependencies:
            libapr-1.so.0 is needed by httpd-2.2.3-6.el5.i386
            libaprutil-1.so.0 is needed by httpd-2.2.3-6.el5.i386
    [root@linux-a ~]#

提示需要libapr-1.so.0和libaprutil-1.so.0的支持
安装libapr-1.so.0

    [root@linux-a ~]# rpm -ivh /media/Server/apr-1.2.7-11.i386.rpm
    warning: /media/Server/apr-1.2.7-11.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:apr                    ########################################### [100%]

apr-util-1.2.7-6.i386.rpm 需要postgresql-libs的支持
安装libpq.so.4

    [root@linux-a ~]# rpm -ivh /media/Server/postgresql-libs-8.1.4-1.1.i386.rpm
    warning: /media/Server/postgresql-libs-8.1.4-1.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:postgresql-libs        ########################################### [100%]
    [root@linux-a ~]#

安装libaprutil-1.so.0

    [root@linux-a ~]# rpm -ivh /media/Server/apr-util-1.2.7-6.i386.rpm
    warning: /media/Server/apr-util-1.2.7-6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:apr-util               ########################################### [100%]
    [root@linux-a ~]#

安装Apache

    [root@linux-a ~]# rpm -ivh /media/Server/httpd-2.2.3-6.el5.i386.rpm
    warning: /media/Server/httpd-2.2.3-6.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:httpd                  ########################################### [100%]
    [root@linux-a ~]#

安装MySql
mysql需要perl(DBI)和perl-DBD-MySQL的支持,因此先安装perl-DBI及perl-DBD-MySQL
perl-DBI安装

    [root@linux-a ~]# rpm -ivh /media/Server/perl-DBI-1.52-1.fc6.i386.rpm
    warning: /media/Server/perl-DBI-1.52-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:perl-DBI               ########################################### [100%]
    [root@linux-a ~]#

perl-DBD-MySQL安装

    [root@linux-a ~]# rpm -ivh /media/Server/perl-DBD-MySQL-3.0007-1.fc6.i386.rpm
    warning: /media/Server/perl-DBD-MySQL-3.0007-1.fc6.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:perl-DBD-MySQL         ########################################### [100%]
    [root@linux-a ~]#

开始安装mysql

    [root@linux-a ~]# rpm -ivh /media/Server/mysql-5.0.22-2.1.i386.rpm
    warning: /media/Server/mysql-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:mysql                  ########################################### [100%]
    [root@linux-a ~]#

安装mysql server

    [root@linux-a ~]# rpm -ivh /media/Server/mysql-server-5.0.22-2.1.i386.rpm
    warning: /media/Server/mysql-server-5.0.22-2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:mysql-server           ########################################### [100%]
    [root@linux-a ~]#

初始化MySql数据库

    [root@linux-a ~]# mysql_install_db
    Installing all prepared tables
    Fill help tables
    To start mysqld at boot time you have to copy support-files/mysql.server
    to the right place for your system
    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:
    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h linux-a.test.com password 'new-password'
    See the manual for more instructions.
    You can start the MySQL daemon with:
    cd /usr ; /usr/bin/mysqld_safe &
    You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:
    cd sql-bench ; perl run-all-tests
    Please report any problems with the /usr/bin/mysqlbug script!
    The latest information about MySQL is available on the web at
    http://www.mysql.com
    Support MySQL by buying support/licenses at http://shop.mysql.com
    [root@linux-a ~]#

修改mysql配置文件

    [root@linux-a ~]# cp /usr/share/doc/mysql-server-5.0.22/my-medium.cnf  /etc/my.cnf

更多设置请参考 [Redhat Linux下MySql数据库的安装配置及简单操作]
安装php
PHP需要libgmp.so.3、php-cli、php-common的支持

    [root@linux-a ~]# rpm -ivh /media/Server/php-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    error: Failed dependencies:
            libgmp.so.3 is needed by php-5.1.6-5.el5.i386
            php-cli = 5.1.6-5.el5 is needed by php-5.1.6-5.el5.i386
            php-common = 5.1.6-5.el5 is needed by php-5.1.6-5.el5.i386

libgmp.so.3安装

    [root@linux-a ~]# rpm -ivh /media/Server/gmp-4.1.4-10.el5.i386.rpm
    warning: /media/Server/gmp-4.1.4-10.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:gmp                    ########################################### [100%]

安装php-common

    [root@linux-a ~]# rpm -ivh /media/Server/php-common-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-common-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:php-common             ########################################### [100%]
    [root@linux-a ~]#

安装php-cli

    [root@linux-a ~]# rpm -ivh /media/Server/php-cli-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-cli-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:php-cli                ########################################### [100%]
    [root@linux-a ~]#

安装PHP

    [root@linux-a ~]# rpm -ivh /media/Server/php-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:php                    ########################################### [100%]
    [root@linux-a ~]#

另外还需要安装PHP-MySql,PHP-MySql需要php-pdo的支持
安装php-pdo

    [root@linux-a ~]# rpm -ivh /media/Server/php-pdo-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-pdo-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:php-pdo                ########################################### [100%]
    [root@linux-a ~]#

安装PHP-MySql

    [root@linux-a ~]# rpm -ivh /media/Server/php-mysql-5.1.6-5.el5.i386.rpm
    warning: /media/Server/php-mysql-5.1.6-5.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
    Preparing...                ########################################### [100%]
       1:php-mysql              ########################################### [100%]
    [root@linux-a ~]#

测试配置:



安装好上面之后还需要安装以下rpm包

php-mbstring-5.1.6-20.e15.i386.rpm

php-imap-5.16-20.e15.i386.rpm
libc-client-2004g-2.2.1.i386.rpm
安装好后 重新启动apache




-2.在Linux上使用Postfix+dovecot+MySQL+PostfixAdmin实现基本的邮件服务


2.1. 配置MySQL
添加Postfix数据库
mysql> CREATE DATABASE postfix;
mysql> GRANT ALL PRIVILEGES ON postfix.* TO 'postfix'@'localhost' IDENTIFIED BY 'postfix';
 
2.2 安装配置PostfixAdmin
到http://sourceforge.net/projects/postfixadmin/下载最新的软件包。
# tar -zxvf postfixadmin-2.2.1.1.tar.gz
# mv postfixadmin-2.2.1.1 /var/www/postfixadmin
# cd /var/www/postfixadmin
# vim config.inc.php
修改下面相应的参数
$CONF['configured'] = true;
$CONF['default_language'] = 'cn';
$CONF['postfix_admin_url'] = '/postfixadmin';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = ‘postfix';
$CONF['database_name'] = 'postfix';
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['encrypt'] = 'md5crypt';
$CONF['emailcheck_resolve_domain] = 'NO';
 

重新启动apache

访问PostfixAdmin的设置页http://IP or domain/postfixadmin/setup.php

出现postfixadmin的输入框
创建Setup password(如:123456)
点击“Generate password hash”获取一段加密代码
将该代码拷贝到配置文件config.inc.php中的以下配置中
$CONF['setup_password'] = 'change';(用加密代码替换change)
然后再次访问PostfixAdmin的设置页,创建管理员的账号和密码
(需要正确输入之前创建的Setup password才能创建管理员账号)
访问PostfixAdmin的登录页http://IP or domain>/postfixadmin/
使用管理员账号登录后,就可以进行相应的管理工作。
创建之后移动setup.php.bak
mv /var/www/html/postfixadmin/setup.php /var/www/html/postfixadmin/setup.php.bak


2.3. 安装配置Postfix
Postfix的大部分RPM包都没有mysql的支持,还好我找到了带有mysql和sasl支持的RPM包。
软件包下载地址:http://www.linuxmail.info/postfix-rpm-packages/
如果你无法下载的话,就只能自己编译安装了。
 
停止系统中默认的sendmail服务
# service sendmail stop
# chkconfig sendmail off
# mv /usr/bin/newaliases /usr/bin/newaliases.bak
# mv /usr/bin/mailq /usr/bin/mailq.bak
# mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
 
安装Postfix
# rpm -ivh postfix-2.5.1-1.mysql.sasl2.vda.rhel5.i386.rpm
给postfix原主配文件改名
#mv /etc/postfix/main.cf /etc/postfix/main.cf.bak
配置Postfix
# vim /etc/postfix/main.cf
#=====================BASE=========================



command_directory = /usr/sbin
data_directory = /var/lib/postfix
myhostname = game222.test.com
mydomain = test.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain
unknown_local_recipient_reject_code = 550
mynetworks = 10.0.0.0/8, 127.0.0.0/8
home_mailbox = Maildir/
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases

#=====================Vritual Mailbox settings=========================
virtual_minimum_uid = 100
virtual_mailbox_base = /var/spool/mail
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
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_uid_maps = static:100    #postfix账号的uid 可以使用id -u postfix 查看
virtual_gid_maps = static:102    #postfix组的gid   可以使用id -g postfix 查看
virtual_transport = virtual
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 1

#====================QUOTA========================

message_size_limit = 52428800
mailbox_size_limit = 209715200
virtual_mailbox_limit = 209715200
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 try again later...
virtual_overquota_bounce = yes

#====================SASL========================

broken_sasl_auth_clients = yes
smtpd_recipient_restrictions =  permit_mynetworks,
    permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = /var/spool/postfix/private/auth      #这里要和dovecot配置文件中的配置相对应
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_banner=$myhostname ESMTP "Version not Available"

#=================================================

readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix



 
Postfix的mysql配置文件
# vim /etc/postfix/mysql_virtual_alias_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
 
# vim /etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
 
# vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username
 
# vim /etc/postfix/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
 
启动Postfix
# service postfix start
 
系统启动时自动启动Postfix服务
# chkconfig postfix on
 
刷新Postfix的配置文件
# postfix reload
 
查看Postfix的当前配置信息
# postconf -n
 
查看Postfix的默认配置信息
# postconf -d

2.4. 安装dovecot用来imap和pop3服务验证
首先安装pam-devel
否则(启动dovecot时出现Auth process died too early)
和mysql_devel的rpm包
否则(编译安装时dovecot出现
configure: error: can't build with Mysql support: libmysqlclient not found)


再安装配置dovecot
如果系统中默认安装了dovecot,那么要先把它卸载或停用。
# service dovecot stop
# chkconfig dovecot off
 
编译安装
下载dovecot的源码包(http://www.dovecot.org/download.html)
# tar zxvf dovecot-1.2.8.tar.gz
# cd dovecot-1.0.rc14
# ./configure --prefix=/usr/local/dovecot --sysconfdir=/usr/local/etc --with-mysql --without-ssl --disable-ipv6
# make
# make install

 
建立启动进程所依赖的用户
# useradd -d /dev/null dovecot -s /bin/false
 
修改配置文件
拴出dovecot.conf的主配置文件
#mv /usr/local/etc/dovecot.conf /usr/local/etc/dovecot.conf.bak

# vim /usr/local/etc/dovecot.conf
base_dir = /var/run/dovecot
protocols = imap imaps pop3 pop3s
listen = *
disable_plaintext_auth = no
shutdown_clients = yes
log_path = /var/log/dovecot.log
ssl = no
mail_location = maildir:/var/spool/mail/%d/%n
auth default {                                    #注意空格
  mechanisms = plain login cram-md5
  passdb sql {
    args = /usr/local/etc/dovecot-mysql.conf
  }
 
  userdb sql {
    args = /usr/local/etc/dovecot-mysql.conf
  }
 
  socket listen {
    client {
        path = /var/spool/postfix/private/auth    #这里要和postfix配置文件的配置相对应
        mode = 0660
        user = postfix
        group = postfix
    }
  }
}
first_valid_uid = 100

dovecot的mysql配置文件
# vim /usr/local/etc/dovecot-mysql.conf
driver = mysql
connect = host=/var/lib/mysql/mysql.sock dbname=postfix user=postfix password=postfix

default_pass_scheme = MD5-CRYPT
password_query = SELECT password FROM mailbox WHERE username = '%u'
user_query = SELECT maildir,100 AS uid,102 AS gid FROM mailbox WHERE username = '%u'


修改/var/spool/mail文件的写入属性(否则dovecot会启动不了)
#chmod o+w /var/spool/mail

启动dovecot
# /usr/local/dovecot/sbin/dovecot
 
可以把启动命令写进/etc/rc.d/rc.local文件,以使系统启动时能够自动启动dovecot服务。
# echo "/usr/local/dovecot/sbin/dovecot" >> /etc/rc.d/rc.local
 
停止dovecot
只能用kill命令来停止dovecot服务
# ps -aux | grep dovecot
# kill <"/usr/local/dovecot/sbin/dovecot"的pid>
 
-3. 验证

POP3验证
[root@game222 ~]# telnet 10.0.0.2 110
Trying 10.0.0.2...
Connected to game222.test.com (10.0.0.2).
Escape character is '^]'.
+OK Dovecot ready.


 
IMAP验证
[root@game222 ~]# telnet 10.0.0.2 143
Trying 10.0.0.2...
Connected to game222.test.com (10.0.0.2).
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE AUTH=PLAIN AUTH=LOGIN AUTH=CRAM-MD5] Dovecot ready.

 

测试POP3接收邮件
(使用postfixadmin建立的用户)

[root@mail ~]# telnet 10.0.0.2 110
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
+OK Dovecot ready.
user [email protected]  //使用邮件用户“userd”登录
+OK
pass aaa           //输入userd的密码userd
+OK Logged in.
List               //查看邮件列表
+OK 1 messages:
1 485
.
retr 1             //收取并查看第一封邮件内容,一下内容就不显示了
quit
+OK Logging out.
Connection closed by foreign host.




客户端可以使用squirrelmail作为IMAP客户端,OE可以使用pop3的客户端
安装直接使用rpm包安装squirrelmail(系统包里自带)
安装好后
修改/etc/squirrelmail/config.php
$squirrelmail_default_language = 'zh_CN'




如果出现问题多查看apache,dovecot,postfix的日志记录
上述日志文件分别为
/var/log/httpd/error_log
/var/log/dovecot.log
/var/log/maillog

相关下载
http://down.51cto.com/data/181203

你可能感兴趣的:(mysql,lamp,postfix,Dovecot,rhel5)