實(shí)際項(xiàng)目中有用到文件共享,整理一下篱瞎。
一、安裝部分
基于centos6.5-mini版痒芝,離線安裝。測試過程中為了方便關(guān)閉了防火墻牵素。
1严衬、上傳安裝包
將rpm安裝包上傳到服務(wù)器,如/root/packages/目錄下:
[root@centos6-nfs-server packages]# pwd
/root/packages
[root@centos6-nfs-server packages]# ls
keyutils-1.4-5.el6.x86_64.rpm nfs-utils-1.2.3-78.el6.x86_64.rpm
keyutils-libs-1.4-5.el6.x86_64.rpm nfs-utils-lib-1.1.5-13.el6.x86_64.rpm
libgssglue-0.1-11.el6.x86_64.rpm python-argparse-1.2.1-2.1.el6.noarch.rpm
libtirpc-0.2.1-15.el6.i686.rpm rpcbind-0.2.0-16.el6.x86_64.rpm
libevent-1.4.13-4.el6.x86_64.rpm
2笆呆、執(zhí)行安裝
[root@centos6-nfs-server packages]#
[root@centos6-nfs-server packages]# rpm -ivh keyutils-libs-1.4-5.el6.x86_64.rpm --force
warning: keyutils-libs-1.4-5.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:keyutils-libs ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh keyutils-1.4-5.el6.x86_64.rpm
warning: keyutils-1.4-5.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:keyutils ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh libevent-1.4.13-4.el6.x86_64.rpm
warning: libevent-1.4.13-4.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libevent ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh libgssglue-0.1-11.el6.x86_64.rpm
warning: libgssglue-0.1-11.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libgssglue ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh libtirpc-0.2.1-15.el6.x86_64.rpm
warning: libtirpc-0.2.1-15.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:libtirpc ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh python-argparse-1.2.1-2.1.el6.noarch.rpm
warning: python-argparse-1.2.1-2.1.el6.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:python-argparse ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh rpcbind-0.2.0-16.el6.x86_64.rpm
warning: rpcbind-0.2.0-16.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:rpcbind ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh nfs-utils-lib-1.1.5-13.el6.x86_64.rpm --nodeps
warning: nfs-utils-lib-1.1.5-13.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:nfs-utils-lib ########################################### [100%]
[root@centos6-nfs-server packages]# rpm -ivh nfs-utils-1.2.3-78.el6.x86_64.rpm
warning: nfs-utils-1.2.3-78.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:nfs-utils ########################################### [100%]
3请琳、查看rpcbind、nfs服務(wù)的狀態(tài)
[root@centos6-nfs-server ~]# service rpcbind status
rpcbind 已停
[root@centos6-nfs-server ~]# service nfs status
rpc.svcgssd 已停
rpc.mountd 已停
nfsd 已停
4赠幕、啟動rpcbind俄精、nfs服務(wù)
[root@centos6-nfs-server ~]# service rpcbind start
正在啟動 rpcbind: [確定]
[root@centos6-nfs-server ~]# service nfs start
啟動 NFS 服務(wù): [確定]
啟動 NFS mountd: [確定]
啟動 NFS 守護(hù)進(jìn)程: [確定]
正在啟動 RPC idmapd: [確定]
5、開機(jī)啟動rpcbind榕堰、nfs服務(wù)
1) 添加rpcbind竖慧、nfs系統(tǒng)服務(wù)
[root@centos6-nfs-server ~]# chkconfig --add rpcbind
[root@centos6-nfs-server ~]# chkconfig --add nfs
2) 設(shè)置開機(jī)啟動
[root@centos6-nfs-server ~]# chkconfig rpcbind on
[root@centos6-nfs-server ~]# chkconfig --list rpcbind
rpcbind 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
?
[root@centos6-nfs-server ~]# chkconfig nfs on
[root@centos6-nfs-server ~]# chkconfig --list nfs
nfs 0:關(guān)閉 1:關(guān)閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關(guān)閉
至此,服務(wù)端rpcbind+nfs服務(wù)安裝部分完成逆屡。
二圾旨、配置部分
1、服務(wù)端配置
[root@centos6-nfs-server ~]# vi /etc/exports
# 共享目錄 客戶端IP(權(quán)限)
/mnt/serverfile 192.168.56.12(rw,no_root_squash)
關(guān)于其他權(quán)限的代碼:
- rw:可讀寫的權(quán)限魏蔗;
- ro:只讀的權(quán)限砍的;
- no_root_squash:登入到NFS主機(jī)的用戶如果是root,該用戶即擁有root權(quán)限莺治;(不添加此選項(xiàng)ROOT只有RO權(quán)限)
- root_squash:登入NFS主機(jī)的用戶如果是root廓鞠,該用戶權(quán)限將被限定為匿名使用者nobody;
- all_squash:不管登陸NFS主機(jī)的用戶是何權(quán)限都會被重新設(shè)定為匿名使用者nobody谣旁。
- anonuid:將登入NFS主機(jī)的用戶都設(shè)定成指定的user id床佳,此ID必須存在于/etc/passwd中。
- anongid:同anonuid蔓挖,但是變成group ID就是了夕土!
- sync:資料同步寫入存儲器中。
- async:資料會先暫時(shí)存放在內(nèi)存中,不會直接寫入硬盤怨绣。
- insecure:允許從這臺機(jī)器過來的非授權(quán)訪問角溃。
2、客戶端
1)查看服務(wù)端配置掛載情況
[root@centos6-nfs-client ~]# showmount -e 192.168.56.11
Export list for 192.168.56.11:
/mnt/serverfile 192.168.56.12
2) 創(chuàng)建掛載目錄
[root@centos6-nfs-client ]# cd /home
[root@centos6-nfs-client home]# mkdir mntdir
[root@centos6-nfs-client home]# ls
mntdir
3)掛載
[root@centos6-nfs-client home]# mount -t nfs 192.168.56.11:/mnt/serverfile /mnt/clientfile/
- 192.168.56.11 代表服務(wù)器ip
- /mnt/serverfile 代表服務(wù)器共享的文件夾
- /mnt/clientfile/ 代表客戶機(jī)掛載地址
4)查看掛載結(jié)果
[root@centos6-nfs-client mntdir]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos65test01-lv_root 6.7G 2.1G 4.3G 33% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
192.168.56.11:/mnt/serverfile 6.7G 2.1G 4.3G 33% /mnt/clientfile
三篮撑、測試部分
服務(wù)端分享目錄初始情況:
[root@centos6-nfs-server serverfile]# pwd
/mnt/serverfile
[root@centos6-nfs-server serverfile]# ll
總用量 0
[root@centos6-nfs-server serverfile]#
客戶端掛載目錄初始情況:
[root@centos6-nfs-client clientfile]# pwd
/mnt/clientfile
[root@centos6-nfs-client clientfile]# ll
總用量 0
1减细、客戶端讀取共享目錄文件
1)服務(wù)端添加文件,添加內(nèi)容為server123
[root@centos6-nfs-server serverfile]# vi server-test-file.txt
[root@centos6-nfs-server serverfile]#
[root@centos6-nfs-server serverfile]# ls
server-test-file.txt
[root@centos6-nfs-server serverfile]# cat server-test-file.txt
server123
2)客戶端查看
[root@centos6-nfs-client clientfile]# pwd
/mnt/clientfile
[root@centos6-nfs-client clientfile]# ll
總用量 4
-rw-r--r--. 1 root root 10 6月 16 10:57 server-test-file.txt
[root@centos6-nfs-client clientfile]# cat server-test-file.txt
server123
客戶端讀取共享目錄文件成功赢笨。
2未蝌、客戶端寫文件到共享目錄
1)客戶端寫入文件,文件內(nèi)容client123
[root@centos6-nfs-client clientfile]# vi client-test-file.txt
[root@centos6-nfs-client clientfile]# ls
client-test-file.txt server-test-file.txt
[root@centos6-nfs-client clientfile]# cat client-test-file.txt
client123
2) 服務(wù)端讀取文件
[root@centos6-nfs-server serverfile]# ll
總用量 8
-rw-r--r--. 1 root root 10 6月 16 11:02 client-test-file.txt
-rw-r--r--. 1 root root 10 6月 16 10:57 server-test-file.txt
[root@centos6-nfs-server serverfile]# cat client-test-file.txt
client123
客戶端寫文件到共享目錄成功茧妒。