httpd 2.4.2 + mysql-5.5.24 +postfix-2.9.3 + Extmail-1.2 + Extman-1.1

httpd 2.4.2 + mysql-5.5.24 +postfix-2.9.3  + Extmail-1.2 + Extman-1.1

http和Mysql的安装这里就不介绍了,前面有写好的文章可以参考,下面来安装postfix

1、首先需要DNS解析,配置就不写了

2、关闭默认的sendmail
# service sendmail stop
# chkconfig sendmail off

安装后面需要的依赖软件包
# yum -y install  openssl-devel  dovecot  perl-DBD-MySQL tcl tcl-devel  libart_lgpl  libart_lgpl-devel libtool-ltdl libtool-ltdl-devel expect

启动http,saslauthd,mysql并设置密码
# service httpd restart;

# service saslauthd start

# service mysqld restart
# mysqladmin -uroot password 'redhat'

3、postfix安装
# groupadd -g 2525 postfix (根据安全策略这里尽量大于1000以上)
# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix
# groupadd -g 2526 postdrop
# useradd -g postdrop -u 2526 -s /sbin/nologin -M postdrop

# tar zxvf postfix-2.9.1.tar.gz
# cd postfix-2.9.1
# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2  -lssl -lcrypto'
# make
# make install

安装的时候发现报错 bin/postconf: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
使用以下方法解决
# vi /etc/ld.so.conf
/usr/local/mysql/lib
# ldconfig

生成别名二进制文件:
#  newaliases

对配置文件稍作修改
# vim /etc/postfix/main.cf
myhostname = mail.peace.com
mydomain = peace.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
        mail.$mydomain, www.$mydomain, ftp.$mydomain
mynetworks = 192.168.80.0/24, 127.0.0.0/8

其意义如下:
mydoaim 自己的域
myhostname  主机名
myorigin  发件人地址伪装
inet_inetfaces 监听范围
mynetworks  指定允许中继IP网段
mydestination 本机所负责接受邮件所在域

添加service启动脚本
# vim /etc/rc.d/init.d/postfix
#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ $NETWORKING = "no" ] && exit 3

[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6

RETVAL=0
prog="postfix"

start() {
 # Start daemons.
 echo -n $"Starting postfix: "
        /usr/bin/newaliases >/dev/null 2>&1
 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
 RETVAL=$?
 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
 return $RETVAL
}

stop() {
  # Stop daemons.
 echo -n $"Shutting down postfix: "
 /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
 RETVAL=$?
 [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
 echo
 return $RETVAL
}

reload() {
 echo -n $"Reloading postfix: "
 /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
 RETVAL=$?
 echo
 return $RETVAL
}

abort() {
 /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
 return $?
}

flush() {
 /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
 return $?
}

check() {
 /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
 return $?
}

restart() {
 stop
 start
}

# See how we were called.
case "$1" in
  start)
 start
 ;;
  stop)
 stop
 ;;
  restart)
 stop
 start
 ;;
  reload)
 reload
 ;;
  abort)
 abort
 ;;
  flush)
 flush
 ;;
  check)
 check
 ;;
  status)
   status master
 ;;
  condrestart)
 [ -f /var/lock/subsys/postfix ] && restart || :
 ;;
  *)
 echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
 exit 1
esac

exit $?

# END


加执行权限后就可以用service启动服务了,启动后测试发送邮件
# telnet mail.peace.com 25
Trying 192.168.80.139...
Connected to mail.peace.com (192.168.80.139).
Escape character is '^]'.
220 mail.peace.com ESMTP Postfix
helo
501 Syntax: HELO hostname
mail from:[email protected]
250 2.1.0 Ok
rcpt to:root
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test,ok!
.
250 2.0.0 Ok: queued as 62DF4B7788
quit

通过mail命令查看已经发现有邮件了。

4、安装courier-authlib-0.64.0
# tar xf courier-authlib-0.64.0.tar.bz2
# cd courier-authlib-0.64.0
#./configure  --prefix=/usr/local/courier-authlib  --sysconfdir=/etc --without-authpam --without-authshadow --without-authvchkpw --without-authpgsql --with-authmysql --with-mysql-libs=/usr/local/mysql/lib --with-mysql-includes=/usr/local/mysql/include --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-mailuser=postfix --with-mailgroup=postfix --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include


# make
# make install


# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon/
# cp /etc/authdaemonrc.dist /etc/authdaemonrc
# cp /etc/authmysqlrc.dist /etc/authmysqlrc

修改/etc/authdaemonrc文件,只留authmysql即可
authmodulelist="authmysql"
authmodulelistorig="authmysql"


