Linux安裝部署FTP服務器


  本文章會將安裝FTP服務器的步驟以及一些遇到的問題來記錄下

  因為項目中要與第三方對接數據,需要用到FTP服務器以提供他們每天上傳數據,因為之前在本地的VMware虛擬機上部署過一次,這次則在天翼雲上部署。

  首先,我們執行安裝命令:yum install -y vsftpd

  

 

  執行后會自動下載,然后安裝,如下:

Loaded plugins: fastestmirror, security
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                                                                                                                                                                                                  | 3.7 kB     00:00     
extras                                                                                                                                                                                                                | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                                                     |  26 kB     00:00     
updates                                                                                                                                                                                                               | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                                                    | 1.9 MB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                 Arch                                                    Version                                                         Repository                                             Size
=============================================================================================================================================================================================================================================
Installing:
 vsftpd                                                  x86_64                                                  2.2.2-24.el6                                                    base                                                  156 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install       1 Package(s)

Total download size: 156 k
Installed size: 340 k
Downloading Packages:
vsftpd-2.2.2-24.el6.x86_64.rpm                                                                                                                                                                                        | 156 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vsftpd-2.2.2-24.el6.x86_64                                                                                                                                                                                                1/1 
  Verifying  : vsftpd-2.2.2-24.el6.x86_64                                                                                                                                                                                                1/1 

Installed:
  vsftpd.x86_64 0:2.2.2-24.el6                                                                                                                                                                                                               

Complete!

  以上就代表安裝成功了!

 

  安裝成功后我們進入FTP文件夾查看是否有問題,FTP在Linux上名稱為 vsftpd ,默認安裝在  /etc/vsftpd 目錄下;

 

  執行:  命令,進入FTP文件夾中查看文件,會看有四個文件,如下:

-rw------- 1 root root  125 Mar 22  2017 ftpusers  黑名單文件,此文件里的用戶不允許訪問 FTP 服務器
-rw------- 1 root root  361 Mar 22  2017 user_list  白名單文件,是允許訪問 FTP 服務器的用戶列表
-rw------- 1 root root 4599 Mar 22  2017 vsftpd.conf  核心配置文件
-rwxr--r-- 1 root root  338 Mar 22  2017 vsftpd_conf_migrate.sh  FTP服務

 

  安裝完成之后先不要着急配置,我們先給Linux系統添加一個用戶,一個登錄FTP服務器的用戶;

  執行  命令,創建一個 ftpuser 的用戶,

  執行 命令,修改此用戶的密碼。

  

  這里需要限制FTP登錄的人數,我們進入 vsftpd 目錄下的 user_list 中修改,如下:

# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root  
ftpuser

  user_list 里面的內容是能夠登錄FTP的用戶列表,若是不想讓其他用戶登錄,則刪除該文件內的其他用戶名,僅保留我們剛才創建的一個用戶(root為系統管理員,若是不需要也可以刪除)。

 

  完成以上步驟我們接下來要配置 vsftpd.conf 這個核心文件,下面是該文件里的內容:

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,

  此配置我們僅需要修改一個地方,就是匿名用戶登錄的時候將其禁止,然后指定FTP根目錄就行了,其他的也可以自行查找網上的一些方式來配置。

  修改: 改為  NO,禁止匿名用戶訪問。

  新增:  指定用戶訪問主目錄(FTP文件存放目錄)。

  但是目前沒有這個文件夾,所以我們需要創建這個文件夾,命令: 

  然后更改目錄訪問用戶,命令:

 

  需要注意的是:當是從阿里雲或者天翼雲上部署FTP的時候,當部署完畢之后一定要開放你的端口規則,不然你是無法訪問默認端口的(也就是你無法訪問FTP服務器,默認端口為21,20)!!!

 

   

  

  使用filezilla連接試試,我出現了如下問題:

 

  

  這是FTP的主動模式和被動模式造成的,所以我選擇了一個很簡單的方式來解決:如下

   

 

   登錄成功了,然后又出現了一個新的問題:

  

  在防火牆內開放 21 端口即可,如下:

   

  再訪問,就好了:

  

  FTP就部署完成了,其實部署過程中很多坎坷,所以一定要多思考,路漫漫其修遠兮!

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM