一篇文章了解开源 FTP 服务器 vsftpd

简介: 一篇文章了解开源 FTP 服务器 vsftpd

1 背景

某客户现场,每天都会批量生成大量 CSV 文件存放到 FTP 系统,这些 CSV 文件需要导入到大数据平台 HIVE 数仓中做后续离线分析,且 HIVE 数仓中的离线分析作业目前是使用 JENKINS 来调度的。

由于这些 CSV 文件是每天都会生成,且文件数比较多数据量也比较大,初步计划使用 DATAX 来导入 FTP 上的 CSV 文件。

但在调度系统 JENKINS 中,如何检测 ftp 上的 csv 文件是否 ready,并及时触发 DATAX 导入作业,成为了一个问题。

为探索和验证 JENKINS 中 FTP 文件的检测和触发机制,笔者搭建了 FTP 服务器。

在此通过系列文章,跟大家分享一个开源的 FTP 服务器 vsftpd, 介绍下其安装配置和使用,然后介绍下 FTP 的 ACTIVE 与 PASSIVE 模式,最后介绍下 CurlFtpFS.

本片文章是系列文章第一篇,介绍下开源的 FTP 服务器 vsftpd,及其安装配置和使用。

2 开源 FTP 服务器 vsftpd 介绍

vsftpd 是一款 UNIX/LINUX 上的 FTP 服务器软件,号称是“ Probably the most secure and fastest FTP server for UNIX-like systems”,其具有以下特点:

  • 安全
  • 快速
  • 稳定
  • 开源 (基于 GPLv2 协议开源)

更多关于 vsftpd 的介绍,可以参考官网:

image.png

3 开源 FTP 服务器 vsftpd 的安装配置和管理

  • 绝大多数 linux 发行版服务器的包管理工具中都自带了 vsftpd 的安装包,直接使用包管理工具的安装命令进行安装即可;
  • 使用包管理工具安装完毕 vsftpd 后,即可使用系统服务 systemd 对 vsftpd 进行启停等常规运维管理;
  • 使用包管理工具安装完毕 vsftpd 后,需要针对自己的环境对配置文件进行修改,配置文件地址一般为 /etc/vsftpd/vsftpd.conf

image.png

以下以 aws ec2 为例,介绍下 vsftpd 的安装和配置要点。

  • yum install vsftpd //安装
  • systemctl start/stop/restart/status vsftpd //启停管理
  • systemctl enable vsftpd //配置开机自启

相关截图:

image.png

image.png

image.png

改配置文件/etc/vsftpd/vsftpd.conf,重要的更改项如下:

  • anonymous_enable=NO // 关闭匿名用户登录
  • local_enable=YES //允许本地系统用户(/etc/passwd 中的用户)登录
  • write_enable=YES //允许对文件系统的写操作,比如上传文件,删除文件
  • chroot_local_user=YES //开启 chroot jail 以增强安全性,开启后本地系统用户登录后会被 jail 到其 home directory
  • listen=YES //开启后, vsftpd 在 stanadalone 模式下运行且监听 IPv4 地址,不受 inetd 等管理
  • listen_ipv6=NO //关闭 ipv6 地址监听
  • pasv_enable=YES // 开启 PASSIVE 模式
  • pasv_min_port=1024 //PASSIVE 模式下最小可用端口号
  • pasv_max_port=1048 //PASSIVE 模式下最大可用端口号
  • pasv_address=http://18.219.xxx.xxx //// PASSIVE 模式下对客户端广播的地址,AWS ec2 中需要使用公网 IP 不能使用内网 IP
  • allow_writeable_chroot=true // 允许用户对 chroot jail 的目录的写权限

以下几点需要注意:

  • 为简便起见,这里没有配置启用ssl: ssl_enable=NO
  • 如果没有配置参数 allow_writeable_chroot=true 以允许用户对 chroot jail 的目录的写权限,客户端访问时可能会遇到以下错误: Error message "500 OOPS: vsftpd: refusing to run with writable root inside chroot()" - keep user jailed
  • 参数 pasv_address 在 AWS ec2 中需要使用公网 IP,不能使用内网 IP,且默认情况下 AWS ec2 重启时(reboot) 其公网 IP 不会改变,但其它操作会改变其公网 ip (比如 stop 然后start);

image.png

4 vsftpd 配置文件 /etc/vsftpd/vsftpd.conf 的重要配置项说明

几项重要参数的说明如下,完整的配置项及其说明,可以通过以下命令查看官方手册: man vsftpd.conf

