1. 程式人生 > >第二十五課預習任務

第二十五課預習任務

特殊 這就是 ftp 權限 文件 影響 intern per 軟件 spa

14.1 NFS介紹
14.2 NFS服務端安裝配置
14.3 NFS配置選項
14.4 exportfs命令
14.5 NFS客戶端問題
15.1 FTP介紹
15.2/15.3 使用vsftpd搭建ftp
15.4 xshell使用xftp傳輸文件
15.5 使用pure-ftpd搭建ftp服務
擴展
vsftp使用mysql存放虛擬用戶並驗證 http://www.aminglinux.com/bbs/thread-342-1-1.html
ftp的主動和被動模式 http://www.aminglinux.com/bbs/thread-961-1-1.html

14.1 NFS介紹

NFS是Network File System的縮寫

NFS最早由Sun公司開發,分2,3,4三個版本,2和3由Sun起草開發,4.0開始Netapp公司參與並主導開發,最新為4.1版本

NFS數據傳輸基於RPC協議,RPC為Remote Procedure Call的簡寫。

NFS應用場景是:A,B,C三臺機器上需要保證被訪問到的文件是一樣的,A共享數據出來,B和C分別去掛載A共享的數據目錄,從而B和C訪問到的數據和A上的一致

NFS架構

技術分享圖片

是網絡層次的,用的挺多的 ,開發更新版本沒我們想象的那麽快,

為了分擔A的負載 所以加了B C ,這樣用戶可能請求到B 或C ,怎麽才可以從B 得到A的數據呢,

一個是 A數據傳到BC,這個辦法可能沒有實時的更新,那麽Nfs 服務就是解決這個問題 ,A數據工具分享給BC

A上更新文件BC很快就看到 , B上更新文件 AC也很快看到

NFS原理圖

技術分享圖片

現在是rpcbind 實現的, 之前centos 5之前我們叫portmap,其實是一個東西,通過啟動這個服務實現了tcp/ip 協議通信,

默認NFS不會監聽任何端口,雖然啟動服務 , 最終監聽端口是rpcbind, 會監聽111端口, TCP兩個先通信 ,

NFS會通過rpcbind 註冊一個端口比如某某某端口 ,NFS 告訴RPC通信的端口是什麽 ,然後告訴客戶端的RPC

總之NFS數據傳輸基於RPC協議

14.2 NFS服務端安裝配置

yum install -y nfs-utils rpcbind

vim /etc/exports //加入如下內容

/home/nfstestdir 192.168.133.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

保存配置文件後,執行如下準備操作

mkdir /home/nfstestdir

chmod 777 /home/nfstestdir

systemctl start rpcbind

systemctl start nfs

systemctl enable rpcbind

systemctl enable nfs

首先準備兩臺機器一個服務端 一個客戶端

首先看下IP

