服务端配置:
Server: 192.168.0.178(CentOS 7.6)
# systemctl stop firewalld
# systemctl disable firewalld
# sed -i 's/=enforcing/=disable/' /etc/selinux/config
安装 NIS 服务端
# yum install -y ypserv rpcbind yp-tools
设置 NIS 域名
# nisdomainname nis.local
# echo "nisdomainname nis.local" >> /etc/rc.d/rc.local
# chmod +x /etc/rc.local
# echo "NISDOMAIN=nis.local" >> /etc/sysconfig/network
# echo "192.168.0.178 nis.local" >> /etc/hosts
编辑 /etc/sysconfig/network 文件,设置 NIS 服务端口为 1011
# sed -i 's/YPSERVER_ARGS=/YPSERVER_ARGS="-p 1011"/' /etc/sysconfig/network
编辑 /etc/sysconfig/yppasswdd 文件,设置访问密码端口为 1012
# sed -i 's/YPPASSWDD_ARGS=/YPPASSWDD_ARGS="--port 1012"/' /etc/sysconfig/yppasswdd
设置允许内网全网段均可访问:
# echo "192.168.0.0/24:*:*:none" >> /etc/ypserv.conf
重新启动服务
# systemctl restart rpcbind
# systemctl restart ypserv
# systemctl restart yppasswdd
将服务设为开机自启
# systemctl enable rpcbind
# systemctl enable ypserv
# systemctl enable yppasswdd
检查服务是否启动:
# rpcinfo -p localhost
# rpcinfo -u localhost ypserv
创建生成 NIS 用户数据库
# /usr/lib64/yp/ypinit -m
每次修改用户后,执行下面命令来生效,不用重启服务
# make -C /var/yp
客户端配置:
Client: 192.168.0.154(RedHat 6.9),192.168.0.155(RedHat 6.7)
# yum install -y rpcbind yp-tools ypbind
# nisdomainname xynis.local
# echo "nisdomainname xynis.local" >> /etc/rc.local
# echo "NISDOMAIN=xynis.local" >> /etc/sysconfig/network
# echo "192.168.0.178 xynis.local" >> /etc/hosts
修改 /etc/nsswitch.conf,添加 NIS 服务认证,做法是:分别该文件的 passwd,shadow,group 以及 hosts 行的 files 后面都添加上 nis。
修改 /etc/sysconfig/authconfig 文件,将 USENIS=no 改为 USENIS=yes
# sed -i 's/USENIS=no/USENIS=yes/' /etc/sysconfig/authconfig
修改 /etc/pam.d/system-auth 文件,在password sufficient 一行中,在 shadow 后面插入 nis
配置 NIS 服务器 IP 地址
# echo "domain nis.local server 192.168.0.178" >> /etc/yp.conf
重启服务
# service rpcbind restart
# service ypbind restart
注:若 ypbind 启动失败的话,需要设置下 NIS 服务器上的防火墙(iptables 或 firewall-cmd)
设置开机自启
# chkconfig rpcbind on
# chkconfig ypbind on