最近公司有一個內部比賽(黑客馬拉松),報名參加了這麼一個賽事,在準備參賽做品的同時(參賽服務器須要本身搭建),藉着這個機會,決定把tomcat部署相關的知識從0到1從新捋一遍。就當備忘錄了。html
FTP服務器(File Transfer Protocol Server)是在互聯網上提供文件存儲和訪問服務的計算機,它們依照FTP協議提供服務。 FTP是File Transfer Protocol(文件傳輸協議)。顧名思義,就是專門用來傳輸文件的協議。簡單地說,支持FTP協議的服務器就是FTP服務器。linux
本文適用範圍win10系統鏈接虛擬機CentOS, 博主使用的是filezilla鏈接CentOS。如果其餘方式僅供參考。vim
確認虛擬機網絡鏈接方式tomcat
儘可能虛擬機和實體機在同一IP段,如實體機:192.168.122.1 虛擬機則:192.168.122.9安全
確保實體機和虛擬機的ip能夠互相ping通服務器
先查看你是否安裝了vsftpd網絡
rpm -q vsftpd
session
如上圖,則未安裝,若已安裝,則顯示例如 vsftpd-3.0.2-10.el7.x86_64app
未安裝那就安裝vsftpd異步
yum install -y vsftpd
如上圖,須要root權限
su root
而後輸入密碼,以下圖,設置root權限成功
而後繼續安裝yum install -y vsftpd
安裝完畢,以下圖。
查看到安裝的目錄whereis vsftpd
vsftpd目錄爲: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz
查看vsftpd服務的狀態systemctl status vsftpd.service
開啓vsftpd服務systemctl start vsftpd.service
開啓以後再查看vsftpd服務的狀態
設置vsftpd服務開機自啓systemctl enable vsftpd.service
防火牆添加FTP服務
systemctl enable firewalld
systemctl restart firewalld
firewall-cmd --permanent --zone=public --add-service=ftp
firewall-cmd --reload
firewall-cmd --reload
設置SELinux
getsebool -a | grep ftp
setsebool -P ftpd_full_access on
查看設置vi /etc/selinux/config
設置SELINUX=disabled
配置以前先備份cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf-bak
配置vsftpd.conf文件vim /etc/vsftpd/vsftpd.conf
推薦使用vim方式,vi方式配置文件註釋和實體沒有顏色區分,會看花眼的。
# 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.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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
#
# Activate logging of uploads/downloads.
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
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
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,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
中文版的(來源於網絡,侵權必刪):
# 是否容許匿名登陸FTP服務器,默認設置爲YES容許
# 用戶可以使用用戶名ftp或anonymous進行ftp登陸,口令爲用戶的E-mail地址。
# 如不容許匿名訪問則設置爲NO
anonymous_enable=YES
# 是否容許本地用戶(即linux系統中的用戶賬號)登陸FTP服務器,默認設置爲YES容許
# 本地用戶登陸後會進入用戶主目錄,而匿名用戶登陸後進入匿名用戶的下載目錄/var/ftp/pub
# 若只容許匿名用戶訪問,前面加上#註釋掉便可阻止本地用戶訪問FTP服務器
local_enable=YES
# 是否容許本地用戶對FTP服務器文件具備寫權限,默認設置爲YES容許
write_enable=YES
# 掩碼,本地用戶默認掩碼爲077
# 你能夠設置本地用戶的文件掩碼爲缺省022,也可根據我的喜愛將其設置爲其餘值
#local_umask=022
# 是否容許匿名用戶上傳文件,須將全局的write_enable=YES。默認爲YES
#anon_upload_enable=YES
# 是否容許匿名用戶建立新文件夾
#anon_mkdir_write_enable=YES
# 是否激活目錄歡迎信息功能
# 當用戶用CMD模式首次訪問服務器上某個目錄時,FTP服務器將顯示歡迎信息
# 默認狀況下,歡迎信息是經過該目錄下的.message文件得到的
# 此文件保存自定義的歡迎信息,由用戶本身創建
#dirmessage_enable=YES
# 是否讓系統自動維護上傳和下載的日誌文件
# 默認狀況該日誌文件爲/var/log/vsftpd.log,也能夠經過下面的xferlog_file選項對其進行設定
# 默認值爲NO
xferlog_enable=YES
# Make sure PORT transfer connections originate from port 20 (ftp-data).
# 是否設定FTP服務器將啓用FTP數據端口的鏈接請求
# ftp-data數據傳輸,21爲鏈接控制端口
connect_from_port_20=YES
# 設定是否容許改變上傳文件的屬主,與下面一個設定項配合使用
# 注意,不推薦使用root用戶上傳文件
#chown_uploads=YES
# 設置想要改變的上傳文件的屬主,若是須要,則輸入一個系統用戶名
# 能夠把上傳的文件都改爲root屬主。whoever:任何人
#chown_username=whoever
# 設定系統維護記錄FTP服務器上傳和下載狀況的日誌文件
# /var/log/vsftpd.log是默認的,也能夠另設其它
#xferlog_file=/var/log/vsftpd.log
# 是否以標準xferlog的格式書寫傳輸日誌文件
# 默認爲/var/log/xferlog,也能夠經過xferlog_file選項對其進行設定
# 默認值爲NO
#xferlog_std_format=YES
# 如下是附加配置,添加相應的選項將啓用相應的設置
# 是否生成兩個類似的日誌文件
# 默認在/var/log/xferlog和/var/log/vsftpd.log目錄下
# 前者是wu_ftpd類型的傳輸日誌,能夠利用標準日誌工具對其進行分析;後者是vsftpd類型的日誌
#dual_log_enable
# 是否將本來輸出到/var/log/vsftpd.log中的日誌,輸出到系統日誌
#syslog_enable
# 設置數據傳輸中斷間隔時間,此語句表示空閒的用戶會話中斷時間爲600秒
# 即當數據傳輸結束後,用戶鏈接FTP服務器的時間不該超過600秒。能夠根據實際狀況對該值進行修改
#idle_session_timeout=600
# 設置數據鏈接超時時間,該語句表示數據鏈接超時時間爲120秒,可根據實際狀況對其個修改
#data_connection_timeout=120
# 運行vsftpd須要的非特權系統用戶,缺省是nobody
#nopriv_user=ftpsecure
# 是否識別異步ABOR請求。
# 若是FTP client會下達「async ABOR」這個指令時,這個設定才須要啓用
# 而通常此設定並不安全,因此一般將其取消
#async_abor_enable=YES
# 是否以ASCII方式傳輸數據。默認狀況下,服務器會忽略ASCII方式的請求。
# 啓用此選項將容許服務器以ASCII方式傳輸數據
# 不過,這樣可能會致使由"SIZE /big/file"方式引發的DoS攻擊
#ascii_upload_enable=YES
#ascii_download_enable=YES
# 登陸FTP服務器時顯示的歡迎信息
# 若有須要,可在更改目錄歡迎信息的目錄下建立名爲.message的文件,並寫入歡迎信息保存後
#ftpd_banner=Welcome to blah FTP service.
# 黑名單設置。若是很討厭某些email address,就可使用此設定來取消他的登陸權限
# 能夠將某些特殊的email address抵擋住。
#deny_email_enable=YES
# 當上面的deny_email_enable=YES時,能夠利用這個設定項來規定哪些郵件地址不可登陸vsftpd服務器
# 此文件需用戶本身建立,一行一個email address便可
#banned_email_file=/etc/vsftpd/banned_emails
# 用戶登陸FTP服務器後是否具備訪問本身目錄之外的其餘文件的權限
# 設置爲YES時,用戶被鎖定在本身的home目錄中,vsftpd將在下面chroot_list_file選項值的位置尋找chroot_list文件
# 必須與下面的設置項配合
#chroot_list_enable=YES
# 被列入此文件的用戶,在登陸後將不能切換到本身目錄之外的其餘目錄
# 從而有利於FTP服務器的安全管理和隱私保護。此文件需本身創建
#chroot_list_file=/etc/vsftpd/chroot_list
# 是否容許遞歸查詢。默認爲關閉,以防止遠程用戶形成過量的I/O
#ls_recurse_enable=YES
# 是否容許監聽。
# 若是設置爲YES,則vsftpd將以獨立模式運行,由vsftpd本身監聽和處理IPv4端口的鏈接請求
listen=YES
# 設定是否支持IPV6。如要同時監聽IPv4和IPv6端口,
# 則必須運行兩套vsftpd,採用兩套配置文件
# 同時確保其中有一個監聽選項是被註釋掉的
#listen_ipv6=YES
# 設置PAM外掛模塊提供的認證服務所使用的配置文件名,即/etc/pam.d/vsftpd文件
# 此文件中file=/etc/vsftpd/ftpusers字段,說明了PAM模塊能抵擋的賬號內容來自文件/etc/vsftpd/ftpusers中
#pam_service_name=vsftpd
# 是否容許ftpusers文件中的用戶登陸FTP服務器,默認爲NO
# 若此項設爲YES,則user_list文件中的用戶容許登陸FTP服務器
# 而若是同時設置了userlist_deny=YES,則user_list文件中的用戶將不容許登陸FTP服務器,甚至連輸入密碼提示信息都沒有
#userlist_enable=YES/NO
# 設置是否阻扯user_list文件中的用戶登陸FTP服務器,默認爲YES
#userlist_deny=YES/NO
# 是否使用tcp_wrappers做爲主機訪問控制方式。
# tcp_wrappers能夠實現linux系統中網絡服務的基於主機地址的訪問控制
# 在/etc目錄中的hosts.allow和hosts.deny兩個文件用於設置tcp_wrappers的訪問控制
# 前者設置容許訪問記錄,後者設置拒絕訪問記錄。
# 如想限制某些主機對FTP服務器192.168.57.2的匿名訪問,編緝/etc/hosts.allow文件,如在下面增長兩行命令:
# vsftpd:192.168.57.1:DENY 和vsftpd:192.168.57.9:DENY
# 代表限制IP爲192.168.57.1/192.168.57.9主機訪問IP爲192.168.57.2的FTP服務器
# 此時FTP服務器雖能夠PING通,但沒法鏈接
tcp_wrappers=YES
編輯user_list文件,vim /etc/vsftpd/user_list
容許test用戶訪問FTP 注意下圖中默認UsRistListDebug
的設置。
默認狀況下能夠不編輯user_list文件。
按步驟操做之後,效果以下:
filezilla效果圖以下:
systemctl stop firewalld
(臨時關閉)或者systemctl disable firewalld
(禁止開機啓動)rpm -qa | grep telnet
yum install telnet-server
FTP數字代碼的意義
110 從新啓動標記應答。
120 服務在多久時間內ready。
125 數據鏈路端口開啓,準備傳送。
150 文件狀態正常,開啓數據鏈接端口。
200 命令執行成功。
202 命令執行失敗。
211 系統狀態或是系統求助響應。
212 目錄的狀態。
213 文件的狀態。
214 求助的訊息。
215 名稱系統類型。
220 新的聯機服務ready。
221 服務的控制鏈接端口關閉,能夠註銷。
225 數據連結開啓,但無傳輸動做。
226 關閉數據鏈接端口,請求的文件操做成功。
227 進入passive mode。
230 使用者登入。
250 請求的文件操做完成。
257 顯示目前的路徑名稱。
331 用戶名稱正確,須要密碼。
332 登入時須要帳號信息。
350 請求的操做須要進一部的命令。
421 沒法提供服務,關閉控制連結。
425 沒法開啓數據鏈路。
426 關閉聯機,終止傳輸。
450 請求的操做未執行。
451 命令終止:有本地的錯誤。
452 未執行命令:磁盤空間不足。
500 格式錯誤,沒法識別命令。
501 參數語法錯誤。
502 命令執行失敗。
503 命令順序錯誤。
504 命令所接的參數不正確。
530 未登入。
532 儲存文件須要帳戶登入。
550 未執行請求的操做。
551 請求的命令終止,類型未知。
552 請求的文件終止,儲存位溢出。
553 未執行請求的的命令,名稱不正確。
其餘參考資料:
做 者:請叫我頭頭哥
出 處:http://www.cnblogs.com/toutou/
關於做者:專一於基礎平臺的項目開發。若有問題或建議,請多多賜教!
版權聲明:本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出原文連接。
特此聲明:全部評論和私信都會在第一時間回覆。也歡迎園子的大大們指正錯誤,共同進步。或者直接私信我
聲援博主:若是您以爲文章對您有幫助,能夠點擊文章右下角【推薦】一下。您的鼓勵是做者堅持原創和持續寫做的最大動力!