當前位置:首頁 » 雲伺服器 » centos伺服器怎麼安裝nfs

centos伺服器怎麼安裝nfs

發布時間: 2022-12-19 00:46:42

⑴ centos7配置nfs共享存儲服務

nfs服務端需要確定這兩個包正確安裝 nfs-utils rpcbind

若是ubuntu伺服器,則是nfs-common,nfs-kernel-server兩個包,rpcbind是默認安裝的。

yum -y install nfs-utils rpcbind

編輯共享目錄配置文件 /etc/exports

/var/www/html 192.168.10.0/24(rw,async,no_root_squash) 192.168.20.0/24(ro)

#多個網段或主機之間用空格分開
/var/www 192.168.10.0/24(ro,sync,root_squash)

參數:ro表示只讀,rw表示可讀寫,sync同步寫*即同時寫入內存和硬碟,async非同步*暫存於內存,no_root_squash表示如果客戶端連接過來的用戶是root,則對服務端的目錄同樣是root許可權****請不要開啟,好危險的,root_squash表示客戶端是root則將其轉為匿名用戶的許可權***建議開啟。

啟動nfs服務,並設為開機自啟動

service rpcbind start #或則 systemctl start rpcbind
service nfs start #或則 systemctl start nfs
######ubuntu伺服器則是 service startnfs-kernel-server start
chkconfig rpcbind on #或則 systemctl enable rpcbind
chkconfig nfs on #或則 systemctl enable nfs

配置防火牆,放行響應埠或服務

firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
firewall-cmd --permanent --add-service=mountd
firewall-cmd --reload
firewall-cmd --list-all #查看firewalld方向的資源

客戶端掛載

showmount -e nfs_server_ip: 查看nfs服務端的可用掛載點

客戶端掛載操作

mount -t nfs nfs_server:/var/www/html /bendikongmulu
或者
mount -t nfs nfs_server:/var/www/html /bendikongmulu -o proto=tcp

無報錯便成功,當然客戶端可以使用 df -h 來查看是否掛載過來了;這里客戶端切換到本地掛載點便可以看見服務端的文件了(注意若,服務端共享的目錄為空,客戶端是無法查看的)網頁鏈接

⑵ 如何在Centos 6上設置NFS掛載目錄

設置NFS至少需要兩台伺服器,一台是提供共享文件夾的服務端,一台客戶端。

假設伺服器和客戶端IP地址:

伺服器: 192.168.1.100

客戶端: 192.168.1.101

一、搭建 NFS 服務端

1、首先使用 yum 安裝 NFS 軟體。

至此步,即可完成在Centos 6上設置NF掛載目錄。

⑶ 如何在centos上配置nfs服務

方法/步驟
Step 1:檢查是否安裝NFS和rpcbind兩個軟體。
打開linux終端,通過rpm -qa命令查看是否安裝這兩個包,如沒有安裝,請通過yum或源碼包進行安裝,這里不再說明安裝方法。如圖:

Step 2:修改配置文件:
用su切換成root用戶,編輯/etc/exports文件,指定共享目錄及許可權等。 如圖所示。我們來分析一下exports文件內容。
第一列是伺服器要輸出的共享目錄。在本例中,共享目錄是/db2Backup。
第二列指定允許哪些ip第一列的共享目錄。
括弧內的參數意義描述如下:
rw:讀/寫許可權,只讀許可權的參數為ro;
sync:數據同步寫入內存和硬碟,async,此時數據會先暫存於內存中,而不立即寫入硬碟。
no_root_squash:NFS 伺服器共享目錄用戶的屬性,如果用戶是 root,那麼對於這個共享目錄來說就具有 root 的許可權。修改文件後,保存退出。

Stet 3 :啟動服務
在啟動NFS伺服器,要先啟動portmap服務,然後再啟動NFS服務。操作方法如圖所示:
在啟動服務時,要用root。

Step 4:掛載目錄
在另一台電腦上面,查看能否訪問NFS服務,如果能訪問,則掛載,如圖所示。
首先查看能否訪問NFS,命令返回的結果是可以正常訪問。然後在本地建立/home/nfs文件夾,並把nfs掛載到該文件夾下面。mount -f參數指明了掛載類型是nfs。

5
Step 5:測試
經過以上4步,已經成功搭建了NFS服務,並載入到了本地文件系統中,接下來我們測試一下。cd到/home/nfs目錄,mkdir一個文件夾,假設文件名是hello,然後進入到nfs伺服器上,應該能看到hello文件。

