RHEL5+postfix+mysql+extmai(原始碼)(一)

技術小甜發表於2017-11-16

RHEL5+postfix+mysql+extmai(原始碼)

配置一個postfix郵件系統,遠比我先前的想象複雜。這次共配置2個postfix系統,花了不少精力,其間也經歷不少麻煩,還好,最後都做成了!在配置過程中,參考了《postfix權威指南》和網上其他人寫的文章,但在實際的配置中,完全按照這些文件還是不易順利完成。現在此行文披露我做這個事情的全部過程,(在這還要多感謝老朱同志幫助經過我們半個月的努力才搞定的)希望對大家的工作有所幫助。還希望大家多多提寶貴意見!!
 *執行環境RHEL5
  本機IP為:172.16.17.86/16 自己為DNS伺服器 郵件伺服器為本機名稱為:mail.test.com

一、(1)配置rhel5yum服務以方便安裝常用軟體

#service iptables stop

#chkconfig iptables off

#mkdir /media/cdrom

#mount /dev/cdrom /media/cdrom

#vim /etc/yum.repos.d/rhel-debuginfo.repo

修改為以下內容:

[rhel-debuginfo]

name=Red Hat Enterprise Linux $releasever – $basearch – Debug

baseurl=file:///media/cdrom/Server

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

2)安裝開發工具

       #yum install gcc*

二、      安裝配置dnsbind)伺服器

#yum install bind caching-nameserver bind-chroot

#cp -a /etc/named.caching-nameserver.conf /etc/named.conf

# vim /etc/named.conf

直接分別執行下面兩個末行模式命令:

:%s/127.0.0.1/any/g

:%s/localhost/any/g

儲存退出

# vim /etc/named.rfc1912.zones

檔案末尾加入以下內容:

 

zone “test.com” IN {

        type master;

        file “test.com.zone”;

};

 

zone “16.172.in-addr.arpa” IN {

        type master;

        file “16.172”;

};

儲存退出

# cp -a /var/named/chroot/var/named/localhost.zone /var/named/chroot/var/named/test.com.zone

#vim /var/named/chroot/var/named/test.com.zone

刪除最下面兩行寫入下面兩行:

@                   IN MX 5        mail.test.com.

mail                IN A                     172.16.17.86

儲存退出

#cp -a /var/named/chroot/var/named/named.local /var/named/chroot/var/named/16.172

#vim /var/named/chroot/var/named/16.172

刪除最下面一行,寫入下面內容:

86.17   IN      PTR     mail.test.com.

儲存退出

#service named restart

#chkconfig named on

#echo `nameserver 172.16.17.86` > /etc/resolv.conf

驗證解析

# nslookup

> 172.16.17.86

Server:         172.16.17.86

Address:        172.16.17.86#53

86.17.16.172.in-addr.arpa       name = mail.test.com.

> mail.test.com

Server:         172.16.17.86

Address:        172.16.17.86#53

Name:   mail.test.com

Address: 172.16.17.86

> set type=mx

> test.com

Server:         172.16.17.86

Address:        172.16.17.86#53

 

test.com        mail exchanger = 5 mail.test.com.

>exit

三、

