LINUX下邮件服务器
郵件服務(wù)器搭建
?
############分割線 編譯安裝Mysql,啟動(dòng)控制Mysql##########
1、卸載已安裝的mysql的RPM包
編譯安裝mysql前,首先查看系統(tǒng)中是否已安裝mysql服務(wù)器軟件:
[root@server01 /]# rpm -qa | grep mysql
[root@server01 /]# rpm -e mysql-server
[root@server01 /]# rpm -e mysql-connector-odbc
[root@server01 /]# rpm -e libdbi-dbd-mysql
[root@server01 /]# rpm -e mysql --nodeps
刪除RPM包創(chuàng)建的mysql賬號(hào)
[root@server01 /]# userdel -r mysql
2、釋放MySQL軟件包
為了避免發(fā)生沖突,建議先卸載掉系統(tǒng)自帶的mysql相關(guān)軟件包
[root@server01 tool]# tar -zxvf mysql-5.0.56.tar.gz
3、添加MySQL用戶(hù)和組,用于運(yùn)行和維護(hù)mysql服務(wù)
[root@server01 tool]# useradd -M -s /sbin/nologin mysql
?-M 選項(xiàng)表示不建立用戶(hù)宿主目錄、
?-s 選項(xiàng)表示指定用戶(hù)的shell
4、編譯前的預(yù)配置
[root@server01 mysql-5.0.56]# ./configure --prefix=/usr/local/mysql
5、編譯并安裝
[root@server01 mysql-5.0.56]# make && make install
6、建立mysql配置文件
在展開(kāi)的源碼包目錄中的support-files文件夾下,提供了多個(gè)MySQL服務(wù)器的配置樣例文件,分別適用于不同負(fù)載的數(shù)據(jù)庫(kù)服務(wù)器。一般選擇my-medium.cnf文件即可,該配置文件適用于中等負(fù)載的數(shù)據(jù)庫(kù),可以滿足大多數(shù)企業(yè)的應(yīng)用需求
[root@server01 mysql-5.0.56]# cp support-files/my-medium.cnf /etc/my.cnf
7、初始化mysql數(shù)據(jù)庫(kù)
以mysql用戶(hù)的身份執(zhí)行mysql_install_db腳本,對(duì)MySQL數(shù)據(jù)庫(kù)進(jìn)行初始化
[root@server01 mysql-5.0.56]# cd /usr/local/mysql/bin/
[root@server01 bin]# ./mysql_install_db --user=mysql
會(huì)在/usr/local/mysql下產(chǎn)生var目錄,并在var目錄下創(chuàng)建2個(gè)默認(rèn)數(shù)據(jù)庫(kù)mysql和test;
8、調(diào)整mysql目錄權(quán)限
修改相關(guān)目錄的所有權(quán),以便mysql用戶(hù)可以讀寫(xiě)數(shù)據(jù)庫(kù)
調(diào)整/usr/loca/mysql目錄的權(quán)限:
[root@server01 local]# ls -ld /usr/local/mysql/
[root@server01 local]# chown -R root.mysql /usr/local/mysql
[root@server01 local]# ls -ld /usr/local/mysql/
調(diào)整/usr/local/mysql/var目錄的權(quán)限:
[root@server01 local]# chown -R mysql /usr/local/mysql/var/
[root@server01 local]# ls -ld /usr/local/mysql/var
9、調(diào)整lib庫(kù)路徑
由于Mysql安裝到了非標(biāo)準(zhǔn)的路徑中。所以還需要將MySQL的庫(kù)文件路徑“/usr/local/mysql/lib/mysql”?加入到系統(tǒng)的庫(kù)文件搜索路徑中,以便在用到時(shí)能夠自動(dòng)搜索到。增加庫(kù)文件搜索路徑可以通過(guò)修改“/etc/ld.so.conf”文件實(shí)現(xiàn)
[root@server01 local]# vi /etc/ld.so.conf
添加路徑:
/usr/local/mysql/lib/mysql
[root@server01 local]# ldconfig
10、Mysql的啟動(dòng)控制
(1) 使用mysqld_safe腳本安全啟動(dòng)服務(wù)
[root@server01 local]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
(2) 設(shè)置MySQL程序的執(zhí)行路徑,主要是為了在執(zhí)行mysql管理工具時(shí)方便
方法一:修改配置文件/etc/profile,使配置永久生效
[root@server01 local]# vi /etc/profile
添加:
PATH=$PATH:/usr/local/mysql/bin
[root@server01 local]# source /etc/profile
方法二:執(zhí)行export命令,使配置僅當(dāng)前生效
[root@server01 local]#export PATH=$PATH:/usr/local/mysql/bin
(3) 將Mysql添加為系統(tǒng)服務(wù),主要是為了mysql服務(wù)啟動(dòng)的方便
[root@server01 local]# cd /tool/mysql-5.0.56
[root@server01 mysql-5.0.56]# cp support-files/mysql.server /etc/init.d/mysqld
[root@server01 mysql-5.0.56]# chmod +x /etc/init.d/mysqld
[root@server01 mysql-5.0.56]# chkconfig --add mysqld
[root@server01 mysql-5.0.56]# chkconfig mysqld on
這樣也就可以使用service mysqld start/restart/stop來(lái)對(duì)mysql服務(wù)進(jìn)行管理了!
#######分割線 停用/卸載sendmail服務(wù),以避免沖突###########
1、查看當(dāng)前系統(tǒng)是否安裝sendmail
[root@server01 /]# rpm -qa | grep sendmail
2、為了避免與要安裝的postfix沖突,可以停用sendmail或卸載
停用方法:
[root@server01 /]# service sendmail stop
[root@server01 /]# chkconfig --level 35 sendmail off
卸載方法:
[root@server01 /]# rpm -e sendmail-cf
[root@server01 /]# rpm -e sendmail --nodeps
3、查看系統(tǒng)是否安裝postfix的rpm包
[root@server01 /]# rpm -qa | grep postfix
確認(rèn)系統(tǒng)沒(méi)有安裝postfix服務(wù)器軟件包
############分割線 編譯安裝postfix及vda補(bǔ)丁包##########
1、創(chuàng)建運(yùn)行郵件系統(tǒng)的用戶(hù)賬號(hào)postfix及用戶(hù)組postfix和postdrop
[root@server01 /]# groupadd -g 1200 postdrop
[root@server01 /]# groupadd -g 1000 postfix
[root@server01 /]# useradd -M -u 1000 -g postfix -G postdrop -s /sbin/nologin postfix
2、解壓釋放postfix源碼包、合并VGA補(bǔ)丁
[root@server01 tools]# tar zxvf postfix-2.4.6.tar.gz
[root@server01 tools]# gunzip postfix-2.4.6-vda-ng.patch.gz
[root@server01 tools]# cd postfix-2.4.6
[root@server01 postfix-2.4.6]# patch -p1 < ../postfix-2.4.6-vda-ng.patch
3、產(chǎn)生postfix編譯前的makefiles配置文件
由于實(shí)驗(yàn)案例的需要,在這里不能使用rpm包安裝的postfix,因?yàn)閞pm安裝的postfix默認(rèn)不支持mysql。
說(shuō)明:在編譯前需要使用“make maekfiles”命令調(diào)整編譯參數(shù),以便Postfix支持SASL認(rèn)證和查詢(xún)MySQL數(shù)據(jù)庫(kù)。
[root@server01 postfix-2.4.6]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl' 'AUXLIBS=-L/usr/local/mysql/lib/mysql -lmysqlclient -lz -lm -L/usr/lib/sasl2 -lsasl2'
---------------------------------------------------------------------------------------------------
編譯參數(shù)CCARGS和AUXLIBS的作用如下:
CCARGS參數(shù):為編譯器提供額外的參數(shù)。“-I”選項(xiàng)指出標(biāo)準(zhǔn)的額外頭文件的存放目錄。
AUXLIBS參數(shù):指出位于標(biāo)準(zhǔn)位置之外的額外函數(shù)庫(kù)。如果需要鏈接SASL、MySQL或任何附加的函數(shù)庫(kù),而且他們不是存在標(biāo)準(zhǔn)位置(/usr/lib目錄),則必須在AUXLIBS參數(shù)中指出這些函數(shù)庫(kù)的路徑。
---------------------------------------------------------------------------------------------------
4、編譯和編譯安裝
[root@server01 postfix-2.4.6]# make && make install
安裝過(guò)程需要設(shè)置一些安裝參數(shù),接受默認(rèn)設(shè)置即可,直接持續(xù)回車(chē)完成安裝。
5、postfix安裝后的主要目錄和配置文件
----------------------------------------------------
配置文件目錄:/etc/postfix/
服務(wù)程序目錄:/usr/libexec/postfix/
郵件隊(duì)列目錄:/var/spool/postfix/*
郵件管理程序目錄:/usr/sbin/*
master主程序的配置文件:/etc/postfix/master.cf
postfix服務(wù)的配置文件:/etc/postfix/main.cf
記錄了postfix服務(wù)的郵件傳遞等過(guò)程信息:/var/log/maillog
-----------------------------------------------------
6、使用postconf工具簡(jiǎn)化postfix配置文件main.cf,只保留與默認(rèn)配置不同的參數(shù),提高易讀性和可編輯性
[root@server01 /]# cd /etc/postfix/
[root@server01 postfix]# postconf -n > main2.cf
[root@server01 postfix]# mv main.cf main.cf.bak
[root@server01 postfix]# mv main2.cf main.cf
7、啟動(dòng)postfix服務(wù)
[root@server01 postfix]# postfix start
查看服務(wù)啟動(dòng)后打開(kāi)的端口:
[root@server01 postfix]# netstat -antp | grep 25
###############分割線 配置DNS服務(wù)器,創(chuàng)建相應(yīng)的資源記錄###
1、在對(duì)應(yīng)的區(qū)域數(shù)據(jù)庫(kù)文件中增加MX記錄:
mail??? IN A??????????? 192.168.1.102
@?????? IN MX 10??????????????? mail.benet.com.
2、測(cè)試mx記錄
[root@server01 postfix]# nslookup
> set type=mx
> benet.com
Server:???????? 192.168.1.102
Address:??????? 192.168.1.102#53
benet.com?????? mail exchanger = 10 mail.benet.com.
###################分割線 構(gòu)建postfix電子郵件系統(tǒng)###########
1、配置postfix,調(diào)整運(yùn)行參數(shù)
[root@server01 postfix]# vi /etc/postfix/main.cf
增加如下參數(shù):
inet_interfaces=192.168.1.102,127.0.0.1
myhostname=mail.benet.com
mydomain=benet.com
myorigin=$mydomain
mydestination=$mydomain,$myhostname
home_mailbox=Maildir/
執(zhí)行命令產(chǎn)生別名數(shù)據(jù)庫(kù)文件aliases.db
[root@server01 ~]# newaliases
[root@server01 ~]# ls /etc/aliases.db
否則會(huì)導(dǎo)致smtpd程序啟動(dòng)失敗!
2、重新加載配置
[root@server01 postfix]# postfix reload
3、建立郵件用戶(hù),通過(guò)telnet方法發(fā)送電子郵件測(cè)試
[root@server01 postfix]# useradd -s /sbin/nologin mail01
[root@server01 postfix]# passwd mail01
[root@server01 postfix]# useradd -s /sbin/nologin mail02
[root@server01 postfix]# passwd mail02
[root@server01 /]# telnet 127.0.0.1 25
SMTP常用命令字:
HELO localhost?? 宣告客戶(hù)端主機(jī)地址
MAIL FROM:?????? 發(fā)件人地址
RCPT TO:???????? 收件人地址
DATA???????????? 郵件數(shù)據(jù)
QUIT???????????? 退出
################分割線 構(gòu)建dovecot服務(wù)器###########################
1、卸載當(dāng)前系統(tǒng)已安裝的dovecot的rpm包
[root@server01 tools]# rpm -e dovecot
2、編譯安裝dovecot服務(wù)器軟件包
[root@server01 tools]# useradd -M -s /sbin/nologin dovecot
[root@server01 tools]# tar zxvf dovecot-1.1.4.tar.gz
[root@server01 tools]# cd dovecot-1.1.4
[root@server01 dovecot-1.1.4]# ./configure --sysconfdir=/etc --with-mysql
[root@server01 dovecot-1.1.4]# make && make install
2、配置dovecot的運(yùn)行參數(shù)
從dovecot的模板配置文件生成簡(jiǎn)單配置文件
[root@server01 dovecot-1.1.4]# cp /etc/dovecot-example.conf /etc/dovecot.conf
[root@server01 dovecot-1.1.4]# vi /etc/dovecot.conf
修改以下配置參數(shù):(建議通過(guò)查找的方式配置以下各項(xiàng))
protocols = imap pop3
ssl_disable = yes
disable_plaintext_auth = no
mail_location = maildir:~/Maildir
3、創(chuàng)建dovecot的PAM認(rèn)證文件
[root@server01 dovecot-1.1.4]# vi /etc/pam.d/dovecot
auth??? required??????? pam_nologin.so
auth??? include???????? system-auth
account include???????? system-auth
session include???????? system-auth
4、啟動(dòng)dovecot服務(wù)
[root@server01 dovecot-1.1.4]# dovecot -c /etc/dovecot.conf
查看dovecot服務(wù)開(kāi)啟的端口:
[root@server01 dovecot-1.1.4]# netstat -antp | grep dovecot
5、pop3郵件測(cè)試
[root@server01 dovecot-1.1.4]# telnet localhost 110
6、在windows客戶(hù)端使用OE連接郵件系統(tǒng)發(fā)送電子郵件測(cè)試
############分割線 添加Webmail郵件界面###########################
準(zhǔn)備條件:
apache服務(wù)器已經(jīng)安裝并配置好,支持php!
這里的配置環(huán)境是apache編譯安裝的,安裝路徑為:/usr/local/apache
1、解壓squirremail軟件包
[root@server01 tools]# tar jxvf squirrelmail-1.4.13.tar.bz2
[root@server01 tools]# mv squirrelmail-1.4.13 /usr/local/apache2/htdocs/webmail
[root@server01 webmail]# cd /usr/local/apache2/htdocs/webmail/
把squirremail的中文補(bǔ)丁包解壓出來(lái)
[root@server01 webmail]# tar -jxvf /tools/zh_CN-1.4.13-20071220.tar.bz2
2、創(chuàng)建及調(diào)整數(shù)據(jù)目錄、附件目錄
[root@server01 webmail]# mkdir -p attach data
[root@server01 webmail]# chown -R daemon:daemon attach/ data/
[root@server01 webmail]# chmod 730 attach/
3、創(chuàng)建并修改squirremail的配置文件
[root@server01 webmail]# cp config/config_default.php config/config.php
[root@server01 webmail]# vim config/config.php
修改如下:(如果查找起來(lái)比較麻煩,可以查找)
$squirrelmail_default_language = 'zh_CN';
$domain = 'benet.com';
$smtpServerAddress = 'localhost';
$default_charset = 'zh_CN.UTF-8';
$imap_server_type = 'dovecot';
$data_dir = '/usr/local/apache2/htdocs/webmail/data';
$p_w_upload_dir = '/usr/local/apache2/htdocs/webmail/attach';
4、通過(guò)客戶(hù)端瀏覽器訪問(wèn)測(cè)試
http://mail.benet.com/webmail/
#################分割線 添加SMTP的用戶(hù)認(rèn)證 ###########################
1、查看系統(tǒng)是否已安裝cyrus sasl認(rèn)證組件
[root@server01 /]# rpm -qa | grep cyrus
在這里如果是rpm安裝的,也可以直接使用
2、設(shè)置cyrus sasl函數(shù)庫(kù)
[root@server01 /]# vi /usr/lib/sasl2/smtpd.conf
添加參數(shù):
pwcheck_method: saslauthd
3、啟動(dòng)saslauthd服務(wù)
[root@server01 /]# service saslauthd start
4、修改postfix主配置文件main.cf
添加sasl認(rèn)證相關(guān)的參數(shù):
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.1
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
5、測(cè)試SMTP發(fā)信認(rèn)證
在這里測(cè)試的方式最好是有2臺(tái)郵件系統(tǒng)的環(huán)境。
測(cè)試可以通過(guò)smtp命令字測(cè)試,也可以通過(guò)郵件客戶(hù)端軟件測(cè)試。
#################分割線 設(shè)置用戶(hù)別名與郵件群組###########################
1、修改postfix主配置文件,使用/etc/aliases文件作為數(shù)據(jù)查詢(xún)表
[root@server01 /]# vi /etc/postfix/main.cf
添加參數(shù):
alias_maps = hash:/etc/aliases
2、修改/etc/aliases配置文件
--配置別名
--配置郵件群發(fā)
--配置郵件轉(zhuǎn)發(fā)
3、生成查詢(xún)數(shù)據(jù)庫(kù)
[root@server01 /]# newaliases
4、使用客戶(hù)端訪問(wèn)測(cè)試
#################分割線 設(shè)置郵件大小、郵箱空間限制###########################
郵件大小限制:
message_size_limit
郵箱空間大小限制:
mailbox_size_limit
?針對(duì)Mailbox郵箱、系統(tǒng)用戶(hù),缺省值為50MB
virtual_mailbox_limit
?針對(duì)使用虛擬用戶(hù)的情況,缺省值為50MB
quota磁盤(pán)配額功能
?針對(duì)使用Linux系統(tǒng)用戶(hù)作為郵件賬號(hào)的情況
##############分割線 配置Postfix虛擬用戶(hù)支持###########################
1、下載并對(duì)extman郵件管理工具解包
[root@www mail]# tar zxvf extman-0.2.5.tar.gz
2、導(dǎo)入extman的SQL腳本文件
[root@www docs]# pwd
/tool/mail/extman-0.2.5/docs
[root@www docs]# mysql -u root -p < extmail.sql
[root@www docs]# mysql -u root -p < init.sql
3、修改postfix配置文件main.cf,添加支持虛擬用戶(hù)的參數(shù)
[root@www /]# vi /etc/postfix/main.cf
添加如下參數(shù):
#mydestination = $mydomain,$myhostname??????? //注釋掉此參數(shù)
virtual_mailbox_base = /mailbox
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_uid_maps = static:1000
virtual_gid_maps = static:1000
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_application_name = smtpd
4、建立虛擬用戶(hù)映射表文件
[root@www docs]# pwd
/tool/mail/extman-0.2.5/docs
把已存在的樣例模板文件復(fù)制到/etc/postfix目錄下:
[root@www docs]# cp mysql_virtual_* /etc/postfix/
5、為虛擬用戶(hù)設(shè)置SMTP發(fā)信認(rèn)證
需要安裝courier-authlib應(yīng)用程序才能提供對(duì)位于mysql數(shù)據(jù)庫(kù)中的郵件虛擬用戶(hù)的驗(yàn)證
[root@www mail]# tar jxvf courier-authlib-0.60.2.tar.bz2
[root@www mail]# cd courier-authlib-0.60.2
[root@www courier-authlib-0.60.2]# ./configure --prefix=/usr/local/courier-authlib --without-stdheaderdir --with-authmysql --with-redhat --with-mysql-libs=/usr/local/mysql/lib/mysql --with-mysql-include=/usr/local/mysql/include/mysql
[root@www courier-authlib-0.60.2]# make && make install
[root@www courier-authlib-0.60.2]# make install-configure
6、修改courier-authlib相關(guān)配置,并啟動(dòng)服務(wù)
[root@www /]# vi /etc/ld.so.conf
增加路徑:
/usr/local/courier-authlib/lib/courier-authlib
[root@www /]# ldconfig
7、修改authdaemonrc主配置文件,僅保留authmysql認(rèn)證方式,去掉其他方式
[root@www /]# cd /usr/local/courier-authlib/etc/authlib/
[root@www authlib]# cp authdaemonrc authdaemonrc.bak
[root@www authlib]# vim authdaemonrc
修改認(rèn)證模塊,如下:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
[root@www authlib]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
8、修改配置文件authmysqlrc,設(shè)置如何向mysql數(shù)據(jù)庫(kù)查詢(xún)信息
[root@www authlib]# cp authmysqlrc authmysqlrc.bak
[root@www authlib]# vim authmysqlrc
修改如下參數(shù)的值:
MYSQL_SERVER??????????? 127.0.0.1
MYSQL_USERNAME?? extmail
MYSQL_PASSWORD?? extmail
MYSQL_SOCKET?? /tmp/mysql.sock
MYSQL_DATABASE?? extmail
MYSQL_USER_TABLE?? mailbox
……
MYSQL_HOME_FIELD? concat('/mailbox/',homedir)
……
MYSQL_MAILDIR_FIELD? concat('/mailbox/',maildir)
[root@www authlib]# chown daemon.daemon authmysqlrc
9、復(fù)制courier-authlib腳本,并啟動(dòng)courier-authlib服務(wù)
[root@www courier-authlib-0.60.2]# cd /tool/mail/courier-authlib-0.60.2
[root@www courier-authlib-0.60.2]# cp courier-authlib.sysvinit /etc/init.d/courier-authlib
[root@www courier-authlib-0.60.2]# chmod 755 /etc/rc.d/init.d/courier-authlib
[root@www courier-authlib-0.60.2]# chkconfig --level 35 courier-authlib on
[root@www courier-authlib-0.60.2]# service courier-authlib start
10、修改cyrus sasl設(shè)置,更改認(rèn)證方式
[root@www /]# vi /usr/lib/sasl2/smtpd.conf
修改為:
pwcheck_method:authdaemond
authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
調(diào)整socked目錄的權(quán)限:
[root@www /]# chmod -R 755 /usr/local/courier-authlib/var/spool/authdaemon/
11、重新啟動(dòng)courier-authlib服務(wù)
[root@www /]# service courier-authlib restart
12、配置dovecot,調(diào)整郵件存儲(chǔ)位置及其他參數(shù)
[root@www /]# vim /etc/dovecot.conf
添加并修改參數(shù)如下:
mail_location = maildir:/mailbox/%d/%n/Maildir
auth default {
? mechanisms = plain
? passdb sql {
???? args = /etc/dovecot-mysql.conf
? }
? userdb sql {
???? args = /etc/dovecot-mysql.conf
? }
}
13、設(shè)置配置文件/etc/dovecot-mysql.conf
[root@www /]# cd /etc
[root@www etc]# touch dovecot-mysql.conf
[root@www etc]# vi dovecot-mysql.conf
添加并設(shè)置參數(shù)如下:
driver = mysql
connect = host=localhost dbname=extmail user=extmail password=extmail
default_pass_scheme = CRYPT
password_query = SELECT username AS user,password AS password FROM mailbox WH
ERE username = '%u'
user_query = SELECT maildir,uidnumber AS uid,gidnumber AS gid FROM mailbox WH
ERE username = '%u'
14、建立虛擬用戶(hù)的郵箱目錄
[root@www /]# mkdir -p /mailbox/extmail.org/postmaster/Maildir/
[root@www /]# cd /mailbox/extmail.org/postmaster/Maildir/
[root@www Maildir]# chown -R postfix:postfix /maibox/
[root@www Maildir]# killall dovecot
[root@www Maildir]# dovecot
15、測(cè)試對(duì)虛擬用戶(hù)的SMTP發(fā)信認(rèn)證
獲得虛擬“用戶(hù)postmaster@extmail.org密碼extmail”的加密的字符串
有2種方法可以獲取:
方法一:
[root@www authlib]# printf "postmaster@extmail.org" | openssl base64
[root@www authlib]# printf "extmail" | openssl base64
方法二:
[root@www authlib]# perl -e 'use MIME::Base64; print encode_base64("postmaster@extmail.org")'
[root@www authlib]# perl -e 'use MIME::Base64; print encode_base64("extmail")'
測(cè)試:
[root@www authlib]# telnet localhost 25
##############分割線 Extmail郵件使用及管理平臺(tái)Extman###########################
1、編譯安裝相關(guān)的perl依賴(lài)包
[root@www /]# rpm -qa | grep Unix
[root@www /]# rpm -qa | grep DBI
perl-DBI-1.52-2.el5
[root@www /]# rpm -qa | grep DBD
perl-DBD-MySQL-3.0007-2.el5
卸載RPM安裝的perl-DBD-MySQL
[root@www /]# rpm -e perl-DBD-MySQL
##安裝Unix-Syslog-1.1.tar.gz
[root@www mail]# tar zxvf Unix-Syslog-1.1.tar.gz
[root@www mail]# cd Unix-Syslog-1.1
[root@www Unix-Syslog-1.1]# perl Makefile.PL
[root@www Unix-Syslog-1.1]# make && make install
##安裝DBI-1.607.tar.gz
[root@www mail]# tar zxvf DBI-1.607.tar.gz
[root@www mail]# cd DBI-1.607
[root@www DBI-1.607]# perl Makefile.PL
[root@www DBI-1.607]# make && make install
##安裝DBD-mysql-4.011.tar.gz?
[root@www mail]# tar zxvf DBD-mysql-4.011.tar.gz
[root@www mail]# cd DBD-mysql-4.011
[root@www DBD-mysql-4.011]# perl Makefile.PL
[root@www DBD-mysql-4.011]# make && make install
2、編譯安裝apache,修改apache配置文件httpd.conf
##查看當(dāng)前系統(tǒng)是否存在rpm的http,如果存在則卸載
[root@www /]# rpm -qa | grep httpd
##釋放apache軟件包
[root@www tool]# tar zxvf httpd-2.2.9.tar.gz
##編譯前的預(yù)配置
[root@www tool]# cd httpd-2.2.9
[root@www httpd-2.2.9]# ./configure --prefix=/usr/local/apache --with-mysql=/usr/local/mysql --enable-so --enable-rewrite --enable-track-vars --enable-cgi --with-zlib --enable-mods-shared=all --enable-suexec --with-suexec-caller=daemon --with-suexec-docroot=/usr/local/apache/htdocs
##編譯并安裝
[root@www httpd-2.2.9]# make && make install
##查看apache是否安裝完成
[root@www httpd-2.2.9]# ls /usr/local/apache/
##配置apache,并啟動(dòng)httpd服務(wù)
修改httpd.conf配置文件:
Listen 192.168.100.2:80
ServerName 192.168.100.2:80
DirectoryIndex index.html index.cgi
去掉以下3個(gè)配置參數(shù)的注釋:
Include conf/extra/httpd-languages.conf
Include conf/extra/httpd-info.conf
Include conf/extra/httpd-vhosts.conf
配置httpd基于域名的虛擬主機(jī):
[root@www /]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
創(chuàng)建虛擬主機(jī):
NameVirtualHost 192.168.100.2
<VirtualHost 192.168.100.2:80>
??? DocumentRoot "/usr/local/apache/htdocs/"
??? ServerName www.jkw.net
</virtualhost>
<VirtualHost 192.168.100.2:80>
??? DocumentRoot "/usr/local/apache/htdocs/extmail/html/"
??? ServerName mail.jkw.net
??? scriptalias /extmail/cgi/ "/usr/local/apache/htdocs/extmail/cgi/"
??? alias /extmail /usr/local/apache/htdocs/extmail/html
??? suexecusergroup postfix postfix
</VirtualHost>
啟動(dòng)apache服務(wù)器:
[root@www /]# /usr/local/apache/bin/apachectl start
##設(shè)置apache服務(wù)開(kāi)機(jī)啟動(dòng)
[root@www /]# echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local
3、安裝并配置extmail套件
[root@www mail]# tar zxvf extmail-1.0.5.tar.gz -C /usr/local/apache/htdocs/
[root@www mail]# cd /usr/local/apache/htdocs/
[root@www htdocs]# mv extmail-1.0.5/ extmail
[root@www htdocs]# cd extmail/
[root@www extmail]# chown -R postfix:postfix cgi
4、建立webmail.cf配置文件
[root@www extmail]# cp webmail.cf.default webmail.cf
[root@www extmail]# vim webmail.cf
修改以下參數(shù)的值:
SYS_USER_LANG = zh_CN
SYS_USER_CHARSET = gb2312
SYS_CONFIG = /usr/local/apache/htdocs/extmail/
SYS_LANGDIR = /usr/local/apache/htdocs/extmail/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extmail/html
SYS_MAILDIR_BASE = /mailbox
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
SYS_AUTHLIB_SOCKET = /usr/local/courier-authlib/var/spool/authdaemon/socket
SYS_G_ABOOK_FILE_PATH = /usr/local/apache/htdocs/extmail/globabook.cf
5、訪問(wèn)測(cè)試
http://mail.jkw.net/extmail/cgi/
6、部署extman web管理界面
##安裝perl支持軟件包GD、file-tail及rrdtool繪圖引擎工具
[root@www mail]# tar zxvf GD-2.41.tar.gz
[root@www mail]# tar zxvf File-Tail-0.99.3.tar.gz
[root@www mail]# tar -zxvf gd-2.0.33.tar.gz
[root@www mail]# cd gd-2.0.33
[root@www gd-2.0.33]#? ./configure
[root@www gd-2.0.33]#? make && make install
[root@www mail]# cd ../GD-2.41
[root@www GD-2.41]# perl Makefile.PL
[root@www GD-2.41]# make && make install
[root@www GD-2.41]# cd ../File-Tail-0.99.3
[root@www File-Tail-0.99.3]# perl Makefile.PL
[root@www File-Tail-0.99.3]# make && make install
[root@www File-Tail-0.99.3]# cd ..
[root@www mail]# rpm -ivh rrdtool-1.2.23-3.el5.i386.rpm
[root@www mail]# rpm -ivh rrdtool-perl-1.2.23-3.el5.i386.rpm
7、安裝并配置extman套件
[root@www mail]# tar zxvf extman-0.2.5.tar.gz -C /usr/local/apache/htdocs/
[root@www mail]# cd /usr/local/apache/htdocs/
[root@www htdocs]# mv extman-0.2.5/ extman
[root@www htdocs]# cd extman/
[root@www extman]# chown -R postfix.postfix cgi
[root@www extman]# mkdir /tmp/extman
[root@www extman]# chown -R postfix.postfix /tmp/extman/
[root@www extman]# vi webman.cf
修改參數(shù)如下:
SYS_CONFIG = /usr/local/apache/htdocs/extman/
SYS_LANGDIR = /usr/local/apache/htdocs/extman/lang
SYS_TEMPLDIR = /usr/local/apache/htdocs/extman/html
SYS_MAILDIR_BASE = /mailbox
SYS_SESS_DIR = /tmp/extman/
SYS_MYSQL_USER = webman
SYS_MYSQL_PASS = webman
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = localhost
SYS_MYSQL_SOCKET = /tmp/mysql.sock
修改httpd.conf配置文件,添加extman的相關(guān)設(shè)置:
[root@www extman]# vi /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.100.2:80>
??? DocumentRoot "/usr/local/apache/htdocs/extmail/html/"
??? ServerName mail.jkw.net
??? scriptalias /extmail/cgi/ "/usr/local/apache/htdocs/extmail/cgi/"
??? alias /extmail /usr/local/apache/htdocs/extmail/html
??? scriptalias /extman/cgi/ "/usr/local/apache/htdocs/extman/cgi/"
??? alias /extman /usr/local/apache/htdocs/extman/html
??? suexecusergroup postfix postfix
</VirtualHost>
重新啟動(dòng)apache服務(wù):
[root@www extman]# /usr/local/apache/bin/apachectl restart
8、使用客戶(hù)端登陸extmail郵件系統(tǒng)
http://mail.jkw.net/extmail
可以使用:
用戶(hù)名:postmaster@extmail.org
密碼:extmail
域名:extmail.org
登陸收發(fā)電子郵件進(jìn)行測(cè)試!!!!
9、使用客戶(hù)端登陸extman管理界面
http://mail.jkw.net/extman/
可以使用:
用戶(hù)名:root@extmail.org
密碼:extmail*123*
登陸管理extman郵件系統(tǒng)。
10、查看郵件系統(tǒng)的圖形化日志信息
啟用 mailgraph_ext 圖形日志插件
[root@www html]# ln -sf /usr/local/apache/htdocs/extman/addon/mailgraph_ext/mailgraph-init /usr/sbin/
[root@www html]# ln -sf /usr/local/apache/htdocs/extman/addon/mailgraph_ext/qmonitor-init /usr/sbin/
[root@www html]# cd /usr/local/apache/htdocs/extman/addon/mailgraph_ext/
[root@www mailgraph_ext]# mkdir /usr/local/mailgraph_ext
[root@www mailgraph_ext]# cp mailgraph_ext.pl qmonitor.pl /usr/local/mailgraph_ext/
[root@www mailgraph_ext]# mailgraph-init start
[root@www mailgraph_ext]# qmonitor-init start
[root@www mailgraph_ext]# echo "/usr/sbin/mailgraph-init start" >> /etc/rc.d/rc.local
[root@www mailgraph_ext]# echo "/usr/sbin/qmonitor-init start" >> /etc/rc.d/rc.local
設(shè)置完成后就可以通過(guò)extman管理界面中的"圖形日志"鏈接查看郵件系統(tǒng)的圖形化日志信息。
說(shuō)明:如果這里日志無(wú)法查看,可以回頭檢查之前的組件安裝及上面的配置是否正確。
##########分割線 基于郵件地址的過(guò)濾###########################
通過(guò)配置postfix主配置文件/etc/main.cf可以實(shí)現(xiàn)郵件過(guò)濾的功能。
----------------------------------------------------------------
根據(jù)客戶(hù)端的主機(jī)名/地址過(guò)濾?? smtpd_client_restrictions
根據(jù)HELO主機(jī)名地址過(guò)濾??????? smtpd_helo_required
????????????????????????????? smtpd_helo_restrictions
根據(jù)發(fā)件人的地址過(guò)濾????????? smtpd_sender_login_maps
????????????????????????????? smtpd_sender_restrictions
根據(jù)收件人的地址過(guò)濾????????? smtpd_recipient_restrictions
----------------------------------------------------------------
應(yīng)用示例1:根據(jù)主機(jī)名/地址過(guò)濾
[root@mail ~]# vi /etc/postfix/access
……
192.168.100????? REJECT
192.168.100.1??? OK
jkw.net?????? REJECT
[root@localhost ~]# postmap? /etc/postfix/access
[root@mail ~]# vi /etc/postfix/main.cf
……
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access
示例測(cè)試需要的虛擬域、虛擬郵件用戶(hù)、客戶(hù)端需要自己創(chuàng)建,并測(cè)試過(guò)濾是否有效。
應(yīng)用示例2:根據(jù)HELO宣告的地址過(guò)濾
[root@mail ~]# vi /etc/postfix/main.cf
……
smtpd_helo_required = yes
smtpd_helo_restrictions =? reject_invalid_hostname
應(yīng)用示例3:根據(jù)發(fā)件人地址過(guò)濾
[root@mail ~]# vi /etc/postfix/main.cf
……
smtpd_sender_login_maps =
? mysql:/etc/postfix/mysql_virtual_sender_maps.cf,
? mysql:/etc/postfix/mysql_virtual_alias_maps.cf
smtpd_sender_restrictions =permit_mynetworks,reject_sender_login_mismatch, reject_non_fqdn_sender, reject_unknown_sender_domain,
? check_sender_access hash:/etc/postfix/sender_access
[root@mail ~]# vi /etc/postfix/sender_access
……
ads@xxxx.com??????????REJECT
marketing@???????????REJECT
fake.jkw.net?? ????????? REJECT
[root@mail ~]# postmap /etc/postfix/sender_access
應(yīng)用示例4:根據(jù)收件人地址過(guò)濾
[root@mail ~]# vi /etc/postfix/main.cf
……
smtpd_recipient_restrictions =
? permit_mynetworks,???????????????????? //允許本郵件系統(tǒng)發(fā)出的郵件
? permit_sasl_authenticated,???????????? //允許通過(guò)sasl認(rèn)證的用戶(hù)作為發(fā)件人
? reject_unauth_destination,???????????? //收件人地址域不包括在Postfix授權(quán)網(wǎng)絡(luò)內(nèi)時(shí)拒絕
? reject_non_fqdn_recipient,???????????? //收件人地址域不屬于合法FQDN時(shí)拒絕
? reject_unknown_recipient_domain??????? //收件人地址域未知或不存在時(shí)拒絕
###########分割線 郵件內(nèi)容過(guò)濾及防病毒###########################
1、安裝MailScanner調(diào)度工具
[root@www mail]# tar zxvf MailScanner-4.75.11-1.rpm.tar.gz
[root@www mail]# cd MailScanner-4.75.11-1
[root@www MailScanner-4.75.11-1]# ./install.sh
說(shuō)明:
mailscanner的安裝會(huì)提示需要安裝多個(gè)perl軟件包,可以掛載光盤(pán)查找安裝即可!
需要大概25分鐘時(shí)間,較長(zhǎng),需要耐心!
2、修改配置文件/etc/MailScanner/MailScanner.conf
[root@mail ~]# vi /etc/MailScanner/MailScanner.conf??????????
……
Run As User = postfix?????????????????????????
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Required SpamAssassin Score = 7
High SpamAssassin Score = 10
Spam Actions = deliver header "X-Spam-Status: Yes"
High Scoring Spam Actions = delete forward spam@extmail.org
3、配置postfix支持調(diào)用MailScanner
[root@mail ~]# vi /etc/postfix/main.cf
……
header_checks = regexp:/etc/postfix/header_checks
4、調(diào)整過(guò)濾隊(duì)列目錄,啟動(dòng)MailScanner服務(wù)
[root@mail ~]# vi /etc/postfix/header_checks
/^Received:/? HOLD
[root@mail ~]# cd /var/spool/MailScanner/
[root@mail MailScanner]# chown -R postfix.postfix? incoming
[root@mail MailScanner]# chown -R postfix.postfix quarantine
[root@mail MailScanner]# service MailScanner start
5、安裝 SpamAssassin 過(guò)濾器
從RHEL5光盤(pán)中查找安裝即可,包括存在依賴(lài)關(guān)系的相關(guān)perl軟件包
啟動(dòng) spamassassin 服務(wù)
?service spamassassin start
6、安裝 F-Prot 病毒掃描工具
[root@www mail]# tar zxvf fp-Linux-i686-ws.tar.gz
[root@www mail]# cd f-prot/
[root@www f-prot]# ./install-f-prot.pl
7、按照書(shū)上給出的測(cè)試方法進(jìn)行郵件內(nèi)容過(guò)濾和防病毒機(jī)制的測(cè)試!
?
?
轉(zhuǎn)載于:https://blog.51cto.com/576642026/458471
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專(zhuān)家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的LINUX下邮件服务器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ACR2010_MTX单药治疗临床疗效良
- 下一篇: 几个常用的Linux监控脚本