红联Linux门户
Linux帮助

基于Ubuntu 12.04搭建NIS Slave服务

发布时间:2017-04-23 10:29:26来源:linux网站作者:guyongqiangx
1.背景
1.1.一大段废话
由于公司某些业务变更的原因,将服务器从原来的IT部门转到了BU,并且没有了支持,所有事情都得自力更生。
迁移过来的多台服务器中有两台NIS服务器,系统是Sun OS 5.10(即Solaris 10),好吧,我是Solaris小白,也不打算再花时间去学习这个东东,但又担心哪天系统挂了或坏了就悲剧了。
所以决定在现有的Ubuntu上先做一个NIS Slave吧,即使系统被挂了或其它原因无法使用,那还能用这个Slave顶一顶。
由于NIS服务主要是一些查询,本身对服务器性能要求不高,手上的台式老机DELL T3400用来做Slave也是绰绰有余的啦。好吧,我比较懒,不想重装为CentOS或者Ubuntu Server了,够用就好啦。
1.2.背景简述
整个环境简述如下:
原有两台NIS服务器,系统为Solaris 10
NIS Master, nis1.she.guyongqiangx.com
NIS Slave,nis2.she.guyongqiangx.com
新增一台NIS服务器,系统为Ubuntu 12.04.5 LTS
备份 NIS Slave,nis3.she.guyongqiangx.com
整个操作分为两大部分:
NIS Master上新增Slave服务器nis3
在nis3上将服务器设置为NIS Slave
 
2.NIS Master上新增Slave
在网上找到一个基于Solaris 11.2新增NIS Slave的说明:
How to Add a New Slave Server:https://docs.oracle.com/cd/E36784_01/html/E36831/anis2-proc-51.html
这篇文章是基于Solaris 11.2的,奇怪的是我之前曾经按照这里面的步骤在Solaris 10上运行的时候失败了,但是这次当我再次验证这个步骤的时候却又是成功的,如果有遇到同样问题的请告诉我。
以下是我的操作记录:
1].进入/var/yp目录
基于Ubuntu 12.04搭建NIS Slave服务
执行makedbm对ypservers数据文件进行反编译
# which makedbm
/usr/sbin/makedbm
# makedbm -u she/ypservers > temp-file
# cat temp-file
nis2.she.guyongqiangx.com 
nis1.she.guyongqiangx.com 
YP_LAST_MODIFIED 1241053445
YP_MASTER_NAME nis1.she.guyongqiangx.com
编辑temp-file,添加nis3
# cat temp-file
nis3.she.guyongqiangx.com
nis2.she.guyongqiangx.com 
nis1.she.guyongqiangx.com 
YP_LAST_MODIFIED 1492590247
YP_MASTER_NAME nis1.she.guyongqiangx.com
编译temp-file重新生成数据库文件
# makedbm temp-file ypservers
在nis2上验证ypservers的内容
# makedbm -u she/ypservers
nis3.she.guyongqiangx.com 
nis2.she.guyongqiangx.com 
nis1.she.guyongqiangx.com 
YP_LAST_MODIFIED 1241053445
YP_MASTER_NAME nis1.she.guyongqiangx.com
 
