close

延續上集

這邊要開始建立 NFS 服務

Server:

Server 端要安裝套件

1. yum install nfs-utils

2.  啟用NFS服務

#systemctl enable nfs-server

#systemctl start nfs-server


防火牆部份: (nfs是已經預先寫好的套件,只要開放就好)

#firewall-cmd --permanent –add-service=nfs

#firewall-cmd --permanent –add-service=mountd

#firewall-cmd --permanent –add-service=rpc-bind

#firewall-cmd –reload

NFS 服務 111/tcp111/udp 2048/tcp 2049/udp

在掛載的時候會隨機使用1024以上port號,所以可以再設定指令port

 

如果有開放Selinux的話 要另外設定開放權限

#setsebool -P nfs_export_all_rw on

#setsebool -P nfs_export_all_ro on


 

接下來設定要分享的資料夾。

我們延伸上一篇說到的NIS 結合 NFS 的架構。

我們那時候為了要讓NIS的帳號在遠端連線時可以讀取到自己的家目錄。

所以我們刻意的將家目錄設置在/rhome下面

 

我們這邊就是要針對/rhome做一個分享的動作

#mkdir /rhome (如果已經創建過,這裡就不用在創建了

 

我們這邊設定只要是10.10.10.0網段的都可以掛載我們的目錄。

#vim /etc/exports

/rhome  10.10.10.0/24(rw,no_root_squash)

設定完後用指令確認一下掛載狀況

#showmount -e localhost

Export list for localhost:

/rhome 10.10.10.11/24

可以這樣查到,代表已經成功分享路徑出去了。


Client:

Client端應該預設就可以掛載nfs分享出來的路徑,

除非是你用最小安裝,造成沒有安裝到nfs-utils套件。

[root@ localhost ~]# mount -t nfs 10.10.10.11:/rhome /rhome

mount: wrong fs type, bad option, bad superblock on 10.10.10.11:/rhome,

missing codepage or helper program, or other error

(for several filesystems (e.g. nfs, cifs) you might

need a /sbin/mount.<type> helper program)

In some cases useful info is found in syslog - try

dmesg | tail or so.

錯誤已經給了我們關鍵字,

我們依訊息仔細去找了一下,發現這台主機竟然沒有這個格式的掛載方式

[root@localhost ~]# ls -l /sbin/m

makedumpfile      mkdumprd          mkfs.ext2         mkhomedir_helper

matchpathcon      mke2fs            mkfs.ext3         mklost+found

mii-diag          mkfs              mkfs.ext4        

[root@ localhost ~]# ls -l /sbin/mod

modinfo   modprobe 

完全沒看到mount.XXX 開頭的檔案

因為使用最小安裝的 CentOS 是不包含 nfs-utils !

 

所以這個時候要另外去安裝

# yum install nfs-utils

才有辦法安裝到這種方式

再確認一次就出現了

[root@localhost ~]# ls -l /sbin/mount

mount.nfs   mount.nfs4  mountstats 

 

再來就掛載就好!!

[root@localhost ~]# mount -t nfs 10.10.10.11:/rhome /rhome

[root@localhost ~]# ls -l /rhome/

total 0

drwx------ 2 1005 1006 79  8  7 22:24 nisclient01

這樣家目錄就掛載過來了

 

[root@localhost ~]# df -Th

Filesystem              Type      Size  Used Avail Use% Mounted on

.

10.10.10.11:/rhome    nfs4       48G  1.2G   47G   3% /rhome

 


我們再試試看用NIS創建的帳號來做登入看看。

用下列方式建立的帳號

#adduser –u 1001 nisclient01 -G sudogrp -d /rhome/ nisclient01

 

會發現登入時不再是以前的

-bash-4.2$

而是像直接用本機帳號登入的感覺
錯誤訊息跟我們前一篇設定的ypserv.conf的設定檔有關係。

(重點在於I have no name!  , 這個問題後面說明) 

/usr/bin/id: cannot find name for user ID 1001

/usr/bin/id: cannot find name for group ID 1001

[I have no name!@localhost ~]$

切換到superuser也可以

[I have no name!@localhost ~]$ sudo su -

Last login: Tue Aug  EDT 2017 from X.X.X.X on pts/0

[root@localhost ~]#

到這邊算是成功一半。


但我們要讓他再開機時能夠自動掛載上來,就要再添加一下設定。

設定開機掛載

#vim /etc/fstab

添加下面那一行

10.10.10.11:/rhome /rhome nfs defaults,_netdev 0 0

就完成了開機掛載的動作。

 

複習一下環境:

1. Server 端要開機啟用的服務有

NIS : rpcbindypservyppasswdd

NFS: nfs-server

 

2.Client 端要開機啟用的服務有

NIS: ypbind

NFS: 開機掛載NFS空間


 

當然這種帳號控管的服務只有一台式很危險的。

所以會建立第二台Slave主機去進行。

這方面就在請各位去尋找一下相關文件了。

 

Slave主機關鍵就是要同步Master上面的帳號密碼

關鍵字 /usr/lib/yp/ypinit -s [主要的NIS伺服器]

 

相關文件可以參考:

柏青哥 SUSE Linux
第十五章 架 NFS NIS Server
http://paching.myweb.hinet.net/lesson15.htm#11


錯誤問題說明及處理:

關於 I have no name! 問題來自於NIS的設定檔

#vim /etc/ypserv.conf
我們前一篇將他設定為port

10.10.10.0/255.255.255.0   : *   : *   : port

*                        : *       : *      : deny

 

這邊我們將他修改為none

10.10.10.0/255.255.255.0   : *   : *   : none

*                        : *       : *      : deny

 

然後Server端重啟服務

#systemctl restart ypserv

 

#!#####################################################

Client端再重新登入測試看看

 

[root@localhost ~]# su - nisclient01

Last login: Tue Aug  8  EDT 2017 on pts/1

[nisclient01@localhost ~]$

 

出現的不再是  I have no name!

附註:

ypserv.cong 的三個設定值

none :無論如何就是可以無條件進入本機;

port :僅允許 < 1024 以下的 port 進入;1024以下的port預設只有root可以啟用

deny :無論如何就是關閉不讓人家登入主機!

這邊關於port的使用可能要再研究一下

 

關於NIS + NFS 使用先說明到這裡。

未來會再研究更適合進行帳號統一控管的服務OpenLDAP。

(本篇完結)

回顧上一篇文章

IT專案-建個集中帳號控管伺服器吧<NIS+NFS> 上集

arrow
arrow
    全站熱搜

    IT001 發表在 痞客邦 留言(0) 人氣()