歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Unix知識 >> 關於Unix

基於LINUX系統的proftp的學習筆記(四)

proftp+mysql+quota的應用 1.首先我們建立相應的用戶和用戶組 groupadd -g 5500 ftpgroup adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser 2.操作 數據庫 mysql mysql -uroot -ppassword create database ftpdb gr ant
  proftp+mysql+quota的應用
  
  1.首先我們建立相應的用戶和用戶組
  
  groupadd -g 5500 ftpgroup
  adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser
  
  2.操作數據庫
  
  mysql mysql -uroot -ppassword
  create database ftpdb
  grant select, update on ftpdb.* to proftpd@localhost identified by 'password'
  use ftpdb
  
  CREATE TABLE `ftpgroup` (
  `groupname` varchar(16) NOT NULL default ',
  `gid` smallint(6) NOT NULL default '5500',
  `members` varchar(16) NOT NULL default ',
  KEY `groupname` (`groupname`)
  ) TYPE=MyISAM COMMENT='ProFTP group table';
  
  INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');
  
  CREATE TABLE `ftpquotalimits` (
  `name` varchar(30) default NULL,
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `per_session` enum('false','true') NOT NULL default 'false',
  `limit_type` enum('soft','hard') NOT NULL default 'soft',
  `bytes_in_avail` float NOT NULL default '0',
  `bytes_out_avail` float NOT NULL default '0',
  `bytes_xfer_avail` float NOT NULL default '0',
  `files_in_avail` int(10) unsigned NOT NULL default '0',
  `files_out_avail` int(10) unsigned NOT NULL default '0',
  `files_xfer_avail` int(10) unsigned NOT NULL default '0'
  ) TYPE=MyISAM;
  
  CREATE TABLE `ftpquotatallies` (
  `name` varchar(30) NOT NULL default ',
  `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  `bytes_in_used` float NOT NULL default '0',
  `bytes_out_used` float NOT NULL default '0',
  `bytes_xfer_used` float NOT NULL default '0',
  `files_in_used` int(10) unsigned NOT NULL default '0',
  `files_out_used` int(10) unsigned NOT NULL default '0',
  `files_xfer_used` int(10) unsigned NOT NULL default '0'
  ) TYPE=MyISAM;
  
  CREATE TABLE `ftpuser` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` varchar(32) NOT NULL default ',
  `passwd` varchar(32) NOT NULL default ',
  `uid` smallint(6) NOT NULL default '5500',
  `gid` smallint(6) NOT NULL default '5500',
  `homedir` varchar(255) NOT NULL default ',
  `shell` varchar(16) NOT NULL default '/sbin/nologin',
  `count` int(11) NOT NULL default '0',
  `aclearcase/" target="_blank" >ccessed` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY (`id`)
  ) TYPE=MyISAM COMMENT='ProFTP user table' ;
  
  注意這裡大家根據實際情況填寫自己數據庫的用戶名和密碼,如果大家對數據庫操作不熟悉的話,不妨可以用phpmyadmin來操作。
  
  3.配置proftp文件
  
  ServerName "Frank's FTP Server" ServerType standalone DefaultServer on
  Port 21
  
  Umask 022
  
  MaxInstances 30
  MaxLoginAttempts 3
  
  User nobody
  Group nobody
  
  MaxHostsPerUser 1 "Sorry, you may not connect more than one time."
  MaxClientsPerUser 2 "Only one such user at a time."
  MaxClientsPerHost 3 "Sorry, you may not connect more than one time."
  
  RootLogin off
  RequireValidShell off
  TimeoutStalled 10
  MaxClients 10
  AllowForeignAddress on
  AllowStoreRestart on
  ServerIdent off
  DefaultRoot ~ ftpgroup
  
  SQLAuthTypes Backend Plaintext
  #Backend表示用戶認證方式為MySQL數據庫的認證方式
  #Plaintext表示明文認證方式,排在最前面的為最先使用的方式
  SQLAuthenticate users* groups*
  
  # databasename@host database_user user_password
  SQLConnectInfo ftpdb@localhost proftpd password
  SQLUserInfo ftpuser userid passwd uid gid homedir shell
  SQLGroupInfo ftpgroup groupname gid members
  SQLHomedirOnDemand on
  #如果用戶主目錄不存在,則系統會根據此用戶在用戶數據表中的homedir字段的值新建一個目錄
  # Update count every time user logs in
  SQLLog PASS updatecount
  SQLNamedQuery updatecount UPDATE "count=count+1,accessed=now() WHERE userid='%u'" ftpuser
  # Update modified everytime user uploads or deletes a file
  SQLLog STOR,DELE modified
  SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
  
  QuotaEngine on
  QuotaDirectoryTally on
  QuotaDisplayUnits Mb
  QuotaShowQuotas on
  QuotaLog "/var/log/quota"
  SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avai
  l, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftpquotalimits WHERE name = '%{0}'
  AND quota_type = '%{1}'"
  
  SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_i
  n_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
  
  SQLNamedQuery update-quota-tally UPDATE "bytes_in_used = bytes_in_used + %{0}, bytes_out_used = bytes_out_used
  + %{1}, bytes_xfer_used = bytes_xfer_used + %{2}, files_in_used = files_in_used + %{3}, files_out_used = files_
  out_used + %{4}, files_xfer_used = files_xfer_used + %{5} WHERE name = '%{6}' AND quota_type = '%{7}'" ftpquota
  tallies
  
  SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
  
  QuotaLimitTable sql:/get-quota-limit
  QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
  
  就這麼簡單,重啟一下proftp服務就已經能使用proftp+mysql+quota的功能
  
  我們可以在數據庫ftpuser添加一個虛擬用戶,
  
  INSERT INTO `ftpuser` VALUES (1, 'test', 'ftppasswd', 5500, 5500, '/home/test', '/sbin/nologin');
  大家可以在phpmyadmin裡直接操作添加一個用戶,相信不用我教大家怎麼添加吧:)
  
  如果你想設置quota,只要在ftpquotalimits表裡設置一下就行了,這個表裡的各個參數分別代表:
  
  quotalimits表
  name: - 用戶帳號
  quota type: - user, group, class, all (we use user)
  per_session: - true or false (we use true)
  limit_type: - 硬限制 or 軟限制 (我們一般用硬限制)
  bytes_in_avail: - 允許上傳的字節數
  bytes_out_avail: - 允許下載的字節數
  bytes_xfer_avail: - 允許傳輸的字節數(包括上傳/下載)
  files_in_avail: - 允許上傳的文件數
  files_out_avail: - 允許下載的文件數
  files_xfer_avail: - 允許傳輸的文件數(包括上傳/下載)
  
  mysql和quota模塊來驗證用戶和設置磁盤限額,但我總覺得還是不夠完善,因為在這個方法中,數據庫表裡還沒有相應的權限的字段,所以說相應用戶的權限還是得用實際得用戶即mysql對應得uid和gid來控制權限。

Copyright © Linux教程網 All Rights Reserved