CentOS平臺下pureftpd搭建
一、系統: CentOS 5.3
二、軟件以及下載地址
pure-ftpd-1.0.24.tar.gz
ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz
三、說明:用來控制用戶的ftp上傳功能,僅允許ftp用戶在自己的目錄文件下操作其網站。前提:CentOS 5.3具有搭建好的LAMP環境。
四、搭建環境
1、編譯安裝pureftp 源代碼http://www.pureftpd.org/
[root@localhost src]$ wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz
--16:21:29-- ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.24.tar.gz
=> `pure-ftpd-1.0.24.tar.gz.1'
正在解析主機 ftp.pureftpd.org... 91.121.49.42
Connecting to ftp.pureftpd.org|91.121.49.42|:21... 已連接。
正在以 anonymous 登錄 ... 登錄成功!
==> SYST ... 完成。 ==> PWD ... 完成。
==> TYPE I ... 完成。 ==> CWD /pub/pure-ftpd/releases ... 完成。
==> SIZE pure-ftpd-1.0.24.tar.gz ... 560565
==> PASV ... 完成。 ==> RETR pure-ftpd-1.0.24.tar.gz ... 完成。
長度:560565 (547K)
- 100%[=======================================>] 560,565 10.5K/s in 28s
- 16:22:04 (19.3 KB/s) - `pure-ftpd-1.0.24.tar.gz.1' saved [560565]
- [root@localhost src]$tar zxvf pure-ftpd-1.0.24.tar.gz
- pure-ftpd-1.0.24/
- pure-ftpd-1.0.24/aclocal.m4
- … …
- pure-ftpd-1.0.24/configuration-file/pure-config.py.in
- pure-ftpd-1.0.24/configuration-file/pure-ftpd.conf.in
- [root@localhost pure-ftpd-1.0.24]#
如果出現類似configure: error: Your MySQL client libraries aren't properly installed 的錯誤,將mysql目錄下的 include/mysql下的mysql.h文件以及lib/mysql下的全部文件,連接(直接復制過去或許也可)到 /usr/lib 目錄下.
如果編譯安裝pure-ftpd出現configure: error: Your MySQL client libraries aren't properly installed錯誤,解決辦法:
- [root@jowei pure-ftpd-1.0.22]#vi /etc/profile 在最后添加
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib/mysql
如果出現你安裝的Mysql是rpm包形式的,則直接用 --with-mysql 將其路徑刪除即可。
- [root@jowei pure-ftpd-1.0.22]# ./etc/profile
然后再進行./configure ......
出現下面這個表示配置成功
- configure: WARNING: unrecognized options: --with-largefile, --with-upload_script_, --with-virtualroot
- configure: +--------------------------------------------------------+
- configure: | You can subscribe to the Pure-FTPd users mailing-list |
- configure: | to ask for help and to stay informed of new releases. |
- configure: | Go to http://www.pureftpd.org/ml/ now! |
- configure: +--------------------------------------------------------+
- [root@localhost pure-ftpd-1.0.22]# make;make install
五、建立配置文件
- [root@localhost pure-ftpd-1.0.22]# mkdir -m 755 /usr/local/pureftpd/etc
- [root@localhost pure-ftpd-1.0.22]#
- cp pureftpd-mysql.conf /usr/local/pureftpd/etc/
- [root@localhost pure-ftpd-1.0.22]#
- cp configuration-file/pure-ftpd.conf /usr/local/pureftpd/etc/
- [root@localhost pure-ftpd-1.0.22]# cp configuration-file/pure-config.pl /usr/local/pureftpd/bin/
- [root@localhost pure-ftpd-1.0.22]#
- chmod 755 /usr/local/pureftpd/bin/pure-config.pl
- [root@localhost pure-ftpd-1.0.22]#
- cp contrib/redhat.init /etc/init.d/pureftpd
- [root@localhost pure-ftpd-1.0.22]# chmod 755 /etc/init.d/pureftpd
- [root@localhost pure-ftpd-1.0.22]# chown root:root /etc/init.d/pureftpd //設置root權限
- [root@localhost pure-ftpd-1.0.22]# chkconfig --add pureftpd
- //加入系統啟動
- [root@localhost pure-ftpd-1.0.22]# chkconfig pureftpd on //開機啟動
- [root@localhost pure-ftpd-1.0.22]# vi /etc/init.d/pureftpd //修改pureftpd一下幾項
- # Path to the pure-ftp binaries.
- prog=pure-config.pl
- fullpath=/usr/local/pureftpd/sbin/$prog //修改此處
- pureftpwho=/usr/local/pureftpd/sbin/pure-ftpwho //修改pure-ftpwho路徑
- start() {
- echo -n $"Starting $prog: "
- $fullpath /usr/local/pureftpd/etc/pure-ftpd.conf --daemonize //修改pure-ftpd.conf路徑
- RETVAL=$?
- [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
- echo
- }
#p#
六、建立mysql認證數據庫表
- [root@jowei pureftpd]# mysql -u root -p
- Enter password: ----輸入mysql root用戶密碼進入
- mysql> create database pureftpd;
- mysql> grant all on pureftpd.* to pureftpd@localhost identified by 'pureftpd';
- mysql> use pureftpd
- mysql> CREATE TABLE users (
- id int(32) unsigned NOT NULL auto_increment,
- User varchar(16) NOT NULL default '*',
- Password varchar(64) NOT NULL default '*',
- Uid varchar(11) NOT NULL default '-1',
- Gid varchar(11) NOT NULL default '-1',
- Dir varchar(128) NOT NULL default '-1',
- QuotaSize smallint(5) NOT NULL default 0,
- QuotaFiles int(11) NOT NULL default 0,
- ULBandwidth smallint(5) NOT NULL default 0,
- DLBandwidth smallint(5) NOT NULL default 0,
- ULRatio smallint(6) NOT NULL default 0,
- DLRatio smallint(6) NOT NULL default 0,
- comment tinytext NOT NULL,
- ipaccess varchar(15) NOT NULL default '*',
- status enum('0','1') NOT NULL default '0',
- create_date datetime NOT NULL default '0000-00-00 00:00:00',
- modify_date datetime NOT NULL default '0000-00-00 00:00:00',
- PRIMARY KEY (id,User),
- UNIQUE KEY User (User)
- ) TYPE=MyISAM AUTO_INCREMENT=5;
建立用戶
你可以用下面建立的test用戶登錄到/var/pureftp
- INSERT INTO users VALUES (1,'test1', '123456', '2000', '2000', '/var/pureftp', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2009-7-11 09:20:33', '2009-7-11 09:20:33');
- INSERT INTO users VALUES (1,'test2', '123456', '2000', '2000', '/var/pureftp', 0, 0, 0, 0, 0, 0, '*', '*', '1', '2009-7-11 09:20:33', '2009-7-11 09:20:33');
/var/pureftp ftp登陸的文件目錄
七、建立用于pureftpd認證用戶的系統信息
你可以自己向下面這樣建立一個用戶做pureftpd驗證但是我下面直接用的是root
- [root@localhost /]# groupadd -g 2000 pureftp
- [root@localhost /]# useradd -u 2000 -g pureftp -d /var/pureftp -s /sbin/nologin pureftp
#p#
八、修改pureftpd的配置文件
- [root@localhost var]# vi /usr/local/pureftpd/etc/pure-ftpd.conf
- ############################################################
- # #
- # Configuration file for pure-ftpd wrappers #
- # #
- ############################################################
- # 如果你想要使用配置文件代替命令行選項來運行 Pure-FTPd ,請運行下面的命令:
- #
- # /usr/local/pureftpd/sbin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
- #
- # RPM 缺省使用另外一個配置文件:
- # /etc/sysconfig/pure-ftpd
- #
- # 請不要忘了瀏覽一下 http://www.pureftpd.org/documentation.html 的
- # 文檔,查看全部的選項列表。
- # 限制所有用戶在其主目錄中
- ChrootEveryone yes
- # 如果前一個指令被設置為了 "no",下面組的成員(GID)就不受主目錄的限制了。而其他的用戶還是
- # 會被限制在自己的主目錄里。如果你不想把任何用戶限制在自己的主目錄里,只要注釋掉 ChrootEveryone
- # 和 TrustedGID 就可以了。
- # TrustedGID 100
- # 兼容ie等比較非正規化的ftp客戶端
- BrokenClientsCompatibility no
- # 服務器總共允許同時連接的最大用戶數
- MaxClientsNumber 50
- # 做為守護(doemon)進程運行(Fork in background)
- Daemonize yes
- # 同一IP允許同時連接的用戶數(Maximum number of sim clients with the same IP address)
- MaxClientsPerIP 8
- # 如果你要記錄所有的客戶命令,設置這個指令為 "yes"。
- # This directive can be duplicated to also log server responses.
- VerboseLog no
- # 即使客戶端沒有發送 '-a' 選項也列出隱藏文件( dot-files )。
- DisplayDotFiles yes
- # 不允許認證用戶 - 僅作為一個公共的匿名FTP。
- AnonymousOnly no
- # 不允許匿名連接,僅允許認證用戶使用。
- NoAnonymous no
- # Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
- # 缺省的功能( facility )是 "ftp"。 "none" 將禁止日志。
- SyslogFacility ftp
- # 定制用戶登陸后的顯示信息(Display fortune cookies)
- # FortunesFile /usr/share/fortune/zippy
- # 在日志文件中不解析主機名。日志沒那么詳細的話,就使用更少的帶寬。在一個訪問量很大
- # 的站點中,設置這個指令為 "yes" ,如果你沒有一個能工作的DNS的話。
- DontResolve yes
- # 客戶端允許的最大的空閑時間(分鐘,缺省15分鐘)
- MaxIdleTime 15
- # LDAP 配置文件 (參考 README.LDAP)
- # LDAPConfigFile /etc/pureftpd-ldap.conf
- # MySQL 配置文件 (參考 README.MySQL)
- MySQLConfigFile /usr/local/pureftpd/etc/pureftpd-mysql.conf #關鍵部分,你整合mysql就靠它了
- # Postgres 配置文件 (參考 README.PGSQL)
- # PGSQLConfigFile /etc/pureftpd-pgsql.conf
- # PureDB 用戶數據庫 (參考 README.Virtual-Users)
- # PureDB /etc/pureftpd.pdb
- # pure-authd 的socket 路徑(參考 README.Authentication-Modules)
- # ExtAuth /var/run/ftpd.sock
- # 如果你要啟用 PAM 認證方式, 去掉下面行的注釋。
- # PAMAuthentication yes
- # 如果你要啟用 簡單的 Unix系統 認證方式(/etc/passwd), 去掉下面行的注釋。
- # UnixAuthentication yes
- # 請注意,LDAPConfigFile, MySQLConfigFile, PAMAuthentication 和
- # UnixAuthentication 這些指令只能被使用一次,不過,他們能被混合在一起用。例如:如果你使用了
- # MySQLConfigFile 和 UnixAuthentication,那么 SQL 服務器將被訪問。如果因為用戶名未找
- # 到而使 SQL 認證失敗的話,就會在/etc/passwd 和 /etc/shadow 中嘗試另外一種認證,如果因
- # 為密碼錯誤而使 SQL 認證失敗的話,認證就會在此結束了。認證方式由它們被給出來的順序而被鏈
- # 接了起來。
- # 'ls' 命令的遞歸限制。第一個參數給出文件顯示的最大數目。第二個參數給出最大的子目錄深度。
- LimitRecursion 2000 8
- # 允許匿名用戶創建時間:2009-11-11 15:38:00新目錄?
- AnonymousCanCreateDirs no
- # 如果系統被 loaded 超過下面的值,匿名用戶會被禁止下載。
- MaxLoad 4
- # 被動連接響應的端口范圍。- for firewalling.
- # PassivePortRange 30000 50000
- # 強制一個IP地址使用被動響應( PASV/EPSV/SPSV replies)。 - for NAT.
- # Symbolic host names are also accepted for gateways with dynamic IP
- # addresses.
- # ForcePassiveIP 192.168.0.1
- # 匿名用戶的上傳/下載的比率。
- # AnonymousRatio 1 10
- # 所有用戶的上傳/下載的比率。
- # This directive superscedes the previous one.
- # UserRatio 1 10
- # 不接受所有者為 "ftp" 的文件的下載。例如:那些匿名用戶上傳后未被本地管理員驗證的文件。
- AntiWarez yes
- # 服務監聽的IP 地址和端口。(缺省是所有IP地址和21端口)
- # Bind 127.0.0.1,21
- # 匿名用戶的最大帶寬(KB/s)。
- # AnonymousBandwidth 8
- # 所有用戶的最大帶寬(KB/s),包括匿名用戶。
- # Use AnonymousBandwidth *or* UserBandwidth, both makes no sense.
- # UserBandwidth 8
- # 新建目錄及文件的屬性掩碼值。<文件掩碼>;:<目錄掩碼>; .
- # 177:077 if you feel paranoid.
- Umask 133:022
- # 認證用戶允許登陸的最小組ID(UID) 。
- MinUID 100
- # 僅允許認證用戶進行 FXP 傳輸。
- AllowUserFXP yes
- # 對匿名用戶和非匿名用戶允許進行匿名 FXP 傳輸。
- AllowAnonymousFXP no
- # 用戶不能刪除和寫點文件(文件名以 '.' 開頭的文件),即使用戶是文件的所有者也不行。
- # 如果 TrustedGID 指令是 enabled ,文件所屬組用戶能夠訪問點文件(dot-files)。
- ProhibitDotFilesWrite no
- # 禁止讀點文件(文件名以 '.' 開頭的文件) (.history, .ssh...)
- ProhibitDotFilesRead no
- # 永不覆蓋文件。當上傳的文件,其文件名已經存在時,自動重命名,如: file.1, file.2, file.3, ...
- AutoRename no
- # 不接受匿名用戶上傳新文件( no = 允許上傳)
- AnonymousCantUpload no
- # 僅允許來自以下IP地址的非匿名用戶連接。你可以使用這個指令來打開幾個公網IP來提供匿名FTP,
- # 而保留一個私有的防火墻保護的IP來進行遠程管理。你還可以只允許一內網地址進行認證,而在另外
- # 一個IP上提供純匿名的FTP服務。
- #TrustedIP 10.1.1.1
- # 如果你要為日志每一行添加 PID 去掉下面行的注釋。
- # LogPID yes
- # 使用類似于Apache的格式創建一個額外的日志文件,如:
- # fw.c9x.org - jedi [13/Dec/1975] "GET /ftp/linux.tar.bz2" 200 21809338
- # 這個日志文件能被 www 流量分析器處理。
- # AltLog clf:/var/log/pureftpd.log
- # 使用優化過的格式為統計報告創建一個額外的日志文件。
- # AltLog stats:/var/log/pureftpd.log
- # 使用標準的W3C格式創建一個額外的日志文件。(與大部分的商業日志分析器兼容)
- # AltLog w3c:/var/log/pureftpd.log
- # 不接受 CHMOD 命令。用戶不能更改他們文件的屬性。
- # NoChmod yes
- # 允許用戶恢復和上傳文件,卻不允許刪除他們。
- # KeepAllFiles yes
- # 用戶主目錄不存在的話,自動創建。
- # CreateHomeDir yes
- # 啟用虛擬的磁盤限額。第一個數字是最大的文件數。
- # 第二個數字是最大的總的文件大小(單位:Mb)。
- # 所以,1000:10 就限制每一個用戶只能使用 1000 個文件,共10Mb。
- # Quota 1000:10
- # 如果你的 pure-ftpd 編譯時加入了獨立服務器( standalone )支持,你能夠改變 pid 文件
- # 的位置。缺省位置是 /var/run/pure-ftpd.pid 。
- # PIDFile /var/run/pure-ftpd.pid
- # 如果你的 pure-ftpd 編譯時加入了 pure-uploadscript 支持,這個指令將會使 pure-ftpd
- # 發送關于新上傳的情況信息到 /var/run/pure-ftpd.upload.pipe,這樣 pure-uploadscript
- # 就能讀然后調用一個腳本去處理新的上傳。
- # CallUploadScript yes
- # 這個選項對允許匿名上傳的服務器是有用的。當 /var/ftp 在 /var 里時,需要保留一定磁盤空間
- # 來保護日志文件。當所在磁盤分區使用超過百分之 X 時,將不在接受新的上傳。
- MaxDiskUsage 99
- # 如果你不想要你的用戶重命名文件的話,就設置為 'yes' 。
- # NoRename yes
- # 是 'customer proof' : 工作區(workaround)反對普通的客戶錯誤,類似于:'chmod 0 public_html' 的錯誤。
- # 那是一個有效的命令,不過,將導致無知的客戶所定他們自己的文件,將使你的技術支持忙于愚蠢的的問題中。
- # 如果你確信你所有的用戶都有基本的Unix知識的話,這個特性將沒什么用了。不過,如果你是一個主機提供商
- # 的話,啟用它。
- CustomerProof yes
- # 每一個用戶的并發限制。只有在添加了 --with-peruserlimits 編譯選項進行編譯后,這個指令才起
- # 作用。(大部分的二進制的發布版本就是例子)
- # 格式是 : <每一個用戶最大允許的進程>;:<最大的匿名用戶進程>;
- # 例如: 3:20 意思是同一個認證用戶最大可以有3個同時活動的進程。而且同時最多只能有20個匿名用戶進程。
- # PerUserLimits 3:20
#p#
九、修改pureftpd-mysql.conf的配置文件
- [root@localhost var]# vi /usr/local/pureftpd/etc/pureftpd-mysql.conf
- ##############################################
- # #
- # Sample Pure-FTPd Mysql configuration file. #
- # See README.MySQL for explanations. #
- # #
- ##############################################
- # Optional : MySQL server name or IP. Don't define this for unix sockets.
- MYSQLServer localhost
- #服務器地址
- # Optional : MySQL port. Don't define this if a local unix socket is used.
- MYSQLPort 3306
- #服務器端口
- # Optional : define the location of mysql.sock if the server runs on this host.
- MYSQLSocket /tmp/mysql.sock
- #這里換成你的真實地址
- # Mandatory : user to bind the server as.
- MYSQLUser root
- #登錄服務器用戶名
- # Mandatory : user password. You must have a password.
- MYSQLPassword 123456
- #登錄服務器密碼
- # Mandatory : database to open.
- MYSQLDatabase pureftpd
- #配置文件所在的數據庫
- # Mandatory : how passwords are stored
- # Valid values are : "cleartext", "crypt", "md5" and "password"
- # ("password" = MySQL password() function)
- # You can also use "any" to try "crypt", "md5" *and* "password"
- MYSQLCrypt cleartext
- #驗證方式
- # In the following directives, parts of the strings are replaced at
- # run-time before performing queries :
- #
- # \L is replaced by the login of the user trying to authenticate.
- # \I is replaced by the IP address the user connected to.
- # \P is replaced by the port number the user connected to.
- # \R is replaced by the IP address the user connected from.
- # \D is replaced by the remote IP address, as a long decimal number.
- #
- # Very complex queries can be performed using these substitution strings,
- # especially for virtual hosting.
- # Query to execute in order to fetch the password
- MYSQLGetPW SELECT Password FROM users WHERE User="\L" AND status="1"
- #登錄服務器的用戶密碼驗證字段,status="1"為此用戶必需為激活模式.
- # Query to execute in order to fetch the system user name or uid
- MYSQLGetUID SELECT Uid FROM users WHERE User="\L"
- #用戶的UID
- # Optional : default UID - if set this overrides MYSQLGetUID
- #MYSQLDefaultUID 1000
- # Query to execute in order to fetch the system user group or gid
- MYSQLGetGID SELECT Gid FROM users WHERE User="\L"
- #用戶的Gid
- # Optional : default GID - if set this overrides MYSQLGetGID
- #MYSQLDefaultGID 1000
- # Query to execute in order to fetch the home directory
- MYSQLGetDir SELECT Dir FROM users WHERE User="\L"
- #用戶的主目錄
- # Optional : query to get the maximal number of files
- # Pure-FTPd must have been compiled with virtual quotas support.
- MySQLGetQTAFS SELECT QuotaFiles FROM users WHERE User="\L"
- #用戶的最大文件數量
- # Optional : query to get the maximal disk usage (virtual quotas)
- # The number should be in Megabytes.
- # Pure-FTPd must have been compiled with virtual quotas support.
- MySQLGetQTASZ SELECT QuotaSize FROM users WHERE User="\L"
- #用戶的最大磁盤空間
- # Optional : ratios. The server has to be compiled with ratio support.
- MySQLGetRatioUL SELECT ULBandwidth FROM users WHERE User="\L"
- MySQLGetRatioDL SELECT DLBandwidth FROM users WHERE User="\L"
- #上邊兩項為,用戶上傳與下載的速度,單位 Kb/s
- # Optional : bandwidth throttling.
- # The server has to be compiled with throttling support.
- # Values are in KB/s .
- # MySQLGetBandwidthUL SELECT ULBandwidth FROM users WHERE User="\L"
- # MySQLGetBandwidthDL SELECT DLBandwidth FROM users WHERE User="\L"
- # Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
- # 1) You know what you are doing.
- # 2) Real and virtual users match.
- # MySQLForceTildeExpansion 1
- # If you upgraded your tables to transactionnal tables (Gemini,
- # BerkeleyDB, Innobase...), you can enable SQL transactions to
- # avoid races. Leave this commented if you are using the
- # traditionnal MyIsam databases or old (< 3.23.x) MySQL versions.
- # MySQLTransactions On
#p#
十、運行pureftpd
啟動pureftpd
- [root@localhost ~]# /etc/init.d/pureftpd start 或者下面也可以
- [root@localhost ~]#/usr/local/pureftpd/bin/pure-config.pl /usr/local/pureftpd/etc/pure-ftpd.conf
【編輯推薦】