歡迎您光臨本站 註冊首頁

Debian 上用iRedMail和Pure-FTPd的虛擬郵件/FTP主機

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
  

iRedMail是一個能讓你在兩分鐘之內快速部署一個全功能郵件解決方案的shell腳本。從0.5版本開始,它已經支持CentOS 5.xDebian 5.xUbuntu 8.04Ubuntu 9.04(包括i386x86_64)。iRedMail支持OpenLDAPMySQL作為存儲虛擬域和用戶的後端。

 

iRedMailOpenLDAP後端允許你集成各種各樣的應用。本指南告訴你在Debian Lenny上怎樣將pure-ftpd集成到iRedMailldap後端。密碼將存儲在ldap中並且你可以通過webmail來改變它們。

 

本教程基於Debian 5.01,因此我建議大家安裝一個最小化的Debian 5.01,在其上安裝iredmail 0.51並選擇OpenLDAP作為其後端。在繼續本教程之前,你可以參看下述教程:

  • iRedMail: Mail Server With LDAP, Postfix, RoundCube/SquirrelMail, Dovecot, ClamAV, SpamAssassin, Amavisd (Debian 5.0.1)
  • iRedMail: Build A Full-Featured Mail Server With LDAP, Postfix, RoundCube, Dovecot, ClamAV,SpamAssassin, DKIM, SPF On CentOS 5.x

 

1 安裝Pure-FTPd

安裝Pure-FTPd:

 

apt-get install pure-ftpd-ldap

 

2 PureFTPd配置成一個獨立運行的伺服器

現在你必須將PureFTPd配置成一個獨立運行的守護進程(原本由inetd控制)。為了達到這個目的,我們打開/etc/default/pure-ftpd-common並且將參數STANDALONE_OR_INETD的值修改成standalone

vi /etc/default/pure-ftpd-common

#STANDALONE_OR_INETD=inetd
STANDALONE_OR_INETD=standalone #修改成standalone

然後我們修改/etc/inetd.conf並且將ftp行註釋掉:

 

#ftp    stream  tcp     nowait  root    /usr/sbin/tcpd /usr/sbin/pure-ftpd-wrapper

再然後我們重啟inetdPureFTPd

 

/etc/init.d/openbsd-inetd restart
/etc/init.d/pure-ftpd-ldap restart

 

3  /etc/pure-ftpd/conf/中的基本設置

創建只包括一個簡單的yes字元串的/etc/pure-ftpd/conf/ChrootEveryone文件

echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone

這個設置使得PureFTPd的每個虛擬用戶chroot到自己的主目錄,因此他將無法瀏覽主目錄以外的目錄和文件。


另外再創建一個/etc/pure-ftpd/conf/CreateHomeDir文件,也只是簡單包含一個叫yes的字元串:

echo "yes" > /etc/pure-ftpd/conf/CreateHomeDir

這將使得用戶登錄並且主目錄尚不存在時,PureFTPd自動創建該用戶的主目錄。

最後,創建/etc/pure-ftpd/conf/DontResolve,依舊只包含一個yes

echo "yes" > /etc/pure-ftpd/conf/DontResolve

這將使得PureFTPd不在查找主機名稱,可以顯著提高連接速度以及降低帶寬消耗。

 

 

4 查找 cn=vmail密碼

Vmail密碼是安裝iredmail時隨機創建的。你可以在etc/postfix/ldap_virtual_mailbox_domains.cf中找到它:

cat /etc/postfix/ldap_virtual_mailbox_domains.cf

bind_dn         = cn=vmail,dc=example,dc=com
bind_pw = kZ6uB29mViWKWI9lOH3cGnF7z3Dw3B #cn=vmail 密碼

 

5 配置LDAP設定

vi /etc/pure-ftpd/db/ldap.conf

LDAPServer localhost
LDAPPort 389
LDAPBaseDN o=domains,dc=example,dc=com
LDAPBindDN cn=vmail,dc=example,dc=com
LDAPBindPW kZ6uB29mViWKWI9lOH3cGnF7z3Dw3B #cn=vmail 密碼
LDAPDefaultUID 1000 # <- UID of 'vmail' user.
LDAPDefaultGID 1000 # <- GID of 'vmail' user.
LDAPFilter (&(objectClass=PureFTPdUser)(mail=\L)(FTPStatus=enabled))
LDAPHomeDir FTPHomeDir # <- This is new attribute, we will add it
LDAPVersion 3

 

