Linux的NIS配置
快速命令
# Server和Client设置NIS域名
nisdomainname nis_server
echo 'NISDOMAIN=nis_server' >> /etc/sysconfig/network
# Server写入ypserv配置文件
echo -e '127.0.0.0/255.255.255.0:*:*:none\n192.168.2.0/255.255.255.0:*:*:none\n*:*:*:deny'>> /etc/ypserv.conf
# 数据库初始化
/usr/lib64/yp/ypinit -m # Server涉及的服务
systemctl start rpcbind
systemctl start yppasswdd
systemctl start ypserv # Clinet配置
authconfig-tui
# Client涉及的服务
systemctl start rpcbind
systemctl start ypbind
NIS
当我们拥有多台Linux服务器时,账号管理就成为一个比较头大的问题了,比如在全部的服务器上新建、删除账户和修改密码,一台一台ssh登录去操作显然不是个好主意,账户同步是个大问题。为此NIS诞生了。
NIS全称Network Information Service,主要功能是对主机账号系统等系统信息提供集中的管理。
Server和Client
NIS有两种角色,Server和Client
Server会将自己的以下文件作成为DBM数据库档案:
- /etc/passwd用户基本信息:用户名、UID、GID、$HOME、$SHELL
- /etc/group用户组信息:GID和群内成员
- /etc/hosts域名:域名和IP解析
- /etc/services守护进程所对应的端口
- /etc/protocolsTCP/IP封包协定
- /etc/rpc每种RPC服务所对应的程序号码
- /var/yp/ypserversNIS服务器所提供的数据库。
当这些文件发生改变时候,需要在Client中生效,要再重新生成DBM数据库。
Client在有用户登录时,会先验证本机保存的用户,如果没有记录,会再向Server搜寻数据库里面数据做为验证用。
- yp-tools :提供 NIS 相关的查寻指令功能
- ypbind :Client提供绑定设定套件,系统中获取 NIS 域名,并使用 RPC 连接到服务器上
- ypserv :为Server提供NIS响应
- rpcbind :NIS和NFS类似的,也需要rpc来作为中转
Slave和Server架构
一般情况下我们一台Server对应为若干台Client服务,当我们有大量的服务器需要为大量Client服务的时候,一台Server可能从响应的服务质量可能就不是那么美好了的。这个时候我们可以额外配置台Slave作为从服务器。Server和Slave之间会进行数据的同步,从而再为Client提供服务。
不过除非有超过一百台的Linux主机,不然其实一个Server也是没问题的。
NIS_Server
安装软件
Server需要安装的软件有rpcbind、ypserv、yp-tools。ypbind为Client使用的,可以选择性安装。
#rpm系列的linux
sudo yum -y install ypserv yp-tools rpcbindypbind
# 这个方法是只下载,如果你的Server配置过nfs,可以很方便的为Clinent服务器安装吧哈哈
# yumdownloader --resolve --destdir=/root/yum ypserv ypbind yp-tools rpcbind
# deb系列的linux
sudo apt -y install nis
设置NIS域
直接用nisdomainname命令来设置
# 后面nisdomainname+域名,设置域名
[root@server_197 ~]# nisdomainname nis_server
# 单纯nisdomainname为返回当前域名
[root@server_197 ~]# nisdomainname
系统重新启动后也生效需要/etc/sysconfig/network中追加NISDONAIN=<name>
[root@server_197 ~]# echo 'NISDOMAIN=nis_server' >> /etc/sysconfig/network
[root@server_197 ~]# cat /etc/sysconfig/network
# Created by anaconda
NISDOMAIN=nis_server
添加NIS授权
相关的权限配置文件在/etc/ypserv.conf。可以先看一下里面的内容。
[root@server_197 ~]# cat /etc/ypserv.conf | grep -v '#'
files: 30 #这里的代表会读到内存中的数据库数量,一般情况30个是足够
xfr_check_port: yes
# 与master/slave 有关,将同步更新的数据库比对所使用的端口,放置于<1024内
# Host(允许的主机或者ip) : Domain(NIS域): Map(可用的数据库名字) : Security(安全限制)
* : * : shadow.byname : port
* : * : passwd.adjunct.byname : port
重点介绍一下后面查询的权限格式,使用冒号隔成四部分:
Host:Domain:Map:Security
# Host : Domain : Map : Security
#
# * : * : passwd.byname : port
# * : * : passwd.byuid : port # Not everybody should see the shadow passwords, not secure, since
# under MSDOG everbody is root and can access ports < 1024 !!!
* : * : shadow.byname : port
* : * : passwd.adjunct.byname : port
- Host为Client的ip或者网段,用来划分服务对象的
- 127.0.0.0/255.255.255.0
- Domain为NIS域名
- 一般情况都直接写*号以用来代表全部
- Map为可用数据库
- 就是由NIS制作出来的数据库名称
- Security为权限限制
- 没有限制(none)、仅能使用<1024 (port)及拒绝(deny)
依据具体情况我们可以这样写。
# 本机可以访问全部domain、map(数据库)、none(没有限制)
127.0.0.0/255.255.255.0 :* :* :none
# 192.168.2.0/24可以访问全部domain、map(数据库)、none(没有限制)
192.168.2.0/255.255.255.0 :* :* :none
# 其他ip全部deny(拒绝),和防火墙规则,这条规则是至关重要的,相当于是默认规则吧
* :* :* :deny
偷懒就echo加上去吧哈哈。
echo -e '127.0.0.0/255.255.255.0:*:*:none\n192.168.2.0/255.255.255.0:*:*:none\n*:*:*:deny'>> /etc/ypserv.conf
启动服务
需要启动rpcbind、yppasswd、ypserv,切记,先启动rpcbind。随便来个开机自启动啦
systemctl start rpcbind && systemctl enable rpcbind
systemctl start yppasswdd && systemctl enable yppasswdd
systemctl start ypserv && systemctl enable ypserv
账户操作
既然NIS的初衷的共享用户的,在生成数据库之前,先要把新建用户删除用户之类的操作完成,再生成数据库。每一次操作都要重新生成数据库和重新启动服务。
[root@server_197 ~]# adduser -s /bin/bash -g test -d /home/test test2022
# 创建个用户随便复习一下adduser
# -s 指定shell路径
# -g 所在组
# -d 设置home目录位置
[root@server_197 ~]# passwd test2022
Changing password for user test2022.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
数据库生成
执行/usr/lib64/yp/ypinit -m初始化(如果你安装的软件包是32位,对应的应该是/usr/lib/yp/ypinit -m),其中会等待我们输入next host to add,直接Ctrl+D跳过即可,再y确认
[root@server_197 ~]# /usr/lib64/yp/ypinit -m
At this point, we have to construct a list of the hosts which will run NIS
servers. server_197 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_197
next host to add:
The current list of NIS servers looks like this: server_197 Is this correct? [y/n: y] y
We need a few minutes to build the databases...
Building /var/yp/nis_server/ypservers...
Running /var/yp/Makefile...
gmake[1]: Entering directory `/var/yp/nis_server'
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_server' server_197 has been set up as a NIS master server. Now you can run ypinit -s server_197 on all slave server.
确保目前的rpcbind、yppasswdd、ypserv服务已经在正常的工作了。没有就systemctl启动一下。
更新后再重新启动一次吧
systemctl start rpcbind
systemctl start yppasswdd
systemctl start ypserv
NIS_Client
现在来配置Client。
安装软件
和Server不相同,不需要安装ypserv。
安装rpcbind、yp-tools、ypbind
# rpm
yum -y install ypbind yp-tools rpcbind # 其实我没有在deb上跑过,不太确定是不是
apt -y install nis
设置NIS域
这里和Server配置一样,domain要一致,否则无法使用。
直接用nisdomainname命令来设置
# 后面nisdomainname+域名,设置域名
[root@server_149 ~]# nisdomainname nis_server
# 单纯nisdomainname为返回当前域名
[root@server_149 ~]# nisdomainname
系统重新启动后也生效需要/etc/sysconfig/network中追加NISDONAIN=<name>
[root@server_149 ~]# echo 'NISDOMAIN=nis_server' >> /etc/sysconfig/network
[root@server_149 ~]# cat /etc/sysconfig/network
# Created by anaconda
NISDOMAIN=nis_server
设置连接
在目录含中输入,可以进入半图形化的设置界面。
authconfig-tui
上下或tab键可以控制光标移动,在NIS位置选择,即按空格。
F12下一页,光标移动到Next选择也可以。
输入一下Domain和Server,即之前设置的nisdomainname和NIS_Server的IP地址。
完成配置后
重新启动一下服务即可。
systemctl start rpcbind
systemctl start ypbind
测试
在Client中尝试登录之前的新建的test2022用户
[root@client_149 ~]# su test2022
bash: /home/test/.bashrc: Permission denied
bash-4.2$
当然目前要注意HOME目录是Server自己的HOME目录,Client自然是没有啦,可以使用NFS来挂载,具体可以看我主页的另外一篇文章。
Linux的NIS配置的更多相关文章
- 在Linux虚拟机下配置tomcat
1.到Apache官网下载tomcat http://tomcat.apache.org/download-80.cgi 博主我下载的是tomcat8 博主的jdk是1.8 如果你们的jdk是1.7或 ...
- 在Linux虚拟机下配置jdk的环境变量
1.到Oracle公司的官网里下载好jdk,网址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133 ...
- Linux网络属性配置
目录 IP地址分类 如何将Linux主机接入到网络中 网络接口的命名方式 ifcfg系列命令 如何配置主机名 如何配置DNS服务器指向 iproute2系列命令 Linux管理网络服务 永久生效配置路 ...
- 阿里云服务器Linux CentOS安装配置(零)目录
阿里云服务器Linux CentOS安装配置(零)目录 阿里云服务器Linux CentOS安装配置(一)购买阿里云服务器 阿里云服务器Linux CentOS安装配置(二)yum安装svn 阿里云服 ...
- 阿里云服务器Linux CentOS安装配置(九)shell编译、打包、部署
阿里云服务器Linux CentOS安装配置(九)shell编译.打包.部署 1.查询当前目录以及子目录下所有的java文件,并显示查询结果 find . -name *.java -type f - ...
- 阿里云服务器Linux CentOS安装配置(八)nginx安装、配置、域名绑定
阿里云服务器Linux CentOS安装配置(八)nginx安装.配置.域名绑定 1.安装nginx yum -y install nginx 2.启动nginx service nginx star ...
- 阿里云服务器Linux CentOS安装配置(七)域名解析
阿里云服务器Linux CentOS安装配置(七)域名解析 1.购买域名 登录阿里云,左侧菜单点击[域名],然后[域名注册],完成域名购买.(一般首年45元) 2.添加域名解析 在域名列表里点击你的域 ...
- 阿里云服务器Linux CentOS安装配置(六)resin多端口配置、安装、部署
阿里云服务器Linux CentOS安装配置(六)resin多端口配置.安装.部署 1.下载resin包 http://125.39.66.162/files/2183000003E08525/cau ...
- 阿里云服务器Linux CentOS安装配置(五)jetty配置、部署
阿里云服务器Linux CentOS安装配置(五)jetty配置.部署 1.官网下载jetty:wget http://repo1.maven.org/maven2/org/eclipse/jetty ...
随机推荐
- 打字练习-编程语言关键字系列-html
以下是小编整理的部分html关键字,专门给有需要的朋友进行打字练习用,通过打字练习的方式,既提高了打字速度,又可以熟悉html关键字~~~ www, url, http, W3C, html, htm ...
- kubernetes code-generator使用
目录 Overview Prerequisites CRD code-generator 编写代码模板 code-generator Tag说明 开始填写文件内容 type.go doc.go reg ...
- 5G的发布加快了智慧城市/三维物联网等行业的发展
最近很多人发现自己的5G手机突然没了5G信号,难道是美国搞的鬼? 不不不,这其实是因为5G的NSA基站被撤站了,官方已经做了部署,要大力推进SA网络建设.所以之前支持NSA模式的5G手机,现在都成了4 ...
- Electron学习(三)之简单交互操作
写在前面 最近一直在做批量测试工具的开发,打包的exe,执行也是一个黑乎乎的dos窗口,真的丑死了,总感觉没个界面,体验不好,所以就想尝试写桌面应用程序. 在技术选型时,Java窗体实现使用JavaF ...
- 2m高分辨率土地利用分类数据
数据下载链接:百度云下载链接 土地利用数据是在根据影像光谱特征,结合野外实测资料,同时参照有关地理图件,对地物的几何形状,颜色特征.纹理特征和空间分布情况进行分析,建立统一解译标志的基础之上,依据多源 ...
- Linux查看内网服务器的出口IP
查看内网服务器的出口IPcurl ifconfig.me [root@vpnserver ~]# curl ifconfig.me111.10.100.100 [root@vpnserver ~]#
- JDBC:获取自增长键值的序号
1.改变的地方 实践: package com.dgd.test; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...
- llinux的mysql数据库完全卸载
https://blog.csdn.net/qq_41829904/article/details/92966943https://www.cnblogs.com/javahr/p/9245443.h ...
- VxWorks环境搭建与学习
搭建环境所需的所有资源: https://pan.baidu.com/s/1sUF2I_DBHs-86IUJ4Ykn2Q 提取码: t7sj 实时系统vxWorks - Shell命令 https:/ ...
- Solution -「COCI 2016-2017」 Mag 结论证明
结论:最多包含一个 \(2\),并且不在链的两端点. 证明:我们问题分成两个 \(\texttt{pass}\). \(\texttt{pass 1}\):\(\forall u,s.t.x_{u}\ ...