nis服务器架设
一、NIS定義
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的步驟
注意第三部分的操作是在兩臺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 -g 組 -u? uid? -d? 自定義目錄? nistest1
#useradd nistest2
#passwd nistest1
#passwd nistest2
四、配置主要的NIS Master Server
1、NIS Server里的用戶資料庫就是服務器里的文件內容轉換而來的,比如從/etc/passwd和/etc/shadow等,轉換過來的資料庫就存放在 /var/yp/<NIS Domain>目錄,要轉換的文件名稱和類型就設定在/var/yp/Makefile文件里。假設我們要設定只驗證用戶密碼和用戶組,可以在這個文件里設定。如下:
#vi /etc/yp/Makefile
i??????????? #只驗證用戶密碼和用戶組
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
vi
3、重啟所有ypserv使用的服務
#service ypserv restart
#service portmap restart
#service yppasswdd restart
#service ypxfrd restart
五、配置備用的NIS Slave Server
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
六、配置NIS Client
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實現NIS Server與NIS Client用戶目錄同步
注意:下面的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。
八、用Auto-Mount實現自動掛載和卸載NIS用戶目錄
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:wq
#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。
附一:NIS服務器搭建過程全程記錄
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
附二:NFS服務器搭建和分享/home目錄過程全程記錄
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
附三、用Auto-Mount實現自動掛載和卸載NIS用戶目錄全程文字記錄
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
?
總結:
服務端添加用戶:
1.添加用戶:
useradd?? -u? uid?? -d? 指定路徑? -g? 組名? 用戶名
2./usr/lib64/yp/ypinit -m? 更新庫
3.重啟所有服務
#service ypserv start
#service portmap start
#service yppasswdd start
#service ypxfrd start
?
新客戶端操作:
1、分別在兩臺NIS Client上安裝所需的軟件包,即執行如下命令:
#yum install portmap ypbind
2、執行authconfig命令,指定使用NIS驗證用戶的方式:
#authconfig --enablenis --update
#authconfig --nisdomain=RHCE --update
#authconfig --nisserver=192.168.1.83 --update
轉載于:https://blog.51cto.com/shitouququ/477780
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: IP SLA的路径控制
- 下一篇: 粤语学习--语法