autofs+nis+nfs

手动挂载

开机自动挂载

Autofs 自动挂载

Autofs介绍:

mount是用来挂载文件系统的,可以在系统启动的时候挂载也可以在系统启动后挂载。对于本地固定设

备,如硬盘可以使用mount挂载;而光盘、软盘、NFS、SMB等文件系统具有动态性,即需要的时候才有

必要挂载。光驱和软盘我们一般知道什么时候需要挂载,但NFS和SMB共享等就不一定知道了,即我们

一般不能及时知道NFS共享和SMB什么时候可以挂载。而autofs服务就提供这种功能,好像windows中的

光驱自动打开功能,能够及时挂载动态加载的文件系统。免去我们手动挂载的麻烦。要实现光驱,软盘

等的动态自动挂载,需要进行相关的配置。

Autofs特点:

Autofs与Mount/Umount的不同之处在于,它是一种看守程序。如果它检测到用户正试图访问一个尚未挂接的文件系统,它就会自动检测该文件系统,如果存在,那么Autofs会自动将其挂接。

另一方面,如果它检测到某个已挂接的文件系统在一段时间内没有被使用,那么Autofs会自动将其卸载。因此一旦运行了Autofs后,用户就不再需要手动完成文件系统的挂接和卸载。

Autofs常用配置:

Autofs需要从/etc/auto.master文件中读取配置信息。该文件中可以同时指定多个挂接点,由Autofs来挂接文件系统。文件中的每个挂接点单独用一行来定义,每一行可包括3个部分,分别用于指定挂接点位置,挂接时需使用的配置文件及所挂接文件系统在空闲多长时间后自动被卸载。例如在文件中包括

了如下一行:  

  /auto /etc/auto.misc --timeout 60

  其中第一部分指定一个安装点为/auto,第二部分指定该挂接点的配置文件为/etc/auto.misc,

  第三部分指定所挂接的文件系统在空闲60秒后自动被卸载。 

  文件/etc/auto.misc的示例如下:

  cd -fstype=iSO9660,ro :/dev/cdrom

  文件每一行都说明某一个文件系统如何被挂接。其中第一行指定将/dev/cdrom挂接在/auto/cd中,第二行指定将/dev/fd0挂接在/auto/fd中。每一行的第二个值-fstype是一个可选项,用来表明所挂接的文件系统的类型和挂接选项,在mount命令中能使用的挂接选项同样适用于-fstype。

案例一:.安装自动挂载软件包

主配置文件/etc/auto.master

/misc   /etc/auto.misc  (定义复制配置文件的路径及文件名)

(不需要创建默认重启服务就会显示该目录)

cd      -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

触发条件 挂载设备类型                    挂载设备名

https://blog.csdn.net/richerg85/article/details/17917129/etc/auto.misc

/etc/autofs.conf

案例二:

/suibian   /etc/auto.suibian  --->

 *  -fstype=iso9660,ro,nodev,nosuid   :/dev/sr0

/sda5     /etc/auto.sda5    --->   haha    -fstype=xfs     :/dev/sda5

/nfsdir   /etc/auto.nfs -->     *      -fstype=nfs     172.16.30.36:/public

NIS

网络信息服务(NIS)是集中控制几个系统管理数据库的网络用品。NIS简化了UNIX和LINUX桌面客户的管理工作,客户端利用它可以使用中心服务器的管理文件。桌面系统的用户无需建立他们自己的/etc/passwd,他们只简单的使用维护在NIS服务器的文件即可。用户只需要在nis服务器上面创建,客户端加入nis域,直接可以使用Nis域上的用户来登录客户端。

一、概述:

1、相关服务:ypservNIS服务器端),ypbind(NIS客户端),yppasswd(修改密码时,NIS客户端与NIS服务器端之前通过这个服务来通信)

2、相关端口:portmap :111,因为NIS、NFS 都是依赖于portmap服务  6.0/7.0 版本用rpcbind取代portmap服务

3、相关包:ypserv(NIS服务器必需的),ypbind(NIS客户端必需的,默认已安装),yp-tools(NIS的常用工具,默认已安装)

二、服务端的的配置:

1、安装ypserv服务相关的包。

Yum list |grep ypserv

Yum install ypserv

2、建立一个Nis专用用户目录文件夹:

mkdir /nishome

3、建立一个NIS用户:(可以使用该方式建立多个用户)

useradd -d /nishome/user1 –u 1000 user1

设定user1用户的密码

4、编辑/etc/sysconfig/network为NIS服务器指定NIS域名:

-------------------------------------------

[root@localhost Server]# vim /etc/sysconfig/network