编辑/etc/authmysqlrc 通过mysql进行邮件账号认证,其中2525,2525 为postfix 用户的UID和GID。
MYSQL_SERVER localhost
MYSQL_USERNAME  extmail      这是为后面要用到的数据库的所有者的用户名MYSQL_PASSWORD extmail        密码
MYSQL_SOCKET  /tmp/mysql.sock 根据mysql配置文件中的socket做更改即可
MYSQL_PORT 3306                   指定你的mysql监听的端口,这里使用默认的3306
MYSQL_DATABASE  extmail
MYSQL_USER_TABLE  mailbox
MYSQL_CRYPT_PWFIELD  password
MYSQL_UID_FIELD  '2525'
MYSQL_GID_FIELD  '2525'
MYSQL_LOGIN_FIELD  username
MYSQL_HOME_FIELD  concat('/var/mailbox/',homedir)
MYSQL_NAME_FIELD  name
MYSQL_MAILDIR_FIELD  concat('/var/mailbox/',maildir)

使用service脚本
# cp courier-authlib.sysvinit /etc/rc.d/init.d/courier-authlib
# chmod 755 /etc/rc.d/init.d/courier-authlib
# chkconfig --add courier-authlib
# chkconfig courier-authlib on
# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf
# ldconfig -v
# service courier-authlib start

通过ps命令可以看到已经产生进程了

 

5、配置虚拟用户
新建虚拟用户邮箱所在的目录,并将其权限赋予postfix用户:
# mkdir -pv /var/mailbox
# chown -R postfix /var/mailbox

配置SMTP 认证,新建 /usr/lib/sasl2/smtpd.conf 文件,内容如下:
pwcheck_method: authdaemond
mech_list:PLAIN LOGIN
log_level: 3
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket


编辑/etc/postfix/main.cf,使其支持虚拟域和虚拟用户和邮箱配额,添加如下内容:
########################Virtual Mailbox ########################
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:2525                     postfix的uid
virtual_gid_maps = static:2525                      postfix的gid
virtual_transport = virtual                             虚拟用户投递代理
maildrop_destination_recipient_limit = 1              一次投递只能投递一次
maildrop_destination_concurrency_limit =  1             并发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                                       超出限额邮件是否弹回

 

6、配置dovecot