6 獲取模板

有兩種辦法來得到pureftpd模板,你只需要選擇其中一種。

  • 下載iredmail修改過的模板。
  • 獲取pure-ftpd自帶的模板並且修改之。

6.1 下載iredmail修改過的模板:

wget http://iredmail.googlecode.com/svn/trunk/extra/pureftpd.schema -P /etc/ldap/schema/

6.2 獲取pure-ftpd-1.0.24自帶的模板:

cd /tmp/
wget http://download.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.bz2
tar xjf pure-ftpd-1.0.24.tar.bz2
cp pure-ftpd-1.0.24/pureftpd.schema /etc/ldap/schema/

修改/etc/ldap/schema/pureftpd.schema:

我們需要在objectclass定義之前增加一個或多個FTPHomeDir屬性,用來存儲用戶的FTP目錄。

vi /etc/ldap/schema/pureftpd.schema

attributetype ( 1.3.6.1.4.1.6981.11.3.9 NAME 'FTPgid'
DESC 'System uid (overrides gidNumber if present)'
EQUALITY integerMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 SINGLE-VALUE )
# 增加新屬性FTPHomeDir.
attributetype ( 1.3.6.1.4.1.6981.11.3.10 NAME 'FTPHomeDir'
DESC 'FTP directory'
EQUALITY caseIgnoreIA5Match
SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE )
## New Pure-FTPd object type

objectclass ( 1.3.6.1.4.1.6981.11.2.3 NAME 'PureFTPdUser'
DESC 'PureFTPd user with optional quota, throttling and ratio'
SUP top AUXILIARY
MAY ( FTPStatus $ FTPQuotaFiles $ FTPQuotaMBytes $ FTPUploadRatio $
FTPDownloadRatio $ FTPUploadBandwidth $ FTPDownloadBandwidth $
FTPuid $ FTPgid $ FTPHomeDir ) ) # <-- Add $ FTPHomeDir

 

7 修改/etc/ldap/slapd.conf

vi /etc/ldap/slapd.conf

iredmail.schema之後包含pureftpd.schema

 

include /etc/ldap/schema/iredmail.schema
include /etc/ldap/schema/pureftpd.schema # <-- 增加這一行.

pureftpd.schema中定義的屬性增加索引:

 

# Default index.
#
index objectClass eq,pres
index ou,cn,mail,surname,givenname,telephoneNumber eq,pres,sub
index uidNumber,gidNumber,loginShell eq,pres
index uid,memberUid eq,pres,sub
index nisMapName,nisMapEntry eq,pres,sub
# <-- 增加以下內容
#Index for FTP attrs.
index FTPQuotaFiles,FTPQuotaMBytes eq,pres
index FTPUploadRatio,FTPDownloadRatio eq,pres
index FTPUploadBandwidth,FTPDownloadBandwidth eq,pres
index FTPStatus,FTPuid,FTPgid,FTPHomeDir eq,pres

 

8 創建FTP主目錄

所有FTP數據都保存在/home/ftp/目錄。創建/home/ftp/,所有者必須是root用戶。

 

mkdir /home/ftp/
ls -dl /home/ftp

drwxr-xr-x 2 root root 4096 Oct 3 16:53 /home/ftp

 

9 重啟OpenLDAP服務讓pureftpd.schema工作:

/etc/init.d/slapd restart
/etc/init.d/pure-ftpd-ldap restart

確保pure-ftpd處於運行態:

 

# netstat -ntlp | grep pure-ftpd

tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 12548/pure-ftpd (SE
tcp6 0 0 :::21 :::* LISTEN 12548/pure-ftpd (SE

 

10 增加LDAP屬性及取值

10.1 為已有的郵件用戶增加LDAP屬性及取值

phpLDAPadmin或者其他工具來增加已有郵件用戶的LDAP示例屬性以及對應的取值。

 

屬性名
取值
objectClass PureFTPdUser
FTPStatus enabled
FTPQuotaFiles 50
FTPQuotaMBytes 10
FTPDownloadBandwidth 50
FTPUploadBandwidth 50
FTPDownloadRatio 5
FTPUploadRatio 1
FTPHomeDir /home/ftp/example.com/username/

登陸phpLDAPadmin

 

查找已有的郵件用戶www@example.com:

 

www@example.com增加對象類:

 

選擇PureFTPdUser這個對象類:

 

結果如下:

 

增加PureFTPdUser屬性:

 

所有關於PureFTPdUser的屬性:

 

開啟FTP狀態:

 

根據下表增加所有的PureFTP屬性:

 

 

10.2 為新用戶增加LDAP屬性和取值

你可以使用iredmail工具快速創建包含PureFTP屬性和取值的新用戶

 

cd iRedMail-0.5.1/tools
vi create_mail_user_OpenLDAP.sh

LDAP_SUFFIX="dc=example,dc=com" # <- Change the LDAP suffix
BINDPW='passwd' # <- The user cn=manager,dc=example,dc=com password
PUREFTPD_INTEGRATION='YES' # <- Change form NO to YES,enable the pureftp inteegration

運行該腳本來創建user1user2用戶。默認密碼和用戶名相同。

 

bash create_mail_user_OpenLDAP.sh example.com user1 user2

adding new entry "ou=Users,domainName=example.com,o=domains,dc=example,dc=com"
ldapadd: Already exists (68)

adding new entry "ou=Groups,domainName=example.com,o=domains,dc=example,dc=com"
ldapadd: Already exists (68)

adding new entry "ou=Aliases,domainName=example.com,o=domains,dc=example,dc=com"
ldapadd: Already exists (68)

adding new entry "mail=user1@example.com,ou=Users,domainName=example.com,o=domains,dc=example,dc=com"

adding new entry "mail=user2@example.com,ou=Users,domainName=example.com,o=domains,dc=example,dc=com"


11 配置iptables

默認情況下2021埠沒有打開。如果你用ftp客戶端進行測試則需要打開它們。

 

vi /etc/default/iptables

# http/https, smtp/smtps, pop3/pop3s, imap/imaps, ssh
-A INPUT -p tcp -m multiport --dport 80,443,25,465,110,995,143,993,587,465,22,20,21 -j ACCEPT # <-- 增加 20 21

重啟iptables服務:

 

/etc/init.d/iptables restart

 

12 測試

你可以使用WindowsFTP客戶端或者Linuxftp客戶端lftp來測試。

 

lftp localhost
lftp localhost:~> debug 4
lftp localhost:~> login user1@example.com user1 # <-- 輸入用戶名和密碼
lftp user1@example.com@localhost:~> ls

---- Connecting to localhost (127.0.0.1) port 21
<--- 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
<--- 220-You are user number 1 of 50 allowed.
<--- 220-Local time is now 16:25. Server port: 21.
<--- 220-IPv6 connections are also welcome on this server.
<--- 220 You will be disconnected after 15 minutes of inactivity.
<--- 211-Extensions supported:
<--- EPRT
<--- IDLE
<--- MDTM
<--- SIZE
<--- REST STREAM
<--- MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
<--- MLSD
<--- ESTP
<--- PASV
<--- EPSV
<--- SPSV
<--- ESTA
<--- AUTH TLS
<--- PBSZ
<--- PROT
<--- UTF8
<--- 211 End.
<--- 500 This security scheme is not implemented
<--- 200 OK, UTF-8 enabled
<--- 200 MLST OPTS type;size;sizd;modify;UNIX.mode;UNIX.uid;UNIX.gid;unique;
<--- 331 User user1@example.com OK. Password required
<--- 230-Your bandwidth usage is restricted
<--- 230-User user1@example.com has group access to: vmail
<--- 230-You must respect a 1:5 (UL/DL) ratio
<--- 230-OK. Current restricted directory is /
<--- 230-0 files used (0%) - authorized: 50 files
<--- 230 0 Kbytes used (0%) - authorized: 10240 Kb
<--- 257 "/" is your current location
<--- 227 Entering Passive Mode (127,0,0,1,32,58)
<--- 150 Accepted data connection
<--- 226-Options: -l
<--- 226 0 matches total

 

13 故障處理

pure-ftpd中啟用詳細信息登陸:

 

echo "yes" > /etc/pure-ftpd/conf/VerboseLog

vi /etc/rsyslog.conf

ftp.*                       -/var/log/pure-ftpd/pureftpd.log # <-- 增加條目

創建pureftpd.log文件:

 

touch /var/log/pure-ftpd/pureftpd.log

啟用ldap日誌:

vi /etc/ldap/slapd.conf

loglevel    256 # <-- 將0改成256  

重啟pure-ftpdsyslogopenldap

 

/etc/init.d/pure-ftpd-ldap restart
/etc/init.d/rsyslog restart
/etc/init.d/slapd restart

監控/var/log/pureftpd.log/var/log/openldap.log用於故障處理:

 

tail -0f /var/log/openldap.log

mail:~# tail -0f /var/log/openldap.log
Nov 11 17:42:09 mail slapd[16124]: warning: /etc/hosts.deny, line 0: missing newline or line too long
Nov 11 17:42:09 mail slapd[16124]: conn=5 fd=14 ACCEPT from IP=127.0.0.1:46247 (IP=0.0.0.0:389)
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=0 BIND dn="cn=vmail,dc=example,dc=com" method=128
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=0 BIND dn="cn=vmail,dc=example,dc=com" mech=SIMPLE ssf=0
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=0 RESULT tag=97 err=0 text=
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=1 SRCH base="o=domains,dc=example,dc=com" scope=2
deref=0 filter="(&(objectClass=PureFTPdUser)(mail=user1@example.com)(FTPStatus=enabled))"
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=1 SRCH attr=FTPHomeDir uidNumber
FTPuid gidNumber FTPgid userPassword loginShell FTPStatus FTPQuotaFiles
FTPQuotaMBytes FTPDownloadRatio FTPUploadRatio FTPDownloadBandwidth FTPUploadBandwidth
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=1 SEARCH RESULT tag=101 err=0 nentries=1 text=
Nov 11 17:42:09 mail slapd[16124]: conn=5 op=2 UNBIND
Nov 11 17:42:09 mail slapd[16124]: conn=5 fd=14 closed

tail -0f /var/log/pure-ftpd/pureftpd.log

mail:~# tail -0f /var/log/pure-ftpd/pureftpd.log
Nov 11 17:39:37 mail pure-ftpd: (?@123.114.254.226) [INFO] New connection from 123.114.254.226
Nov 11 17:39:37 mail pure-ftpd: (?@123.114.254.226) [DEBUG] Command [user] [user1@example.com]
Nov 11 17:39:38 mail pure-ftpd: (?@123.114.254.226) [DEBUG] Command [pass] [<*>]
Nov 11 17:39:38 mail pure-ftpd: (?@123.114.254.226) [INFO] user1@example.com is now logged in
Nov 11 17:39:38 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [syst] []
Nov 11 17:39:39 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [feat] []
Nov 11 17:39:39 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [pwd] []
Nov 11 17:39:39 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [type] [A]
Nov 11 17:39:40 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [port] [123,114,254,226,17,57]
Nov 11 17:39:40 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [list] [-a]
Nov 11 17:39:48 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [type] [I]
Nov 11 17:39:49 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [port] [123,114,254,226,17,60]
Nov 11 17:39:49 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [stor] [test.pdf]
Nov 11 17:39:51 mail pure-ftpd: (user1@example.com@123.114.254.226) [NOTICE]
/home/ftp/example.com/u/us/use/user1-2009.11.11.17.22.26/ftp//chenshake.pdf uploaded (14317 bytes, 9.45KB/sec)
Nov 11 17:39:51 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [type] [A]
Nov 11 17:39:52 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [port] [123,114,254,226,17,61]
Nov 11 17:39:53 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [list] [-a]
Nov 11 17:40:24 mail pure-ftpd: (user1@example.com@123.114.254.226) [DEBUG] Command [pwd] []
Nov 11 17:40:34 mail pure-ftpd: (user1@example.com@123.114.254.226) [INFO] Logout.

 

14 相關鏈接

  • 討論論壇: http://www.iredmail.org/forum/
  • 項目主頁: http://code.google.com/p/iredmail/
  • /etc/pure-ftpd/db/ldap.conf 示例文件: click here


[火星人 ] Debian 上用iRedMail和Pure-FTPd的虛擬郵件/FTP主機已經有876次圍觀

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