部署YUM仓库及NFS共享服务

本文涉及的产品
云防火墙,500元 1000GB
简介: 部署YUM仓库及NFS共享服务

一、yum常用命令


    image.png

    yum的配置文件:/etc/yum.conf

    注意:只有在线源可以缓存下载的软件包,本地源无法缓存

    本地源的搭建在之前Linux软件安装和管理中已经写过了,此处不再赘述


二、通过http搭建yum仓库

2.1 关闭防火墙和安全机制


  • [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# setenforce 0
    

2.2 下载并开启http服务


  • [root@localhost ~]# yum -y install httpd
    [root@localhost ~]# systemctl start httpd
    

2.3 在/var/www/html目录下创建一个光驱挂载目录centos7,并将光驱挂载到centos7目录下


  • [root@localhost yum.repos.d]# cd /var/www/html/
    [root@localhost html]# mkdir centos7
    [root@localhost html]# mount /dev/cdrom /var/www/html/centos7/
    mount: /dev/sr0 写保护,将以只读方式挂载
    [root@localhost html]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   47G  3.6G   43G    8% /
    devtmpfs                 969M     0  969M    0% /dev
    tmpfs                    984M     0  984M    0% /dev/shm
    tmpfs                    984M  9.2M  975M    1% /run
    tmpfs                    984M     0  984M    0% /sys/fs/cgroup
    /dev/sda1                950M  179M  772M   19% /boot
    tmpfs                    197M  4.0K  197M    1% /run/user/42
    tmpfs                    197M   48K  197M    1% /run/user/0
    /dev/sr0                 4.3G  4.3G     0  100% /var/www/html/centos7
    

2.4 创建yum源配置文件,清除缓存,建立元数据


  • [root@localhost /]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# mkdir backup
    [root@localhost yum.repos.d]# mv *.repo backup/
    [root@localhost yum.repos.d]# ls
    backup
    [root@localhost yum.repos.d]# vim httpd.repo
    [httpd]
    name=httpd
    baseurl=http://192.168.147.100/centos7
    gpgcheck=0
    :wq!
    
    [root@localhost yum.repos.d]# yum clean all && yum makecache 
    已加载插件:fastestmirror, langpacks
    正在清理软件源: httpd
    Cleaning up everything
    Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
    已加载插件:fastestmirror, langpacks
    httpd                                                                                       | 3.6 kB  00:00:00     
    (1/4): httpd/group_gz                                                                       | 156 kB  00:00:00     
    (2/4): httpd/primary_db                                                                     | 3.1 MB  00:00:00     
    (3/4): httpd/filelists_db                                                                   | 3.1 MB  00:00:00     
    (4/4): httpd/other_db                                                                       | 1.2 MB  00:00:00     
    Determining fastest mirrors
    元数据缓存已建立
    


三、通过FTP搭建yum仓库

3.1 关闭防火墙和安全机制


  • [root@localhost ~]# systemctl stop firewalld
    [root@localhost ~]# setenforce 0
    

3.2 下载并开启FTP服务


  • [root@localhost yum.repos.d]# yum -y install vsftpd
    [root@localhost yum.repos.d]# systemctl start vsftpd
    

3.3 在/var/ftp目录下创建一个光驱挂载目录centos7,并将光驱挂载到centos7目录下


  • [root@localhost yum.repos.d]# umount /dev/cdrom /var/www/html/centos7/      //解挂载
    umount: /var/www/html/centos7/:未挂载
    [root@localhost yum.repos.d]# cd /var/ftp/
    [root@localhost ftp]# mkdir centos7
    [root@localhost ftp]# ls
    centos7  pub
    [root@localhost ftp]# mount /dev/cdrom /var/ftp/centos7/
    mount: /dev/sr0 写保护,将以只读方式挂载
    [root@localhost ftp]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   47G  3.7G   43G    8% /
    devtmpfs                 969M     0  969M    0% /dev
    tmpfs                    984M     0  984M    0% /dev/shm
    tmpfs                    984M  9.2M  975M    1% /run
    tmpfs                    984M     0  984M    0% /sys/fs/cgroup
    /dev/sda1                950M  179M  772M   19% /boot
    tmpfs                    197M  4.0K  197M    1% /run/user/42
    tmpfs                    197M   48K  197M    1% /run/user/0
    /dev/sr0                 4.3G  4.3G     0  100% /var/ftp/centos7
    

3.4 创建yum源配置文件,清除缓存,建立元数据


  • [root@localhost ftp]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# rm -rf httpd.repo 
    [root@localhost yum.repos.d]# ls
    backup
    
    [root@localhost yum.repos.d]# vim ftpd.repo
    [ftpd]
    name=ftpd
    baseurl=ftp://192.168.147.100/centos7
    gpgcheck=0
    :wq!
    
    [root@localhost yum.repos.d]# yum clean all && yum makecache 
    已加载插件:fastestmirror, langpacks
    正在清理软件源: ftpd
    Cleaning up everything
    Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
    已加载插件:fastestmirror, langpacks
    ftpd                                                                                        | 3.6 kB  00:00:00     
    (1/4): ftpd/group_gz                                                                        | 156 kB  00:00:00     
    (2/4): ftpd/filelists_db                                                                    | 3.1 MB  00:00:00     
    (3/4): ftpd/primary_db                                                                      | 3.1 MB  00:00:00     
    (4/4): ftpd/other_db                                                                        | 1.2 MB  00:00:00     
    Determining fastest mirrors
    元数据缓存已建立
    


四、NFS共享储存服务

4.1 NFS网络文件


    • 依赖于RFC(远程过程调用)
    • 需要安装nfs-utils,rpcbind软件包
    • 共享配置文件:/etc/exports
    • NFS是网络上共享文件系统的协议,允许多个服务器通过,共享文件和目录

4.2 工作原理

  • 服务端:将指定的目录标记为共享目录,给这个目录权限。(777,全部权限)

    客户端:通过NFS协议,发送请求到服务端,获取操作这个共享目录的权限

4.3 优点


    1. 共享,多个客户端可以同时访问和共享同一文件系统,方便操作
    2. 透明,不关系底层网络细节,能访问即可
    3. 性能出众,访问速度比较快
    4. 可靠性,NFS提供了一些机制确保了文件的完整性和一致性(写同步)

4.4 应用场景

4.5 需要的服务

  • 服务名 作用 端口号 协议
    rpcbind 远程共享调用 111 TCP
    nfs-utils 提供共享服务 2049 TCP

4.6 NFS的权限选项


  • 权限 含义
    rw 读写权限
    ro 只能读
    no_root_squash 客户端以root用户访问服务器,赋予本地root权限
    root_squash 客户端以root用户访问服务器,root用户映射成匿名用户
    all_squash 所有访问服务器的用户都映射为匿名用户

4.7 实际操作


  • 虚拟机1

    [root@localhost ~]# vim /etc/exports
    /opt/share 192.168.147.0/24(rw,sync,no_root_squash)
    :wq!
    [root@localhost ~]# cd /opt
    [root@localhost opt]# mkdir share
    [root@localhost opt]# chmod 777 share
    [root@localhost opt]# systemctl start rpcbind
    [root@localhost opt]# systemctl start nfs
    

虚拟机2

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# mkdir /myshare
[root@localhost ~]# mount 192.168.147.100:/opt/share /myshare

验证:

image.png

image.png

目录
相关文章
|
4月前
|
Unix Linux 网络安全
NFS挂载服务
【10月更文挑战第14天】
140 2
|
6月前
|
运维 Ubuntu 安全
在Linux中,如何配置NFS共享?
在Linux中,如何配置NFS共享?
|
6月前
|
存储 Ubuntu Linux
NFS服务部署全攻略:从零到一,轻松驾驭网络文件系统,让你的文件共享像飞一样畅快无阻!
【8月更文挑战第5天】NFS(网络文件系统)能让网络中的电脑无缝共享文件与目录。基于客户端-服务器模式,用户可像访问本地文件般透明操作远程文件。部署前需准备至少两台Linux机器:一台服务器,其余作客户端;确保已装NFS相关软件包且网络通畅。服务器端安装NFS服务与rpcbind,客户端安装nfs-utils。
230 4
|
6月前
|
Ubuntu Linux 网络安全
在Linux中,如何配置Samba或NFS文件共享?
在Linux中,如何配置Samba或NFS文件共享?
|
6月前
|
Kubernetes 关系型数据库 MySQL
k8s练习--通过NFS+PV+PVC+POD,部署一个MySQL服务,并将MySQL的数据进行持久化存储
本文档介绍了如何使用Kubernetes (K8s)、NFS、PersistentVolume (PV)、PersistentVolumeClaim (PVC)和Pod来部署并实现MySQL服务的数据持久化存储。Kubernetes是一个用于自动化部署、扩展和管理容器化应用的强大平台。NFS作为一种网络文件系统协议,能够使Kubernetes集群中的Pod跨节点访问共享文件。PV和PVC机制则提供了持久化的存储解决方案,确保数据即使在Pod生命周期结束后仍得以保留。
323 0
|
6月前
|
Linux
在Linux中,如何挂载远程NFS共享或iSCSI目标?
在Linux中,如何挂载远程NFS共享或iSCSI目标?
|
6月前
|
缓存 Linux 网络安全
解决 CentOS 7 官方 yum 仓库无法使用的最佳实践
【8月更文挑战第18天】若 CentOS 7 的官方 YUM 仓库无法使用,可按以下步骤解决: 1. **检查网络连接**: - 确认服务器能正常上网,可通过访问外部网站或网络诊断测试。 - 检查防火墙设置,避免其阻挡 YUM 的网络访问。 2. **检查 YUM 配置**: - 核实 `/etc/yum.repos.d/` 下的 `CentOS-Base.repo` 文件中仓库地址正确无误。 - 确认配置文件内的 `enabled` 选项设为 `1` 以启用仓库。
2566 0
|
6月前
|
存储 Kubernetes 调度
使用 Kubeadm 部署 Kubernetes(K8S) 安装 -- 持久化存储(NFS网络存储)
使用 Kubeadm 部署 Kubernetes(K8S) 安装 -- 持久化存储(NFS网络存储)
85 0
|
9月前
|
Linux
Linux安装NFS挂载NFS卸载客户端服务端都有
Linux安装NFS挂载NFS卸载客户端服务端都有
204 0
|
9月前
|
Ubuntu 网络协议 Unix
【Linux】新唐NUC977挂载NFS实现网络文件传输
【Linux】新唐NUC977挂载NFS实现网络文件传输
102 0