6
以上就是簡單的配置NFS服務的方法,未涉及防火牆等內容。如果在第4步時出現錯誤,請檢查防火牆的設置。歡迎大家多多交流。

⑷ NFS服務搭建及數據無縫遷移

五一節辦公室要停電,機房雖有UPS,但也支撐不了8小時。
因生產環境有業務系統掛了辦公室機房的NAS存儲,故需要進行遷移,步驟記錄如下:

先閑談下技術-----------------------
NFS和samba的區別
samba是混合型網路中的共享服務,windows伺服器可建samba服務,linux伺服器也可建samba服務
nfs只面向unix、linux間的共享,linux伺服器可建nfs服務(winodws系統也可以掛載nfs,就是有點不穩定)

NFS伺服器上的操作--------------------------

nfs伺服器操作系統版本:
[root@c7110 ~]# more /etc/system-release
CentOS Linux release 7.9.2009 (Core)

nfs伺服器安裝nfs服務
[root@c7110 ~]# yum -y install nfs-utils rpcbind

創建nfs目錄,並授權
[root@c7110 ~]# mkdir /opt/nfs-test
[root@c7110 ~]# chmod 777 /opt/nfs-test

編輯nfs服務配置文件
[root@c7110 ~]# vi /etc/exports
內容如下:
/opt/nfs-test *(rw,root_squash,all_squash,sync)

重新載入nfs配置:
[root@c7110 ~]# exportfs -r

nfs服務設置開機啟動
[root@c7110 ~]# systemctl enable rpcbind
[root@c7110 ~]# systemctl enable nfs
[root@c7110 ~]# systemctl enable nfs-lock
[root@c7110 ~]# systemctl enable nfs-idmap

啟動nfs服務
[root@c7110 ~]# systemctl start rpcbind
[root@c7110 ~]# systemctl start nfs
[root@c7110 ~]# systemctl start nfs-lock
[root@c7110 ~]# systemctl start nfs-idmap

查看nfs服務啟動後,所監聽的埠信息:
[root@c7110 ~]# rpcinfo -p

linux伺服器伺服器上操作-------------------------------
業務伺服器安裝nfs軟體客戶端
[root@c7111 ~]# yum -y install nfs-utils

建立一個掛載目錄
[root@c7111 ~]# mkdir /opt/test-m

掛載nfs伺服器共享出來的目錄
[root@c7111 ~]# mount -t nfs 10.x.x.10:/opt/nfs-test /opt/test-m/

