分类: LINUX
2010-11-15 14:32:08
[ 文章作者:韦少乾 转载请注明原文链接: ]
NIS(Network Information Service,网络信息服务)也称YP(Yellow Pages)协议,是一个提供目录服务的RPC(远程过程调用)应用服务。通过它,就可以在网络上共享一个集中式的口令文件,从而大大简化客户端用户对帐 户和口令的维护工作。
四台CentOS5.4服务器,分别作用是:
一台NIS Master Server
机器名:rhce1.eryin.com
IP地址:192.168.1.83
一台NIS Slave Server
机器名称:rhce2.eryin.com
IP地址:192.168.1.85
两台NIS Client
机器名称分别是:rhce3.eryin.com和rhce4.eryin.com
IP地址对应上面:192.168.1.88、192.168.1.89
注意第三部分的操作是在两台NIS Server上操作的。
1、在NIS Server上安装所需的软件包:
#yum install portmap ypserv
2、在NIS Server上设定NIS Domain名称:
分别执行如下命令:
#nisdomainname RHCE
#vi /etc/sysconfig/network,加入下面一行,
NISDOMAIN=RHCE
3、设定要限制哪些电脑可以使用NIS Server:
#vi /var/yp/securenets,输入以下内容:
255.255.255.0 192.168.1.0
文件格式为:
子网掩码 IP地址
上面的设定代表可以让192.168.1.0网段的所有服务器都可以使用NIS Server进行身份验证。
4、启动NIS Server所使用的服务和设置开机自动启动:
#service ypserv start
#service portmap start
#service yppasswdd start
#service ypxfrd start
#chkconfig ypserv on
#chkconfig portmap on
#chkconfig yppasswdd on
#chkconfig ypxfrd on
5、因为下面需要多个用户,我们先创建好,此操作只在Master Server上执行:
#useradd nistest1
#useradd nistest2
#passwd nistest1
#passwd nistest2
1、NIS
Server里的用户资料库就是服务器里的文件内容转换而来的,比如从/etc/passwd和/etc/shadow等,转换过来的资料库就存放在
/var/yp/
#vi /etc/yp/Makefile
all:passwd group hosts #只验证用户密码和用户组
NOPUSH=true #如果没有Slave的情况下
MINUID=500 #意思是只转UID为500以后的帐号,之前都是系统帐号
MINGID=500 #意思是只转GID为500以后的帐号,之前都是系统帐号
2、建立NIS资料库,建立之前确认/var/yp目录下没有/etc/sysconfig/network文件里设置的NISDOMAIN目录
#/usr/lib/yp/ypinit -m #m是指Master Server
3、重启所有ypserv使用的服务
#service ypserv restart
#service portmap restart
#service yppasswdd restart
#service ypxfrd restart
1、所有Slave Server的清单都是设定在Master Server的/var/yp/ypservers这个文件里
2、当Master Server建立的资料库后,在Slave Server执行如下指令:
#/usr/lib/yp/ypinit -s masterIP或hosts #s是Slave Server的意思
3、如果Master Server更新了,需重建NIS的资料库,和复制给Slave Server
在Master Server里使用如下命令:
#cd /var/yp; make
4、重启所有ypserv使用的服务
#service ypserv restart
#service portmap restart
#service yppasswdd restart
#service ypxfrd restart
1、分别在两台NIS Client上安装所需的软件包,即执行如下命令:
#yum install portmap ypbind
2、执行authconfig命令,指定使用NIS验证用户的方式:
#authconfig –enablenis –update
#authconfig –nisdomain=RHCE –update
#authconfig –nisserver=192.168.1.83 –update
测试可以登陆了就行了,上面写的是书面的步骤,明天把整个过程中所有执行的命令全程文字记录发上来,呵呵。
还有,明天加上后面两章,关于使用NIS验证用户后的用户根目录问题。
注意:下面的NFS Server同时也包括NIS Server,NFS Client同时也包括NIS Client。
1、在四台服务器上全部安装NFS服务:
#yum install nfs-utils
2、在NFS Server设置分享的目录;
#vi /etc/exports #加入一行
/home 192.168.1.0/255.255.255.0(rw,sync)
3、在NFS Server上重启NFS服务:
#service nfs restart
4、在两台NFS Client上查看NFS Server分享的目录:
#showmount -e 192.168.1.83
5、在两台NFS Client上卸载原有的/home目录
#umount /home
6、在两台NFS Client上挂载NFS Server分享的目录:
#mount 192.168.1.83:/home /home
7、在两台NFS Client上测试登陆nistest1和nistest2。
1、在NFS Server创建实验用户和根目录
#mkdir /nishome
#useradd -u 5001 -d /nishome/nis1 nis1
#useradd -u 5002 -d /nishome/nis2 nis2
#/usr/lib/yp/ypinit -m #重新生成用户资料库
#service ypserv restart #以下四行重新启动服务
#service portmap restart
#service yppasswdd restart
#service ypxfrd restart
2、在两台NFS Client上安装自动挂载程序
#yum install autofs
3、编辑自动挂载和卸载程序配置文件
#vi /etc/auto.master #加入一行
/home /etc/auto.nis –timeout=60
#cp /etc/auto.misc /etc/auto.nis
#vi auto.nis #加入两行
nis1 -rw,soft,intr 192.168.1.83:/nishome/nis1
nis2 -rw,soft,intr 192.168.1.83:/nishome/nis2
为了以后更加方便,或者只加入一行:
* -rw.soft,intr 192.168.1.83:/nishome/&
4、重新启动autofs服务
#service autofs restart
5、在两台NFS Client上测试登陆nis1和nis2。
1、NIS Master Server:192.168.1.83
[root@rhce1 ~]# yum install portmap
[root@rhce1 ~]# yum install ypserv
[root@rhce1 yp]# nisdomainname RHCE
[root@rhce1 ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=rhce1.eryin.com
GATEWAY=192.168.1.254#Add NISDOMAIN
NISDOMAIN=RHCE
“/etc/sysconfig/network” 5L, 96C written
[root@rhce1 ~]# vi /var/yp/securenets
255.255.255.0 192.168.1.0
“/var/yp/securenets” [New] 1L, 28C written
[root@rhce1 ~]# service ypserv start
[root@rhce1 ~]# useradd nistest1
[root@rhce1 ~]# useradd nistest2
[root@rhce1 ~]# passwd nistest1
[root@rhce1 ~]# passwd nistest2
[root@rhce1 ~]# vi /var/yp/Makefile
NOPUSH=false
MINUID=500
MINGID=500
“/var/yp/Makefile” 496L, 16670C written
[root@rhce1 ~]# /usr/lib/yp/ypinit -m
[root@rhce1 ~]# cd /var/yp/
[root@rhce1 yp]# ls
Makefile RHCE securenets ypservers
[root@rhce1 yp]# cd RHCE
[root@rhce1 RHCE]# ls
group.bygid hosts.byaddr mail.aliases passwd.byname protocols.byname rpc.byname services.byname ypservers
group.byname hosts.byname netid.byname passwd.byuid protocols.bynumber rpc.bynumber services.byservicename
[root@rhce1 yp]# vi ypservers
rhce1.eryin.com
rhce2.eryin.com
“ypservers” 2L, 32C written
[root@rhce1 yp]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 rhce1 localhost.localdomain localhost rhce1.eryin.com
192.168.1.85 rhce2 rhce2.eryin.com
::1 localhost6.localdomain6 localhost6
“/etc/hosts” 5L, 239C written
[root@rhce1 yp]# service portmap start
[root@rhce1 yp]# service ypserv start
[root@rhce1 yp]# service yppasswdd start
[root@rhce1 yp]# chkconfig portmap on
[root@rhce1 yp]# chkconfig ypserv on
[root@rhce1 yp]# chkconfig yppasswdd on
[root@rhce1 yp]# rpcinfo -p 127.0.0.1
[root@rhce1 yp]# service ypserv restart
[root@rhce1 yp]# /usr/lib/yp/ypinit -m
[root@rhce1 yp]# service ypxfrd start
[root@rhce1 yp]# chkconfig ypxfrd on
2、NIS Slave Server:192.168.1.85
[root@rhce2 ~]# yum install portmap ypserv
[root@rhce2 ~]# nisdomainname RHCE
[root@rhce2 ~]# vi /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=rhce2.eryin.com
GATEWAY=192.168.1.254
NISDOMAIN=RHCE
“/etc/sysconfig/network” 5L, 96C written
[root@rhce2 ~]# vi /var/yp/securenets
255.255.255.0 192.168.1.0
“/var/yp/securenets” [New] 1L, 26C written
[root@rhce2 ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 rhce2 localhost.localdomain localhost rhce2.eryin.com
192.168.1.83 rhce1 rhce1.eryin.com
::1 localhost6.localdomain6 localhost6
“/etc/hosts” 5L, 239C written
[root@rhce2 ~]# service ypserv start
[root@rhce2 ~]# service yppasswdd start
[root@rhce2 ~]# service portmap start
[root@rhce2 ~]# chkconfig ypserv on
[root@rhce2 ~]# chkconfig yppasswdd on
[root@rhce2 ~]# chkconfig portmap on
[root@rhce2 ~]# /usr/lib/yp/ypinit -s rhce1
3、NIS Client 1:192.168.1.88
[root@rhce3 ~]# yum install portmap ypbind
[root@rhce4 ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 rhce4 localhost.localdomain localhost rhce4.eryin.com
192.168.1.83 rhce1 rhce1.eryin.com
192.168.1.85 rhce2 rhce2.eryin.com
::1 localhost6.localdomain6 localhost6
“/etc/hosts” 6L, 273C written
[root@rhce3 ~]# authconfig –enablenis –update
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server..
[root@rhce3 ~]# authconfig –nisdomain=RHCE –update
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
Shutting down NIS services: [ OK ]
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server..
[root@rhce3 ~]# authconfig –nisserver=192.168.1.83 –update
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
Shutting down NIS services: [ OK ]
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server..
[root@rhce3 ~]# ls
anaconda-ks.cfg install.log install.log.syslog
[root@rhce3 ~]# ypwhich
rhce1
[root@rhce3 ~]# exit
logout
Last login: Wed May 26 01:49:48 2010
[root@rhce3 ~]# su nistest1
bash-3.2$ pwd
/root
bash-3.2$ exit
exit
4、NIS Client 2:192.168.1.89
[root@rhce4 ~]# yum install portmap ypbind
[root@rhce4 ~]# vi /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 rhce4 localhost.localdomain localhost rhce4.eryin.com
192.168.1.83 rhce1 rhce1.eryin.com
192.168.1.85 rhce2 rhce2.eryin.com
::1 localhost6.localdomain6 localhost6
“/etc/hosts” 6L, 273C written
[root@rhce4 ~]# authconfig –enablenis –update
[root@rhce4 ~]# authconfig –nisdomain=RHCE –update
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
Shutting down NIS services: [ OK ]
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server..
[root@rhce4 ~]# authconfig –nisserver=192.168.1.83 –update
Stopping portmap: [ OK ]
Starting portmap: [ OK ]
Shutting down NIS services: [ OK ]
Binding to the NIS domain: [ OK ]
Listening for an NIS domain server..
[root@rhce4 ~]# su nistest
su: user nistest does not exist
[root@rhce4 ~]# su nistest1
bash-3.2$ exit
exit
[root@rhce4 ~]# su nistest2
bash-3.2$ su nistest1
Password:
bash-3.2$ exit
exit
bash-3.2$ exit
exit
1、NFS Server:192.168.1.83
[root@rhce1 ~]# yum install nfs-utils
[root@rhce1 ~]# vi /etc/exports/home 192.168.1.0/255.255.255.0(rw,sync)
“/etc/exports” 1L, 41C written
[root@rhce1 ~]# service nfs restart
2、NFS Client1:192.168.1.88
[root@rhce3 ~]# yum install nfs-utils
[root@rhce3 ~]# showmount -e 192.168.1.83
Export list for 192.168.1.83:
/home 192.168.1.0/255.255.255.0
[root@rhce3 ~]# umount /home
[root@rhce3 ~]# mount 192.168.1.83:/home /home
[root@rhce3 ~]# su – nistest1
[nistest1@rhce3 ~]$ touch test.txt
[nistest1@rhce3 ~]$ ls
test.txt
[nistest1@rhce3 ~]$ echo $HOME
/home/nistest1
3、NFS Client2:192.168.1.89
[root@rhce4 ~]# yum install nfs-utils
[root@rhce4 ~]# showmount -e 192.168.1.83
Export list for 192.168.1.83:
/home 192.168.1.0/255.255.255.0
[root@rhce4 ~]# umount /home
[root@rhce4 ~]# mount 192.168.1.83:/home /home
[root@rhce4 ~]# su – nistest1
[nistest1@rhce4 ~]$ ls
test.txt
[nistest1@rhce4 ~]$ echo $HOME
/home/nistest1
1、NFS Server:192.168.1.83
[root@rhce1 home]# mkdir /nisname
[root@rhce1 nishome]# chmod 1777 /nishome/
[root@rhce1 nisname]# useradd -u 5001 -d /nishome/nis1 nis1
[root@rhce1 nisname]# useradd -u 5002 -d /nishome/nis2 nis2
[root@rhce1 yp]# /usr/lib/yp/ypinit -m
[root@rhce1 ~]# service ypserv restart
[root@rhce1 ~]# service portmap restart
[root@rhce1 ~]# service yppasswdd restart
[root@rhce1 ~]# service ypxfrd restart
[root@rhce1 yp]# su – nis1
[nis1@rhce1 ~]$ pwd
/nishome/nis1
[root@rhce1 nishome]# passwd nis1
[root@rhce1 nishome]# passwd nis2
[root@rhce1 nishome]# vi /etc/exports
/nishome 192.168.1.0/255.255.255.0(rw,sync)
[root@rhce1 nishome]# exportfs -r
2、NFS Client1:192.168.1.88
[root@rhce3 home]# yum install autofs
[root@rhce3 home]# vi /etc/auto.master
/nishome /etc/auto.nis –timeout=60
[root@rhce3 home]# cp /etc/auto.misc /etc/auto.nis
[root@rhce3 home]# vi /etc/auto.nis
nis1 -rw,soft,intr 192.168.1.83:/nishome/nis1
nis2 -rw,soft,intr 192.168.1.83:/nishome/nis2
[root@rhce3 home]# service autofs restart
[root@rhce3 nishome]# su – nis1
[nis1@rhce3 ~]$ exit
3、NFS Client2:192.168.1.89
[root@rhce4 ~]# yum install autofs
[root@rhce4 ~]# vi /etc/auto.master
/nishome /etc/auto.nis –timeout=60
[root@rhce4 ~]# cp /etc/auto.misc /etc/auto.nis
[root@rhce4 ~]# vi /etc/auto.nis
* -rw,soft,intr 192.168.1.83:/home/&
[root@rhce4 ~]# service autofs restart
[root@rhce4 ~]# su – nis2
[nis2@rhce4 ~]$ exit