PureFtpd 服务
2018-12-23 本文已影响0人
fangfc
1. 概述
- Pure-FTPd 是一个免费的FTP服务器, 相比较传统的vsftpd 功能更加强大, 性能稳定.
- 支持多种余元编写客户端程序.
- 支持使用使用 SSL/TLS 加密.
- 支持使用数据库存储和管理账户.
2. 安装和配置
2.1 源码包安装
- 下载源码包并解压
[root@node10009 src]# ls -lh ./pure-ftpd-1.0.47.tar.bz2
-rw-r--r-- 1 root root 478K Jun 4 2018 ./pure-ftpd-1.0.47.tar.bz2
[root@node10009 src]# tar jxf pure-ftpd-1.0.47.tar.bz2
[root@node10009 src]# cd pure-ftpd-1.0.47
[root@node10009 pure-ftpd-1.0.47]#
- 预编译
[root@node10009 pure-ftpd-1.0.47]# ./configure --prefix=/opt/app/pureftpd --with-capabilities --with-sendfile --with-paranoidmsg --with-altlog --with-puredb --with-pam --with-cookie --with-throttling --with-ratios --with-quotas --with-ftpwho --with-welcomemsg --with-uploadscript --with-vritualhosts --with-diraliases --with-puruserlimits --with-mysql --with-privsep --with-rfc2640 --without-bonjour
- 编译并安装
[root@node10009 pure-ftpd-1.0.47]# make -j4
...
[root@node10009 pure-ftpd-1.0.47]# make install
...
[root@node10009 pure-ftpd-1.0.47]# ls /opt/app/pureftpd/
bin etc sbin share
- 安装ftp 客户端
[root@node10009 pureftpd]# yum -y install ftp
...
Installed:
ftp.x86_64 0:0.17-67.el7
Complete!
2.2 配置
- 目录以及用户设置
### 添加用户和用户和组
[root@node10009 pureftpd]# groupadd pureftp
[root@node10009 pureftpd]# useradd -g pureftp -d /dev/null -s /sbin/nologin -r pureftp
### 创建目录和 ftp 用户
[root@node10009 pureftpd]# mkdir -p /opt/ftp/share
[root@node10009 pureftpd]# ./bin/pure-pw useradd testuser1 -u pureftp -d /opt/ftp/share/
Password:
Enter it again:
- 编辑配置文件, 指定 用户数据库
[root@node10009 pureftpd]# ./bin/pure-pw mkdb
[root@node10009 pureftpd]# vim etc/pure-ftpd.conf
...
PureDB /opt/app/pureftpd/etc/pureftpd.pdb
...
- 添加测试文件, 并设置好目录权限
[root@node10009 pureftpd]# echo 'hello' > /opt/ftp/share/a.txt
[root@node10009 pureftpd]# chown -R pureftp. /opt/ftp/share/
- 启动服务
[root@node10009 pureftpd]# ./sbin/pure-ftpd /opt/app/pureftpd/etc/pure-ftpd.conf
[root@node10009 pureftpd]# ss -tan | grep 21
LISTEN 0 9 *:21 *:*
LISTEN 0 9 :::21 :::*
[root@node10009 pureftpd]#
2.3 测试
- 登陆测试
[root@node10009 pureftpd]# ftp localhost
Trying ::1...
Connected to localhost (::1).
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 18:23. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
Name (localhost:root): testuser1
331 User testuser1 OK. Password required
Password:
230 OK. Current directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
- 下载测试
ftp> ls
229 Extended Passive mode OK (|||33927|)
150 Accepted data connection
drwxr-xr-x 2 958 pureftp 19 Dec 22 17:45 .
drwxr-xr-x 2 958 pureftp 19 Dec 22 17:45 ..
-rw-r--r-- 1 958 pureftp 6 Dec 22 17:45 a.txt
226-Options: -a -l
226 3 matches total
ftp> get a.txt
local: a.txt remote: a.txt
229 Extended Passive mode OK (|||44663|)
150 Accepted data connection
226-File successfully transferred
226 0.000 seconds (measured here), 119.30 Kbytes per second
6 bytes received in 2.4e-05 secs (250.00 Kbytes/sec)
ftp>
- 上传测试
ftp> put /home/fangfc/b.txt b.txt
local: /home/fangfc/b.txt remote: b.txt
229 Extended Passive mode OK (|||9919|)
150 Accepted data connection
226-File successfully transferred
226 0.000 seconds (measured here), 63.02 Kbytes per second
6 bytes sent in 3.4e-05 secs (176.47 Kbytes/sec)
ftp> ls
229 Extended Passive mode OK (|||41164|)
150 Accepted data connection
drwxr-xr-x 2 958 pureftp 32 Dec 22 18:25 .
drwxr-xr-x 2 958 pureftp 32 Dec 22 18:25 ..
-rw-r--r-- 1 958 pureftp 6 Dec 22 17:45 a.txt
-rw-r--r-- 1 958 pureftp 6 Dec 22 18:25 b.txt
226-Options: -a -l
226 4 matches total
ftp>
3. 配置使用MySQL 登陆
3.1 MySQL 相关设置
- 创建用于存储pure-ftp 用户 的数据库和数据表
MySQL [(none)] > CREATE database pureftp DEFAULT CHARACTER SET=utf8;
Query OK, 1 row affected (0.00 sec)
MySQL [(none)] > use pureftp
MySQL [pureftp] >
CREATE TABLE `ftpuser` (
`user` VARCHAR(20) NOT NULL,
`password` VARCHAR(255) NOT NULL,
`uid` INT NOT NULL default '-1',
`gid` INT NOT NULL default '-1',
`dir` VARCHAR(255) NOT NULL,
`status` TINYINT NOT NULL DEFAULT '0',
PRIMARY KEY(User)
)ENGINE=InnoDB DEFAULT CHARACTER SET=utf8;
Query OK, 0 rows affected (0.02 sec)
- 创建 pureftpd 连接数据库的用户.
MySQL [pureftp] > GRANT ALL ON pureftp.* TO 'pureftp'@'127.0.0.1' IDENTIFIED BY 'pureftp';
Query OK, 0 rows affected, 1 warning (0.01 sec)
MySQL [pureftp] > FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.02 sec)
- 插入用户数据
MySQL [pureftp] > INSERT INTO `ftpuser`(`user`, `password`, `uid`, `gid`, `dir`,`status`) VALUES('user1', MD5('123'), 958,, 2001
Query OK, 1 row affected (0.01 sec)
MySQL [pureftp] > SELECT * FROM `ftpuser`;
+-------+----------------------------------+-----+-------+----------------+--------+
| user | password | uid | gid | dir | status |
+-------+----------------------------------+-----+-------+----------------+--------+
| user1 | 202cb962ac59075b964b07152d234b70 | 958 | 2001 | /opt/ftp/share | 1 |
+-------+----------------------------------+-----+-------+----------------+--------+
1 row in set (0.01 sec)
3.2 修改配置文件
- 修改主配置文件
/opt/app/pureftp/etc/pure-ftpd.conf
## 1. 注释 PureDB 项
# PureDB /opt/app/pureftpd/etc/pureftpd.pdb
...
## 2. 设置 MySQLConfigFile
MySQLConfigFile /opt/app/pureftp/etc/pureftpd-mysql.conf
/opt/app/pureftp/etc/pureftp-mysql.conf
MYSQLServer 127.0.0.1
MYSQLPort 3306
MYSQLSocket /tmp/mysql.sock
MySQLDatabase pureftp
MYSQLUser pureftp
MYSQLPassword pureftp
MySQLCrypt md5
MYSQLGetPW SELECT password FROM ftpuser WHERE user ='\L' AND status=1
MYSQLGetUID SELECT uid FROM ftpuser WHERE user ='\L' AND status=1
MYSQLGetGID SELECT gid FROM ftpuser WHERE user ='\L' AND status=1
MYSQLGetDir SELECT dir FROM ftpuser WHERE user = '\L' AND status=1
3.3 测试
- 登陆
[root@node10009 ~]# ftp localhost
Trying ::1...
Connected to localhost (::1).
220---------- Welcome to Pure-FTPd [privsep] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 00:47. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
Name (localhost:root): user1
331 User user1 OK. Password required
Password:
230 OK. Current restricted directory is /
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
- 下载
ftp> ls
229 Extended Passive mode OK (|||16372|)
150 Accepted data connection
drwxr-xr-x 2 958 pureftp 32 Dec 22 18:25 .
drwxr-xr-x 2 958 pureftp 32 Dec 22 18:25 ..
-rw-r--r-- 1 958 pureftp 6 Dec 22 17:45 a.txt
-rw-r--r-- 1 958 pureftp 6 Dec 22 18:25 b.txt
226-Options: -a -l
226 4 matches total
ftp> get a.txt /root/test/a.txt
local: /root/test/a.txt remote: a.txt
229 Extended Passive mode OK (|||15025|)
150-Accepted data connection
150 The computer is your friend. Trust the computer
226-File successfully transferred
226 0.000 seconds (measured here), 136.53 Kbytes per second
6 bytes received in 2.3e-05 secs (260.87 Kbytes/sec)
- 上传
[root@node10009 ~]# mkdir test
[root@node10009 ~]# cd test
[root@node10009 test]# echo 'hello' > abc.txt
...
ftp> put /root/test/abc.txt abc.txt
local: /root/test/abc.txt remote: abc.txt
229 Extended Passive mode OK (|||58248|)
150 Accepted data connection
226-File successfully transferred
226 0.000 seconds (measured here), 12.13 Kbytes per second
6 bytes sent in 3.3e-05 secs (181.82 Kbytes/sec)
ftp>
END