查看下已掛載的nfs
[root@c7111 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.5G 0 1.5G 0% /dev
tmpfs 1.5G 0 1.5G 0% /dev/shm
tmpfs 1.5G 8.8M 1.5G 1% /run
tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup
/dev/mapper/centos-root 97G 2.3G 95G 3% /
/dev/sda1 1014M 171M 844M 17% /boot
tmpfs 297M 0 297M 0% /run/user/0
10.x.x.6:/opt/nfs-test 97G 4.1G 93G 5% /opt/test-m

經測試,數據可讀可寫,證明nas服務沒有問題,於是進行數據同步,數據同步用rsync命令。

rsync -avp [email protected]::nas_6 /mnt/guidang/ --password-file=/root/rsync_pass --bwlimit=100000

數據同步完,通知研發進行掛載切換。研發同事在測試時,發現文件屬性中的uid及gid與原來的不一致,有些擔心,於是又小完善了一下NFS服務。

編輯nfs服務配置文件
[root@c7110 ~]# vi /etc/exports
內容如下:
/opt/nfs-test *(no_all_squash,anonuid=600,anongid=600)

重新載入nfs配置:
[root@c7110 ~]# exportfs -r

⑸ centos7安裝nfs掛載

下面記錄了NFS伺服器和客戶端的安裝步驟,並進行NFS共享,伺服器和客戶端都使用在CentOS 7系統。

服務端安裝

准備一個要共享的目錄:

編輯/etc/exports:

添加一行:(輸入一下,按i鍵進入編輯,按Esc退出,再輸入:wq保存)

更新配置文件,使之生效:

/var/nfs:共享的NFS目錄
192.168.0.0/24: 客戶端 IP 范圍,* 代表所有,即沒有限制。
rw: 許可權設置,可讀可寫。
sync: 同步共享目錄。
no_root_squash: 可以使用 root 授權。
no_all_squash: 可以使用普通用戶授權。

啟動相關服務:

重啟 NFS 服務

可以檢查一下本地的共享目錄

防火牆需要打開 rpc-bind 和 nfs 的服務
二種二選一都試試
1、

2、

客戶端安裝
安裝NFS:

(設置啟動,也可能不需要設置這個步驟)

創建一個目錄,做為NFS共享目錄的掛載點:

掛載NFS共享目錄:

查看所有掛載點:

客戶端自動掛載

在結尾添加類似如下配置

由於修改了 /etc/fstab,需要重新載入 systemctl。

此時已經啟動好了。如果實在不放心,可以重啟一下客戶端的操作系統,之後再查看一下。

⑹ centos7 掛載群輝nas文件夾

1、開啟群輝上的nfs服務

2、將cnetos機器ip加入到nfs的白名單
注意:有時候ip可能經過了nat,我們要配置成 * ,允許所有ip訪問。

3、在centos中創建目錄例如 :mkdir /home/mnt/NFStest

4、centos系統安裝nfs服務:並啟動服務

5、使用命令掛載 mount -t nfs 192.168.XXX.225:/volume1/test /home/mnt/NFStest

具體根據實際情況 修改IP地址和路徑

6、開啟開機掛載 :vi /etc/fstab

192.168.XXX.225:/volume1/test /NFSfile nfs defaults 0 0

7、驗證掛載:192.168.x.188:/volume1/test 35T 6.6T 29T 19% /home/mnt/NFStest

⑺ 如何Centos上掛載Synology的一個NFS共享文件夾

為什麼要掛載Synology的NFS,是因為不想用Rsync進行同步備份。

現在的配置是在Centos上掛載Synology的一個NFS共享文件夾,然後利用Centos的的計劃任務,進行定時備份。

准備:

1.打開Synology的控制面板,NFS服務,點擊啟動NFS服務,保存。

2.安裝nfs相關的插件(未知實際是否需要,做過測試的朋友,可以的話請告訴結果小弟,謝謝)

yum install -y nfs*

到這里,准備工作已經完成。

掛載

將Synology的文件夾信息加入到fstab中

vi /etc/fstab
插入

172.16.1.12:/volume/usbshare/Websback /www/backup nfs defaults 0 0
保存並掛載

mount -a

⑻ NFS筆記(二)NFS伺服器配置實例

一、NFS伺服器配置實例

實驗拓撲

二、實驗要求及環境

2.1實驗環境

NFS伺服器 IP:192.168.8.5

環境:

[root@server7 ~]# uname -a

Linux server7.ctos.zu 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux

[root@server7 ~]# cat /etc/redhat-release

CentOS release 7.3.1611 (AltArch)

客戶端IP:192.168.8.7

環境:

[root@client-A ~]# uname -a

Linux client-A.ctos.zu 2.6.32-696.el6.i686 #1 SMP Tue Mar 21 18:53:30 UTC 2017 i686 i686 i386 GNU/Linux

[root@client-A ~]# cat /etc/redhat-release

CentOS release 6.9 (Final)

2.2、實驗要求

NFS伺服器

1、/home/share 目錄可讀寫,並且不限制用戶身份,共享給192.168.8.0/24網段不的所有主機;

2、/home/data 這個目錄僅共享給192.168.8.7這台主機,以供該主機上面的這個用戶來使用,

也就是說在192.168.8.5和192.168.8.7上均有賬號,且賬號均為;

3、/home/upload 這個目錄做為192.168.8.0/24網段的數據上傳目錄,其中/home/upload

的用戶和所屬組為nfs-upload這個名字,它的UID和GID均為222;

4、/home/nfs  這個目錄的屬性為只讀,可提供除了網段內的工作站外,向Internet也提供數據內容。

三、伺服器端設置

1、 編輯/etc/exports內容

[root@server7 etc]# cat /etc/exports

/home/share  192.168.8.0/24(rw,no_root_squash)

/home/data  192.168.8.7(rw)

/home/upload   192.168.8.0/24(rw,all_squash,anonuid=222,anongid=222)

/home/nfs     192.168.8.0/24(ro)  *(ro,all_squash)

2、按要求建立每個對應目錄

    2.1、創建/home/share目錄 任何人都可以在 /home/share內新增、修改文件,但

    僅有該文件/目錄的建立者與root能夠刪除自己的目錄或文件。

    [root@server7 etc]# mkdir -p  /home/share

    [root@server7 etc]# ll -d /home/share/

    drwxr-xr-x. 2 root root 6 9月   5 15:50 /home/share/

    [root@server7 etc]# chmod 1777  /home/share/

    [root@server7 etc]# ll -d /home/share/

    drwxrwxrwt. 2 root root 6 9月   5 15:50 /home/share/

    2.2、創建/home/nfs

    [root@server7 etc]# ll -d /home/nfs/

    drwxr-xr-x. 2 root root 6 9月   5 16:52 /home/nfs/

    2.3、創建/home/data目錄

    [root@server7 etc]# mkdir -v /home/data

    mkdir: 已創建目錄 "/home/data"

    [root@server7 etc]# ll -d /home/data/

    drwxr-xr-x. 2 root root 6 9月   5 16:57 /home/data/

    [root@server7 etc]# useradd

    root@server7 etc]# passwd

    更改用戶 的密碼 。

    新的 密碼:

    無效的密碼: 密碼少於 8 個字元

    重新輸入新的 密碼:

    passwd:所有的身份驗證令牌已經成功更新。

    [root@server7 etc]# cat /etc/passwd | grep

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

    [root@server7 etc]# chmod 700 /home/data/

    [root@server7 etc]# chown -R : /home/data/

    [root@server7 etc]# ll -d /home/data/

    drwx------. 2 6 9月   5 16:57 /home/data/

    2.4、創建/home/upload目錄

