部署YUM仓库及NFS共享服务

一、YUM仓库服务

1.1 YUM概述

■ YUM

  • 基于RPM包构建的软件更新机制
  • 可以自动解决依赖关系
  • 所有软件包由集中的YUM软件仓库提供

YUM的前身是YUP( Yellow dog Updater,Yellow dog Linux的软件更新器 ),最初由TSS公司使用Python语言开发而成,后来由杜克大学的Linux开发队伍进行改进,命名为YUM(Yellow dog Updater Modified)。
借助于YUM软件仓库,可以完成安装、下载、自动升级rpm软件包等任务,能够自动查找并解决rpm包之间的依赖关系,而无须管理员逐个、手工地去安装每一个rpm包,使管理员在维护大量Linux服务器时更加轻松自如。特别是在拥有大量Linux主机的本地网络中,构建一台源服务器可以大大缓解软件安装、升级等对Internet的依赖。
在这里插入图片描述

1.2 准备安装源-1

■ 软件仓库的提供方式

  • FTP服务:ftp://……
  • HTTP服务: http://……
  • 本地目录:file://……

■ RPM软件包的来源

  • CentOS发布的RPM包集合
  • 第三方组织发布的RPM包集合
  • 用户自定义的RPM包集合
1.3 准备安装源-2

■ 在软件仓库中加入非官方RPM包组

  • 包括存在依赖关系的所有RPM包
  • 使用createrepo工具建立仓库数据文件
1.4 准备安装源-3

■ 为客户机指定YUM仓库位置

  • 配置文件:letc/yum.repos.d/centos7.repo
[root@localhost ~]# vi l/etclyum.repos.d/centos7.repo
[base]
name=CentOS 7.3
baseurl=ftp:/l/192.168.4.254/centos7enabled=1
软件校验公钥
gpgcheck=1
gpgkey=file:llletc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[other]
name=Other RPM Packages
baseurl=ftp://192.168.4.254/other
enabled=1
gpgcheck=0

二、YUM仓库概述

2.1 yum工具概述-1

■ 关于YUM命令

  • 由软件包yum-3.4.3-150.el7.centos.noarch提供

  • 用来访问YUM仓库,查询,下载及安装,卸载软件包

