Centos7部署nis服务

2024-03-05
2分钟阅读时长

修改hosts

目前有server端10.249.2.7 和 client端 10.249.2.100

server端主机名为master,client端主机名为node1

所有节点都要添加server端hosts

10.249.2.7 master nis.local master.nis.local

服务端部署

 yum -y install ypserv ypbind yp-tool 

设置NIS服务器域名 nis.local

 ypdomainname nis.local

将nis域名加入网络配置中,重启也能生效

echo "NISDOMAIN=nis.local" >> /etc/sysconfig/network

编辑客户端权限 **/var/yp/securenets **,第一列为掩码,第二列为网段

255.255.255.0 10.249.2.0

启动服务

 systemctl start rpcbind ypserv ypxfrd yppasswdd
 systemctl enable rpcbind ypserv ypxfrd yppasswdd

初始化NIS数据库

[root@master ~]# /usr/lib64/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS
servers.  hstack 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:  master
        next host to add:  master.nis.local
        next host to add:
The current list of NIS servers looks like this:

hstack
master.nis.local

Is this correct?  [y/n: y]  y
We need a few minutes to build the databases...
Building /var/yp/nis.local/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/nis.local'
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/nis.local'

hstack has been set up as a NIS master server.

Now you can run ypinit -s hstack on all slave server.

其中第一个提示按ctrl+d组合键离开

客户端

安装相应软件

 yum -y install ypbind rpcbind

设置nis域名为nis.local

ypdomainname nis.local

同样加入开机自启

echo "NISDOMAIN=nis.local" >> /etc/sysconfig/network

加入认证

authconfig \
--enablenis \
--nisdomain=nis.local \
--nisserver=master.nis.local \
--enablemkhomedir \
--update

启动服务

systemctl start rpcbind ypbind
systemctl enable rpcbind ypbind

测试

服务端 添加新用户bob和mike,并设置密码后,更新服务端数据库

make -C /var/yp

客户端测试 可以切进服务端创建的用户

[root@node1 ~]# su - bob
Creating home directory for bob.
Last login: Mon Feb 26 13:23:54 CST 2024 on pts/0
[bit@node1 ~]$ pwd
/home/bob