Linux Mail基本服務器構建之postfix源碼安裝(上)

    postfixWietse VenemaIBMGPL協議之下開發的MTA(郵件傳輸代理)軟件。postfixWietse Venema想要爲使用最廣泛的sendmail提供替代品的一個嘗試。在nternet世界中,大部分的電子郵件都是通過sendmail來投遞的,大約有100萬用戶使用sendmail,每天投遞上億封郵件。這真是一個讓人吃驚的數字。Postfix試圖更快、更容易管理、更安全,同時還與sendmail保持足夠的兼容性。

一、預安裝環境

1.軟件包準備

Unix-Syslog-1.1.tar.gz

extmail-1.2.tar.gz

extman-1.1.tar.gz

postfix-2.8.2.tar.gz

courier-authlib-0.63.1.20111230.tar.bz2

將軟件包上傳到服務器,可以上傳到管理員家目錄(略)

2.系統環境

Linux 5.4 2.6.18-164.el5

想要實現源碼安裝,必須先要配置好編譯環境。使用yum grouplist |less進行查看。

Development Tools --開發工具

Legacy Software Development  -- 傳統軟件開發工具

Development Libraries –開發工具庫

    如果需要圖形。那麼以下安裝包是需要的。

    Kde環境需要安裝:

    Kde software development

    Gnome環境需要安裝:

    Gnome software development

    X software development

[root@server ~]# yum groupinstall "Development Libraries"

[root@server ~]# yum groupinstall "Development Tools"

 

3.修改相關文件

卸載sendmail

[root@phoenix ~]# rpm -e sendmail --nodeps

[root@phoenix ~]# vim /etc/resolv.conf  

修改網卡

[root@phoenix ~]# vim /etc/sysconfig/network 

修改主機名稱

[root@phoenix ~]# hostname mail.phoenix.com

[root@phoenix ~]# export hostname

[root@phoenix ~]# init 6

[root@mail ~]# hostname

mail.phoenix.com

4.安裝DNS

安裝DNS

[root@phoenix /]# yum install bind bind-chroot caching-nameserver -y

修改相關文件

[root@phoenix ~]# cd /var/named/chroot/etc/

[root@phoenix etc]# ll

total 16

-rw-r--r-- 1 root root   405 Feb  8 02:08 localtime

-rw-r----- 1 root named 1230 Jul 30  2009 named.caching-nameserver.conf

-rw-r----- 1 root named  955 Jul 30  2009 named.rfc1912.zones

-rw-r----- 1 root named  113 Feb  8 02:43 rndc.key

[root@phoenix etc]# cp -p named.caching-nameserver.conf named.conf

[root@phoenix etc]# vim named.conf

 

[root@phoenix etc]# vim named.rfc1912.zones 

 

[root@phoenix etc]# pwd

/var/named/chroot/etc

[root@phoenix etc]# cd ../var/named

[root@phoenix named]# pwd

/var/named/chroot/var/named

[root@phoenix named]# ll

total 36

drwxrwx--- 2 named named 4096 Aug 26  2004 data

-rw-r----- 1 root  named  198 Jul 30  2009 localdomain.zone

-rw-r----- 1 root  named  195 Jul 30  2009 localhost.zone

-rw-r----- 1 root  named  427 Jul 30  2009 named.broadcast

-rw-r----- 1 root  named 1892 Jul 30  2009 named.ca

-rw-r----- 1 root  named  424 Jul 30  2009 named.ip6.local

-rw-r----- 1 root  named  426 Jul 30  2009 named.local

-rw-r----- 1 root  named  427 Jul 30  2009 named.zero

drwxrwx--- 2 named named 4096 Jul 27  2004 slaves

[root@phoenix named]# cp -p localhost.zone phoenix.com.db

[root@phoenix named]# cp -p named.local 10.168.192.db

[root@phoenix named]# vim phoenix.com.db 

 

[root@phoenix named]# vim 10.168.192.db 

 

 

測試DNS是否正常啓動

[root@phoenix named]# rndc reload

server reload successful

[root@phoenix named]# service named restart

Stopping named:                                            [  OK  ]

