NIS和NFS
- 环境
- 服务端(server):
192.168.111.100
- 客户端(client):
192.168.111.200
- 两台服务器的防火墙和selinux需要关闭
- 服务端(server):
NIS搭建
服务端配置
-
安装
ypserv
:yum install ypserv -y
-
创建用户
-
useradd aaa echo 123456 | passwd --stdin aaa useradd bbb echo 123456 | passwd --stdin bbb
-
-
修改网络配置
-
vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=server # 服务器名 NISDOMAIN=bhlu.com # 域名
-
-
设置开机启动的时候修改nis域名
-
vim /etc/rc.d/rc.local /bin/nisdomainname bhlu.com
-
-
手动修改nis域名:
nisdomainname bhlu.com
-
启动
ypserv
并设置开机启动:systemctl start ypserv && systemctl enable ypserv
-
/usr/lib64/yp/ypinit -m
-
At this point, we have to construct a list of the hosts which will run NIS servers. server 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: server next host to add: # 按ctrl + D The current list of NIS servers looks like this: server Is this correct? [y/n: y] y # 输入y We need a few minutes to build the databases... Building /var/yp/bhlu.com/ypservers... Running /var/yp/Makefile... gmake[1]: 进入目录“/var/yp/bhlu.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]: 离开目录“/var/yp/bhlu.com” server has been set up as a NIS master server. Now you can run ypinit -s server on all slave server.
-
-
cd /var/yp/ && make
客户端配置
-
启动setup:
setup
-
进入authentication configuration
-
空格勾选上nis,直接下一步
-
设置服务端的域名和ip,然后确定
-
-
测试用户有没有同步:
id aaa
Autofs搭建
服务端
-
配置共享目录
-
vim /etc/exports /home 192.168.111.0/24(rw,sync,no_root_squash) # /home 允许192.168.111.0这个网段的使用 /tools 192.168.111.0/24(rw,sync,no_root_squash) # 设置多个
-
-
exportfs -rv
-
检查共享目录:
showmount -e 192.168.111.100
客户端
-
安装
autofs
:yum install -y autofs
-
配置挂载目录
-
vim /etc/auto.master /- /etc/auto.nis # 设置挂载所有
-
-
配置挂载方式和地址
-
vim /etc/auto.nis /home -fstype=nfs 192.168.111.100:/home /tools -fstype=nfs 192.168.111.100:/tools # 挂载多个
-
-
启动
autofs
并设置开机自启:systemctl restart autofs && systemctl enable autofs
-
测试是否成功:
cd /home/aaa