本篇,我们将讲解用CentOS6作为客户端,连接我们上篇搭建的nis和nfs服务端,我们的客户端ip是192.168.42.102,hostname就叫client。

安装NFS

[root@client ~]# yum -y install nfs-utils

启动相关服务,并设置为开机启动

[root@client ~]# service rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@client ~]# service netfs start
Mounting filesystems:                                      [  OK  ]
[root@client ~]# chkconfig rpcbind on
[root@client ~]# chkconfig netfs on

安装Autofs

[root@client ~]# yum -y install autofs

配置自动挂载设置

[root@client ~]# echo -e "/home\t/etc/auto.home" >> /etc/auto.master
[root@client ~]# echo -e "*\t192.168.42.101:/home/&" >> /etc/auto.home

注意,auto.home文件中间可以添加nfs一些挂载选项,本文直接用默认选项,故没有添加额外内容。

启动服务,并加入开机自启:

[root@client ~]# chkconfig autofs on
[root@client ~]# service autofs start

安装NIS客户端

[root@client ~]# yum -y install ypbind

临时指定nis域名:

[root@client ~]# ypdomainname yyshell.com

永久生效:

[root@client ~]# echo "NISDOMAIN=yyshell.com" >> /etc/sysconfig/network

配置一下:

[root@client ~]# authconfig --enablenis \
> --nisdomain=yyshell.com \
> --nisserver=192.168.42.101 \
> --enablemkhomedir \
> --update

因为本次我们是通过autofs挂载home目录,其实本次我们没有必要使用–enablemkhomedir选项的,这个选项主要是给本地的nis用户使用的,我们这里加上也无妨。

上面的配置会自动启动ypbind服务,接下来,我们只需要把这个加入开机启动就可以了。

[root@client ~]# chkconfig ypbind on

安全设定

指定ypbind端口:

[root@client ~]# vim /etc/init.d/ypbind

第18行,把OTHER_YPBIND_OPTS=””修改成:

OTHER_YPBIND_OPTS="-p 666"

把NFS相关的端口也指定下:

[root@client ~]# vim /etc/sysconfig/nfs

20和22行分别取消注释:
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
57行取消注释:
MOUNTD_PORT=892
63行取消注释:
STATD_PORT=662

接下来就是开放防火墙:

[root@client ~]# iptables -I INPUT -m multiport -p tcp --dport 111,662,666 -j ACCEPT
[root@client ~]# iptables -I INPUT -m multiport -p udp --dport 111,662,666 -j ACCEPT
[root@client ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@client ~]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

利用tcp_wrapper限制rpc访问地址:
vim /etc/hosts.deny

rpcbind: ALL

vim /etc/hosts.allow

rpcbind: 127. 192.168.42.101

NIS用户挂载测试

我们现在server的机器上添加用户alice测试:

[root@server ~]# useradd alice
[root@server ~]# passwd alice

更新下nis数据库:

[root@server ~]# cd /var/yp
[root@server yp]# make

我们先在client的机器上看下能否获取alice用户:

[root@client ~]# getent passwd

显示这些内容:

root:x:0:0:root:/root:/bin/bash
…省略若干行…
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
alice:x:500:500::/home/alice:/bin/bash

接下来用alice用户登录:

[alice@client ~]$ whoami
alice
[alice@client ~]$ pwd
/home/alice

显示登录成功。再查看下home目录权限:

[alice@client home]$ ll
total 4
drwx------. 2 alice alice 4096 Oct 26 22:53 alice

权限也没有问题,说明nfsidmap也成效了。

CentOS6,Ubuntu 16.04安装、使用NIS,NFS,AutoFS教程(2)
Tagged on:                     

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注