[root@linux01 ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.253.143

[root@linux02 ~]# ifconfig

ens37: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.253.144

inet 192.168.253.143 作為服務端安裝兩個包

[root@linux01 ~]# yum install -y nfs-utils rpcbind

而客戶端也需要

[root@linux02 ~]# yum install -y nfs-utils

每次剛開機yum 時候都比較慢,因為要生成一個緩沖文件,我們再安裝 nfs-utils時候他也會把rpcbind 裝上,所以寫不寫都會幫你安裝上,如果yum 很卡,可以先禁掉 ,怎樣禁掉呢下面

[root@linux01 ~]# cd /etc/yum.repos.d/

[root@linux01 yum.repos.d]# ls

CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo

CentOS-CR.repo CentOS-Media.repo epel.repo

CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo

[root@linux01 yum.repos.d]# mv epel.repo epel.repo.1^C 因為我這不卡所以沒改名字

[root@linux01 ~]# vim /etc/exports 在服務端上 ,編輯添加兩端 , 保證A機器和B機器最終數據一致 ,那說的是哪個目錄的數據一致,分享的目錄 要共享和的服務器IP(特殊的選項)

/home/nfstestdir 192.168.253.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

~

[root@linux01 yum.repos.d]# mkdir /home/nfstestdir

[root@linux01 yum.repos.d]# chmod 777 /home/nfstestdir

之所以改成777的權限是為了一會做實驗

我的兩臺都是沒有啟動rpcbind

[root@linux01 ~]# netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 896/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1329/master

tcp 0 0 192.168.253.143:8730 0.0.0.0:* LISTEN 93924/rsync

tcp6 0 0 :::80 :::* LISTEN 96749/httpd

tcp6 0 0 :::22 :::* LISTEN 896/sshd

tcp6 0 0 ::1:25 :::* LISTEN 1329/master

老師的

技術分享圖片

技術分享圖片

這時候老師的rpcbind 已經啟動另外 ,兩個的名稱還有個是systemd,這可能是因為centos7的原因

我的沒啟動,應該按照完就啟動的 端口是111

所以我的是

[root@linux02 ~]# ps aux |grep rpc

root 5281 0.0 0.0 112724 960 pts/1 R+ 21:57 0:00 grep --color=auto rpc

老師的,因為有個服務所以監聽了111端口

技術分享圖片

[root@linux01 ~]# systemctl start nfs 啟動NFS後

[root@linux01 ~]# ps aux |grep nfs

root 114514 0.0 0.0 0 0 ? S< 21:59 0:00 [nfsd4_callbacks]

root 114520 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114521 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114522 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114523 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114524 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114525 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114526 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114527 0.0 0.0 0 0 ? S 21:59 0:00 [nfsd]

root 114531 0.0 0.0 112724 964 pts/0 R+ 21:59 0:00 grep --color=auto nfs

[root@linux01 ~]# ps aux |grep rpc 實際啟動nfs時候也會啟動rpc相關的服務

root 114485 0.0 0.0 0 0 ? S< 21:59 0:00 [rpciod]

rpcuser 114488 0.0 0.1 42424 1756 ? Ss 21:59 0:00 /usr/sbin/rpc.statd

rpc 114492 0.0 0.1 65008 1340 ? Ss 21:59 0:00 /sbin/rpcbind -w

root 114493 0.0 0.0 42608 940 ? Ss 21:59 0:00 /usr/sbin/rpc.mountd

root 114504 0.0 0.0 43868 540 ? Ss 21:59 0:00 /usr/sbin/rpc.idmapd

root 114533 0.0 0.0 112724 960 pts/0 R+ 22:00 0:00 grep --color=auto rpc

如果想rpc ,nfs 開機就啟動 需要執行

[root@linux01 ~]# systemctl enable nfs

Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.

[root@linux01 ~]# systemctl enable rpcbind

一會再客戶端上演示,在演示之前看下nfs掛載的選項

14.3 NFS配置選項

rw 讀寫

ro 只讀

sync 同步模式,內存數據實時寫入磁盤 ,這樣就會相應的降低磁盤的效率

async 非同步模式 ,隔一段時間把內存數據刷到磁盤,好處是增加磁盤效率,不好處是斷電會丟一小部分數據

no_root_squash 客戶端掛載NFS共享目錄後,root用戶不受約束,權限很大,如果客戶端像用服務端的一個共享目錄,需要掛在到客戶端上一個掛載點,就和本地目錄一樣的,操作本地這個目錄 如果用root用戶就不受限制,相當於root用戶在本地磁盤讀寫。

root_squash 與上面選項相對,客戶端上的root用戶收到約束,被限定成某個普通用戶 ,如果切換到掛載的目錄下,就不是root用戶了

all_squash 客戶端上所有用戶在使用NFS共享目錄時都被限定為一個普通用戶

anonuid/anongid 和上面幾個選項搭配使用,定義被限定用戶的uid和gid

yum install -y nfs-utils

showmount -e 192.168.133.130 //該ip為NFS服務端ip

mount -t nfs 192.168.133.130:/home/nfstestdir /mnt

df -h

touch /mnt/aminglinux.txt

ls -l /mnt/aminglinux.txt //可以看到文件的屬主和屬組都為1000

[root@linux01 ~]# vim /etc/exports

/home/nfstestdir 192.168.253.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

~

現在客戶端上做個掛載 ,我的開始是沒問題的

[root@linux02 ~]# showmount -e 192.168.253.143

Export list for 192.168.253.143:

/home/nfstestdir 192.168.253.0/24

老師的報錯了可能由於網絡問題,AB機器不能互連

看下A上服務端監聽的端口是有111的

[root@linux01 ~]# netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:37162 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 114492/rpcbind

tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 114493/rpc.mountd

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 896/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1329/master

tcp 0 0 192.168.253.143:8730 0.0.0.0:* LISTEN 93924/rsync

tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:36198 0.0.0.0:* LISTEN 114488/rpc.statd

tcp6 0 0 :::34958 :::* LISTEN 114488/rpc.statd

tcp6 0 0 :::111 :::* LISTEN 114492/rpcbind

雖然RPC可以通信了,但NFS 比較特殊,他們用了不固定的端口 ,此時可能是由於防火墻導致 所以先關下

[root@linux01 ~]# systemctl stop firwalld

Failed to stop firwalld.service: Unit firwalld.service not loaded.

[root@linux01 ~]# getenforce

Enforcing

[root@linux01 ~]# setenforce 0

[root@linux01 ~]#

[root@linux02 ~]# systemctl stop firwalld

Failed to stop firwalld.service: Unit firwalld.service not loaded.

[root@linux02 ~]# getenforce

Enforcing

[root@linux02 ~]# setenforce 0

[root@linux02 ~]# getenforce

Permissive

showmount 就可以了

在客戶端上

[root@linux02 ~]# mount -t nfs 192.168.253.143:/home/nfstestdir /mnt/ 規定掛載類型nfs類型 ,掛載的服務端IP:/路徑 掛載到哪裏

[root@linux02 ~]# df -h

文件系統 容量 已用 可用 已用% 掛載點

/dev/sda3 18G 3.5G 15G 20% /

devtmpfs 479M 0 479M 0% /dev

tmpfs 489M 0 489M 0% /dev/shm

tmpfs 489M 6.8M 482M 2% /run

tmpfs 489M 0 489M 0% /sys/fs/cgroup

/dev/sda1 197M 109M 88M 56% /boot

tmpfs 98M 0 98M 0% /run/user/0

192.168.253.143:/home/nfstestdir 18G 6.1G 12G 35% /mnt 這就是遠程服務端共享的目錄,

[root@linux02 ~]# cd /mnt/ 在客戶端上 建文件 然後看服務端有沒有更新

[root@linux02 mnt]# touch 111.test

[root@linux02 mnt]# ls -l

總用量 0

-rw-r--r--. 1 mysql mysql 0 10月 8 22:25 111.test

結果是有的也創建了相同的文件

[root@linux01 ~]# ls -l /home/nfstestdir/

總用量 0

-rw-r--r--. 1 mysql mysql 0 10月 8 22:25 111.test

老師的結果創建的用戶是不一樣的 ,客戶端是mysql 。服務端是aming 用戶

原來是配置文件導致的,一旦掛載來了服務端的文件,物理用那個用戶操作,最終會以1000 UID,1000gid創建文件目錄。

/home/nfstestdir 192.168.253.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

而我的

[root@linux01 ~]# cat /etc/passwd 正好都是MySQL用戶1000

chrony:x:997:995::/var/lib/chrony:/sbin/nologin

mysql:x:1000:1000::/home/mysql:/bin/bash

或者這樣看

[root@linux01 ~]# id mysql

uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)

