CentOS 5.x编译安装配置ProFTPd与添加MySQL虚拟用户

有运维或运维开发方面的需求,可以联系博主QQ 452336092或Email:admin#centos.bz(收费)

文章目录
[隐藏]

在安装ProFTPd与配置MySQL虚拟用户之前,请确保你的系统已经正常运行MySQL服务器。

编译安装ProFTPd

  1. wget ftp://ftp-stud.fht-esslingen.de/pub/Mirrors/ftp.proftpd.net/distrib/source/proftpd-1.3.1.tar.gz
  2. tar xzvf proftpd-1.3.1.tar.gz
  3. cd proftpd-1.3.1
  4. ./configure --with-modules=mod_sql:mod_sql_mysql:mod_quotatab:mod_quotatab_sql \
  5. --with-includes=/usr/include/mysql \
  6. --with-libraries=/usr/lib/mysql
  7. make && make install

请根据你的MySQL安装路径修改–with-includes和–with-libraries的参数。

添加ftp用户和用户组

  1. groupadd -g 5500 ftpgroup
  2. adduser -u 5500 -s /bin/false -d /bin/null -c "proftpd user" -g ftpgroup ftpuser

MySQL配置

登录MySQL并创建数据库。

  1. mysql -u root -p
  2. create database ftpdb;
  3. grant select, insert, update on ftpdb.* to proftpd@localhost identified by 'password';
  4.  
  5. use ftpdb;
  6.  
  7. #
  8. # Table structure for table `ftpgroup`
  9. #
  10.  
  11. CREATE TABLE ftpgroup (
  12. groupname varchar(16) NOT NULL default '',
  13. gid smallint(6) NOT NULL default '5500',
  14. members varchar(16) NOT NULL default '',
  15. KEY groupname (groupname)
  16. ) TYPE=MyISAM COMMENT='ProFTP group table';
  17.  
  18. #
  19. # Dumping data for table `ftpgroup`
  20. #
  21.  
  22. INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpuser');
  23. INSERT INTO `ftpgroup` VALUES ('ftpgroup', 5500, 'ftpguest');
  24.  
  25. CREATE TABLE `ftpquotatallies` (
  26. `name` varchar(30) NOT NULL default '',
  27. `quota_type` enum('user','group','class','all') NOT NULL default 'user',
  28. `bytes_in_used` float NOT NULL default '0',
  29. `bytes_out_used` float NOT NULL default '0',
  30. `bytes_xfer_used` float NOT NULL default '0',
  31. `files_in_used` int(10) unsigned NOT NULL default '0',
  32. `files_out_used` int(10) unsigned NOT NULL default '0',
  33. `files_xfer_used` int(10) unsigned NOT NULL default '0'
  34. ) TYPE=MyISAM;
  35.  
  36. # --------------------------------------------------------
  37.  
  38. #
  39. # Table structure for table `ftpuser`
  40. #
  41.  
  42. CREATE TABLE ftpuser (
  43. id int(10) unsigned NOT NULL auto_increment,
  44. userid varchar(32) NOT NULL default '',
  45. passwd varchar(32) NOT NULL default '',
  46. uid smallint(6) NOT NULL default '5500',
  47. gid smallint(6) NOT NULL default '5500',
  48. homedir varchar(255) NOT NULL default '',
  49. shell varchar(16) NOT NULL default '/sbin/nologin',
  50. count int(11) NOT NULL default '0',
  51. accessed datetime NOT NULL default '0000-00-00 00:00:00',
  52. modified datetime NOT NULL default '0000-00-00 00:00:00',
  53. PRIMARY KEY (id),
  54. UNIQUE KEY userid (userid)
  55. ) TYPE=MyISAM COMMENT='ProFTP user table';
  56. INSERT INTO `ftpuser` VALUES (1, 'testaccount', 'ftppasswd', 5500, 5500, '/home/testdomain.com', '/sbin/nologin',0,'','');
  57.  
  58. exit;

proftpd配置文件