Starting named:                                            [  OK  ]

[root@phoenix named]#

[root@mail ~]# chkconfig named on

[root@mail ~]# chkconfig --list |grep named

named           0:off  1:off  2:on   3:on   4:on   5:on   6:off

 

 

5.開啓mysql

開啓mysql

[root@mail ~]# service mysqld start

Starting MySQL:                                            [  OK  ]

[root@mail ~]# chkconfig mysqld on

[root@mail ~]# chkconfig --list |grep mysqld

mysqld             0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail ~]#

[root@mail ~]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.0.77 Source distribution

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

+--------------------+

3 rows in set (0.00 sec)

 

mysql> \q

Bye

[root@mail ~]#

但是這樣並不安全,需要修改密碼

[root@mail ~]# mysqladmin -u root -p password 'redhat'

Enter password:

[root@mail ~]#

可以發現直接登錄失敗

[root@mail ~]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@mail ~]#

添加遠程管理等

[root@mail ~]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 5.0.77 Source distribution

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> SET  PASSWORD FOR root@'localhost'=PASSWORD('redhat'); //授權本地用戶

Query OK, 0 rows affected (0.00 sec)

 

mysql> SET  PASSWORD FOR root@'127.0.0.1'=PASSWORD('redhat'); //授權本地用戶

Query OK, 0 rows affected (0.00 sec)

 

mysql> FLUSH PRIVILEGES; //讓設置的內容生效

Query OK, 0 rows affected (0.00 sec)

 

mysql> GRANT  ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'redhat'; //授權遠程用戶

Query OK, 0 rows affected (0.00 sec)

 

mysql> FLUSH PRIVILEGES; //讓設置的內容生效

Query OK, 0 rows affected (0.01 sec)

 

mysql> \q

Bye

[root@mail ~]# 

 

二、安裝postfix

1.創建有關用戶

[root@mail ~]# groupadd -g 2525 postfix

[root@mail ~]# useradd -g postfix -u 2525 -s /sbin/nologin -M postfix

[root@mail ~]# groupadd -g 2526 postdrop

[root@mail ~]# useradd -g postdrop -u 2526 -s /bin/false -M postdrop

[root@mail ~]#

2.拆包

[root@mail ~]# ll

total 6972

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -zxvf postfix-2.8.2.tar.gz -C /usr/src

3.配置

[root@mail ~]# cd /usr/src/postfix-2.8.2/

[root@mail postfix-2.8.2]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl  -DUSE_TLS ' 'AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2   -lssl -lcrypto'

4.編譯安裝

[root@mail postfix-2.8.2]# make

[root@mail postfix-2.8.2]# make install 

5.查看支持的模塊

[root@mail postfix-2.8.2]# postconf -m

btree

cidr

environ

hash

internal

mysql

nis

proxy

regexp

static

tcp

texthash

unix

[root@mail postfix-2.8.2]#

6.修改相關配置文件

[root@mail postfix-2.8.2]# cd /etc/postfix/

[root@mail postfix]# cp -p main.cf main.cf.bak //可以進行備份,防止將文件修改錯誤後無法進行恢復

[root@mail postfix]# vim main.cf

 

 

相關參數說明:

myorigin參數用來指明發件人所在的域名;

mydestination參數指定postfix接收郵件時收件人的域名,即您的postfix系統要接收到哪個域名的郵件;

myhostname 參數指定運行postfix郵件系統的主機的主機名,默認情況下,其值被設定爲本地機器名;

mydomain參數指定您的域名,默認情況下,postfixmyhostname的第一部分刪除而作爲mydomain的值;

mynetworks 參數指定你所在的網絡的網絡地址,postfix系統根據其值來區別用戶是遠程的還是本地的,如果是本地網絡用戶則允許其訪問;

inet_interfaces 參數指定postfix系統監聽的網絡接口;

注意:

1、在postfix的配置文件中,參數行和註釋行是不能處在同一行中的;

2任何一個參數的值都不需要加引號,否則,引號將會被當作參數值的一部分來使用;

3每修改參數及其值後執行 postfix reload 即可令其生效;但若修改了inet_interfaces,則需重新啓動postfix

