天天看點

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

計算機網絡的功能:資料通信,資源共享,增加可靠性,提供系統處理能力。本文主要分享在生活和工作經常使用的資源共享方法。在nfs,ftp,samab中,其中下載下傳速度或者說性能最好的是nfs,其次ftp,最後samba。

注:所有伺服器開始服務的過程:裝包-->配置---->啟服務,nfs,ftp,samba也是這樣的過程。啟動服務前把firewall和selinux關閉。

(File Transfer Protocl)檔案傳輸協定

工作模式:主動工作模式和被動工作模式

是否可跨平台:是 linux,windows

軟體包:vsftpd

]# yum -y install vsftpd

協定和端口号:tcp 21/20

預設共享目錄:/var/ftp/

配置檔案:/etc/vsftpd/vsftpd.conf

啟動服務:systemctl start vsftpd //啟動服務

systemctl enable vsftpd //開機自啟

驗證服務:

linux用戶端:

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!
linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!
linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

基本功能實作。

以下是擴充:(有興趣可以浏覽)

小技巧分享:

]# ps -C vsftpd //檢視程序是否起來

]# ss -anptu | grep vsftpd //檢視網絡連結狀态

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

出現上圖就說明服務已經起來了。

]# rpm -qc vsftpd //如果不知配置檔案可以找到配置檔案的位置,适合rpm和yum安裝軟體

]# cat /etc/services |grep ftp //如果不知道協定和端口号,可以用這樣查找

windows用戶端:

在浏覽器或者點選我的電腦位址欄輸入共享位址:

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

FTP(檔案傳輸協定)是TCP/IP協定棧所提供的一種子協定,該子協定具體可以實作在以下功能:

從客戶向伺服器發送一個檔案

從伺服器向客戶發送一個檔案

從伺服器向客戶發送檔案或目錄清單

此外可以通過修改/var/ftp/下目錄或者檔案的權限,來控制通路者有什麼權限!

Linux 中常用的 FTP 用戶端軟體有 lftp, ftp, lftpget, wget, curl 等。Windows 中可以使用浏覽器,資料總管或 Filezilla 等軟體。

(Network File system)網絡檔案系統

是否可跨平台:否 linux

軟體包:nfs-utils

]# yum -y install nfs-utils

協定和端口号:tcp/udp 2049

預設共享目錄:沒有預設共享目錄,需要指定共享目錄

配置檔案:/etc/exports

配置檔案内容:

]# vim /etc/exports

/content/ 192.168.1.0/24(ro) //對192.168.1.0/24共享/content目錄讀權限

/share 192.168.2.0/24(rw) //對192.168.2.0/24共享/share目錄 有讀寫權限

啟動服務:systemctl restart nfs //開啟服務

systemctl enable nfs //開機自啟

服務端:(出現如下内容說明成功)

]# exportfs -rv

exporting 192.168.1.0/24:/content

exporting 192.168.2.0/24:/share

用戶端:

]# mkdir /share //建立挂載點目錄(可以是任意)

]# vim /etc/fstab //開機自動挂載配置檔案

192.168.2.254:/share /share nfs _netdev 0 0

目标主機位址:檔案夾路徑 本機挂載點 nsf defaults,_netdev 0 0

]# mount -a //有報錯的可能,檢視/etc/fstab内容,然後在執行

]# showmount -e 192.168.2.254

Export list for 192.168.2.254:

/share 192.168.2.0/24

/content 192.168.1.0/24

在伺服器的共享目錄下放檔案,在客戶機就可以檢視了。

此處理論:(有興趣可以看)

NFS 全稱是 Network FileSystem,NFS 和其他檔案系統一樣,是在 Linux 核心中實作的,是以 NFS 很難做到與 Windows 相容。

NFS 的實作使用了 RPC(Remote Procedure Call) 的機制,遠端過程調用使得用戶端可以調用服務端的函數。由于有 VFS 的存在,用戶端可以像使用其他普通檔案系統一樣使用 NFS 檔案系統,由作業系統核心将 NFS 檔案系統的調用請求通過 TCP/IP 發送至服務端的 NFS 服務,執行相關的操作,之後服務端再講操作結果傳回用戶端。

SMB(Server Messages Blocak) 資訊服務塊

服務端:

軟體包:samba

]# yum -y install samba

協定和端口号:tcp139/445 udp137/138

注:詳細的協定和端口參考以下連接配接

https://blog.csdn.net/wangsifu2009/article/details/6780749

配置檔案:/etc/samba/smb.conf

啟動服務:systemctl restart smb //開啟服務

systemctl enable smb //開機自啟

[common] //設定共享名

path = /common //設定共享實際路徑

]# mkdir /common //常見共享目錄

]# echo "test document" > /common/test.txt //建立共享檔案

]# getsebool -a | grep samba //檢視selinux對samba的限制

]# setsebool -P samba_export_all_rw=on //開啟對samba的讀寫限制

]# useradd -s /sbin/nologin tom ; pdbedit -a tom //建立samba使用者,需要設定秘密

注:(配置檔案内容)

[global] //全局配置

[homes] //家目錄共享

[printers] //列印機共享

[samba]

path = /smb/ //共享目錄路徑

public = yes|no //預設no;公用的

browseable = yes|no //預設yes;是否可以浏覽

read only = yes|no //預設yes;隻讀

writable = yes|no //預設yes;可寫

write list = user //預設無;可寫入的使用者清單

valid users = user,user1//預設所有使用者;有效的使用者清單

hosts allow = 客戶位址 //允許的客戶機位址

hosts deny = 客戶位址 //禁止的客戶機位址

comment = 注釋 //說明

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

輸入賬戶和密碼:(使用者tom)

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

共享功能實作!

linux用戶端:samba-client cifs-utils

]# yum -y install samba-client cifs-utils //安裝samba用戶端依賴包

]# sambaclient -L 192.168.122.1 //檢視伺服器共享的目錄

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

注:不用輸入密碼,直接回車

]# mkdir /mnt/common //建立挂載目錄

]# vim /etc/fstab //設定自動挂載

//192.168.122.1/common /mnt/common cifs defaults,user=tom,pass=123456,_netdev 0 0

//目标主機位址/共享名 本機挂載點 cifs username=使用者名,password=密碼,_netdev 0 0

]# mount -a

linux系統資源共享方式一,FTP二,NFS三,samba其他共享方式共勉:I hear and I forget. I see and I remember. I do and I understand!

功能實作!驗證過程和nfs類似。注意nfs和samba的自動挂載的格式有差別,避免挂載失敗!

(python也可以實作共享,以後博文将展現)

scp和rsync指令

1.scp

secure copy,linux系統下基于ssh登陸進行安全的遠端檔案拷貝指令。

scp [可選參數] 源檔案 目标檔案

常用:-r遞歸複制整個目錄。

-C:允許壓縮。

-P port:注意是大寫的P, port是指定資料傳輸用到的端口号

詳情參考下面連結:

http://www.runoob.com/linux/linux-comm-scp.html

2.rsync

一個遠端資料同步工具,可通過LAN/WAN快速同步多台主機間的檔案。

rsync [可選參數] 源檔案 目标檔案

http://man.linuxde.net/rsync

其他參看網絡資源:

https://www.cnblogs.com/wxl-dede/p/5042398.html

繼續閱讀