NIS主从服务器搭建

NIS主服务器搭建

  1. 安装nis、rpcbind服务,
sudo apt-get install nis rpcbind

安装NIS服务后会自动弹出一个窗口要写填写ypdomainname;之后也可以修改,通过下面一条指令,重新弹出窗口设置:

sudo dpkg-reconfigure nis

ypdomainname和hostname不是一回事

ypmomainname需要在整个集群中保持一致,在本例中是设置成mgt

  1. 修改/etc/default/nis两行内容NISSERVER,NISCLIENT
# line 6: change (set NIS master server)
NISSERVER=master

# line 9: Are we a NIS client?
NISCLIENT=true

如果有从服务器,主服务器也需要开始client模式,所以NISCLIENT也要设置成true

留一个疑问:如果没有从服务器,还需要设置成true吗?

  1. 如有必要,修改/etc/ypserv.securenets,设置允许访问的IP

  2. 修改/var/yp/Makefile

# line 23: change
NOPUSH=false

# line 52: change
MERGE_PASSWD=true

# line 56: change
MERGE_GROUP=true

如果有从服务器,nopush行一定要设置成false,不然不会同步到从服务器

  1. 修改 /etc/hosts,将集群中的服务端和客户端的域名和IP都写进去

  2. **重要!!!!**如果是主从模式,要将主服务器也设置成客户端模式,配置NIS client的步骤也要在主服务器上进行一遍。

  • 修改/etc/yp.conf,把主从的信息都写上

    domain mgt server mgt.test
    domain mgt server mgt-slave.test
    
  • 修改 /etc/nsswitch.conf

    passwd:     compat nis     # line 7; add
    group:     compat nis     # add
    shadow:     compat nis     # add
    hosts:     files dns nis     # add
    
    • 添加一行信息到/etc/pam.d/common-session
    # add to the end
    session optional        pam_mkhomedir.so skel=/etc/skel umask=077
    
  1. 初始化主服务器

    sudo systemctl restart rpcbind nis 
    sudo /usr/lib/yp/ypinit -m 
    

    会弹出一些列信息,需要添加上从服务器的hostname

    At this point, we have to construct a list of the hosts which will run NIS
    servers.  dlp.srv.world 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:  mgt.test
            # specify NIS slave
            next host to add: mgt-slave.test
            next host to add:     # Ctrl + D key
    The current list of NIS servers looks like this:
    
    mgt.test
    mgt-slave.test
    
    Is this correct? [y/n: y] y
    We need a few minutes to build the databases...
    Building /var/yp/mgt/ypservers...
    ...
    ...
    Now you can run ypinit -s mgt.test on all slave server.
    

    不知道是不是从服务器初始化一次后这里又要运行一次,还是上面一开始就把从服务器写上的话就不需要再重新运行,重新运行可能只是中途插入一个从服务器才需要

    至此,主服务器就设置完毕

NIS从服务器搭建

  1. 安装rpcbind,nis,配置ypdomainname

  2. 将从服务器配置成主服务器的客户端模式(下面三步完全依照第一章<NIS主服务器搭建>的内容填写即可)

    • 修改/etc/yp.conf,把主从的信息都写入

    • 修改 /etc/nsswitch.conf

    • 修改/etc/pam.d/common-session

  3. 将主服务器也配置成从服务器的客户端模式(在第一章<NIS主服务器搭建>中已完成)

  4. 修改/etc/default/nis

    # line 6: change (set NIS master server)
    NISSERVER=slave
    
    # line 9: Are we a NIS client?
    NISCLIENT=true
    
  5. 如有必要,修改 /etc/ypserv.securenets

  6. 修改 /var/yp/Makefile

    # line 52: change
    MERGE_PASSWD=true
    
    # line 56: change
    MERGE_GROUP=true
    

    从服务器的NOPUSH不需要设置

  7. 设置/etc/hosts,跟主服务器的保持一致即可

  8. 初始化从服务器

    sudo systemctl restart rpcbind nis
    sudo /usr/lib/yp/ypinit -s mgt.test
    
    # 弹出下列信息即表示成功
    We will need a few minutes to copy the data from mgt.test.
    Transferring group.bygid...
    Trying ypxfrd ... success
    ...
    ...
    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.
    

    至此,从服务器配置完毕

NIS客户端搭建

  1. 安装rpcbind,nis,配置ypdomainname

  2. 修改/etc/yp.conf,主从都要写,按第一章的内容填写即可

  3. 修改/etc/nsswitch.conf,第一章内容填写即可

  4. 修改/etc/pam.d/common-session,按第一章内容填写即可

  5. 重启rpcbind和nis服务

    sudo systemctl restart rpcbind nis
    

    NIS客户端是不需要修改/etc/default/nis和/var/yp/Makefile,也不需要运行ypinit

​ 至此,NIS客户端配置完成

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

请我喝杯咖啡吧~

支付宝
微信