# vi /etc/dovecot.conf
mail_location = maildir:/var/mailbox/%d/%n/Maildir
……
auth default {
    mechanisms = plain
    passdb sql {
        args = /etc/dovecot-mysql.conf
    }
    userdb sql {
        args = /etc/dovecot-mysql.conf
    }
    ……

建立dovecot-mysql.conf文件添加如下信息:

# vim /etc/dovecot-mysql.conf                
driver = mysql
connect = host=/tmp/mysql.sock 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'

注意这里的host=/tmp/mysql.sock根据mysql的文件更改

启动dovecot服务:
# service dovecot start
# chkconfig dovecot on

启用虚拟域以后,需要取消中心域,即注释掉myhostname, mydomain, myorigin, mydestination几个指令;当然,你也可以把mydestionation的值改为你自己需要的。

之后重启服务
# service postfix restart

7、安装Extmail-1.2
先安装依赖软件
# tar zxvf Unix-Syslog-0.100.tar.gz
# cd Unix-Syslog-0.100
# perl Makefile.PL
# make
# make install


# tar zxvf extmail-1.2.tar.gz
# mkdir -p /var/www/extsuite
# mv extmail-1.2 /var/www/extsuite/extmail
# cp /var/www/extsuite/extmail/webmail.cf.default  /var/www/extsuite/extmail/webmail.cf

# vi /var/www/extsuite/extmail/webmail.cf


SYS_MESSAGE_SIZE_LIMIT = 5242880 用户可以发送的最大邮件
SYS_USER_LANG = zh_CN   语言选项
SYS_MAILDIR_BASE = /var/mailbox  之前文所设置的用户邮件的存放目录
SYS_MYSQL_USER = extmail  连接数据库服务器所使用用户名
SYS_MYSQL_PASS = extmail  连接数据库服务器所使用密码
SYS_MYSQL_HOST = localhost  指明数据库服务器主机名,这里默认即可
SYS_MYSQL_SOCKET = /tmp/mysql.sock
SYS_MYSQL_TABLE = mailbox  登录里所用到的表
SYS_MYSQL_ATTR_USERNAME = username 用户名
SYS_MYSQL_ATTR_DOMAIN = domain  域名
SYS_MYSQL_ATTR_PASSWD = password 用户密码
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket 指明authdaemo socket文件的位置

修改http配置文件
# vim /etc/httpd/httpd.conf
User postfix
Group postfix
Include /etc/httpd/extra/httpd-vhosts.conf

# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
        ServerName mail.peace.com
        DocumentRoot /var/www/extsuite/extmail/html/
        ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
        Alias /extmail /var/www/extsuite/extmail/html
</VirtualHost>
重启服务
#service httpd restart

 

8、安装Extman-1.1
# tar zxvf  extman-1.1.tar.gz

导入mysql库
# cd extman-1.1/docs
# mysql -u root -p < extmail.sql
# mysql -u root -p <init.sql
# cp mysql_virtual_* /etc/postfix/

委派extmail用户数据库权限
mysql> GRANT all privileges on extmail.* TO extmail@localhost IDENTIFIED BY 'extmail';
mysql> GRANT all privileges on extmail.* TO [email protected] IDENTIFIED BY 'extmail';
mysql> FLUSH PRIVILEGES;

注意:如出现: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

错误原因是mysql5.5以上不再支持TYPE存储引擎,改成ENGINE了,所以:

# sed -i "s/TYPE=MyISAM/ENGINE=MyISAM/g" extmail.sql
# sed -i "s/TYPE=MyISAM/ENGINE=MyISAM/g" init.sql

在重新执行,发现extmail已存在,是刚才的错误,库文件有了,表没有,删除库重新执行即可

# mv /root/extman-1.1 /var/www/extsuite/extman
# cp /var/www/extsuite/extman/webman.cf.default  /var/www/extsuite/extman/webman.cf

修改配置文件
# vim /var/www/extsuite/extman/webman.cf
SYS_MAILDIR_BASE = /var/mailbox  设置的用户邮件的存放目录
SYS_DEFAULT_UID = 2525   postfix用户id号
SYS_DEFAULT_GID = 2525   postfix组的id号
SYS_MYSQL_USER = extmail  数据库用户名
SYS_MYSQL_PASS = extmail  数据库密码
SYS_MYSQL_SOCKET = /tmp/mysql.sock

修改cgi目录的属主:
# chown -R postfix.postfix /var/www/extsuite/extman/cgi/

在httpd的虚拟主机配置文件中Extmail的虚拟主机部分,添加如下两行如下:
# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
        ServerName mail.peace.com
        DocumentRoot /var/www/extsuite/extmail/html/
        ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
        Alias /extmail /var/www/extsuite/extmail/html
        ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
        Alias /extman /var/www/extsuite/extman/html
</VirtualHost>

创建其运行时所需的临时目录,并修改其相应的权限:
# mkdir -p /tmp/extman
# chown postfix.postfix  /tmp/extman

重启http服务访问即可

当浏览器出现如下错误时

Forbidden

You don't have permission to access /extmail/cgi/index.cgi on this server.

修改虚拟主机配置文件,添加权限,重启服务
# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
        ServerName mail.peace.com
        DocumentRoot /var/www/extsuite/extmail/html/
        ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
        Alias /extmail /var/www/extsuite/extmail/html
        ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
        Alias /extman /var/www/extsuite/extman/html
        <Directory "/var/www/extsuite">
                Options none
                AllowOverride   none
                Require all granted
        </Directory>
</VirtualHost>

在访问时只有脚本没执行是,修改/etc/httpd/httpd.conf,如下行,启动cgi模块即可

LoadModule cgi_module modules/mod_cgi.so


重启服务即可访问
#service httpd restart

选着如下,默认管理帐号为:[email protected]  密码为:extmail*123*


校验码不刷新问题:
可以安装perl-GD或修改# vim /var/www/extsuite/extman/webman.cf
SYS_CAPTCHA_ON = 1 为 SYS_CAPTCHA_ON = 0 


9、为postfix添加ssl
# vim /etc/pki/tls/openssl.cnf
# cd /etc/pki/CA/
# (umask 077; openssl genrsa 1024 > private/cakey.pem)
# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
# mkdir certs newcerts crl
# touch index.txt
# echo 01 > serial

# mkdir /etc/dovecot/ssl -p
# cd /etc/dovecot/ssl/
# (umask 077 ; openssl genrsa 1024 > dovecot.key)
# openssl req -new dovecot.key -out dovecot.csr
# openssl req -new -key dovecot.key -out dovecot.csr
# openssl ca -in dovecot.csr -out dovecot.crt

修改dovecot配置文件,添加ssl
# vim /etc/dovecot.conf
protocols = imaps pop3 pop3s

ssl_disable = no

ssl_cert_file = /etc/dovecot/ssl/dovecot.crt
ssl_key_file = /etc/dovecot/ssl/dovecot.key

# service dovecot restar
可以看到已经监听端口了。客户端选着995端口连接即可,不再使用110了

 

 

你可能感兴趣的:(httpd,2.4.2,mysql-5.5.24,Extman-1.1,postfix-2.9.3,Extmail-1.2)