用户的共享
用户共享的优势:
在生产环境中我们要实现自动化的运维,就不能一个机器一个机器的操作,而是只需要一台机器就可以搞定全部的机器,这个用户的共享呢就是解决用户创建的问题,从而实现一台机器创建的用户其余机器都可以登录的结果。
我们以centos7作为服务器centos6作为客户端来实验
说明:
centos7(服务器)ip:192.168.127.143
centos6 (客户端)ip:192.168.127.142
区分:
服务端:[[email protected] ~]#
客户端:[[email protected] ~]#
服务器包的安装:
[[email protected] ~]# yum -y install ypserv ypbind yp-tools
[[email protected] ~]# yum -y install nfs-utils
客户端包的安装:
[[email protected] ~]# yum install ypbind -y
[[email protected] ~]# yum -y install autofs
配置域:
#重启后生效
[[email protected] ~]# vim /etc/sysconfig/network
# Created by anaconda
NISDOMAIN=lei
#当前生效
[[email protected] ~]# nisdomainname lei
配置nis服务
[[email protected] ~]# vim /etc/ypserv.conf
127.0.0.1:*:*:none #允许本机访问nis
192.168.127.0/255.255.255.0:*:*:none #允许这个网段的访问nis
*:*:*:deny #其他的全部拒绝
[[email protected] ~]# systemctl restart ypserv #重启nis服务
[[email protected] ~]# systemctl enable ypserv #使nis开机自启动
创建用户:
[[email protected] ~]# useradd -u 2018 -d /app/homedir/zhang zhang
[[email protected] ~]# passwd zhang
Changing password for user zhang.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
生成nis数据库
[[email protected] ~]# /usr/lib64/yp/ypinit -m
ctrl+d
y
客户端设置nis服务
[[email protected] ~]# setup
在Use NIS这里安空格即可选中
这里的lei是域,而ip是服务器的ip地址
NFS 共享家目录
[[email protected] ~]# vim /etc/exports.d/mage.exports
/app/homedir *(rw,sync) #注意*和()之间没有空格
autofs 自动挂载家目录
[[email protected] ~]# vim /etc/auto.master
/app/homedir /etc/auto.mage --timeout=10
[[email protected] ~]# vim /etc/auto.mage
* -fstype=nfs 192.168.127.143:/app/homedir/&
[[email protected] ~]# service autofs restart
测试
[[email protected] ~]# yptest
.........
.........
.........
Test 3: yp_match
WARNING: No such key in map (Map passwd.byname, key nobody)
1 tests failed
#Test 3: yp_match 下面的这个警告客户忽略,所以 1 tests failed 这个不算失败,这个是成功的
演示
[[email protected] ~]# su - zhangsan
[[email protected] ~]$ su - zhang
Password:
[[email protected] ~]$ pwd
/app/homedir/zhang