实验注解——YUM仓库的部署与NFS共享服务

YUM仓库服务

YUM概述

  • YUM(Yellow dog Updater Modified)
    • YUM基于RPM包构建的软件更新机制
    • YUM可以自动解决依赖关系
    • 所有软件包由集中的YUM软件仓库提供
  • YUM的配置文件
    • 基本设置:/etc/yum.conf
    • 仓库设置:/etc/yum.repos.d/*.repo
    • 日志文件:/var/log/yum.log
  • 图释
    在这里插入图片描述

部署YUM软件仓库

  • 软件仓库的提供方式
    • FTP服务:ftp://…
    • HTTP服务:http://…
    • 本地目录:file://…

配置本地YUM仓库

mount /dev/cdrom /mnt/          #光盘挂载到/mnt目录下
cd /etc/yum.repos.d/
mkdir  repos.bak                #创建一个新目录用来存放本目录内 .repo 格式的文件
mv *.repo  repos.bak

cd /etc/yum.repos.d/            #回到目录
vim local.repo                  #进入local.repo进行配置
[local]                         #仓库类别
name=local                      #仓库名称
baseurl=file:///mnt             #指定 URL 访问路径为光盘挂载目录 /mnt
enabled=1                       #开启此yum源,此为默认项,可省略
gpgcheck=0                      #不验证软件包的签名

yum clean all && yum makecache  #删除yum缓存并更新

配置阿里云仓库

[root@localhost /]# cd etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
local.repo  repos.bak
[root@localhost yum.repos.d]# mv local.repo repos.bak/
【将local.repo文件移动到repos.bak目录下(也可以是别的备份目录)】
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2021-01-15 17:03:06--  https://mirrors.aliyun.com/repo/Centos-7.repo
【将阿里云镜像下载到/etc/yum.repos.d/目录下,需连接外网】
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  repos.bak
[root@localhost yum.repos.d]# yum clean all && yum makecache 
【清理缓存并且生成新的缓存。然后就可以直接用阿里云仓库里的软件包安装文件了,但是必须有网的环境下才可以使用。如果想在没有网
的情况下也能使用yum仓库里的软件,就需要将阿里云仓库下载到本地,占用空间较高】

为客户机指定YUM仓库位置

[root@localhost ~]# vim /etc/yum.repos.d/cetons7.repo

[base]
namec=CentOS 7.3
baseurl=192.168.131.10/centos7                          【IP地址+工作目录】
enabled=1
gpgcheck=1                                              【序列号签名,如果=1则需要gpgkey】
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7     【软件检验公钥】

使用YUM工具管理软件包

  • 关于YUM命令
    • 由软件包yum-3.4.3-150.el7.centos.noarch提供
    • 用来访问YUM仓库,查询,下载及安装、卸载软件包
  • YUM缓存目录
    • 存放下载的软件包、仓库信息等数据
    • 位于/var/cache/yum
      在这里插入图片描述

yum常用命令

命令 说明
yum -y install 软件名 安装、升级软件包,“-y”选项表示自动确认
yum -y remove 软件名 卸载软件包,可自动解决其依赖关系
yum -y update 软件名 升级软件包
yum list 查询软件包列表
yum list installed 查询系统中已安装的软件包
yum list available 查询仓库中尚未安装的软件包
yum list updates 查询可以升级版本的软件包
yum info 软件名 查询软件包的描述信息
yum search [all] 关键字 根据某个关键词来查找相关的软件包
yum whatprovies 命令 查询命令属于哪个软件包

NFS共享存储服务

概述

NFS(Network File System)网络文件系统

  • NFS是一种基于TCP/IP传输的网络文件系统协议。通过使用NFS协议,客户机可以像访问本地目录一样访问远程服务器中的共享资源。
  • 对于大多数负载均衡群集来说,使用NFS协议来共享数据存储是比较常见的做法,NFS也是NAS存储设备必然支持的一种协议。但是由于NFS没有用户认证机制,而且数据在网络上明文传输,所以安全性很差,一般只能在局域网中使用。
  • 依赖于RPC(远端过程调用)
  • 需安装nfs-utils、rpcblind软件包、rpcbind默认使用111端口
  • 共享配置文件:/etc/exports
  • 格式:共享的目录位置 客户机地址(权限选项)
  • NFS工作原理简图
    在这里插入图片描述

使用NFS发布共享资源(操作步骤+注释)

  • 实验环境:192.168.131.10为NFS服务机,192.168.131.11为NFS客户机
  • 服务机

1.安装nfs-utils rpcblind软件包并查询

[root@localhost ~]# yum -y install nfs-utils rpcblind
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
没有可用软件包 rpcblind。
无须任何处理
[root@localhost ~]# rpm -q rpcbind nfs-utils      
rpcbind-0.2.0-42.el7.x86_64
nfs-utils-1.3.0-0.48.el7.x86_64

2.设置共享目录

[root@localhost ~]# mkdir -p /opt/html                      【共享目录可以使用系统已存在的也可以自己创建 】
[root@localhost ~]# chmod 777 /opt/html/                    【给共享目录权限】
[root@localhost ~]# vim /etc/exports                        【通过修改/etc/exports设置共享策略】
/html 192.168.131.0/24(rw,sync,no_root_squash)
【客户机地址可以是主机名、IP地址、网段地址,且允许使用"*""?"通配符】
【rw:表示允许读写。ro:只读】
【sync:表示同步写入到内存与硬盘中】
【no_root_squash:表示当客户机以root身份访问时,赋予本地root权限】
【root_squash:表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户】
【all_squash:表示所有访问用户都映射为匿名用户或者用户组】
【async:表示将数据先保存在内存缓存区内,必要时才写入磁盘】
【subtree_check(默认):表示若输出目录是一个子目录,则nfs服务器将检查其父目录的权限】
【no_subtree_check:表示即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率】
【anonuid=xxx:表示指定NFS服务器/etc/passwd文件中的匿名用户的UID】
【anongid=xxx:表示指定NFS服务器/etc/passwd文件中的匿名用户的GID】

4.启动NFS服务程序并查看端口情况

  • 手动加载NFS共享服务时,应该先启动rpcbind,再启动nfs
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs    
[root@localhost /]# systemctl enable rpcbind             【开机自启rpcbind】
[root@localhost /]# systemctl enable nfs                 【开机自动nfs】
[root@localhost ~]# lsof -i :111                         【查看端口开启情况】
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd    1 root   49u  IPv6  15010      0t0  TCP *:sunrpc (LISTEN)
systemd    1 root   50u  IPv4  15011      0t0  TCP *:sunrpc (LISTEN)
rpcbind 3839  rpc    4u  IPv6  15010      0t0  TCP *:sunrpc (LISTEN)
rpcbind 3839  rpc    5u  IPv4  15011      0t0  TCP *:sunrpc (LISTEN)
rpcbind 3839  rpc    8u  IPv4  37204      0t0  UDP *:sunrpc 
rpcbind 3839  rpc   10u  IPv6  37206      0t0  UDP *:sunrpc 

5.查看本机发布的NFS共享目录

[root@localhost html]# echo 111 > text1.txt              
[root@localhost html]# echo 222 > text2.txt                              【创建测试文件并输入内容】
[root@localhost html]# ll
总用量 8
-rw-r--r--. 1 root root 4 1月  15 17:37 text1.txt
-rw-r--r--. 1 root root 4 1月  15 17:37 text2.txt
[root@localhost /]# exportfs -rv                                         【发布共享】
exporting 192.168.131.0/24:/opt/html
[root@localhost /]# showmount -e                                         【查看共享】
Export list for localhost.localdomain:
/opt/html 192.168.131.0/24

6.查看客户端对共享文件进行的编辑内容

[root@localhost /]# cd /opt/html/
[root@localhost html]# ll
总用量 16
-rw-r--r--. 1 root root 4 115 17:37 text1.txt
-rw-r--r--. 1 root root 4 115 17:37 text2.txt
-rw-r--r--. 1 root root 4 115 17:59 text3.txt
-rw-r--r--. 1 root root 4 115 18:15 text4.txt
[root@localhost html]# ls
text1.txt  text2.txt  text3.txt  text4.txt
[root@localhost html]# cat text4.txt 
444

在客户端访问NFS共享

1.安装并启动NFS服务程序

[root@localhost ~]# yum -y install nfs-utils rpcblind
[root@localhost ~]# rpm -q rpcbind nfs-utils      
[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs    
[root@localhost /]# systemctl enable rpcbind            
[root@localhost /]# systemctl enable nfs  
  • 查看nfs服务端共享了哪些目录
[root@localhost ~]# showmount -e 192.168.131.10
Export list for 192.168.131.10:
/opt/html 192.168.131.0/24

2.手动挂载nfs共享目录

[root@localhost mnt]# mkdir /myshare
[root@localhost mnt]# mount 192.168.131.10:/opt/html /myshare/
[root@localhost mnt]# df -Th                                     【也可用mount进行查看】
[root@localhost /]# cat /myshare/text1.txt                       【查看共享文件的内容】
111
[root@localhost /]# cat /myshare/text2.txt 
222
[root@localhost /]# echo 444 > /myshare/text4.txt                
【因为服务端给共享文件设置了权限777,所有客户机也可进行共享文件的编辑】

3.设置自动挂载

[root@localhost /]# umount myshare/
[root@localhost /]# vim /etc/fstab 
......
192.168.131.10:/opt/html                      /myshare                nfs     defaults,_netdev 0 0
【_netdev:表示挂载设备需要网络】
:wq

[root@localhost /]# showmount -e 192.168.131.10
Export list for 192.168.131.10:
/opt/html 192.168.131.0/24
[root@localhost /]# mount -a       【重新加载】
[root@localhost /]# df -h          【查看挂载情况】
文件系统                  容量  已用  可用 已用% 挂载点
/dev/sda3                  36G  4.2G   32G   12% /
......
192.168.131.10:/opt/html   36G  3.2G   33G    9% /myshare
:wq

[root@localhost /]# touch cd /myshare/text5
[root@localhost /]# cd /myshare/
[root@localhost myshare]# ll
总用量 16
-rw-r--r--. 1 root      root      4 115 17:37 text1.txt
-rw-r--r--. 1 root      root      4 115 17:37 text2.txt
-rw-r--r--. 1 root      root      4 115 17:59 text3.txt
-rw-r--r--. 1 root      root      4 115 18:15 text4.txt
-rw-r--r--. 1 nfsnobody nfsnobody 0 115 18:35 text5

4.强制解挂载

  • 如果服务端的NFS服务突然停止,而客户端正在挂载使用中,这时在客户端执行df -h操作时就会出现命令卡死的现象。这个时候直接用umount命令时无法直接解挂的,需要加上"lf"选项才能进行解挂操作
    umount -lf /myshare

猜你喜欢

转载自blog.csdn.net/TaKe___Easy/article/details/114506100