[root@linux02 mnt]# id mysql

uid=1000(mysql) gid=1000(mysql) 組=1000(mysql)

就是因為我們限定了用戶

14.4 exportfs命令

常用選項

-a 全部掛載或者全部卸載

-r 重新掛載

-u 卸載某一個目錄

-v 顯示共享目錄

以下操作在服務端上

vim /etc/exports //增加

/tmp/ 192.168.133.0/24(rw,sync,no_root_squash)

exportfs -arv //不用重啟nfs服務,配置文件就會生效

以下操作在客戶端

mkdir /aminglinux

mount -t nfs -onolock 192.168.133.130:/tmp /aminglinux

touch /aminglinux/test.txt

ls -l !$

-oremount,nfsvers=3

exportfs 這個命令實際和nfs-utils 一起安裝的 ,假如第一次配置NFS共享目錄,過段時間我們需要增加機器或增加共享目錄

此時需要更改配置文件,重啟NFS服務等,如果遠程客戶端正在使用掛載NFS服務的話, 如果先停止NFS服務的話,遠程的客戶端就會先掛起,這個影響還是蠻大的,

加入A共享目錄,B讀寫這個目錄,如果A停掉了,B正在掛載這A目錄,服務都停了,B肯定不能正常訪問A掛載的目錄。此時如果B服務器讀寫非常頻繁,會使B讀寫共享文件的進程(Nginx,Apache等)就會掛起,最早學過ps aux 查看進程狀態時候,有個進程狀態D,D就是進程不能中斷, 就會變成D,那麽B進程就不正常了,殺也殺不死,重啟也重啟不了。會把機器搞死 ,所以NFS不能隨便重啟, 如果分要重啟,先把 B或C掛載的目錄卸載下來,