3.nis3上设置为NIS Slave服务
3.1.修改IP
根据nis3的环境修改IP和路由等设置,修改后如下:
ygu@stbszx-adm-1:~$ cat /etc/network/interfaces 
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.148.7.35
netmask 255.255.254.0
gateway 10.148.6.1
dns-nameservers 192.19.189.30 192.19.189.10
dns-search she.guyongqiangx.com guyongqiangx.com she.guyongqiangx.net guyongqiangx.net
3.2.修改hostname
原有hostname为stbszx-adm-1,修改为nis3,如下:
ygu@stbszx-adm-1:~$ cat /etc/hostname 
nis3
3.3.修改hosts
修改hosts文件,添加对本机nis3以及nis1和nis2的hostname和IP映射:
ygu@stbszx-adm-1:~$ cat /etc/hosts
127.0.0.1       localhost
10.148.7.35     nis3 nis3.she.guyongqiangx.com nis3.she.guyongqiangx.net
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# 2017-04-22 adminbse ygu - NIS servers
10.148.138.17   nis2.she.guyongqiangx.com
10.148.138.16   nis1.she.guyongqiangx.com
3.4.重启并检查设置
由于主机名等设置需要重启才能生效,所以在安装NIS组件前重启电脑
ygu@stbszx-adm-1:~$ sudo shutdown -r now
Broadcast message from ygu@stbszx-adm-1
(/dev/pts/1) at 15:55 ...
The system is going down for reboot NOW!
检查 3.1-3.3的所有设置是否生效:
ygu@nis3:~$ hostname
nis3
ygu@nis3:~$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:10:18:55:8c:b0  
inet addr:10.148.7.35  Bcast:10.148.7.255  Mask:255.255.254.0
inet6 addr: fe80::210:18ff:fe55:8cb0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:720 errors:0 dropped:0 overruns:0 frame:0
TX packets:260 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000 
RX bytes:91702 (91.7 KB)  TX bytes:38110 (38.1 KB)
Interrupt:16 
3.5.安装NIS组件
nis服务基于rpcbind提供服务,所以需要同时安装rpcbind和nis组件,
ygu@nis3:~$ sudo apt-get install rpcbind nis
安装nis时会弹出设置NIS domain的对话框,这里填写为she:
基于Ubuntu 12.04搭建NIS Slave服务
这个对话框实际上是创建文件/etc/defaultdomain,并写入内容she,如下:
ygu@nis3:~$ cat /etc/defaultdomain 
she
3.6.配置NIS
3.6.1.配置
ygu@nis3:~$ sudo /usr/lib/yp/ypinit -s nis1.she.guyongqiangx.com
We will need a few minutes to copy the data from nis1.she.guyongqiangx.com.
Transferring auto_tools...
Transferring auto_projects...
Transferring auto_home...
Transferring auto_master...
Transferring netmasks.byaddr...
Transferring netgroup.byhost...
Transferring netgroup.byuser...
Transferring netgroup...
Transferring services.byservicename...
Transferring services.byname...
Transferring passwd.adjunct.byname...
Transferring ethers.byaddr...
Transferring ethers.byname...
Transferring hosts.byaddr...
Transferring hosts.byname...
Transferring group.bygid...
Transferring group.byname...
Transferring passwd.byuid...
Transferring ypservers...
Transferring passwd.byname...
nis3's NIS data base has been set up.
If there were warnings, please figure out what went wrong, and fix it.
At this point, make sure that /etc/passwd and /etc/group have
been edited so that when the NIS is activated, the data bases you
have just created will be used, instead of the /etc ASCII files.
3.6.2.验证ypservers设置
ygu@nis3:/var/yp$ find /usr -type f -name makedbm
/usr/lib/yp/makedbm
ygu@nis3:/var/yp$ sudo /usr/lib/yp/makedbm -u she/ypservers 
nis2.she.guyongqiangx.com
nis1.she.guyongqiangx.com
YP_LAST_MODIFIED        1492590247
YP_MASTER_NAME  nis1.she.guyongqiangx.com
nis3.she.guyongqiangx.com   nis3.she.guyongqiangx.com
显然,这里she/ypservers文件里面已经包含了nis1,nis2和nis3了。
3.6.3.修改/etc/default/nis
主要修改包括:
设置为NIS Slave Server
NISSERVER=false 修改为 NISSERVER=slave
关闭当前作为NIS客户端(如果本机既作为Slave Sever,又作为Client则不要停需要改)
NISCLIENT=true 修改为 NISCLIENT=false
设置NIS Master
NISMASTER= 修改为 NISMASTER=nis1.she.guyongqiangx.com
修改后的内容如下:
ygu@nis3:~$ cat /etc/default/nis 
#
# /etc/defaults/nis     Configuration settings for the NIS daemons.
#
# Are we a NIS server and if so what kind (values: false, slave, master)?
NISSERVER=slave
# Are we a NIS client?
NISCLIENT=false
# Location of the master NIS password file (for yppasswdd).
# If you change this make sure it matches with /var/yp/Makefile.
YPPWDDIR=/etc
# Do we allow the user to use ypchsh and/or ypchfn ? The YPCHANGEOK
# fields are passed with -e to yppasswdd, see it's manpage.
# Possible values: "chsh", "chfn", "chsh,chfn"
YPCHANGEOK=chsh
# NIS master server.  If this is configured on a slave server then ypinit
# will be run each time NIS is started.
NISMASTER=nis1.she.guyongqiangx.com
# Additional options to be given to ypserv when it is started.
YPSERVARGS=
# Additional options to be given to ypbind when it is started.  
YPBINDARGS=-no-dbus
# Additional options to be given to yppasswdd when it is started.  Note
# that if -p is set then the YPPWDDIR above should be empty.
YPPASSWDDARGS=
# Additional options to be given to ypxfrd when it is started. 
YPXFRDARGS=
如果不修改/etc/defaults/nis,则启动ypserv会失败,查询rpc服务也找不到ypserv信息,如下:
基于Ubuntu 12.04搭建NIS Slave服务
3.7.启动ypserv服务
重新启动ypserv并查询其rpc服务:
基于Ubuntu 12.04搭建NIS Slave服务
由于第一次启动误用了restart指令,所以会提示stop: Unknow instance,正常启动后再使用restart就不会有这个提示了。
 
4.登录验证
在另外一台CentOS终端上配置并使用nis3提供的nis服务
1].命令行运行setup命令,弹出对话框
基于Ubuntu 12.04搭建NIS Slave服务
2].选择“Authentication Information”设置验证方式,弹出对话框中选择“Use NIS”
基于Ubuntu 12.04搭建NIS Slave服务
3].在NIS Settings对话框中设置Domain为she,Server为nis3.she.guyongqiangx.com,如下:
基于Ubuntu 12.04搭建NIS Slave服务
设置完成后点击OK,返回命令行。
运行yptest可以看到各项测试结果,说明nis3已经可以正常工作了。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30238.html