文档下载地址:http://www.minunix.com/docs/document/postfix.pdf

转载请注明出处:http://www.minunix.com/2013/04/centoslamppostfixextmail  作者:MinUnix

Postfix 之LAMP环境部署   http://www.minunix.com/2013/04/centoslamppostfixextmail

Postfix 之postfix安装配置   http://www.minunix.com/2013/07/postfix-2/

Postfix 之maildrop配置   http://www.minunix.com/2013/07/postfix-3/ 

Postfix 之病毒防御安全配置   http://www.minunix.com/2013/07/postfix-4/

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

准备工作:

下载mail.tar.gz 中包含本实验中所需要的所有软件包

本实验主要用到postfix、courier-authlib、courier-imap、extmail、extman、maildrop等软件集合而成。

本实验中暂不提及DNS的部署管理知识。
本例中暂时所用的软件包的版本(稍后文档更新会对本部分做出相应更新):
httpd-2.4.4.

mysql-5.5.30.

php-5.4.7.

postfix-2.8.12.

cyrus-sasl-2.1.25.

courier-authlib-0.65.0.

courier-imap-4.9.3.

extmail-1.2.

extman-1.1.
以上是暂时会用到的主要软件包, 可通过http://www.minunix.com/docs/mail中下载mail.tar.gz, 之后会对刚tar包进行更新,请继续关注MinUnix.

一、            安装前准备工作
1. 实验环境
CentOS 6.2 x86_64
LAMP+Postfix+Courier-authlib+courier-imap-extmail+extman+...
2. 安装开发组件及所依赖软件包:
yum  -y groupinstall  “Development Tools”
yum  -y install ncurses-devel  gcc automake autoconf libtool-ltdl-devel make gcc-c++ glibc libxml2-devel libcurl-devel curl-devel openldap-devle openssl-devel bzip2-devel db4-devel libjpeg-devel  libpng-devel  freetype-devel  cpan libart_lgpl-devel  redhat-lsb pango-devel* cairo-devel* perl-DBD-MySQL
3. 关闭卸载sendmail
注: 高版本的centos 默认已经去掉了sendmail,为了安全起见,还是检查以下!
# rpm  -qa|grep sendmail
# rpm  -qa|grep postfix
若发现有安装,则使用”rpm  -e  <rpmname> ” 对其卸载之!
4. 卸载与后期安装有冲突的软件包
因本实验使用编译安装,所以最好把mysql php httpd 之类的软件对其卸载
# rpm  -qa|grep –E ‘(mysql|php|httpd)’
# rpm  -e <name> --nodeps
卸载完之后再检查看看是否还存在相关软件包
5. 下载本实验所需软件包:
为了方便后者下载使用,MinUnix 为您都打到一个包里, 您无需单个下载!
软件包存放位置  /tmp/src
# cd /tmp/ && wget http://www.minunix.com/docs/mail/mail.tar.gz
# tar xf mail.tar.gz  -C ./src/ && cd src/ && ls * |xargs  -n1 tar xf
6. 修改系统信息
# 修改selinux
# 修改hostname
# 暂时关闭防火墙
# 以上修改方法不再陈述步骤, 不会者找度娘, 谷姐

二、            安装MySQL
# useradd  -M  -s /sbin/nologin mysql
# cd mysql-5.5.30
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/var/mysql/data
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306
# make
# make install
# chown  -R mysql.mysql /usr/local/mysql
# vim  /etc/ld.so.conf.d/mysql/conf
##### 输入以下内容######
/usr/local/mysql/lib
/usr/local/mysql/include
/usr/local/mysql/include/mysql   \\\ 保存退出
# ldconfig  -v
加入环境变量
# echo “export PATH=$PATH:/usr/local/mysql/bin” > /etc/profile.d/mysql.sh
# source  /etc/profile  \\\ 使环境变量立刻生效
# cp /usr/local/mysql/support-files/my-large.cnf  /etc/my.cnf
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig  --add mysqld && chkconfig mysqld on
编辑my.cnf 在[mysqld] 中加入datadir的路径
# vim /etc/my.cnf
加入一行 datadir  =  /var/mysql/data
# chown  -R mysql.mysql /var/mysql/data
# /usr/local/mysql/scripts/mysql_install_db  --user=mysql  --basedir=/usr/local/mysql  --datadir=/var/mysql/data
# service mysqld start