[root@linux02 mnt]# umount /mnt 卸載

umount.nfs4: /mnt: device is busy

出現這種情況兩種解決辦法

[root@linux02 mnt]# umount -l /mnt 或cd 退出來再umount /mnt

[root@linux02 mnt]# cd

[root@linux02 ~]# df -h

文件系統 容量 已用 可用 已用% 掛載點

/dev/sda3 18G 3.5G 15G 20% /

devtmpfs 479M 0 479M 0% /dev

tmpfs 489M 0 489M 0% /dev/shm

tmpfs 489M 6.8M 482M 2% /run

tmpfs 489M 0 489M 0% /sys/fs/cgroup

/dev/sda1 197M 109M 88M 56% /boot

tmpfs 98M 0 98M 0% /run/user/0

如果掛載了幾十臺機器,一臺臺卸載太麻煩了,我們就可以用exportfs

所以我們會一般這樣用

[root@linux01 ~]# exportfs -arv

exporting 192.168.253.0/24:/home/nfstestdir

上面會讓配置文件重新生效 ,可以試驗下

[root@linux01 ~]# vim /etc/exports

/home/nfstestdir 192.168.253.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)

/tmp 192.168.253.144 (rw,sync,no_root_squash)

[root@linux01 ~]# exportfs -arv

exportfs: No options for /tmp 192.168.253.144: suggest 192.168.253.144(sync) to avoid warning

exportfs: No host name given with /tmp (rw,sync,no_root_squash), suggest *(rw,sync,no_root_squash) to avoid warning

exporting 192.168.253.144:/tmp

exporting 192.168.253.0/24:/home/nfstestdir

exporting *:/tmp

[root@linux02 ~]# showmount -e 192.168.253.143 並沒重啟也生效了

Export list for 192.168.253.143:

/home/nfstestdir 192.168.253.0/24

/tmp/ (everyone)

[root@linux02 ~]# mount -t nfs 192.168.253.143:/tmp/ /mnt/

[root@linux02 ~]# df -h

文件系統 容量 已用 可用 已用% 掛載點

/dev/sda3 18G 3.5G 15G 20% /

devtmpfs 479M 0 479M 0% /dev

tmpfs 489M 0 489M 0% /dev/shm

tmpfs 489M 6.8M 482M 2% /run

tmpfs 489M 0 489M 0% /sys/fs/cgroup

/dev/sda1 197M 109M 88M 56% /boot

tmpfs 98M 0 98M 0% /run/user/0

192.168.253.143:/tmp 18G 6.1G 12G 35% /mnt

[root@linux02 ~]# ls /mnt/

111.back

123.txt

1.txt

php_errors.log

rsync

systemd-private-e042408672ad43509447474a6c527839-vmtoolsd.service-8C3IHP

zhang

現在 兩個目錄一樣文件

[root@linux01 ~]# ls /tmp/

111.back

123.txt

1.txt

php_errors.log

rsync

