一、安装前的准备工作
1.关闭防火墙与SELinux
service iptables stop service ip6tables stop chkconfig iptables off chkconfig ip6tables off 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 - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted reboot
2.修改主机名
vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=mail.free.com
3.下载并安装yum源
(1).下载163的yum源到当前目录
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
(2).下载rpmforge
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
(3).备份原有的yum源
mkdir /etc/yum.repos.d/backup mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup
(4). 增加新的yum源
cp CentOS6-Base-163.repo /etc/yum.repos.d/ rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
(5).清理yum缓存并更新系统
yum clean all yum update & yum makecache
4.创建一个vmail用户,用作管理虚拟邮箱的文件夹
useradd –u 2000 –d /var/vmail –m –s /sbin/nologin vmail
二、安装并配置LAMP环境
PostfixAdmin2.3.6+Roundcubemail0.92的PHP环境要求最低PHP5.2,此处安装的是5.3.3。
简易安装LAMP环境[如果采用其它方式安装切记要安装imap扩展]
yum -y install httpd mysql mysql-devel mysql-server php php-pecl-Fileinfo php-mcrypt php-devel php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc pcre pcre-devel
整合Apache与PHP
vim /etc/httpd/conf/httpd.conf #增加下面现行 AddType application/x-httpd-php .php #apache解析php程序 PHPIniDir "/etc/php.ini" #指定php.ini配置文件路径 #增加一行[也可指定虚拟域名,不然重启httpd会有警告] ServerName localhost:80
#修改这一行增加index.php DirectoryIndex index.php index.html index.html.var #修改apache运行的用户和组 User vmail Group vmail
service httpd restart chkconfig httpd on chkconfig httpd –list httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
测试phpinfo
vim /var/www/html/phpinfo.php
输入
<?php phpinfo();
查看是否配置正确,重点看一看imap扩展和session,注意session存放目录权限
二、安装并配置postfixadmin
1.上传所需源码postfixadmin-2.3.6.tar.gz到 /var/www/html,解压,改名
cd /var/www/html
tar –zxvf postfixadmin-2.3.6.tar.gz
mv postfixadmin-2.3.6 postfixadmin
2.配置并测试
cd postfixadmin/
cp config.inc.php config.inc.php.bk
cp setup.php setup.php.bk
vim config.inc.php
#找到下面几行并修改
$CONF['configured'] = true;
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix';
$CONF['database_name'] = 'postfix';
$CONF['admin_email'] = '[email protected]';
$CONF['encrypt'] = 'dovecot:CRAM-MD5';
$CONF['dovecotpw'] = "/usr/bin/doveadm pw";
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['aliases'] = '1000';
$CONF['mailboxes'] = '1000';
$CONF['maxquota'] = '1000';
$CONF['fetchmail'] = 'NO';
$CONF['quota'] = 'YES';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';
2. 为postfixadmin创建Mysql数据库与权限
service mysqld start
chkconfig mysqld on
chkconfig mysqld –list
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
mysql
create database postfix;
grant all on postfix.* to postfix@'localhost'
identified by
'postfix';
flush privileges;
quit;
mysql -upostfix –p
postfix
show databases;
3.修改所有者与所有组
chown -R vmail.vmail postfixadmin/
4.具体配置过程如下图
(1).http://192.168.1.121/postfixadmin/setup.php
注:检查PHP环境,并初始化数据库
(2).创建设置密码并修改配置文件(我这里的密码是123456)
vim config.inc.php
$CONF['setup_password'] = '6471f6462d427bf547c07fb2a08fdecf:09a43f1679223
4050d298b7d0333c101d4bbd48e';
(3).创建管理员密码
先输入你刚才设置的密码,我这里是123456,然后输入管理员邮箱,管理员密码!
出现错误,说没有dovecotpw,是因为我们还没安装dovecot,我们这里先来安装一下dovecot,后面再进行配置!
yum install -y dovecot dovecot-devel dovecot-mysql
chkconfig dovecot on
chkconfig dovecot –list
dovecot 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
我们再来设置一下管理员的账户与密码,(我这里设置是[email protected]密码:123456)
成功后登录
http://192.168.1.121/postfixadmin/login.php
4.postfxiadmin不能自动创建目录,所以我们得增加自动建立目录的功能
(1).建立创建虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-creation.sh,脚本内容如下:
[root@mail ~]#vim /usr/local/bin/maildir-creation.sh
#!/bin/bash
#
HOME_DIR="/var/vmail"
USER_NAME="vmail"
GROUP_NAME="vmail"
if [ ! -d ${HOME_DIR}/$1 ] ; then
mkdir ${HOME_DIR}/$1
chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1
fi
mkdir ${HOME_DIR}/$1/$2
chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2
(2).建立删除虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-deletion.sh ,脚本内容如下:
[root@mail ~]#vim /usr/local/bin/maildir-deletion.sh
#!/bin/bash
#
# vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
#
if [ $# -ne 2 ] ; then
exit 127
fi
DOMAIN="$1"
USER="$2"
HOME_DIR="/var/vmail"
USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}"
TRASH_DIR="${HOME_DIR}/deleted-maildirs"
DATE=`date "+%Y%m%d_%H%M%S"`
if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then
mkdir -p "${TRASH_DIR}/${DOMAIN}"
fi
if [ -d "${USER_DIR}" ] ; then
mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE}
fi
5.建立删除目录
[root@mail ~]# mkdir /var/vmail/deleted-maildirs
[root@mail ~]# chown -R vmail.vmail /var/vmail/deleted-maildirs/
6.赋予脚本可执行权限
[root@mail ~]# chmod 750 /usr/local/bin/maildir-*
[root@mail ~]# chown vmail.vmail /usr/local/bin/maildir-*
7.配置sudo
[root@mail ~]#vim /etc/sudoers
#在 /etc/sudoers 最后增加两行
vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh
vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
#在/etc/sudoers 注释掉下面内容
#Defaults requiretty
:wq! #由于这个文件是只读的,所以得强制保存并退出
8.修改postfixadmin的相关文件
[root@mail ~]# cd /var/www/html/postfixadmin/
[root@mail postfixadmin]# vim create-mailbox.php
修改create-mailbox.php 文件,229行内容应该是:
db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername");
在该行前面增加下面一行,
system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']);
[root@mail postfixadmin]# vim delete.php
修改delete.php 文件,146行内容应该是,
db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete);
在该行下面增加下面4行,
$userarray=explode("@",$fDelete);
$user=$userarray[0];
$domain=$userarray[1];
system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");
postfixadmin配置全部完成
参考链接:http://freeloda.blog.51cto.com/2033581/1245492