配置NIS服務器,在server端操作可以使所有client端的用戶帳號同步
測試為兩台centos7,server端192.168.52.137 client端192.168.52.140
前置條件:
關閉防火牆
關閉selinux
配置nis server端
1、安裝需要的軟件包:
yum -y install ypserv rpcbind
2、設置nis域名:
[root@spgpu ~]# ypdomainname srv.world
[root@spgpu ~]# echo "NISDOMAIN=srv.world" >> /etc/sysconfig/network
3、添加允許訪問NIS服務器的IP地址
根據自己的環境添加
[root@spgpu ~]# cat /var/yp/securenets
255.255.255.0 192.168.52.0
255.0.0.0 127.0.0.0
4、添加服務和客戶端解析:
ip地址 主機名和域名的結合 主機名
5、啟動相關服務並設置成開機自啟:
[root@spgpu ~]# systemctl start rpcbind ypserv ypxfrd yppasswdd
[root@spgpu ~]# systemctl enable rpcbind ypserv ypxfrd yppasswdd
6、更新nis數據庫:
[root@spgpu ~]# /usr/lib64/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. spgpu.srv.world 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>. 這里輸入:Ctrl + D
next host to add: spgpu.srv.world
next host to add:
The current list of NIS servers looks like this:
spgpu.srv.world
Is this correct? [y/n: y] y 這里輸入:y
We need a few minutes to build the databases...
Building /var/yp/srv.world/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/srv.world'
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/srv.world'
spgpu.srv.world has been set up as a NIS master server.
Now you can run ypinit -s spgpu.srv.world on all slave server.
7、檢測server服務是否正常:
rpcinfo -u 主機名 ypserv
[root@spgpu ~]# rpcinfo -u spgpu ypserv
program 100004 version 1 ready and waiting
program 100004 version 2 ready and waiting
配置nis客戶端
1、安裝相關的軟件包:
[root@spgpu01 ~]# yum -y install ypbind rpcbind
2、設置nis域名:
[root@spgpu01 ~]# ypdomainname srv.world
[root@spgpu01 ~]# echo "NISDOMAIN=srv.world" >> /etc/sysconfig/network
3、添加服務和客戶端解析:
ip地址 主機名和域名的結合 主機名
4、更新nis服務器:
authconfig \
--enablenis \
--nisdomain=srv.world \
--nisserver=spgpu.srv.world \ 這里填寫 nis server域名
--enablemkhomedir \
--update
5、啟動相關服務並設置成開機自啟:
[root@spgpu01 ~]# systemctl start rpcbind ypbind
[root@spgpu01 ~]# systemctl enable rpcbind ypbind
到此client端設置完成!
在server端創建用戶,修改用戶密碼之后需要執行一個命令才可以同步到所有的客戶端下
make -C /var/yp
因為沒做home目錄共享!client不會自動創建用戶家目錄,但是用戶是已經同步創建好了。
所以需要在client端需要su -用戶 才會創建用戶的家目錄!
可以通nfs共享server的home目錄到client端這樣自動創建家目錄。
在client也可以修改server端創建用戶的密碼:yppasswd 用戶名
[root@spgpu01 ~]# yppasswd qwer
Changing NIS account information for qwer on spgpu.szsp.cn.
Please enter root password: 這里輸入本機的root密碼
Changing NIS password for qwer on spgpu.szsp.cn.
Please enter new password:
Please retype new password:
The NIS password has been changed on spgpu.szsp.cn.