systemd-private-e042408672ad43509447474a6c527839-vmtoolsd.service-8C3IHP

zhang

[root@linux01 ~]# vim /tmp/8.txt

[root@linux01 ~]# ls -l /tmp/

總用量 20

drwxr-xr-x. 2 root root 32 10月 2 17:08 111.back

-rw-r--r--. 1 root root 1049 9月 22 17:08 123.txt

-rw-r--r--. 1 root root 1049 9月 22 17:08 1.txt

-rw-r--r--. 1 root root 11 10月 8 23:03 8.txt

[root@linux02 ~]# ls -l /mnt/

總用量 20

drwxr-xr-x. 2 root root 32 10月 2 17:08 111.back

-rw-r--r--. 1 root root 1049 9月 22 17:08 123.txt

-rw-r--r--. 1 root root 1049 9月 22 17:08 1.txt

-rw-r--r--. 1 root root 11 10月 8 23:03 8.txt

8.txt都是root用戶

通常我們不限制用戶的情況多

14.5 NFS客戶端問題

客戶端文件屬主屬組nobody

NFS 4版本會有該問題

客戶端掛載共享目錄後,不管是root用戶還是普通用戶,創建新文件時屬主、屬組為nobody

解決上面問題 第一個 客戶端掛載時加上 -o nfsvers=3 指定NFS版本為3 也就是不是4了

客戶端和服務端都需要

第二種辦法是 vim /etc/idmapd.conf //

“#Domain = local.domain.edu” 改為 “Domain = xxx.com” (這裏的xxx.com,隨意定義吧),然後再重啟rpcidmapd服務

centos 6時候遇到比較多,不是每次都有,偶爾會出現

[root@linux02 ~]# mount -t nfs -o nfsvers=3 192.168.253.143:/tmp/ /mnt/

[root@linux02 ~]# mount -t nfs -oremount,fsvers=3 192.168.253.143:/tmp/ /mnt/

centos7裏面是沒有rpc這個服務的 那重啟什麽呢 重啟rpcidmapd 就可以了

15.1 FTP介紹

FTP是File Transfer Protocol(文件傳輸協議,簡稱文傳協議)的英文簡稱,用於在Internet上控制文件的雙向傳輸。

FTP的主要作用就是讓用戶連接一個遠程計算機(這些計算機上運行著FTP服務器程序),並查看遠程計算機中的文件,然後把文件從遠程計算機復制到本地計算機,或把本地計算機的文件傳送到遠程計算機。

小公司用的多,大企業不用FTP,因為不安全 ,大公司 使用自動化發布的工具,不規範 所以 GIT 版本管理工具,

之前講過rz sz 這個命令是widows Linux互相傳文件的 ,但遇到文件比較大,就不好使了,或用阿裏雲 一臺機器調到另外一臺機器時候也不好使

所以FTP就可以, 在Linux搭建一個服務, widows安裝一個軟件 就可以連到服務端,互相傳

15.2 使用vsftpd搭建ftp服務(上)

centos上自帶vsftpd

yum install -y vsftpd

useradd -s /sbin/nologin virftp

vim /etc/vsftpd/vsftpd_login //內容如下,奇數行為用戶名,偶數行為密碼,多個用戶就寫多行

testuser1

aminglinux

chmod 600 /etc/vsftpd/vsftpd_login

db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db

mkdir /etc/vsftpd/vsftpd_user_conf

cd /etc/vsftpd/vsftpd_user_conf

vim testuser1 //加入如下內容

local_root=/home/virftp/testuser1

anonymous_enable=NO

write_enable=YES

local_umask=022

anon_upload_enable=NO

anon_mkdir_write_enable=NO

idle_session_timeout=600

data_connection_timeout=120

max_clients=10

mkdir /home/virftp/testuser1

touch /home/virftp/testuser1/aming.txt

chown -R virftp:virftp /home/virftp

vim /etc/pam.d/vsftpd //在最前面加上

auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

vim /etc/vsftpd/vsftpd.conf

anonymous_enable=YES 改為 anonymous_enable=NO

#anon_upload_enable=YES 改為 anon_upload_enable=NO