■ yum的配置文件

  • 基本设置:/etc/yum.conf
  • 仓库设置:/etc/yum.repos.d/*.repo
  • 日志文件:/var/log/yum.log
2.2 yum工具概述-2

■ yum缓存目录

  • 存放下载的软件包、仓库信息等数据
  • 位于/varlcache/yum/ b a s e a r c h / basearch/ basearch/releasever
    硬件架构,如x86_64
    os版本
[root@localhost ~]# yum clean all
清理缓存数据
2.3 yum工具概述-3

■ 查询软件包列表**

yum list[软件名]
yum info [软件名]
yum search<关键词>
yum whatprovides<关键词>

■ 示例

[root@localhost ~]# yum list
[root@localhost ~]# yum list httpd
[root@localhost ~]# yum info vsftpd
[root@localhost ~]# yum search gcc
[root@localhost ~]# yum whatprovides vim

2.4 软件包查询-1

■ 查询软件包

yum list[软件名]yum info[软件名]
yum search<关键词>
yum whatprovides<关键词>

■ 示例

[root@localhost ~]# yum list
[root@localhost ~]# yum list httpd
[root@localhost ~]# yum info vsftpd
[root@localhost ~]# yum search gcc
[root@localhost ~]# yum whatprovides vim
2.5 软件包查询-2

■ 查询软件包组

yum grouplist[包组名]
yum groupinfo<包组名>
```bash
■  示例
[root@localhost ~]# yum grouplist
[root@localhost ~]# yum grouplist gnome-desktop
[root@localhost ~]# yum groupinfo gnome-desktop
2.6 软件安装、升级、软件卸载

■ 安装软件

yum install [软件名]
yum groupinstall <包组名>

■ 升级软件

yum update
yum groupdate

yum update 更新软件包,连内核一起更新
yum upgrade 只更新软件包,但不更新内核

■ 卸载软件

yum remove <软件名>…
yum groupremove <包组名>

三、NFS 共享存储服务

3.1 共享存储服务

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

  • 依赖于RPC(远端过程调用)
  • 需安装nfs-utils、rpcbind软件包
  • 系统服务:nfs、rpcbind
  • 共享配置文件:/etc/exports
3.2 使用NFS发布共享资源-1

■ 安装nfs-utils、rpcbind软件包

[root@localhost ~]# yum -y install nfs-utils rpcbind
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind

■ 设置共享目录

[root@localhost ~]# mkdir -p lopt/wwwroot
[root@localhost ~]# vi letclexports
lopt/wwwroot192.168.7.0/24(Iw,sync,no_root_squash)
/var/ftp/pub192.168.4.11(ro)192.168.4.110(w)

3.3 使用NFS发布共享资源-2

■ 启动NFS服务程序
■ 查看本机发布的NFS共享目录

[root@localhost~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# netstat -anpt | grep rpctcp o0 0.0.0.0:20048
o.0.0.0:*LISTEN10508/rpc.mountd
tcp o0 0.0.0.0:52732
o.0.0.0:* LISTEN 10495/rpc.statd
tcp6o0 :::20048
LISTEN10508/rpc.mountd
tcp6
o0 :::47669
LISTEN10495/rpc.statd
[root@localhost ~]# showmount -e
lopt/wwwroot 192.168.7.0/24
/var/ftp/pub 192.168.4.110,192.168.4.11
3.4 使用NFS发布共享资源-4

■ 安装rpcbind软件包,并启动rpcbind服务

[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start rpcbind[root@localhost ~]# showmount -e 192.168.7.250Export list for 192.168.7.250:
loptlwwwroot 192.168.7.0/24
/var/ftp/pub 192.168.4.110,192.168.4.11
3.5 使用NFS发布共享资源-5

■ 在客户机中访问NFS共享资源3-2手动挂载NFS共享目录

[root@localhost ~]# mount 192.168.7.250:/optlwwwroot /varlwww/html
[root@localhost ~]# tail -1 letc/mtab
192.168.7.250:/opt/wwwroot /varlwww/html nfs4
rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.7.21,local_logk=none,
addr=192.168.7.250 o 0
[root@localhost ~]# vi lvarlwww/html/index.htmlReal Web Server Document
3.6 使用NFS发布共享资源-6

■ fstab自动挂载设置

[root@localhost ~]# vi letclfstab
......//省略部分信息
192.168.7.250:/optlwwwroot /varlwww/html nfs defaults,_netdev 0 0

■ 强制卸载NFS

[root@localhost ~]# umount lmntumount: /mnt: device is busy
[root@localhost ~]# umount -lf /mnt
[root@localhost ~]#

三、实验操作

服务器yum仓库建立,客户端,本地源

注:实验基于所有的基础配置都已经搭建好了,ip,挂载,防火墙,

服务器:
准备网络安装源(服务端yum部署),线网源!!
1.构建centos7软件仓库:

*rpm包来自centos7 DVD光盘
*通过FTP方式提供给客户机

1.创建目录
[root@as ~]# mkdir  -p /var/ftp/centos7

2.复制光盘挂载点下的所有文件到
[root@as ~]# cp -rf  /mnt/*   /var/ftp/centos7/

3. 
rpm -ivh /mnt/Packages/vsftpd-3.0.2-22.el7.x86_64.rpm 
4.开启服务和开机自启
[root@as ~]# systemctl   start vsftpd
[root@as ~]# systemctl  enable vsftpd




2.在软件仓库中加入非官方的RPM包组

*包括存在的依赖关系的所有RPM包
*使用createrepo工具建立仓库数据文件


1.首先yum安装createrepo工具
yum -y install createrepo
2.
[root@as ~]# mkdir /var/ftp/other
[root@as ~]# cd  /var/ftp/other/
3.以现有的repodata目录为样板
createrepo  -g  /mnt/repodata/repomd.xml   ./

客户端:

之前的配置源/etc/yum.repos.d/  目录下之前是官方的源,不要删除,新建一个目录,放到新建目录下;


1.之前的cp的配置local.repo里添加(local.repo文件是之前cp的Centos-Base+tab出来文件)

[root@hgg backup]# vi /etc/yum.repos.d/local.repo 
[centos]
name=CentOS
baseurl=ftp://20.0.0.18/centos7
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


[other]
name=other
baseurl=ftp://20.0.0.18/other
gpgcheck=0
enabled=1

2.清楚缓存,重新加载缓存
yum clean all;
yum makecache;

本地源搭建:

1.进入文件/etc/yum.repos.d/


创建一个新目录;
把源都移动到新建的目录里;
复制目录下的模板, 命名local.repo;





进入vi编辑器改参数,先删掉前36行,36dd

完成如下配置


【类别】
名称=说明
baseurl=file:///mnt  去哪个路径找,挂载点
Gpgcheck=0   不验证软件包的签名
Enabled=1  开机自启


5.
Centos7.4 yum缓存是需要手动清除的;
在重新mkae加载缓存;

NFS:
在服务器:

1.安装nfs-utils , rpcbind软件包;
 yum -y install rpcbind  nfs-utils
2.启动服务和设置开机自启
 systemctl enable nfs
 systemctl enable rpcbind;
3.设置共享目录
[root@as other]# mkdir -p /opt/wwwroot
[root@as other]# vi /etc/exports
/opt/wwwroot  20.0.0.0/24(rw,sync,no_root_squash)
注:(rw,sync,no_root_squash)读写的权限,表示同步写入,当客户机以root身份访问时,赋予本地root权限

4.启动服务程序;
systemctl start rpcbind;
systemctl start nfs;
netstat -anpt | grep rpcbind

5.查看本地发布的NFS共享目录
showmount -e
Export list for as:
/opt/wwwroot 20.0.0.0/24
6.将共享文件挂载,两边都要挂载才可以;
[root@hgg ~]# mount   20.0.0.18:/opt/wwwroot  /var/www/html/
[root@hgg ~]# df -Th

在客户端:

*手动挂载NFS共享目录,挂载到/var/www/html
*与本地挂载文件不同的是,设备位置处应指出服务器地址;
1.也需要下载软件包:nfs-utils,  rpcbind
 yum -y install rpcbind  nfs-utils

2.启动rpcbind服务,设置开机自启
 systemctl start rpcbind;
 systemctl enable rpcbind;
  systemctl start nfs
systemctl enable nfs
3.进行手动挂载
[root@hgg ~]# showmount -e 20.0.0.18 (记住是服务器的地址)
Export list for 20.0.0.18:
/opt/wwwroot 20.0.0.0/24
先查看一下,显示出来说明就可以挂载了;

挂载:(挂载之后查看一下挂载,在确认挂载结果;)
将服务器的共享文件挂载,前面要加服务器地址的ip

[root@hgg ~]# mount   20.0.0.18:/opt/wwwroot  /var/www/html/
[root@hgg ~]# df -Th
Filesystem             Type      Size  Used Avail Use% Mounted on
/dev/sda3              xfs        17G  987M   17G   6% /
devtmpfs               devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                  tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                  tmpfs     1.9G  8.6M  1.9G   1% /run
tmpfs                  tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sr0               iso9660   4.3G  4.3G     0 100% /mnt
/dev/sda1              xfs      1014M  135M  880M  14% /boot
tmpfs                  tmpfs     378M     0  378M   0% /run/user/0
20.0.0.18:/opt/wwwroot nfs4       17G  5.2G   12G  31% /var/www/html
[root@hgg ~]# tail -1 /etc/mtab 
20.0.0.18:/opt/wwwroot /var/www/html nfs4 rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=20.0.0.19,local_lock=none,addr=20.0.0.18 0 0

4.测试文件:(在客户端的共享目录下创建文件,服务器端也会可以显示文件的)
两个测试文件自己拟定;
vi  /var/www/html/as.html  
vi  /var/www/html/index.html 
在共享目录挂载点下,创建一个文件测试下服务器端可不可以共享的到

服务器端

查看::
[root@as ~]# ll /var/www/html/
total 8
-rw-r--r-- 1 root root 13 Jul 31 16:14 as.html
-rw-r--r-- 1 root root 12 Jul 31 16:17 index.html



fstab自动挂载设置;
1.修改/etc/fstab配置文件,加入NFS共享目录的挂载设置。
[root@hgg html]# vi /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Jul 30 08:59:39 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=0a7d740d-097d-4c18-89e6-0a759b7086a7 /                       xfs     defaults        0 0
UUID=5e0de58b-b88d-4595-b5fd-8120d133f522 /boot                   xfs     defaults        0 0
UUID=d5b40c3b-7424-4c99-b37a-90c3e2793791 swap                    swap    defaults        0 0
/dev/cdrom  /mnt   iso9660   defaults 0 0
20.0.0.18:/opt/wwwroot  /var/www/html  nfs  defaults_netdev  0 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值