NISDOMAIN=www.example.com

-------------------------------------------

5、运行:nisdomainname example.com //这里的域名和上面=号后面的一样!加入域example.com

-------------------------------------------

[root@localhost Server]# nisdomainname

(none)

[root@localhost Server]# nisdomainname www.example.com

[root@localhost Server]# nisdomainname

example.com

-------------------------------------------

6、编辑/etc/rc.d/rc.local,每次开机自动运行步骤五的命令,加入example.com域;

-------------------------------------------

[root@localhost Server]# echo "/bin/nisdomainname www.example.com" >> /etc/rc.local

----------------------------------------------------

7、启动ypserv服务:

----------------------------------------------------

[root@client Server]#systemctl restart ypserv.service

查看ypserv服务状态:systemctl status ypserv.service

----------------------------------------------------

8、生成NIS 用户数据库:/usr/lib64/yp/ypinit -m(该服务器上的所有用户名都将用作客户端身份认证)    注意,每次添加用户之后,都需要重新生成nis数据库

----------------------------------------------------

Vim /var/yp/Makefile

[root@localhost Server]# /usr/lib/yp/ypinit -m

At this point, we have to construct a list of the hosts which will run NIS

servers.  localhost.localdomain is in the list of NIS server hosts.  Please coninue 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:  localhost.localdomain     ----服务器hostname,只有一个服务器的话,就按下面的ctrl+d  ,如果有多个服务器,接着输入

next host to add:                  //这里直接按Ctrl+D

The current list of NIS servers looks like this:

localhost.localdomain

Is this correct?  [y/n: y]  y

We need a few minutes to build the databases...

Building /var/yp/rhce.org/ypservers...

Running /var/yp/Makefile...

gmake[1]: Entering directory `/var/yp/rhce.org'

Updating passwd.byname...

Updating passwd.byuid...

Updating group.byname...

Updating group.bygid...

Updating hosts.byname...

Updating hosts.byaddr...

Updating rpc.byname...

Updating rpc.bynumber...

Updating services.byname...

Updating services.byservicename...

Updating netid.byname...

Updating protocols.bynumber...

Updating protocols.byname...

Updating mail.aliases...

gmake[1]: Leaving directory `/var/yp/rhce.org'

localhost.localdomain has been set up as a NIS master server.

Now you can run ypinit -s localhost.localdomain on all slave server.

----------------------------------------------------

备注:提示输入NIS服务器主机名,有多个可以输入多个,按Y确认。

配置完以上命令后在/var/yp下检查有没有生成一个NIS域名命名的目录,这是NIS用户数据库,如果没有则删除该目录下的’”(none)”目录,再重新生成数据库。

8、重启相关服务:

systemctl restart ypserv.service

9、使用NFS共享NIS用户家目录:

Vim /etc/exports

加入内容:/nishome *(rw)

Systemctl restart nfs.service

Systemctl enable nfs.service

二、客户端的配置:

 [root@xian ~]# vi /etc/selinux/config      关闭selinux  setenforce 0 改为警告模式

# This file controls the state of SELinux on the system.

# SELINUX= can take one of these three values:

#       enforcing - SELinux security policy is enforced.

#       permissive - SELinux prints warnings instead of enforcing.

#       disabled - SELinux is fully disabled.

SELINUX=disabled

# SELINUXTYPE= type of policy in use. Possible values are:

#       targeted - Only targeted network daemons are protected.

#       strict - Full SELinux protection.

SELINUXTYPE=targeted

修改之后需要重启机器

3、客户端加入NIS域:

输入setup  --该命令在图形化界面的终端上面执行

选择:启用NIS支持,点击“配置NIS”;输入NIS域,及NIS服务器Ip地址

/etc/init.d/portmap restart   注意6.07.0 版本上没有portmap服务,服务名称改变为rpcbind

Systemctl restart portmap

设置客户端机器上的自动挂载

安装自动挂载服务:yum install autofs

编辑控制文件

[root@client ~]# vi /etc/auto.master

/nishome   /etc/auto.misc

配置配置文件

[root@client ~]# vi /etc/auto.misc

*  -fstype=nfs         192.168.10.40:/nishome/&              适合于所有nis用户自动挂载家目录

Nis1 -fstype=nfs  192.168.10.40:/nishome/nis1  只适合nis1用户自动挂载家目录

重启服务

[root@client ~]# service autofs restart

Nis服务器上面,新建立的用户,如果需要客户端验证访问,那么需要在服务器端重新生成nis数据库,然后重启ypserv服务。

猜你喜欢

转载自blog.csdn.net/Albert__Einstein/article/details/121325407
nis
今日推荐