#安装软件包配置基础环境
yum -y install ypserv rpcbind
echo ‘/usr/bin/ypdomainname hpc.com‘>>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/usr/bin/ypdomainname hpc.com
#设定允许使用NIS的客户端网段
vi /var/yp/securenets
255.0.0.0 127.0.0.0
255.0.0.0 10.0.0.0
#编辑hosts表
vi /etc/hosts
10.0.0.30 mgt01
10.0.0.32 client01
#设定服务启动
systemctl start rpcbind ypserv ypxfrd yppasswdd
systemctl enable rpcbind ypserv ypxfrd yppasswdd
#初始化
/usr/lib64/yp/ypinit -m
next host to add: mgt01
next host to add:# Ctrl + D key
Is this correct? [y/n: y] y
#重启服务
systemctl restart rpcbind ypserv ypxfrd yppasswdd
#添加用户后执行刷新数据库
cd /var/yp
make
#客户端安装
yum -y install ypbind rpcbind
echo ‘/usr/bin/ypdomainname hpc.com‘>>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/usr/bin/ypdomainname hpc.com
#编辑hosts表
vi /etc/hosts
10.0.0.30 mgt01
10.0.0.31 client01
#客户端加入
authconfig --enablenis --nisdomain=hpc.com --nisserver=mgt01 --updateall
#设定服务启动
systemctl start rpcbind ypbind
systemctl enable rpcbind ypbind
#首先配置以上客户端添加
#配置副服务器
yum -y install ypserv rpcbind
echo ‘/usr/bin/ypdomainname hpc.com‘>>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
/usr/bin/ypdomainname
#设定允许使用NIS的客户端网段
vi /var/yp/securenets
255.0.0.0 127.0.0.0
255.0.0.0 10.0.0.0
#编辑hosts表
vi /etc/hosts
10.0.0.30 mgt01
10.0.0.31 mgt02
10.0.0.32 client01
#设定服务启动
systemctl start rpcbind ypserv ypxfrd yppasswdd
systemctl enable rpcbind ypserv ypxfrd yppasswdd
#从主节点同步数据
/usr/lib64/yp/ypinit -s hpc.com
#配置主节点为客户端
authconfig --enablenis --nisdomain=hpc.com --nisserver=mgt01 --updateall
#主节点编辑配置
vi /var/yp/Makefile
NOPUSH=false
#添加副节点
/usr/lib64/yp/ypinit -m
next host to add: mgt02
next host to add: # Ctrl + D key
Is this correct? [y/n: y] y
#所有节点添加副服务器
vi /etc/yp.conf
domain hpc.com server mgt01
domain hpc.com server mgt02
#主节点手动推送数据库
cd /var/yp/hpc.com/ && yppush -h mgt02 *
编辑/usr/local/bin/nisadd
#!/bin/bash
name=$1
if [ -z $name ]
then
echo "please input your username"
exit 0
fi
passwd=$2
if [ -z $passwd ]
then
echo "please input your passwd"
exit 0
fi
#if [`cat /etc/passwd |grep ^$name:`]
# then
# echo "User $name exit"
# exit 0
#fi
useradd $name && echo $passwd |passwd --stdin $name
su $name -c "ssh-keygen -t rsa -N ‘‘ -f ~/.ssh/id_rsa ; cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys ;echo ‘StrictHostKeyChecking no‘ > ~/.ssh/config;chmod 644 ~/.ssh/authorized_keys ~/.ssh/config"
cd /var/yp && make
EOF
chmod +x /usr/local/bin/nisadd
原文:https://www.cnblogs.com/leaus/p/13703589.html