#先建立對應賬號與組名及UID

[root@server7 etc]# groupadd  -g 222 nfs-upload

[root@server7 etc]# useradd -g 222 -u 222 -M nfs-upload

[root@server7 etc]# cat /etc/passwd|grep nfs

rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin

nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

nfs-upload:x:222:222::/home/nfs-upload:/bin/bash

#創建目錄,修改屬主

[root@server7 etc]# mkdir /home/upload

[root@server7 etc]# chown -R nfs-upload:nfs-upload  /home/upload/

[root@server7 etc]# ll -d /home/upload/

drwxr-xr-x. 2 nfs-upload nfs-upload 6 9月   6 08:38 /home/upload/

2.5、重啟NFS服務

[root@server7 etc]# systemctl restart  nfs

[root@server7 etc]# systemctl status  nfs

● nfs-server.service - NFS server and services

   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)

   Active: active (exited) since 三 2017-09-06 08:41:40 CST; 8s ago

  Process: 9171 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS)

  Process: 9169 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS)

  Process: 9168 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS)

  Process: 9181 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)

  Process: 9180 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)

 Main PID: 9181 (code=exited, status=0/SUCCESS)

   CGroup: /system.slice/nfs-server.service

9月 06 08:41:40 server7.ctos.zu systemd[1]: Starting NFS server and services...

9月 06 08:41:40 server7.ctos.zu systemd[1]: Started NFS server and services.

[root@server7 etc]# tail /var/log/messages

Sep  6 08:41:40 server7 systemd: Started NFS Mount Daemon.

Sep  6 08:41:40 server7 rpc.mountd[9178]: Version 1.3.0 starting

Sep  6 08:41:40 server7 systemd: Started NFSv4 ID-name mapping service.

Sep  6 08:41:40 server7 systemd: Starting NFS server and services...

Sep  6 08:41:40 server7 kernel: NFSD: starting 90-second grace period (net c0c932c0)

Sep  6 08:41:40 server7 systemd: Started NFS server and services.

Sep  6 08:41:40 server7 systemd: Starting Notify NFS peers of a restart...

Sep  6 08:41:40 server7 sm-notify[9198]: Version 1.3.0 starting

Sep  6 08:41:40 server7 sm-notify[9198]: Already notifying clients; Exiting!

Sep  6 08:41:40 server7 systemd: Started Notify NFS peers of a restart.

2.6、查看NFS伺服器共享出來目錄

2.7、關閉防火牆、selinux

2.8查看配置

[root@server7 ~]# exportfs -v

/home/data     192.168.8.7(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)

/home/share       192.168.8.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

/home/upload      192.168.8.0/24(rw,wdelay,root_squash,all_squash,no_subtree_check,anonuid=222,anongid=222,sec=sys,rw,secure,root_squash,all_squash)

/home/nfs         192.168.8.0/24(ro,wdelay,root_squash,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)

/home/nfs         <world>(ro,wdelay,root_squash,all_squash,no_subtree_check,sec=sys,ro,secure,root_squash,all_squash)

四、客戶端配置

4.1、客戶端也要安裝nfs-utils和rcpbind軟體包

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

4.2、啟動RPC

[root@client-A ~]# service rpcbind start  /systemctl start rpcbind

Starting rpcbind:                                          [  OK  ]

[root@client-A ~]# service rpcbind status

rpcbind (pid  1926) is running...

[root@client-A ~]# chkconfig --list |grep rpcbind

4.3、客戶端關閉防火牆、selinux

[root@client-A ~]# service iptables stop /systemctl stop firewalld

iptables: Setting chains to policy ACCEPT: filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading moles:                               [  OK  ]