4如果一個參數的值有多個,可以將它們放在不同的行中,只需要在其後的每個行前多置一個空格即可;postfix會把第一個字符爲空格或tab的文本行視爲上一行的延續;

 

7.爲了使用方便使用腳本

[root@mail postfix]# mkdir ~/abc

[root@mail postfix]# cd ~/abc

[root@mail abc]# cp /mnt/cdrom/Server/postfix-2.3.3-2.1.el5_2.i386.rpm ./ //從光盤複製到本地

[root@mail abc]# rpm2cpio postfix-2.3.3-2.1.el5_2.i386.rpm |cpio id //拆解文件

[root@mail abc]# cd etc/rc.d/init.d/

[root@mail init.d]# ll

total 4

-rwxr-xr-x 1 root root 2404 Feb  8 04:24 postfix

[root@mail init.d]# cp postfix /etc/init.d

[root@mail init.d]# ll /etc/init.d/postfix

-rwxr-xr-x 1 root root 2404 Feb  8 04:26 /etc/init.d/postfix

[root@mail init.d]# vim /etc/init.d/postfix //如果您需要修改本配置腳本,可以進行修改,但是建議保持爲默認

 

 重啓服務

[root@mail init.d]# service postfix start

Starting postfix:                                          [  OK  ]

[root@mail init.d]# chkconfig --add postfix

[root@mail init.d]# chkconfig postfix on

[root@mail init.d]# chkconfig --list |grep postfix

postfix            0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail init.d]# 

 

8.小問題

[root@mail ~]# ll /etc/aliases*

-rw-r--r-- 1 root root  1512 Apr 26  2005 /etc/aliases

-rw-r--r-- 1 root root 12288 Feb  8 04:27 /etc/aliases.db //如果您發現並沒有此文件,那麼您應該執行 newaliases ,手工進行創建該文件

9.測試

 

三、爲postfix開啓基於cyrus-sasl的認證功能

1.查看

[root@mail ~]# postconf -a

cyrus

dovecot

[root@mail ~]# 

 

2.修改相關文件

root@mail ~]# vim /etc/postfix/main.cf  

 

[root@mail ~]# cd /usr/lib/sasl2/

[root@mail sasl2]# vim smtpd.conf 

 

3.重啓服務

[root@mail ~]# service saslauthd start

Starting saslauthd:                                        [  OK  ]

[root@mail ~]# chkconfig saslauthd on

[root@mail ~]# chkconfig --list |grep saslauthd

saslauthd         0:off  1:off  2:on   3:on   4:on   5:on   6:off

[root@mail ~]# service postfix restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [  OK  ]

[root@mail ~]#

4.再次查看

[root@mail ~]# postfix reload  //postfix重新加載配置文件

查看

 

四、安裝Courier authentication library

1.拆包

[root@mail ~]# ll

total 6980

drwxr-xr-x 5 root root    4096 Feb  8 04:24 abc

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw------- 1 root root     488 Feb  8 04:31 mbox

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -jxvf courier-authlib-0.63.1.20111230.tar.bz2 -C /usr/src

 

2.配置

[root@mail ~]# cd /usr/src/courier-authlib-0.63.1.20111230/

[root@mail courier-authlib-0.63.1.20111230]# ./configure --prefix=/usr/local/courier-authlib --sysconfdir=/etc --with-authmysql --with-mysql-libs=/usr/lib/mysql --with-mysql-includes=/usr/include/mysql --with-redhat --with-authmysqlrc=/etc/authmysqlrc --with-authdaemonrc=/etc/authdaemonrc --with-ltdl-lib=/usr/lib --with-ltdl-include=/usr/include

 

3.編譯安裝

[root@mail courier-authlib-0.63.1.20111230]# make

[root@mail courier-authlib-0.63.1.20111230]# make install

 

4.修改有關文件

[root@mail courier-authlib-0.63.1.20111230]# cd ~

[root@mail ~]#

[root@mail ~]# chmod 755 /usr/local/courier-authlib/var/spool/authdaemon

[root@mail ~]# cp /etc/authdaemonrc.dist  /etc/authdaemonrc