#anon_mkdir_write_enable=YES 改為 anon_mkdir_write_enable=NO

再增加如下內容

chroot_local_user=YES

guest_enable=YES

guest_username=virftp

virtual_use_local_privs=YES

user_config_dir=/etc/vsftpd/vsftpd_user_conf

allow_writeable_chroot=YES

systemctl start vsftpd //啟動vsftpd服務

vsftpd 這個軟件包 可以使用系統級別的用戶,假如創建了普通用AA,設置一個密碼,這時候可以用vsftpd 啟動這個用戶,用AA登錄,只不過登錄的形式是ftp

登錄後進入AA家目錄下,這樣有點不安全,我們設置用戶 密碼是登錄系統的,所以我們設置一個用戶 虛擬用戶,映射成系統裏面的一個普通用戶,可以映射多個用戶,

即使給了用戶名密碼也不會登錄我們的系統的,比較安全

[root@linux01 ~]# useradd -s /sbin/nologin virftp 創建這個用戶就是我們以哪個用戶傳下載啊 -s 是用戶的shell ,不能登錄 ,

虛擬用戶的密碼文件, 定義用戶名和密碼,格式比較特殊 奇數行為用戶名,偶數行為密碼

[root@linux01 ~]# vim /etc/vsftpd/vsftpd_login

test1

12345678

user1

12345678

[root@linux01 ~]# chmod 600 /etc/vsftpd/vsftpd_login

[root@linux01 ~]# db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db

[root@linux01 ~]# ls -l /etc/vsftpd/

總用量 36

-rw-------. 1 root root 125 8月 3 2017 ftpusers

-rw-------. 1 root root 361 8月 3 2017 user_list

-rw-------. 1 root root 5030 8月 3 2017 vsftpd.conf

-rwxr--r--. 1 root root 338 8月 3 2017 vsftpd_conf_migrate.sh

-rw-------. 1 root root 30 10月 8 23:32 vsftpd_login

-rw-r--r--. 1 root root 12288 10月 8 23:33 vsftpd_login.db

密碼文件是不能直接cat的,

創建虛擬用戶 所在配置文件路徑

[root@linux01 ~]# mkdir /etc/vsftpd/vsftpd_user_conf

[root@linux01 ~]# cd /etc/vsftpd/vsftpd_user_conf

創建配置文件有點特殊,如果給test1用戶創建配置文件名字就叫test1

[root@linux01 vsftpd_user_conf]# vim test1

local_root=/home/virftp/test1 虛擬用戶的家目錄,得知道在哪個目錄傳文件

anonymous_enable=NO --是否允許匿名用戶

write_enable=YES 是否可寫

local_umask=022 新目錄新文件的權限

anon_upload_enable=NO 是否允許匿名用戶可上傳

anon_mkdir_write_enable=NO 是否允許匿名用戶可創建目錄並且寫

idle_session_timeout=600 連文件空閑時間段

data_connection_timeout=120 數據傳輸的超時時間

max_clients=10 最大的客戶端是多少

定義完虛擬用戶的配置文件後,我們在創建虛擬用戶的家目錄

[root@linux01 vsftpd_user_conf]# mkdir /home/virftp/test1

[root@linux01 vsftpd_user_conf]# touch /home/virftp/test1/test1.txt 然後創建一個文件 我們登錄的時候就可以看到這個文件

[root@linux01 vsftpd_user_conf]# chown -R virftp:virftp /home/virftp 權限設置

[root@linux01 vsftpd_user_conf]# vim /etc/pam.d/vsftpd 用戶的密碼文件認證的文件,可以自定義,但要讓系統指定自定義到哪裏,去哪裏找,,登錄ftp 得有個過程,總得有個庫比對

[root@linux01 vsftpd_user_conf]# vim /etc/pam.d/vsftpd

#%PAM-1.0

auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login

account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login 增加這兩行

session optional pam_keyinit.so force revoke

auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

auth required pam_shells.so

auth include password-auth

account include password-auth

session required pam_loginuid.so

session include password-auth