4.4測試網路

[root@client-A ~]# ping 192.168.8.5

PING 192.168.8.5 (192.168.8.5) 56(84) bytes of data.

64 bytes from 192.168.8.5: icmp_seq=1 ttl=64 time=2.16 ms

64 bytes from 192.168.8.5: icmp_seq=2 ttl=64 time=0.697 ms

64 bytes from 192.168.8.5: icmp_seq=3 ttl=64 time=0.346 ms

64 bytes from 192.168.8.5: icmp_seq=4 ttl=64 time=0.336 ms

64 bytes from 192.168.8.5: icmp_seq=5 ttl=64 time=0.335 ms

64 bytes from 192.168.8.5: icmp_seq=6 ttl=64 time=0.317 ms

64 bytes from 192.168.8.5: icmp_seq=7 ttl=64 time=0.512 ms

64 bytes from 192.168.8.5: icmp_seq=8 ttl=64 time=0.320 ms

^C

--- 192.168.8.5 ping statistics ---

8 packets transmitted, 8 received, 0% packet loss, time 7555ms

rtt min/avg/max/mdev = 0.317/0.629/2.169/0.595 ms

4.5 在客戶端查看NFS伺服器共享出來目錄

[root@client-A ~]# showmount -e 192.168.8.5

Export list for 192.168.8.5:

/home/nfs     (everyone)

/home/upload  192.168.8.0/24

/home/share   192.168.8.0/24

/home/data 192.168.8.7

4.6、掛載NFS伺服器上/home/nfs目錄到本地/opt/data目錄下

#臨時掛載

#永久掛載

編輯、/etc/fstab文件,新增如下條目:

192.168.8.5:/home/nfs  /opt/data/ nfs4 defaults 0 0

更多信息參考 nfs參數詳解

#查看信息

[root@client-A data] # df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                      6.5G  644M  5.6G  11% /

tmpfs                 250M     0  250M   0% /dev/shm

/dev/sda1             477M   26M  426M   6% /boot

192.168.8.5:/home/nfs

                      8.0G  1.6G  6.5G  20% /opt/data

[root@client-A data]# mount

/dev/mapper/VolGroup-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw)

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

192.168.8.5:/home/nfs on /opt/data type nfs (rw,vers=4,addr=192.168.8.5,clientaddr=192.168.8.7)

#創建文件測試

[root@client-A data]# touch testabc