[root@mail ~]# cp /etc/authmysqlrc.dist  /etc/authmysqlrc

[root@mail ~]#

[root@mail ~]# vim /etc/authdaemonrc

 

[root@mail ~]# vim /etc/authmysqlrc

 

[root@mail ~]# cp /usr/src/courier-authlib-0.63.1.20111230/courier-authlib.sysvinit /etc/init.d/courier-authlib

[root@mail ~]# chmod 755 /etc/init.d/courier-authlib

重啓服務

[root@mail ~]# chkconfig --add courier-authlib

[root@mail ~]# chkconfig --level 2345 courier-authlib on

 

[root@mail ~]# cd /usr/local/courier-authlib/lib

[root@mail lib]# ldconfig -v |grep courier

[root@mail lib]# echo "/usr/local/courier-authlib/lib/courier-authlib" >> /etc/ld.so.conf.d/courier-authlib.conf

[root@mail lib]#

[root@mail lib]# service courier-authlib start

Starting Courier authentication services: authdaemond

[root@mail lib]#

[root@mail lib]# ldconfig -v |grep courier

/usr/local/courier-authlib/lib/courier-authlib:

    libcourierauth.so -> libcourierauth.so.0

    libcourierauthcommon.so -> libcourierauthcommon.so.0

    libcourierauthsasl.so -> libcourierauthsasl.so.0

    libcourierauthsaslclient.so -> libcourierauthsaslclient.so.0

[root@mail lib]#

新建虛擬用戶郵箱所在的目錄,並將其權限賦予postfix用戶:

[root@mail ~]# mkdir -pv /var/mailbox

mkdir: created directory `/var/mailbox'

[root@mail ~]# chown -R postfix /var/mailbox/

接下來重新配置SMTP 認證,編輯 /usr/local/lib/sasl2/smtpd.conf ,確保其爲以下內容:

[root@mail ~]# vim /usr/lib/sasl2/smtpd.conf 

 

五、讓postfix支持虛擬域和虛擬用戶

1.編輯文件

[root@mail ~]# vim /etc/postfix/main.cf

 

 

2.拆包

使用extman源碼目錄下docs目錄中的extmail.sqlinit.sql建立數據庫:

[root@mail ~]# ll

total 6980

drwxr-xr-x 5 root root    4096 Feb  8 04:24 abc

-rw------- 1 root root    1291 Feb  8 02:05 anaconda-ks.cfg

-rw-r--r-- 1 root root 2268626 Feb  8 02:37 courier-authlib-0.63.1.20111230.tar.bz2

-rw-r--r-- 1 root root  541279 Feb  8 02:37 extmail-1.2.tar.gz

-rw-r--r-- 1 root root  586234 Feb  8 02:37 extman-1.1.tar.gz

-rw-r--r-- 1 root root   35236 Feb  8 02:04 install.log

-rw-r--r-- 1 root root    3995 Feb  8 02:02 install.log.syslog

-rw------- 1 root root     488 Feb  8 04:31 mbox

-rw-r--r-- 1 root root 3644570 Feb  8 02:37 postfix-2.8.2.tar.gz

-rw-r--r-- 1 root root   13738 Feb  8 02:37 Unix-Syslog-1.1.tar.gz

[root@mail ~]# tar -zxvf extman-1.1.tar.gz

[root@mail ~]# cd extman-1.1

[root@mail extman-1.1]# cd  docs/

[root@mail docs]# mysql -u root -p <extmail.sql

Enter password:

[root@mail docs]# mysql -u root -p <init.sql

Enter password:

[root@mail docs]#

 

[root@mail docs]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 19

Server version: 5.0.77 Source distribution

 

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| extmail            |

| mysql              |

| test               |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> \q

Bye

[root@mail docs]#

 

[root@mail docs]# cp mysql*  /etc/postfix/

 

[root@mail docs]# service  postfix  restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [  OK  ]

 3.授權

 

 

    聲明:未完,由於文章格式的問題,本篇被迫分爲上、下兩篇,如果您對本文章感興趣,您可以繼續瀏覽本篇文章下篇,給您造成的不便,筆者表示抱歉!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章