在 /lib64/security/pam_userdb.so db centos6時候分32為64為的,要看是哪一種 ,如果導致文件不存在,用戶名密碼再對也沒辦法完成認證

[root@linux01 vsftpd_user_conf]# vim /etc/vsftpd/vsftpd.conf 最大的配置文件

anonymous_enable=NO

anon_upload_enable=NO

anon_mkdir_write_enable=NO

最後增加幾行

chroot_local_user=YES

guest_enable=YES 既然guest_username 生效就得找個是yes

guest_username=virftp 映射到哪個用戶呢

virtual_use_local_privs=YES 告訴服務我們用的是虛擬用戶

user_config_dir=/etc/vsftpd/vsftpd_user_conf 虛擬用戶配置文件所在的路徑

allow_writeable_chroot=YES

[root@linux01 vsftpd_user_conf]# systemctl start vsftpd

[root@linux01 vsftpd_user_conf]# ps aux |grep vsftp

root 114713 0.0 0.0 53260 576 ? Ss 23:53 0:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

root 114715 0.0 0.0 112724 964 pts/0 S+ 23:53 0:00 grep --color=auto vsftp

[root@linux01 vsftpd_user_conf]# netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:37162 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 114492/rpcbind

tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 114493/rpc.mountd

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 896/sshd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1329/master

tcp 0 0 192.168.253.143:8730 0.0.0.0:* LISTEN 93924/rsync

tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -

tcp 0 0 0.0.0.0:36198 0.0.0.0:* LISTEN 114488/rpc.statd

tcp6 0 0 :::34958 :::* LISTEN 114488/rpc.statd

tcp6 0 0 :::111 :::* LISTEN 114492/rpcbind

tcp6 0 0 :::20048 :::* LISTEN 114493/rpc.mountd

tcp6 0 0 :::80 :::* LISTEN 96749/httpd

tcp6 0 0 :::21 :::* LISTEN 114713/vsftpd

tcp6 0 0 :::36085 :::* LISTEN -

tcp6 0 0 :::22 :::* LISTEN 896/sshd

tcp6 0 0 ::1:25 :::* LISTEN 1329/master

tcp6 0 0 :::2049 :::* LISTEN -

21 FTP ,22 sshd, 23 TELNET 端口

15.3 使用vsftpd搭建ftp服務(下)

yum install -y lftp

lftp [email protected]

執行命令ls,看是否正常輸出

若不正常查看日誌/var/log/messages和/var/log/secure

windows下安裝filezilla客戶端軟件,進行測試

15.4 xshell使用xftp傳輸文件

在xshell按快捷鍵 ctrl+alt+f ,會自動彈出一個xftp的提示下載界面

進入到下載界面

選擇下載以後,會進入一個填寫資料的頁面,上面的是免費的,下面的收費的,我們選擇一個填寫資料

郵箱項,很重要。因為會在你的郵箱裏有下載地址和使用教程,是通過郵箱發送,而且最好使用一些比較權威的郵箱;如果是qq郵箱國外發送郵件會有一些延遲;

獲取到下載地址開始下載,就可以直接下載了

下載完成後,直接默認安裝,就可以使用了,這時再使用xshell登錄主機,按下ctrl+alt+f;就會彈出一個xftp的頁面

打開之後會進入到root目錄下,使用的是ssh協議

這時在虛擬機上暫停掉21端口,會發現仍然可以傳輸文件

若是需要下載linux系統裏的文件,只需雙擊,或者直接拖動到左邊(桌面)就會有下載的文件

15.5 使用pure-ftpd搭建ftp服務

yum install -y epel-release

yum install -y pure-ftpd

vim /etc/pure-ftpd/pure-ftpd.conf//找到pureftpd.pdb這行,把行首的#刪除

systemctl stop vsftpd

systemctl start pure-ftpd

mkdir /data/ftp

useradd -u 1010 pure-ftp

chown -R pure-ftp:pure-ftp /data/ftp

pure-pw useradd ftp_usera -u pure-ftp -d /data/ftp

pure-pw mkdb

pure-pw list/userdel/usermod/passwd

第二十五課預習任務