三、            安装Openssl、mcrypt、mhash、apr-util
1. 安装openssl
# cd  /tmp/src/openssl-1.0.1
# ./config shared zlib
# make
# make install
# mv /usr/bin/openssl /usr/bin/openssl.bak
# mv  /usr/include/openssl /usr/include/openssl.bak
# rm /usr/lib64/libssl.so
# ln -s /usr/local/ssl/bin/openssl  /usr/bin/openssl
# ln -s /usr/local/ssl/include/
# ln -s /usr/local/ssl/include/openssl /usr/include/openssl
# ln -sv /usr/local/ssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so
# echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
# ldconfig –v
# 检查安装后的Openssl 版本
# openssl version
OpenSSL 1.0.1 14 Mar 2012
2. 安装mcrypt
# cd /tmp/src/mhash -0.9.9.9
# ./configure --prefix=/usr/local/mhash
# make && make install
# ln -sv /usr/local/mhash/lib/* /usr/local/lib64/
# ln -sv /usr/local/mhash/include/* /usr/local/include/
# cd /tmp/src/libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
# make
# make install
# cd /tmp/src/mcrypt-2.6.8
# ln -sv /usr/local/libmcrypt/lib/* /usr/lib/
# ln -sv /usr/local/libmcrypt/lib/* /usr/lib64/
# LD_LIBRARY_PATH=/usr/local/lib64 ./configure       --with-libmcrypt-prefix=/usr/local/libmcrypt
# make && make install
3. 安装apr-util 、pcre
# cd /tmp/src/apr-1.4.6
# ./configure --prefix=/usr/local/apr
# make && make install
# cd /tmp/src/apr-util-1.4.1
# ./configure --with-apr=/usr/local/apr
# make && make install

# cd /tmp/src/pcre-8.31
# ./configure
# make && make install

四、            安装Apache
#
# cd /tmp/src/httpd-2.4.4
#./configure --prefix=/usr/local/apache  \
--sysconfdir=/etc/httpd  \
--enable-so --enable-ssl  \
--enable-track-vars --enable-rewrite  \
--enable-mods-shared=most  \
--enable-cgi --enable-suexec  \
--with-suexec-caller=postfix  \
--with-libxml2 --with-apr  \
--with-apr-util --with-pcre  \
--with-ssl=/usr/local/ssl  --with-zlib
# echo “/usr/loca/apache/bin/apachectl  -k  start” >> /etc/rc.local (系统启动时自动启动apache服务)

安装PHP
# cd /tmp/src/php-5.4.7
# ./configure --prefix=/usr/local/php  \
--with-apxs2=/usr/local/apache/bin/apxs  \
--with-config-file-path=/usr/local/php/etc  \
--with-mysql=/usr/local/mysql --with-mysqli  \
--with-iconv-dir --with-freetype-dir  \
--with-jpeg-dir --with-png-dir --with-zlib  \
--with-libxml-dir --enable-xml --disable-rpath  \
--enable-bcmath --enable-shmop --with-gettext  \
--enable-sysvsem --enable-inline-optimization  \
--with-curl --with-curlwrappers --enable-mbregex  \
--enable-mbstring --with-mcrypt=/usr/local/libmcrypt \
--with-gd --enable-gd-native-ttf --with-openssl  \
--with-mhash --enable-pcntl --enable-sockets  \
--with-xmlrpc --enable-zip --with-pcre-dir --enable-soap  \
--enable-zend-signals --without-pear  --with-bz2\
--disable-pdo --disable-debug  --with-pcre-regex --enable-sysvshm
# make && make install
# cp php.ini-development  /usr/local/php/etc/php.ini
1. 编辑http.conf , 添加以下两行,以便apache可以支持php
# vim /etc/httpd/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2. 修改DirectoryIndex 后面的参数, 增加index.php
3. 可以注释掉DocumentRoot 参数, 并 修改
<Directory  “/usr/local/apache/htdocs”> 为:
<Directory  “/var/www”>
4. 修改/etc/httpd/extra/httpd-vhosts.conf 文件
<VirtualHost *:80>
ServerName  mail1.minunix.com
DocumentRoot “/var/www”
ErrorLog  “logs/mail-error.log”
CustomLog  “logs/mail-access.log”
</VirtualHost>
5. 在/var/www/ 目录下新建index.php文件
# cat /var/www/index.php
<?php
phpinfo(); ?>
6. 启动apache 并予以访问测试
/usr/local/apache/bin/apachectl  -k start

未完.... 待续...........

接下篇 Postfix 之postfix安装配置 http://www.minunix.com/2013/07/postfix-2/