chroot_local_user
If set to YES, local users will be (by default) placed in a chroot() jail in their home directory after login. Warning: This option has security implications, especially if the users have upload permission, or shell access. Only enable if you know what you are doing. Note that these security implications are not vsftpd specific. They apply to all FTP daemons which offer to put local users in chroot() jails.
Default: NO
chroot_list_enable
If activated, you may provide a list of local users who are placed in a chroot() jail in their home directory upon login. The meaning is slightly different if chroot_local_user is set to YES. In this case, the list becomes a list of users which are NOT to be placed in a chroot() jail. By default, the file containing this list is /etc/vsftpd/chroot_list, but you may override this with the chroot_list_file setting.
Default: NO
chroot_list_file
The option is the name of a file containing a list of local users which will be placed in a chroot() jail in their home directory. This option is only relevant if the option chroot_list_enable is enabled. If the option chroot_local_user is enabled, then the list file becomes a list of users to NOT place in a chroot() jail.
Default: /etvsftpd.confc/vsftpd.chroot_list
allow_writeable_chroot
Allow chroot()'ing a user to a directory writable by that user. Note that setting this to YES is potentially dangerous. For example, if the user creates an 'etc' directory in the new root directory, they could potentially trick the C library into loading a user-created configuration file from the /etc/ directory.
Default: NO
local_root
This option represents a directory which vsftpd will try to change into after a local (i.e. non-anonymous) login. Failure is silently ignored.
Default: (none)
local_enable
Controls whether local logins are permitted or not. If enabled, normal user accounts in /etc/passwd (or wherever your PAM config references) may be used to log in. This must be enable for any non-anonymous login to work, including virtual users.
Default: NO
pasv_address
Use this option to override the IP address that vsftpd will advertise in response to the PASV command. Provide a numeric IP address, unless pasv_addr_resolve is enabled, in which case you can provide a hostname which will be DNS resolved for you at startup.
Default: (none - the address is taken from the incoming connected socket)

5 vsftpd 的使用

在确保服务端 vsftpd 配置正确,且正常启动的情况下,即可通过各种 ftp 客户端来使用 vsftpd。

image.png

以下截图展示了通过 wget 命令行下载 vsftpd 上指定文件:

image.png

在使用 FileZilla 图形客户端访问 aws ec2 中的 vsftpd 服务时,需要配置 active 和 passive 模式使用外网地址,如下如所示:

image.png

image.png

以下截图展示了通过 FileZilla 访问 vsftpd:

image.png

关于 FTP 的 ACTIVE 与 PASSIVE 模式,敬请期待下一篇博文。

相关文章
|
1月前
|
SQL 分布式计算 DataWorks
DataWorks常见问题之dataworks连接FTP服务器失败如何解决
DataWorks是阿里云提供的一站式大数据开发与管理平台,支持数据集成、数据开发、数据治理等功能;在本汇总中,我们梳理了DataWorks产品在使用过程中经常遇到的问题及解答,以助用户在数据处理和分析工作中提高效率,降低难度。
|
1月前
|
Java Maven
【开源视频联动物联网平台】J2mod库写一个Modbus RTU 服务器
【开源视频联动物联网平台】J2mod库写一个Modbus RTU 服务器
64 0
|
1月前
|
存储 网络协议 安全
如何搭建外网可访问的Serv-U FTP服务器,轻松远程共享文件!
如何搭建外网可访问的Serv-U FTP服务器,轻松远程共享文件!
|
1月前
|
Java API Maven
【开源视频联动物联网平台】JAIN-SIP库写一个SIP服务器
【开源视频联动物联网平台】JAIN-SIP库写一个SIP服务器
79 0
|
1月前
|
网络协议 Java
【开源视频联动物联网平台】J2mod库写一个Modbus TCP 服务器
【开源视频联动物联网平台】J2mod库写一个Modbus TCP 服务器
67 0
|
2月前
|
Java
java上传、下载、预览、删除ftp服务器上的文件
java上传、下载、预览、删除ftp服务器上的文件
|
2月前
|
弹性计算 缓存 负载均衡
ECS配置问题之FTP密码修改失败如何解决
ECS配置指的是对阿里云Elastic Compute Service(弹性计算服务)实例的硬件和软件资源进行设置的过程;本合集将详述如何选择合适的ECS配置、调整资源配比以及优化实例性能,以满足不同应用场景的需求。
|
3月前
|
Ubuntu 安全 网络安全
百度搜索:蓝易云【Ubuntu系统搭建FTP服务器教程】
现在,你已经成功在Ubuntu系统上搭建了FTP服务器。你可以使用FTP客户端连接到你的FTP服务器,并上传、下载文件。注意,为了安全起见,建议配置SSL/TLS加密以保护数据传输。
63 0
|
5月前
|
Unix Shell Linux
客户端如何查找FTP服务器的用户名和密码
客户端如何查找FTP服务器的用户名和密码
|
6月前
|
存储 网络协议 文件存储
手把手教你搭建Serv-U FTP服务器共享文件并实现外网远程访问「无公网IP」
手把手教你搭建Serv-U FTP服务器共享文件并实现外网远程访问「无公网IP」