touch: cannot touch `testabc': Read-only file system

4.7掛載/home/upload 目錄到客戶端/opt/upload目錄下

#掛載

[root@client-A data]# mkdir /opt/upload

[root@client-A data]# mount -t nfs  192.168.8.5:/home/upload   /opt/upload/

#查看掛載是否成功

[root@client-A data]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root

                      6.5G  644M  5.6G  11% /

tmpfs                 250M     0  250M   0% /dev/shm

/dev/sda1             477M   26M  426M   6% /boot

192.168.8.5:/home/nfs

                      8.0G  1.6G  6.5G  20% /opt/data

192.168.8.5:/home/upload

                      8.0G  1.6G  6.5G  20% /opt/upload

#客戶端創建nfs-upload用戶

[root@client-A ~]# groupadd  -g 222 nfs-upload

[root@client-A ~]# useradd -g 222 -u 222 -m nfs-upload

#測試,可以看到創建的文件及目錄默認屬主為nfs-upload屬組為nfs-upload

[@client-A upload]$ pwd

/opt/upload

[@client-A upload]$ ll

total 0

#測試創建文件

[@client-A upload]$ touch test123

測試創建目錄

[@client-A upload]$ mkdir  testdir

[@client-A upload]$ ll -a

total 4

drwxr-xr-x  3 nfs-upload nfs-upload   36 Sep  6 10:28 .

drwxr-xr-x. 4 root       root       4096 Sep  6 18:22 ..

-rw-rw-r--  1 nfs-upload nfs-upload    0 Sep  6 10:28 test123

drwxrwxr-x  2 nfs-upload nfs-upload    6 Sep  6 10:28 testdir

# 在客戶端用root用戶創建文件測試

root@client-A upload]# touch testabc

[root@client-A upload]# ll

total 0

-rw-r--r-- 1 root       root       0 Sep  6 10:31 nfstest123

-rw-r--r-- 1 nfs-upload nfs-upload 0 Sep  6 10:32 testabc

drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep  6 10:28 testdir

可以看到用root用戶創建的文件屬主仍是nfs-upload

#測試刪除文件

[@client-A upload]$ rm test123

[@client-A upload]$ ll

total 0

drwxrwxr-x 2 nfs-upload nfs-upload 6 Sep  6 10:28 testdir

⑼ linux配置nfs步驟

NFS的配置過程很簡單。在伺服器端中編輯 /etc/exports 文件,添加如下內容: /home/nfs-share 192.168.1.122 (rw,sync)
第一項是要共享的目錄,後者為共享的配置參數一般為: (rw,sync,no_root_squash,no_all_squash,no_subtree_check)
然後開啟NFS和portmap服務:
/etc/init.d/nfs start //用service nfs start也可以 /etc/init.d/portmap start //用service portmap stasrt也可以
在centos6.5中portmap已經改為rpcbind 在客戶端,用mount –t nfs 192.168.123:/home/nfs-share /home/remote_file掛載伺服器端的共享目錄到本地的/home/remote-file掛載點,然後我們就可以在客戶端上應用到遠程主機上的/home/nfs-share目錄了。想要系統在開機時自動掛載,修改/etc/fstab文件,把NFS伺服器的共享目錄添加進去就可以了,這個不用多說。

如何知道遠程主機上的共享目錄情況呢?使用showmount命令,這個命令需要root許可權。它有三個選項(記住這三個選項代表的含義: showmount –a IP 顯示指定NFS伺服器的客戶端以及伺服器端在客戶端的掛載點 showmount –d IP 顯示指定NFS伺服器在客戶端的掛載點 showmount –e IP 顯示指定NFS伺服器上的共享目錄列表(或者叫輸出列表) 我們輸入命令showmount –a 192.168.1.123:

圖片客戶端中出現的mount clntudp_create: RPC: Program not registered錯誤是怎麼回事?噢,我剛才重啟了一下伺服器端,重啟後NFS服務沒有開啟。 我們開啟伺服器端的NFS服務,再從客戶端上查看一下NFS伺服器的情況:

Showmount –a顯示出NFS伺服器192.168.1.123的共享目錄被客戶端192.168.122掛載到/home中;

在showmount -e IP,出現clnt_create: RPC: Port mapper failure - Timed out報錯
解決方案:
被訪問的NFS伺服器上的防火牆沒有添加規則,向iptables裡面添加以下查看的所有埠即可(目前解決的方法,當然你也可以關閉防火牆,不過這樣是比較不安全的,如果你的nfs作用不大,建議你另選別的應用來替代吧!畢竟開那麼多的埠,比較不安全呀!)

通過#rpcinfo -p 10.10.209.148
[root@rh01 /]# rpcinfo -p 10.10.209.148program vers proto port service100000 4 tcp 111 portmapper100000 3 tcp 111 portmapper100000 2 tcp 111 portmapper100000 4 udp 111 portmapper100000 3 udp 111 portmapper100000 2 udp 111 portmapper100024 1 udp 52943 status100024 1 tcp 37706 status100011 1 udp 875 rquotad100011 2 udp 875 rquotad100011 1 tcp 875 rquotad100011 2 tcp 875 rquotad100003 2 tcp 2049 nfs100003 3 tcp 2049 nfs100003 4 tcp 2049 nfs100227 2 tcp 2049 nfs_acl100227 3 tcp 2049 nfs_acl100003 2 udp 2049 nfs100003 3 udp 2049 nfs100003 4 udp 2049 nfs100227 2 udp 2049 nfs_acl100227 3 udp 2049 nfs_acl100021 1 udp 37438 nlockmgr100021 3 udp 37438 nlockmgr100021 4 udp 37438 nlockmgr100021 1 tcp 46331 nlockmgr100021 3 tcp 46331 nlockmgr100021 4 tcp 46331 nlockmgr100005 1 udp 57177 mountd100005 1 tcp 43147 mountd100005 2 udp 49154 mountd100005 2 tcp 54810 mountd100005 3 udp 55707 mountd100005 3 tcp 58309 mountd
[root@rh01 /]#

剛才在重啟NFS服務的時候,細心的話可以注意到,我們在輸入命令/etc/init.d/nfs start開啟nfs服務時,系統還自作主張地開啟了NFS quotas等其它3個服務。

怎麼回事?我們只輸入了一條啟動NFS服務的命令,它怎麼額外的啟動了3個服務?後面的啟動portmap服務又是怎麼回事? 我們首先要了解一點:NFS文件系統要提供服務單靠本身的NFS服務是不夠的,還需要調用其它服務,這個其它服務就是RPC(remote procere call,遠程過程調用)服務和portmap服務。由於NFS服務本身不提供文件傳輸功能,我們要遠程使用NFS文件系統就需要RPC服務的支持;而portmap服務用來為RPC服務進行動態埠分配和映射,所以portmap服務也是NFS服務所必須的。

我們查看一下服務的啟動情況:

所遇錯誤:
/etc/init.d/nfs-kernel-server: 沒有那個文件或目錄
解決方案:
沒有配置、安裝NFS
Linux 下配置NFS服務
1、安裝

2、配置

3、客戶端

所遇問題:centos6.5
portmap: 未被識別的服務
解決方案:
由於在6系列裡面,portmap已經改名了 ,6系列需要使用 service rpcbind start啟動[root@unix-big-bang ~]# service portmap start
portmap: 未被識別的服務
[root@unix-big-bang ~]# service rpcbind status
rpcbind (pid 1312) is running...
[root@unix-big-bang ~]#

好文共賞:
linux nfs文件共享

◆一、概念
NFS是網路文件系統(Network File System)的簡稱,是分布式計算機系統的一個組成部分,可實現在異構網路上共享和裝配遠程文件系統。
NFS由SUN公司開發,目前已成為文件服務的一種標准(RFC1904,RFC1813)。其最大的功能就是可以通過網路,讓不同 操作系統 的計算機可以共享數據,所以也可以看作是一個文件伺服器。NFS是除了SAMBA之外Windows與Linux及Unix與Linux之間通信的方法。

理想條件下的NFS 網路拓撲結構

1、設置Linux系統之間的文件共享(Linux與Windows中間文件共享採用SAMBA服務);
2、NFS只是一種文件系統,本身沒有傳輸功能,是基於RPC協議實現的,才能達到兩個Linux系統之間的文件目錄共享;
3、NFS為C/S 架構 ;
◆二、伺服器配置
1、配置文件
主要配置文件為:/etc/exports
格式為: 共享目錄 可mount主機IP(參數1,參數2,……)
如:/var/nfs 172.20. . (rw,sync,no_rootl_squash)
說明:必須注意nfs/目錄的訪問許可權,必須設置成777許可權;父目錄/var許可權無要求,普通的755即可;
2、啟動相關服務
然後依次啟動相關服務:portmap,nfslock,nfs
service portmap start
service nfslock start
service nfs start
關閉順序相反。
3、檢查共享目錄
隨後可以採用showmount –e查看一下,看看共享的目錄情況:
[root@ns var]# showmount -e
Export list for ns.osserver:
/var/nfs 172.20. .
OK,到此為止,NFS伺服器搭建完畢;
◆三、客戶端配置
1、確保portmap運行
客戶端必須確保RPC協議相應的portmap正常運行,否則mount將失敗;
2、掛載/var/nfs目錄(本地掛載點為/mnt/nfs)
mount -t nfs 172.20.65.16:/var/nfs /mnt/nfs
成功mount以後,即可同本地目錄一樣隨意操作;
◆四、其它相關命令
1、當修改了/etc/exports文件後,可以不用重新啟動nfs服務,直接採用exports –rv 即可重新導出共享目錄;
該命令格式如下:
exportfs [-aruv]
-a :全部mount或者unmount /etc/exports中的內容
-r :重新mount /etc/exports中分享出來的目錄
-u :umount 目錄
-v :在 export 的時候,將詳細的信息輸出到屏幕上。
具體例子:
[root@ns var]# showmount -e
Export list for ns.osserver:
/var/nfs 172.20. .
[root@ns var]# exportfs –au #全部卸載
[root@ns var]# showmount -e
Export list for ns.osserver:
[root@ns var]# exportfs –rv #全部重新 export 一次
exporting 172.20. . :/var/nfs
[root@ns var]#
2、showmout命令對於NFS的操作和查錯有很大的幫助,所以我們先來看一下showmount的用法
showmout
-a :這個參數是一般在NFS SERVER上使用,是用來顯示已經mount上本機nfs目錄的cline機器。
-e :顯示指定的NFS SERVER上export出來的目錄。
例如:
[root@localhost ~]# showmount -e 172.20.16.139
Export list for 172.20.16.139 :/root/share 172.20.16.137
[root@ns var]# showmount -a
All mount points on localhost.localdomain: :/root/share,172.20. . :/root/share,172.20.16. :/root/share,172.20.16.139:/nfsshare,172.20.16.139:/root/share172.20.16.137: 172.20.16.137:,172.20. . 172.20.16.137:,172.20.16. 172.20.16.137:/root/share172.20.16.139: 172.20.16.139:,172.20. . 172.20.16.139:,172.20.16. 172.20.16.139:,172.20.16.139172.20.16.139:DEFAULT
◆五、常見問題解答
1、提示:mount to NFS server 餄.20.67.203' failed: server is down.
解決方案:可能是NFS伺服器的防火牆有問題;
2、提示:mount: RPC: Timed out
解決方案:由於RPC協議沒運行;啟動portmap服務;
也有可能是防火牆問題;Server/Client均有可能。

⑽ 如何在Centos 6上設置NFS掛載目錄

NFS共享服務設置(服務端):
第1步:創建NFS服務端的共享目錄。
清空iptables默認的規則鏈:
[root@linuxprobe ~]# iptables -F

保存清空後的iptables規則:
[root@linuxprobe ~]# service iptables save

創建nfsfile共享目錄:
[root@linuxprobe ~]# mkdir /nfsfile

寫入一個文件,用於NFS客戶端讀取:
[root@linuxprobe ~]# echo "welcome to linuxprobe.com" > /nfsfile/readme

NFS服務端配置文件是"/etc/exports",用於定義要共享的目錄以及相應許可權。
[root@linuxprobe ~]# vim /etc/exports
//格式為:共享目錄的絕對路徑 允許訪問NFS資源的客戶端(許可權參數)
/nfsfile 192.168.10.* (rw,sync,root_squash)

NFS配置共享的參數有:
參數 作用
ro 只讀默認
rw 讀寫模式
root_squash 當NFS客戶端使用root用戶訪問時,映射為NFS服務端的匿名用戶。
no_root_squash 當NFS客戶端使用root用戶訪問時,映射為NFS服務端的root用戶。
all_squash 不論NFS客戶端使用任何帳戶,均映射為NFS服務端的匿名用戶。
sync 同時將數據寫入到內存與硬碟中,保證不丟失數據。
async 優先將數據保存到內存,然後再寫入硬碟,效率更高,但可能造成數據丟失。

第2步:啟動NFS服務端
剛剛講到NFS服務是依賴於RPC服務的,但在紅帽RHEL7系統中RPC服務已經默認運行(active)了,所以無需再配置RPC服務啦。
[root@linuxprobe ~]# systemctl status rpcbind

啟動nfs-server程序:
[root@linuxprobe ~]# systemctl start nfs-server

設置NFS服務端為開機啟動:
[root@linuxprobe ~]# systemctl enable nfs-server

將共享掛載到客戶端
第3步:配置NFS客戶端
如果NFS客戶端也是紅帽RHEL7系統,那麼軟體包nfs-utils一定也是已經默認安裝,直接掛載共享就可以了。
showmount命令用於查詢NFS服務端共享信息,格式為:「showmount [參數] [遠程主機]」。
參數 作用
-e 顯示NFS服務端的共享列表
-a 顯示本機掛載NFS資源的情況
-v 顯示版本號
查詢遠程NFS服務端中可用的共享資源:
[root@linuxprobe ~]# showmount -e 192.168.10.10
Export list for 192.168.10.10:
/nfsfile (everyone)

創建本地掛載目錄:
[root@linuxprobe ~]# mkdir /nfsfile
[root@linuxprobe ~]# mount -t nfs 192.168.10.10:/nfsfile /nfsfile

順利查看到剛剛寫入文件內容:
[root@linuxprobe ~]# cat /nfsfile/readme
welcome to linuxprobe.com

如果希望開機後自動將NFS資源掛載到本地,那麼就可以通過修改fstab文件來實現:
[root@linuxprobe ~]# vim /etc/fstab
192.168.10.10:/nfsfile /nfsfile nfs defaults 0 0

具體過程和截圖可以參看一下這篇文章:http://www.linuxprobe.com/chapter-11/#113_NFS

熱點內容
卡西歐相機存儲卡異常 發布:2025-03-16 18:54:10 瀏覽:914
69hz的電腦玩吃雞如何調配置 發布:2025-03-16 18:52:37 瀏覽:913
java的append 發布:2025-03-16 18:51:52 瀏覽:930
h5本地資料庫 發布:2025-03-16 18:43:59 瀏覽:593
編程器資源 發布:2025-03-16 17:59:48 瀏覽:903
加密軟體廠商 發布:2025-03-16 17:59:44 瀏覽:680
魚鉤怎麼樣配置 發布:2025-03-16 17:59:04 瀏覽:157
安卓手機怎麼設置快點 發布:2025-03-16 17:45:35 瀏覽:331
c語言字元串右對齊 發布:2025-03-16 17:42:35 瀏覽:131
充值釣魚源碼 發布:2025-03-16 17:28:16 瀏覽:470