歡迎您光臨本站 註冊首頁
此文參考了網上各個博文,《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、創建郵件系統所需的用戶與組:

[[email protected] ~]# groupadd vmail

[[email protected] ~]# groupadd postfix

[[email protected] ~]# groupadd postdrop

[[email protected] ~]# groupadd amavis

[[email protected] ~]# groupadd clamav

[[email protected] ~]# groupmod -g 1001 vmail

[[email protected] ~]# useradd mysql -g mysql

[[email protected] ~]# usradd vmail -g vmail -u 1001

[[email protected] ~]# useradd postfix -g postfix

[[email protected] ~]# useradd amavis -g amavis

3、建立網路環境

[[email protected] ~]# hostname

mail1.mail.sery.com

[[email protected] ~]# cat /etc/resolv.conf
nameserver 192.168.20.205
search mail.sery.com

[[email protected] ~]# 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伺服器,這裡只把配置寫出來,建立過程不作詳細說明:

[[email protected] ~]# 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";
};

[[email protected] ~]# 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

[[email protected] ~]# 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

[[email protected] ~]# 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

[[email protected] ~]# 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

[[email protected] ~]# 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

[[email protected] ~]# 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.

[[email protected] ~]# 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

查看靜態模塊 [[email protected] ~]# /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 已經加入到模塊中了

查看動態模塊:

[[email protected] ~]# 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";

[[email protected] 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,正常的話,將得到類似下圖的頁面:

本文出自 「IT」 博客,請務必保留此出處http://benly.blog.51cto.com/460663/786434


[火星人 ] Linux Postfix 全面安裝指導手冊一之Postfix基本網路與LAMP環境配置已經有548次圍觀

http://coctec.com/docs/linux/show-post-47222.html