四、安裝mysql伺服器(用資料庫儲存使用者資訊

        http://downloads.mysql.com

#groupadd mysql

#useradd –g mysql –s /bin/false –M mysql

#tar -zxvf mysql-5.0.22.tar.gz -C /usr/local/src/

#cd /usr/local/src/mysql-5.0.22/

#yum install ncurses-devel

#./configure –prefix=/usr/local/mysql –enable-thread-safe-client –enable-local-infile –with-charset=gbk –with-extra-charset=all –with-low-memory

#make

#make install

#cp /usr/local/src/mysql-5.0.22/support-files/my-medium.cnf /etc/my.cnf

#cd /usr/local/mysql
#chown -R mysql:mysql .
#bin/mysql_install_db –user=mysql
#chown -R root .
#chown -R mysql var
#bin/mysqld_safe –user=mysql &

#cd /usr/local/src/mysql-5.0.22/

#cp support-files/mysql.server /etc/rc.d/init.d/mysqld

#chmod 700 /etc/rc.d/init.d/mysqld

#chkconfig –add mysqld

#chkconfig mysqld on

#/usr/local/mysql/bin/mysqladmin ping

mysqld is alive

/usr/local/mysql/bin/mysqladmin version

/usr/local/mysql/bin/mysqladmin  Ver 8.41 Distrib 5.0.22, for pc-linux-gnu on i686

Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL license

Server version          5.0.22-log

Protocol version        10

Connection              Localhost via UNIX socket

UNIX socket             /tmp/mysql.sock

Uptime:                 4 min 7 sec

 

Threads: 1  Questions: 2  Slow queries: 0  Opens: 0  Flush tables: 1  Open tables: 6  Queries per second avg: 0.008

#/usr/local/mysql/bin/mysql –u root -p[f1] 
mysql> grant all privileges on *.* to root@”%” identified by `password[f2] ` with grant option;[f3] 

mysql>quit

配置庫檔案搜尋路徑

# echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf
# ldconfig -v
新增/usr/local/mysql/bin到環境變數PATH
#export PATH=$PATH:/usr/local/mysql/bin
#ln -sv /usr/local/mysql/bin/* /usr/bin/
#service mysqld restart


 [f1]使用root使用者連線mysql資料庫預設密碼為空

 [f2]本地root密碼

 [f3]root使用者通過3066埠連到資料庫讓root使用者通過3066埠連到資料庫

五、安裝openssl基於密碼學的安全開發包

www.openssl.org

#tar -zxvf openssl-0.9.8h.tar.tar -C /usr/local/src/

#cd /usr/local/src/openssl-0.9.8h/

#yum install zlib-devel

#./config shared zlib

#make

#make test

#make install

#mv /usr/bin/openssl /usr/bin/openssl.OFF

# ln -sv /usr/local/ssl/bin/openssl /usr/bin/openssl
# ln -sv /usr/local/ssl/include/openssl /usr/include/openssl
# ln -sv /usr/local/ssl/lib/libssl.so.0.9.8 /usr/lib/libssl.so

# echo “/usr/local/ssl/lib” >> /etc/ld.so.conf
# ldconfig
# ldconfig -v
檢測安裝結果
# openssl version

openSSL 0.9.8h 28 May 2008


六、安裝ssl(安全套接層協議)

     http://www.oracle.com/database/berkeley-db.html

#tar -zxvf cyrus-sasl-2.1.22.tar.tar -C /usr/local/src/

#cd /usr/local/src/cyrus-sasl-2.1.22/

#./configure –prefix=/usr/local/sasl2 –disable-gssapi –disable-anon –disable-sample –disable-digest –enable-plain –enable-login –enable-sql –with-mysql=/usr/local/mysql –with-mysql-includes=/usr/local/mysql/include/mysql –with-mysql-libs=/usr/local/mysql/lib/mysql –with-authdaemond=/usr/local/courier-authlib/var/spool/authdaemon/socket

#cp /usr/local/src/cyrus-sasl-2.1.22/mac/libdes/public/des.h ./

#make

#make install

# mv /usr/lib/libsasl2.so.2.0.22 /usr/lib/libsasl2.so.2.0.22.OFF
# mv /usr/lib/sasl2 /usr/lib/sasl2.OFF

#rm –rf /usr/lib/libsasl2.so.2

#rm -rf /usr/sbin/pluginviewer 
rm -rf /usr/sbin/saslauthd 
# rm -rf /usr/sbin/sasldblistusers2 
# rm -rf /usr/sbin/saslpasswd2 
# rm -rf /usr/sbin/testsaslauthd

# ln -sv /usr/local/sasl2/lib/* /usr/lib

# ln -sv /usr/local/sasl2/lib/* /usr/local/lib
# ln -sv /usr/local/sasl2/include/sasl/* /usr/local/include
# ln -sv /usr/local/sasl2/sbin/* /usr/sbin
# ln -sv /usr/local/sasl2/sbin/* /usr/local/sbin/

# mkdir -pv /var/state/saslauthd

啟動測試

# /usr/local/sbin/saslauthd -a shadow pam

# /usr/local/sbin/testsaslauthd -u root -p password[f1] 

0: OK “Success.”

配置庫檔案搜尋路徑

# echo “/usr/local/sasl2/lib” >> /etc/ld.so.conf
# echo “/usr/local/sasl2/lib/sasl2” >> /etc/ld.so.conf
# ldconfig
# ldconfig -v

配置開機啟動

#echo “/usr/local/sbin/saslauthd -a shadow pam”>>/etc/rc.local


 [f1]本地root密碼


七、安裝db庫(嵌入式資料庫系統

http://www.oracle.com/technology/products/berkeley-db/db/index.html

#tar -zxvf db-4.7.25.tar.gz -C /usr/local/src/

#cd /usr/local/src/db-4.7.25/build_unix/

#../dist/configure –prefix=/usr/local/BerkeleyDB
#make
#make install

修改相應檔案指向

# ln -sv /usr/local/BerkeleyDB/include /usr/include/db4
# ln -sv /usr/local/BerkeleyDB/include/db.h /usr/include/db.h
# ln -sv /usr/local/BerkeleyDB/include/db_cxx.h /usr/include/db_cxx.h

配置庫檔案搜尋路徑

# echo “/usr/local/BerkeleyDB/lib” >> /etc/ld.so.conf
# ldconfig
# ldconfig -v

八、安裝httpdWeb方式管理郵件

      http://archive.apache.org/dist/httpd/binaries

#tar jxvf httpd-2.2.4.tar.bz2 -C /usr/local/src/

#cd /usr/local/src/httpd-2.2.4/

#./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-cgi –enable-so –enable-ssl –with-ssl=/usr/local/ssl –enable-track-vars –enable-rewrite –with-zlib –enable-mods-shared=most –enable-suexec –with-suexec-caller=daemon –with-suexec-docroot=/var/www/extsuite/
#make 

#make install
#echo “/usr/local/apache/bin/apachectl start” >> /etc/rc.local

九、安裝phpPhp 直譯器,與apache一起使用

        http://www.php.net

#tar jxvf php-5.2.5.tar.bz2 –C /usr/local/src

# mkdir -p /usr/local/php
# cd /usr/local/src/php-5.2.5
#./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-zlib
#make
#make install
#cp php.ini-dist /usr/local/php/lib/php.ini

#vim /etc/httpd/httpd.conf

修改以下內容(大約351行,新增後面兩行,針對php支援)

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

AddType application/x-httpd-php .php

AddType application/x-httpd-source .phps

209行,將index.html改為index.php

<IfModule dir_module>

     DirectoryIndex index.php

</IfModule>

147行,修改預設網站目錄)

DocumentRoot “/var/www”

174行,修改預設目錄)

<Directory “/var/www”>

#mkdir –p /var/www

#echo “<? phpinfo(); ?>” > /var/www/index.php

# /usr/local/apache/bin/apachectl restart

httpd: Syntax error on line 99 of /etc/httpd/httpd.conf: Cannot load /usr/local/apache/modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied[f1] 

#chcon -t texrel_shlib_t /usr/local/apache/modules/libphp5.so

客戶端直接使用瀏覽器輸入地址瀏覽即可(http://172.16.17.86

 


 [f1]selinux有關,需要下面命令修改庫檔案型別

 

 

 

本文轉自legendfu51CTO部落格,原文連結:http://blog.51cto.com/legendfu/1073368 ,如需轉載請自行聯絡原作者


相關文章