Fedora 17配置NFS (未完成版)

http://www.server-world.info/en/note?os=Fedora_17&p=nfs



安裝nfs及相關依賴:sudo yum install nfs-utils* -y

根據需要編輯配置文件:sudo gedit /etc/exports,如果共享目錄是/opt/nfs,且希望掛載後對其可讀可寫,則在裏面添加一行:/opt/nfs  *(sync,rw),*表示所有IP,如果指定要IP訪問,則可以直接替換爲指定IP;若希望/opt/nfs只能讀不能寫則將rw改爲ro即可,詳細參數,查看手冊。
開啓nfs相關服務:sudo systemctl enable nfs-server.service
nfs-server檢查是否開啓:systemctl is-enabled nfs-server.service,會顯示enabled
其它機器遠程加載時只需:mount x.x.x.x:/opt/nfs /mnt,x.x.x.x是nfs服務的ip地址。



----------------------------------------------------------------------------------------------------------------------

編輯nfs配置文件:

vim /etc/exports

/path/to/your/directory  192.168.221.0/24(rw,sync,no_root_squash)

激活exports,可直接用exportfs刷新或者重啓服務:

1. exportfs刷新:

# exportfs -avf
exporting 192.168.221.0/24:/path/to/your/directory
2. 重啓服務:
# systemctl restart nfs-server.service

查看本機共享出的nfs文件夾:

# showmount -e
Export list for tp:
/path/to/your/directory

換臺機器掛載nfs文件夾:

# mount -t nfs 192.168.221.1:/path/to/your/directory   /mnt
# df -h
文件系統              容量  已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
                      188G  2.7G  176G   2% /
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sr0              3.6G  3.6G     0 100% /media
192.168.221.1:/path/to/your/directory  932G  806G  127G  87% /mnt

注意問題:

1. 檢查配置沒有問題後,仍無法發現nfs共享,可以先臨時關閉防火牆(systemctl stop iptables.service)和SELINUX(setenforce 0),再試試看。

2. 客戶機上能發現nfs共享,並且可以成功mount,但是沒有權限列出mount後的目錄,需要加no_root_squash到nfs exports選項裏,這樣客戶機能以root權限來查看nfs共享文件夾。

man exports

       root_squash
              Map requests from uid/gid 0 to the anonymous uid/gid. Note  that
              this  does  not  apply  to  any other uids or gids that might be
              equally sensitive, such as user bin or group staff.

       no_root_squash
              Turn off root squashing. This option is mainly useful for  disk‐
              less clients.



---------------------------------------------------------------------------------------------------------------------------

 
Configure NFS Server to share any directories on your Network.
[1] It's the Configuration on the system you want to build NFS server.
[root@master ~]#
yum -y install nfs-utils
[root@master ~]#
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain =
server.world
[root@master ~]#
vi /etc/exports
# write like below *note

/home 10.0.0.0/24(rw,sync,no_root_squash,no_all_squash)
# *note
/home
⇒ shared directory

10.0.0.0/24
⇒ range of networks NFS permits accesses

rw
⇒ writable

sync
⇒ synchronize

no_root_squash
⇒ enable root privilege

no_all_squash
⇒ enable users' authority
[root@master ~]#
systemctl start rpcbind.service

[root@master ~]#
systemctl start nfs-server.service

[root@master ~]#
systemctl start nfs-lock.service

[root@master ~]#
systemctl start nfs-idmap.service

[root@master ~]#
systemctl enable rpcbind.service

[root@master ~]#
systemctl enable nfs-server.service

[root@master ~]#
systemctl enable nfs-lock.service

[root@master ~]#
systemctl enable nfs-idmap.service
[2] Configuration on NFS clients
[root@www ~]#
yum -y install nfs-utils
[root@master ~]#
vi /etc/idmapd.conf
# line 5: uncomment and change to your domain name

Domain =
server.world
[root@www ~]#
systemctl start rpcbind.service

[root@www ~]#
systemctl start nfs-lock.service

[root@www ~]#
systemctl start nfs-idmap.service

[root@www ~]#
systemctl start nfs-mountd.service

[root@www ~]#
systemctl enable rpcbind.service

[root@www ~]#
systemctl enable nfs-lock.service

[root@www ~]#
systemctl enable nfs-idmap.service

[root@www ~]#
systemctl enable nfs-mountd.service

[root@www ~]#
mount -t nfs master.server.world:/home /home

[root@www ~]#
df -h

Filesystem                    Size  Used Avail Use% Mounted on
rootfs                         16G  832M   14G   6% /
devtmpfs                      995M     0  995M   0% /dev
tmpfs                        1003M     0 1003M   0% /dev/shm
tmpfs                        1003M   39M  964M   4% /run
/dev/mapper/VolGroup-lv_root   16G  832M   14G   6% /
tmpfs                        1003M   39M  964M   4% /run
tmpfs                        1003M     0 1003M   0% /sys/fs/cgroup
tmpfs                        1003M     0 1003M   0% /media
/dev/vda2                     485M   32M  428M   7% /boot
master.server.world:/home/     16G  848M   14G   6% /home
# home directory on NFS is mounted
[root@www ~]#
vi /etc/fstab
/dev/mapper/VolGroup-lv_root /                       ext4    defaults  1 1
UUID=65ec32e2-f459-4d63-b8b0-e18124b50f3a /boot      ext4    defaults  1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults  0 0
# add at the lat line: change home directory this server mounts to the one on NFS

master.server.world:/home /home                      nfs     defaults  0 0



發佈了25 篇原創文章 · 獲贊 3 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章