要目录下建proftpd.conf配置文件,请在下面的代码修改好MySQL数据库登录信息。

  1. ServerName "Khoosys Proftpd Server"
  2. ServerType Standalone
  3. ServerAdmin stephen@khoosys.net
  4.  
  5. # Hide as much as possible to outside users
  6. ServerIdent on "Welcome to the Khoosys FTP server. Please login..."
  7. DeferWelcome on
  8.  
  9. DefaultServer on
  10.  
  11. # Allow FTP resuming.
  12. # Remember to set to off if you have an incoming ftp for upload.
  13. AllowStoreRestart on
  14.  
  15. # Port 21 is the standard FTP port.
  16. Port 21
  17.  
  18. # Umask 022 is a good standard umask to prevent new dirs and files
  19. # from being group and world writable.
  20. Umask 022
  21.  
  22. # To prevent DoS attacks, set the maximum number of child processes
  23. # to 30. If you need to allow more than 30 concurrent connections
  24. # at once, simply increase this value. Note that this ONLY works
  25. # in standalone mode, in inetd mode you should use an inetd server
  26. # that allows you to limit maximum number of processes per service
  27. # (such as xinetd).
  28. MaxInstances 30
  29.  
  30. # Set the user and group under which the server will run.
  31. User ftpuser
  32. Group ftpgroup
  33.  
  34. # To cause every FTP user to be "jailed" (chrooted) into their home
  35. # directory, uncomment this line.
  36. DefaultRoot ~
  37.  
  38. # Normally, we want files to be overwriteable.
  39.  
  40. AllowOverwrite on
  41.  
  42. # The passwords in MySQL are encrypted using CRYPT
  43. SQLAuthTypes Plaintext Crypt
  44. SQLAuthenticate users* groups*
  45.  
  46. # used to connect to the database
  47. # databasename@host database_user user_password
  48. SQLConnectInfo ftpdb@localhost proftpd password
  49.  
  50. # Here we tell ProFTPd the names of the database columns in the "usertable"
  51. # we want it to interact with. Match the names with those in the db
  52. SQLUserInfo ftpuser userid passwd uid gid homedir shell
  53.  
  54. # Here we tell ProFTPd the names of the database columns in the "grouptable"
  55. # we want it to interact with. Again the names match with those in the db
  56. SQLGroupInfo ftpgroup groupname gid members
  57.  
  58. # set min UID and GID - otherwise these are 999 each
  59. SQLMinID 500
  60.  
  61. # create a user's home directory on demand if it doesn't exist
  62. SQLHomedirOnDemand on
  63.  
  64. # Update count every time user logs in
  65. SQLLog PASS updatecount
  66. SQLNamedQuery updatecount UPDATE "count=count+1, accessed=now() WHERE userid='%u'" ftpuser
  67.  
  68. # Update modified everytime user uploads or deletes a file
  69. SQLLog STOR,DELE modified
  70. SQLNamedQuery modified UPDATE "modified=now() WHERE userid='%u'" ftpuser
  71.  
  72. # User quotas
  73. # ===========
  74. QuotaEngine on
  75. QuotaDirectoryTally on
  76. QuotaDisplayUnits Mb
  77. QuotaShowQuotas on
  78.  
  79. SQLNamedQuery get-quota-limit SELECT "name, quota_type, per_session, limit_type, bytes_in_avail, bytes_out_avail, bytes_xfer_avail, files_in_avail, files_out_avail, files_xfer_avail FROM ftpquotalimits WHERE name = '%{0}' AND quota_type = '%{1}'"
  80.  
  81. SQLNamedQuery get-quota-tally SELECT "name, quota_type, bytes_in_used, bytes_out_used, bytes_xfer_used, files_in_used, files_out_used, files_xfer_used FROM ftpquotatallies WHERE name = '%{0}' AND quota_type = '%{1}'"
  82.  
  83. 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}'" ftpquotatallies
  84.  
  85. SQLNamedQuery insert-quota-tally INSERT "%{0}, %{1}, %{2}, %{3}, %{4}, %{5}, %{6}, %{7}" ftpquotatallies
  86.  
  87. QuotaLimitTable sql:/get-quota-limit
  88. QuotaTallyTable sql:/get-quota-tally/update-quota-tally/insert-quota-tally
  89.  
  90.  
  91. RootLogin off
  92. RequireValidShell off

proftpd启动文件

创建/etc/init.d/proftpd文件,并写入下面的代码。

  1. #!/bin/sh
  2. # $Id: proftpd.init,v 1.1 2004/02/26 17:54:30 thias Exp $
  3. #
  4. # proftpd This shell script takes care of starting and stopping
  5. # proftpd.
  6. #
  7. # chkconfig: - 80 30
  8. # description: ProFTPD is an enhanced FTP server with a focus towards \
  9. # simplicity, security, and ease of configuration. \
  10. # It features a very Apache-like configuration syntax, \
  11. # and a highly customizable server infrastructure, \
  12. # including support for multiple 'virtual' FTP servers, \
  13. # anonymous FTP, and permission-based directory visibility.
  14. # processname: proftpd
  15. # config: /etc/proftp.conf
  16. # pidfile: /var/run/proftpd.pid
  17. # Source function library.
  18. . /etc/rc.d/init.d/functions
  19.  
  20. # Source networking configuration.
  21. . /etc/sysconfig/network
  22.  
  23. # Check that networking is up.
  24. [ ${NETWORKING} = "no" ] && exit 0
  25.  
  26. [ -x /usr/sbin/proftpd ] || exit 0
  27.  
  28. RETVAL=0
  29.  
  30. prog="proftpd"
  31.  
  32. start() {
  33. echo -n $"Starting $prog: "
  34. daemon proftpd
  35. RETVAL=$?
  36. echo
  37. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd
  38. }
  39.  
  40. stop() {
  41. echo -n $"Shutting down $prog: "
  42. killproc proftpd
  43. RETVAL=$?
  44. echo
  45. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/proftpd
  46. }
  47.  
  48. # See how we were called.
  49. case "$1" in
  50. start)
  51. start
  52. ;;
  53. stop)
  54. stop
  55. ;;
  56. status)
  57. status proftpd
  58. RETVAL=$?
  59. ;;
  60. restart)
  61. stop
  62. start
  63. ;;
  64. condrestart)
  65. if [ -f /var/lock/subsys/proftpd ]; then
  66. stop
  67. start
  68. fi
  69. ;;
  70. reload)
  71. echo -n $"Re-reading $prog configuration: "
  72. killproc proftpd -HUP
  73. RETVAL=$?
  74. echo
  75. ;;
  76. *)
  77. echo "Usage: $prog {start|stop|restart|reload|condrestart|status}"
  78. exit 1
  79. esac
  80.  
  81. exit $RETVAL
  1. chmod 755 /etc/init.d/proftpd

之后,我们可以使用
service proftpd (start|stop|restart|reload|condrestart|status)来管理proftpd服务器。

测试proftpd

之前在配置MySQL的时候,我们添加了测试帐号testaccount和密码ftppasswd,可以用这个帐号来测试proftpd是否运行正常。

转载请保留原文链接:Linux运维日志 » CentOS 5.x编译安装配置ProFTPd与添加MySQL虚拟用户

打赏

如果此文对你有所帮助,请随意打赏鼓励作者^_^