Home | Mirror | Search |
目錄
過程 54.1. 安裝NIS伺服器
ypserv
# yum install ypserv -y
/etc/hosts
[root@nis ~]# hostname nis.example.com [root@nis ~]# echo "192.168.3.5 nis.example.com" >> /etc/hosts [root@nis ~]# cat /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 datacenter.example.com datacenter localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 127.0.0.1 kerberos.example.com 192.168.3.5 nis.example.com
設置NIS域名
# nisdomainname example.com # nisdomainname example.com
加入 /etc/rc.local 開機腳本
# echo '/bin/nisdomainname example.com' >> /etc/rc.local # echo 'NISDOMAIN=example.com' >> /etc/sysconfig/network
設置/etc/ypserv.conf主配置檔案
# vim /etc/ypserv.conf 127.0.0.0/255.255.255.0 : * : * : none 192.168.3.0/255.255.255.0 : * : * : none * : * : * : deny
創建 /var/yp/securenets 檔案
securenets 安全配置檔案
# vim /var/yp/securenets host 127.0.0.1 255.255.255.0 192.168.3.0
啟動NIS伺服器
NIS伺服器需要portmap服務的支持,並且需要啟動ypserv和yppasswdd兩個服務
[root@nis ~]# service portmap status portmap (pid 2336) is running... [root@nis ~]# service ypserv start Starting YP server services: [ OK ] [root@nis ~]# service yppasswdd start Starting YP passwd service: [ OK ]
構建NIS資料庫
32bit: /usr/lib/yp/ypinit -m
64bit: /usr/lib64/yp/ypinit -m
[root@nis ~]# /usr/lib64/yp/ypinit -m At this point, we have to construct a list of the hosts which will run NIS servers. nis.example.com is in the list of NIS server hosts. Please continue to add the names for the other hosts, one per line. When you are done with the list, type a <control D>. next host to add: nis.example.com next host to add: next host to add: The current list of NIS servers looks like this: nis.example.com Is this correct? [y/n: y] We need a few minutes to build the databases... Building /var/yp/example.com/ypservers... Running /var/yp/Makefile... gmake[1]: Entering directory `/var/yp/example.com' Updating passwd.byname... Updating passwd.byuid... Updating group.byname... Updating group.bygid... Updating hosts.byname... Updating hosts.byaddr... Updating rpc.byname... Updating rpc.bynumber... Updating services.byname... Updating services.byservicename... Updating netid.byname... Updating protocols.bynumber... Updating protocols.byname... Updating mail.aliases... gmake[1]: Leaving directory `/var/yp/example.com' nis.example.com has been set up as a NIS master server. Now you can run ypinit -s nis.example.com on all slave server.
檢查
# ls /var/yp/ binding example.com Makefile nicknames securenets ypservers
Service
[root@datacenter ~]# chkconfig --list | grep yp ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off yppasswdd 0:off 1:off 2:off 3:off 4:off 5:off 6:off ypserv 0:off 1:off 2:off 3:off 4:off 5:off 6:off ypxfrd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@nis ~]# chkconfig ypserv on [root@nis ~]# chkconfig yppasswdd on
Now you can run ypinit -s nis.example.com on all slave server.
# ypinit -s nis.example.com
過程 54.2. 安裝NIS客戶端軟件
NIS客戶機需要安裝ypbind和yp-tools兩個軟件包
# yum install ypbind yp-tools -y
NIS域名
# nisdomainname example.com
/etc/hosts
192.168.3.5 nis.example.com
/etc/yp.conf
# vim /etc/yp.conf domain example.com server nis.example.com
/etc/nsswitch.conf
# vim /etc/nsswitch.conf passwd: files nis shadow: files nis group: files nis hosts: files nis dns
啟動ypbind服務程序
[root@test ~]# service portmap status portmap is stopped [root@test ~]# service portmap start Starting portmap: [ OK ] [root@test ~]# service ypbind start Turning on allow_ypbind SELinux boolean Binding to the NIS domain: [ OK ] Listening for an NIS domain server..
yp-tools 測試工具
yptest 命令可對NIS伺服器進行自動測試
# yptest
ypwhich 命令可顯示NIS客戶機所使用的NIS伺服器的主機名稱和資料庫檔案列表
# ypwhich # ypwhich -x
ypcat命令顯示資料庫檔案列表和指定資料庫的內容
# ypcat -x # ypcat passwd
NIS Client Service
# chkconfig ypbind on
# authconfig-tui
Use NIS
┌────────────────┤ Authentication Configuration ├─────────────────┐ │ │ │ User Information Authentication │ │ [ ] Cache Information [*] Use MD5 Passwords │ │ [ ] Use Hesiod [*] Use Shadow Passwords │ │ [ ] Use LDAP [ ] Use LDAP Authentication │ │ [*] Use NIS [ ] Use Kerberos │ │ [ ] Use Winbind [ ] Use SMB Authentication │ │ [ ] Use Winbind Authentication │ │ [ ] Local authorization is sufficient │ │ │ │ ┌────────┐ ┌──────┐ │ │ │ Cancel │ │ Next │ │ │ └────────┘ └──────┘ │ │ │ │ │ └─────────────────────────────────────────────────────────────────┘
NIS Settings
┌─────────────────┤ NIS Settings ├─────────────────┐ │ │ │ Domain: example.com_____________________________ │ │ Server: nis.example.com_________________________ │ │ │ │ ┌──────┐ ┌────┐ │ │ │ Back │ │ Ok │ │ │ └──────┘ └────┘ │ │ │ │ │ └──────────────────────────────────────────────────┘
nis server:
在NIS伺服器上創建一個test用戶
# adduser test # passwd test # /usr/lib64/yp/ypinit -m
nis client
使用test用戶登錄到客戶機
ssh test@client.example.com
測試
[root@test ~]# yptest Test 1: domainname Configured domainname is "example.com" Test 2: ypbind Used NIS server: nis.example.com Test 3: yp_match WARNING: No such key in map (Map passwd.byname, key nobody) Test 4: yp_first neo neo:$1$e1nd3pts$s7NikMnKwpL4vUp2LM/N9.:500:500::/home/neo:/bin/bash Test 5: yp_next test test:$1$g4.VCB7i$I/N5W/imakprFdtP02i8/.:502:502::/home/test:/bin/bash svnroot svnroot:!!:501:501::/home/svnroot:/bin/bash Test 6: yp_master nis.example.com Test 7: yp_order 1271936660 Test 8: yp_maplist rpc.byname protocols.bynumber ypservers passwd.byname hosts.byname rpc.bynumber group.bygid services.byservicename mail.aliases passwd.byuid services.byname netid.byname protocols.byname group.byname hosts.byaddr Test 9: yp_all neo neo:$1$e1nd3pts$s7NikMnKwpL4vUp2LM/N9.:500:500::/home/neo:/bin/bash test test:$1$g4.VCB7i$I/N5W/imakprFdtP02i8/.:502:502::/home/test:/bin/bash svnroot svnroot:!!:501:501::/home/svnroot:/bin/bash 1 tests failed
更改密碼
$ yppasswd Changing NIS account information for test on nis.example.com. Please enter old password: Changing NIS password for test on nis.example.com. Please enter new password: Please retype new password: The NIS password has been changed on nis.example.com.
-bash-3.2$ ypcat hosts 127.0.0.1 localhost.localdomain localhost 127.0.0.1 kerberos.example.com 192.168.3.5 nis.example.com -bash-3.2$ ypcat passwd neo:$1$e1nd3pts$s7NikMnKwpL4vUp2LM/N9.:500:500::/home/neo:/bin/bash test:$1$g4.VCB7i$I/N5W/imakprFdtP02i8/.:502:502::/home/test:/bin/bash svnroot:!!:501:501::/home/svnroot:/bin/bash
-bash-3.2$ ypwhich nis.example.com ypwhich -x Use "ethers" for map "ethers.byname" Use "aliases" for map "mail.aliases" Use "services" for map "services.byname" Use "protocols" for map "protocols.bynumber" Use "hosts" for map "hosts.byname" Use "networks" for map "networks.byaddr" Use "group" for map "group.byname" Use "passwd" for map "passwd.byname"