Linux Postfix 全面安装指导手册一之Postfix基本网络与LAMP环境配置

 
此文参考了网上各个博文,《Postfix权威指南》。经过本人精心测试,实现了各个软件的整合及企业一般邮件系统需求。现在将它分享给大家,希望对大家工作有所帮助

◆运行环境:Centos5

◆所需软件:

httpd-2.2.0.tar.gz,

mysql-5.0.41.tar.gz,

php-5.2.3.tar.gz,

courier-authlib-0.59.3.tar.bz2,

courier-imap-4.5.0.tar.bz2,

cyrus-sasl-2.1.23.tar.gz

postfixadmin-2.1.0.gz

postfix-2.4.9.tar.gz

pcre-7.2.tar.gz

maildrop-2.5.tar.bz2

◆准备工作:

1、卸载相关软件:全新进行postfix与各软件整合。

    1/1:rpm -e --nodeps sendmail

    1/2:rpm -qa | grep sasl

        rpm -e --nodeps cyrus-sasl-*   注: (ls -al /usr/lib | grep sasl) 应该没有目录sasl与sasl2

    1/4:rpm -qa | grep perl

        yum remove perl 执行完后,运行perl -v 注:(如果出现-bash:perl:command not found"则表明已经把perl清除掉了。

2、创建邮件系统所需的用户与组:

[root@mail1 ~]# groupadd vmail

[root@mail1 ~]# groupadd postfix

[root@mail1 ~]# groupadd postdrop

[root@mail1 ~]# groupadd amavis

[root@mail1 ~]# groupadd clamav

[root@mail1 ~]# groupmod -g 1001 vmail

[root@mail1 ~]# useradd mysql -g mysql

[root@mail1 ~]# usradd vmail -g vmail -u 1001

[root@mail1 ~]# useradd postfix -g postfix

[root@mail1 ~]# useradd amavis -g amavis

3、建立网络环境

[root@mail1 ~]# hostname

mail1.mail.sery.com

[root@mail1 ~]# cat /etc/resolv.conf
nameserver 192.168.20.205
search mail.sery.com

[root@mail1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:50:56:A6:00:0D
ONBOOT=yes
IPADDR=192.168.20.206
NETMASK=255.255.255.0

4、建立DNS服务器,这里只把配置写出来,建立过程不作详细说明:

[root@ben ~]# cat /usr/local/named/etc/named.conf
options {
     directory "/data/named";
     allow-query-cache {any;};
     pid-file "named.pid";
 };
key "rndc-key" {
        algorithm hmac-md5;
        secret "s8sFAwD/KNS8bI9myo27aw==";
 };
controls {
        inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { "rndc-key"; };
 };
logging {
        channel query_log {
                file "query.log" versions 5 size 20m;
                severity  info;
                print-time yes;
                print-category yes;
  };
category queries {
            query_log;
           };
 };
zone "." IN {
       type hint;
       file "named.ca";
 };
zone "localhost" IN {
    type master;
    file "localhost.zone";
    allow-update { none; };
 };
zone "0.0.127.in-addr.arpa" IN {
    type master;
    file "named.local";
   allow-update { none; };
 };
#zone "formyz.cn" IN {
#    type master;
#    file "formyz.cn.zone";
#    allow-update { none; };
# };
zone "mail.sery.com" IN {
    type master;
     file "mail.sery.com.zone";
     };
zone "20.168.192.in-addr.arpa" {
      type master;
      file "192.168.0.zone";
      };

[root@ben ~]# cat /usr/local/named/etc/rndc.conf
# Start of rndc.conf
key "rndc-key" {
        algorithm hmac-md5;
        secret "s8sFAwD/KNS8bI9myo27aw==";
};

options {
        default-key "rndc-key";
        default-server 127.0.0.1;
        default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key "rndc-key" {
#       algorithm hmac-md5;
#       secret "s8sFAwD/KNS8bI9myo27aw==";
# };
#
 controls {
        inet 127.0.0.1 port 953
                allow { 127.0.0.1; } keys { "rndc-key"; };
 };
# End of named.conf

[root@ben ~]# cat /data/named/named.ca
;;G 9.3.3rc2 <<>>
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42143
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 14

;; QUESTION SECTION:
;.                              IN      NS

;; ANSWER SECTION:
.                       445881  IN      NS      h.root-servers.net.
.                       445881  IN      NS      i.root-servers.net.
.                       445881  IN      NS      b.root-servers.net.
.                       445881  IN      NS      d.root-servers.net.
.                       445881  IN      NS      m.root-servers.net.
.                       445881  IN      NS      a.root-servers.net.
.                       445881  IN      NS      l.root-servers.net.
.                       445881  IN      NS      k.root-servers.net.
.                       445881  IN      NS      c.root-servers.net.
.                       445881  IN      NS      e.root-servers.net.
.                       445881  IN      NS      g.root-servers.net.
.                       445881  IN      NS      j.root-servers.net.
.                       445881  IN      NS      f.root-servers.net.

;; ADDITIONAL SECTION:
a.root-servers.net.     3461941 IN      A       198.41.0.4
a.root-servers.net.     3532082 IN      AAAA    2001:503:ba3e::2:30
b.root-servers.net.     3523625 IN      A       192.228.79.201
c.root-servers.net.     3462350 IN      A       192.33.4.12
d.root-servers.net.     3462598 IN      A       128.8.10.90
d.root-servers.net.     3542767 IN      AAAA    2001:500:2d::d
e.root-servers.net.     3462564 IN      A       192.203.230.10
f.root-servers.net.     3523443 IN      A       192.5.5.241
f.root-servers.net.     3534003 IN      AAAA    2001:500:2f::f
g.root-servers.net.     3523452 IN      A       192.112.36.4
h.root-servers.net.     3523453 IN      A       128.63.2.53
h.root-servers.net.     3553028 IN      AAAA    2001:500:1::803f:235
i.root-servers.net.     3523432 IN      A       192.36.148.17
i.root-servers.net.     3586381 IN      AAAA    2001:7fe::53

;; Query time: 64 msec
;; SERVER: 202.96.104.17#53(202.96.104.17)
;; WHEN: Fri Feb 10 12:48:59 2012
;; MSG SIZE  rcvd: 512

[root@ben ~]# cat /data/named/named.local
$TTL    86400
@       IN      SOA  localhost. root.localhost.  (
                      2006121601       ;serial (d.adams)
                          3H           ; refresh
                          15M          ; retry
                          1W           ;expiry
                          1D )         ; minimum
       IN      NS   localhost.
1     IN       PTR  localhost

[root@ben ~]# cat /data/named/localhost.zone
$TTL     86400
$ORIGIN localhost.
@                     1D IN SOA     @ root (
                                 42      ; serial (d.adams)
                                 3H      ; refresh
                                 15M     ; retry
                                 1W      ; expiry
                                 1D )    ; minimum
                      1D IN NS  @
                      1D IN A  127.0.0.1

[root@ben ~]# cat /data/named/mail.sery.com.zone
$TTL    1D
@        IN SOA  ben.mail.sery.com.   root.mail.sery.com.   (
                              2009071966   ; serial
                                3H         ;
                                15M        ;
                                1W         ;
                                1D )       ;
@                 IN  NS       ben.mail.sery.com.
ben                  IN  A         192.168.20.205
mail1                IN  A         192.168.20.206
mail2                IN  A         192.168.20.204
mail.sery.com.                   IN  MX  20   mail1.mail.sery.com.
mail.sery.com.                    IN MX  30   mail2.mail.sery.com.
benson-PC                IN    A       192.168.10.115

[root@ben ~]# cat /data/named/192.168.0.zone
$TTL     86400
@         IN SOA  ben.mail.sery.com.   root.mail.sery.com.  (
                                 42      ; serial (d.adams)
                                 3H      ; refresh
                                 15M     ; retry
                                 1W      ; expiry
                                 1D )    ; minimum
@            IN       NS   ben.mail.sery.com.
205             IN       PTR  ben.mail.sery.com.
204              IN      PTR   mail2.mail.sery.com.
206            IN      PTR      mail1.mail.sery.com.
115            IN      PTR       benson-PC.mail.sery.com.

[root@ben ~]# nslookup
> 192.168.20.206
Server:         192.168.20.205
Address:        192.168.20.205#53

206.20.168.192.in-addr.arpa     name = mail1.mail.sery.com.
> mail1
Server:         192.168.20.205
Address:        192.168.20.205#53

** server can't find mail1: NXDOMAIN
> mail1.mail.sery.com
Server:         192.168.20.205
Address:        192.168.20.205#53

Name:   mail1.mail.sery.com
Address: 192.168.20.206
> set type=mx
> mail1
Server:         192.168.20.205
Address:        192.168.20.205#53

** server can't find mail1: NXDOMAIN
> mail.sery.com
Server:         192.168.20.205
Address:        192.168.20.205#53

mail.sery.com   mail exchanger = 20 mail1.mail.sery.com.
mail.sery.com   mail exchanger = 30 mail2.mail.sery.com.

◆配置过程:LAMP

1、 Apache 

    yum -y install gcc gcc-c++

    tar zxvf httpd-2.2.0.tar.gz

    cd httpd-2.2.0

     ./configure --prefix=/usr/local/apache   --enable-so

     make 

     make install  

     查看静态模块 [root@mail1 ~]# /usr/local/apache/bin/httpd -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_include.c
  mod_filter.c
  mod_log_config.c
  mod_env.c
  mod_setenvif.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_cgi.c
  mod_negotiation.c
  mod_dir.c
  mod_actions.c
  mod_userdir.c
  mod_alias.c

 ( mod_so.c  )     则表明--enable-so 已经加入到模块中了  

  查看动态模块:

[root@mail1 ~]# ls -l /usr/local/apache/modules/
total 12224
-rw-r--r-- 1 root root     8873 Feb 16 09:10 httpd.exp
-rwxr-xr-x 1 root root 12485669 Feb 16 10:21 libphp5.so

 

2 mysql
Yum –y install ncurses-devel  libxml2 libxml2-devel
tar zxvf mysql-5.0.41.tar.gz
cd mysql-5.0.41
./configure -prefix=/usr/local/mysql
make,make install     //安装完成
cp support-files/my-medium.cnf  /etc/my.cnf
cd /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db  --user=mysql //初始化数据库
chown -R root .
chown -R mysql var
chgrp -R mysql .
echo "/usr/local/mysql/lib/mysql">>/etc/ld.so.conf
ldconfig
echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source /etc/profile
红色字体这几行命令如果不在此处执行的话,以后在安装courier-authlib将出现不少麻烦,切记!!设置mysql路径的目的是将来需要使用mysql-config文件.
 
3、php
Yum –y install perl
--在安装ncurses-devel 时如果有依赖包perl 那么就不需要在安装Perl        
注 perl解释器
tar zxvf php-5.2.3.tar.gz
cd php-5.2.3
./configure -prefix=/usr/local/php -with-apxs2=/usr/local/apache/bin/apxs -with-mysql=/usr/local/mysql               //如果不先安装mysql,这一步将不能进行下去
 
*** 注: 在configure过程中, 可能会遇到下面的错误! Sorry, I cannot run apxs. ***
 这是因为我前面卸载了perl软件才会报错:
configure: error: Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs
 
  解决方法及思路:
   首先, 通过错误提示, 我们得知"I cannot run apxs". 我一直以为是apxs安装有问题, 但找了很久仍未得到合理的解释和解决方法.
   于是我直接运行"/usr/local/apache/bin/apxs"这个脚本, 得到下面的错误提示: 
    bash: ./apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
   哦, 给人的感觉很像仍然是apxs程序有问题, 但问题在哪里呢? "interpreter"是什么呢? interpreter是"解释程序"!
  嗯, 看来我们接近答案了,
  运行"head -1 /usr/local/apache/bin/apxs"得到下面内容: 
 #!/replace/with/path/to/perl/interpreter -w
 天啊, 这里没有指明正确的perl执行程序的位置! 原来这就才是真正的问题原因所在!!!
 把这一行更改为"#!/usr/bin/perl -w". 再运行php的configure, 一切正常! 
 至此, 问题已解决. 
  Make clean;make;make install
 cp  php.ini-dist /usr/local/php/lib/php.ini
在配置过程中,除了指定安装目录外,还有-with-apxs2和-with-mysql这两个选项。-with-apxs2的作用是与 apache的工具apxs配合,产生模块文件到目录/usr/local/apache/modules/,
同时在apache的配置文件/usr/local/apache/conf/httpd.conf中写入一行
 "LoadModule php5_module modules/libphp5.so";

[root@myest modules]# ll
total 12212
-rw-r--r--  1 root root     8873 Jul 30 14:55 httpd.exp
-rwxr-xr-x  1 root root 12473318 Jul 31 09:29 libphp5.so

选项-with-mysql的作用非常重要,如果不加这个,以后在使用web管理工具postfixadmin时将出现不能连接数据库的错误。接着我们需要把php与apache整合在一起,这个过程很简单,由于在安装php时已经完成了一部分工作,接下来只要在apache的配置文件 httpd.conf加上
"AddType application/x-httpd-php  .php"这么一行就行了(注意:.php前面有一个空格)。在目录/usr/local/apache/htdocs下创建一个最简单的php测试文件,其内容为:

vi test.php
<?
phpinfo();
?>

检查一下apache配置文件是否正确(/usr/local/apache/b
in/apachectl -t),输出"Syntax OK"后就可以启动apache服务(/usr/local/apache/bin/apachectl start)。在别的机器的浏览器输入我们配置的这个服务器的url,正常的话,将得到类似下图的页面:

 

 

 

你可能感兴趣的:(linux,职场,postfix,休闲,搭建全过程详细说明)