RHCE-autofs自动挂载实验

目录

实验要求

实验步骤

一、在主机上提供 DNS 和 WEB 服务

二、主机名解析

三、服务端

 编辑nfs配置文件,新建共享目录,并设置权限

 定位服务端 启动服务 必须先启动rpcbind服务

四、客户端

编辑自动挂载配置文件

测试

配置防⽕墙放⾏规则


实验要求

现有主机 node01 和 node02,完成如下需求:
1、在 node01 主机上提供 DNS 和 WEB 服务
2、dns 服务提供本实验所有主机名解析
3、web服务提供 www.rhce.com 虚拟主机
4、该虚拟主机的documentroot目录在 /nfs/rhce 目录
5、该目录由 node02 主机提供的NFS服务共享
6、该目录可以通过autofs服务实现自动挂载
7、所有服务应该在重启之后依然可以正常使用

实验步骤

一、在主机上提供 DNS 和 WEB 服务

vim /etc/named.conf



options {
        listen-on port 53 { 172.25.250.130; };
        directory       "/var/named";
};

zone "rhce.com" IN {
        type master;
        file "named.rhce";
};
vim /etc/httpd/conf.d/vhost.conf

/

<directory /nfs>
allowoverride none
require all granted
</directory>

<virtualhost 172.25.250.130:80>
documentroot /nfs/rhce
servername www.rhce.com
</virtualhost>
 vim /var/named/named.rhce    //修改区域文件



$TTL 1D
@       IN      SOA     @       admin.rhce.com. (  
                                                0 
                                                1
                                                1
                                                1
                                                1)
        IN      NS      ns.rhce.com.
ns      IN      A       172.25.250.130
www     IN      A       172.25.250.130
mkdir /nfs/rhce  -p

echo welcome to rhce > /nfs/rhce/index.html

[root@localhost ~]# systemctl restart named

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# curl www.rhce.com
welcome to rhce

二、主机名解析

[root@localhost ~]# dig -t A www.rhce.com

; <<>> DiG 9.16.23-RH <<>> -t A www.rhce.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57220
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: d09e378851fcf33f01000000668f9cb4c1b60ebc9896814f (good)
;; QUESTION SECTION:
;www.rhce.com.			IN	A

;; ANSWER SECTION:
www.rhce.com.		86400	IN	A	172.25.250.130

;; Query time: 3 msec
;; SERVER: 172.25.250.130#53(172.25.250.130)
;; WHEN: Thu Jul 11 16:49:56 CST 2024
;; MSG SIZE  rcvd: 85
status: NXDOMAIN  //把dns和主机ip配为相同 删除/etc/hosts里的ip

三、服务端

setenforce 0

systemctl stop firewalld

dnf install nfs-utils -y  //服务端及客户端都安装

dnf install nfs-utils autofs -y

 编辑nfs配置文件,新建共享目录,并设置权限

vim /etc/exports

[root@localhost ~]# cat /etc/exports
/nfs/rhce	172.25.250.137(rw,sync,all_squash)

exportfs -r    //重启生效
mkdir /nfs/rhce -p

chmod  -Rf  777  /nfs/rhce 

///

[root@localhost ~]# ll /nfs/rhce/
total 4
-rwxrwxrwx. 1 root root 16 Jul 10 17:30 index.html

 定位服务端 启动服务 必须先启动rpcbind服务

systemctl start rpcbind

systemctl start nfs-server

systemctl enable rpcbind

systemctl enable nfs-server

四、客户端

编辑自动挂载配置文件

自动挂载本地目录: /nfs/rhce
  [root@localhost ~]# vim /etc/auto.master



  1 #
  2 # Sample auto.master file
  3 # This is a 'master' automounter map and it has the following format:
  4 # mount-point [map-type[,format]:]map [options]
  5 # For details of the format look at auto.master(5).
  6 #
  7 /misc   /etc/auto.misc
  8 /nfs    /etc/auto.nfs   💖添加这一行~  
  9 #


# /nfs为本地挂载路径的父目录 可以不用创建 autofs会自动创建,
  auto.nfs为子配置文件,名称自定义

//
systemctl restart autofs
//
# 查看共享信息

[root@localhost ~]# showmount -e 172.25.250.130
Export list for 172.25.250.130:
/nfs/rhce 172.25.250.137
# 编辑自动挂载的子配置文件

[root@localhost ~]# vim /etc/auto.nfs

[root@localhost ~]# cat /etc/auto.nfs
rhce   172.25.250.130:/nfs/rhce  
//书写本地挂载目录的子目录及远程共享目录

systemctl restart autofs
systemctl enable autofs

测试

[root@localhost ~]# df -h

//

Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               4.0M     0  4.0M   0% /dev
tmpfs                  867M     0  867M   0% /dev/shm
tmpfs                  347M  7.2M  340M   3% /run
/dev/mapper/rhel-root   47G  4.5G   43G  10% /
/dev/nvme0n1p1         960M  299M  662M  32% /boot
tmpfs                  174M   92K  174M   1% /run/user/0
/dev/sr0               9.9G  9.9G     0 100% /mnt

此时并没有挂载上
[root@localhost ~]# cd /nfs //进入本地挂载目录 会自动新建

[root@localhost nfs]# ll
total 0

[root@localhost nfs]# cd rhce  
//进入本地挂载目录的下级目录 会触发自动挂载 文件夹名手动打全

[root@localhost rhce]# ll
total 4
-rwxrwxrwx. 1 root root 16 Jul 10 17:30 index.html
-rwxrwxrwx. 1 root root  0 Jul 10 23:07 test

[root@localhost rhce]# df -h
Filesystem                Size  Used Avail Use% Mounted on
devtmpfs                  4.0M     0  4.0M   0% /dev
tmpfs                     867M     0  867M   0% /dev/shm
tmpfs                     347M  7.2M  340M   3% /run
/dev/mapper/rhel-root      47G  4.5G   43G  10% /
/dev/nvme0n1p1            960M  299M  662M  32% /boot
tmpfs                     174M   92K  174M   1% /run/user/0
/dev/sr0                  9.9G  9.9G     0 100% /mnt
172.25.250.130:/nfs/rhce   47G  4.5G   43G  10% /nfs/rhce
成功!

配置防⽕墙放⾏规则

firewall-cmd --permanent --add-service=nfs

firewall-cmd --permanent --add-service=mountd

firewall-cmd --permanent --add-service=rpc-bind

firewall-cmd --reload

firewall-cmd --list-services  //显示已放行

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值