Nis服务器之Master-Slave设置

来源:互联网 发布:淘宝运动鞋 编辑:程序博客网 时间:2024/06/05 14:36

1、NIS slave server是将master server的数据库作为本身的数据库来源

2、使用Master/Slave主从架构可以分散NIS主服务器的负载

3、可以避免NIS服务器的单点故障


master.example.com   192.168.1.250  作为Nis的Master服务器

slave.example.com   192.168.1.150  作为Nis的Slave服务器

client.example.com    192.168.1.200  作为Nis服务器的客户端

Nis Master/Slave服务器的/etc/hosts和/etc/sysconfig/networks已经配置好


Nis服务器的Master端:

[root@master ~]#vim  /var/yp/Makefile     #允许master服务器向Slave服务器传递数据库文件

NOPUSH=false       

[root@master ~]# vim  /var/yp/ypservices  #告诉Master要推出去的数据库是给哪台服务器的

master.example.com

slave.example.com

[root@master ~]# /etc/init.d/ypserv  restart

[root@master ~]# /etc/init.d/yppasswdd  restart

[root@master ~]# /etc/init.d/ypxfrd      restart

[root@master ~]#chkconfig    ypserv   on

[root@master ~]#chkconfig   yppasswdd  on

[root@master ~]#chkconfig  ypxfrd   on

[root@master ~]#yppush   -h  slave.example.com   passwd.*       通过yppush可以直接将Master的数据库传递给Slave,如果Master/Slave数据库不符,就该用passwd.byname和passwd.byuid来同步


Nis服务器Slave端:

[root@slave ~]# vim  /etc/ypserv.conf

*                          :RHCE         :*                 :none

[root@slave ~]# /etc/init.d/ypserv  restart

[root@slave ~]# /etc/init.d/ypxfrd   restart

[root@slave ~]# chkconfig   ypserv   on

[root@slave ~]# chkconfig   ypxfrd   on

[root@slave ~]# /usr/lib64/yp/ypinit  -s  192.168.1.250           #同步NIS主服务器的所有数据库文件

[root@slave ~]# ypcat  -h  localhost  passwd.byname    通过ypcat命令测试数据库是否同步了,看是否输出了Master server的账号数据,如果一致,则成功


Cron设置Master/Slave自动同步

[root@slave ~]# vim  /etc/crontab           #Nis Master/Slave服务器通过ypxfrd服务来同步数据库

42  *  *  *  *  root  /usr/lib64/yp/ypxfr  -h  master.example.com  passwd.byname
42  *  *  *  *  root  /usr/lib64/yp/ypxfr  -h  master.example.com  passwd.byuid

即在每小时的第42分钟执行从master服务器传送数据库passwd.byname和passwd.byuid到Slave服务器,以此来保证Master/Slave的同步


Nis服务器客户端测试:

[root@client ~]# vim  /etc/yp.conf                    #Nis Client的ypbind服务也要指定Nis Slave服务器的IP

domain RHCE server 192.168.1.250
domain RHCE server 192.168.1.150
ypserver  192.168.1.250

[root@client ~]# service   ypbind  restart


[root@client ~]# ypwhich              #Clent用ypwhich命令查看当前所连接的服务器,如果测试时为NIS Master服务器

master.example.com

[root@master ~]# service  ypserv  stop          #那就模拟NIS Master服务器单点故障,停掉ypserv服务

[root@client ~]# ypwhich                                 #可以看到Clent现在所连接的服务器是slave服务器

slave.example.com

[root@master ~]# service  ypserv start          #模拟单点故障恢复

[root@client ~]# service  ypbind  restart       #Clent  ypbind服务重启

[root@client ~]# ypwhich   # master的优先级高,client会首先连接master,master宕机后,Slave会马上顶替master位置,master恢复后,client重启后会首先连接master

master.example.com


客户端远程修改用户密码:

[root@client ~]# su  -  nisuser1
[nisuser1@client ~]$ yppasswd                            #服务端需要开启yppasswdd服务
Changing NIS account information for nisuser1 on master.example.com.
Please enter old password:  输入旧密码
Changing NIS password for nisuser1 on master.example.com.
Please enter new password:  输入新密码
Please retype new password:  输入新密码

The NIS password has been changed on master.example.com.

[root@client ~]#ypwhich       

slave.example.com

 #这个时候你连接的是slave,改的密码确是master数据库中的密码,由于cron需要一段间隔来执行master/slave同步,会出现master/slave不一致的情况,那么使用新密码不能成功登陆的,这时你可以手动通过yppush来同步数据库

0 0
原创粉丝点击