YUM仓库及NFS共享服务

YUM仓库服务

一 、YUM概述

1.1 YUM,(Yellow dog Updater Modified)

  • 基于RPM包构建的软件更新机制
  • 可以自动解决依赖关系
  • 所有软件包由集中的YUM软件仓库提供
    在这里插入图片描述

二 : 准备安装源

2.1 软件仓库的提供方式

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

2.2 RPM软件包的来源

  • Centos 发布的RPM包集合
  • 第三方组织发布的RPM集合
  • 用户自定义的RPM包集合

2.3 构建Centos 7 软件仓库

  • RPM包来自Centos 7 DVD光盘,或者镜像文件
  • 通过FTP、HTTP或本地目录file 提供给客户机

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

  • 包括存在依赖关系的所有安装包也要加入其中

  • 使用createrepo工具建立仓库数据文件。
    createrepo 命令用于创建yum源(软件仓库),即为存放于本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据。

    [root@localhost ~]# mkdir /var/ftp/other
    [root@localhost ~]# cd /var/ftp/other/
    [root@localhost other]# createrepo -g /opt/repodata/repomd.xml ./
    

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

  • 配置文件: /etc/yum/repos.d/*.repo

    [root@localhost ~]# vi /etc/yum/repos.d/*.repo
    
    [base]
    name=centos7
    baseurl=ftp://192.168.139.132/centos7
    enabled=1
    gpgcheck=1
    gpgkey=ftp:///opt/RPM-GPG-KEY-CentOS-7
    [other]
    name=Other RPM Packages
    baseurl=ftp://192.168.139.132/other
    enabled=1
    gpgcheck=0
    

2.6 直接以centos7 光盘作本地软件仓库

  • 将centos7 光盘放入光驱

  • 指定仓库位置,baseurl地址为file:///opt/

    [root@server1 yum.repos.d]# vi local.repo 
    [local]
    name=centos7
    baseurl=file:///opt
    enabked=1
    gpgcheck=0
    

三、关于YUM的工具概述

3.1 关于YUM命令

  • 由软件包yum-3.4.3-150.el7.centos。noarch提供
  • 用来访问YUM仓库,查询、下载及安装、卸载软件包

3.2 YUM的配置文件

基本设置 : /etc/yum.conf
仓库设置 : /etc/yum.repos.d/*.repo
日志文件 : /var/log/yum.log

3.3 YUM缓存目录

存放下载的软件包、仓库信息等数据

  • 位于/var/cache/yum/basearch/ $basearch/ $releaserver

  • $basearch 硬件架构
    $releaserver OS版本

    [root@localhost yum.repos.d]# yum clean all		'清楚缓存数据'
    已加载插件:fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    正在清理软件源: base extras local other updates
    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
    Cleaning up list of fastest mirrors
    

3.4 查询软件包

yum list [软件名] #查看清单列表
选项:-y 表示自动确认
yum info [软件名] #查看软件信息,后面接软件名可以只查看指定的信息
yum search <关键词> #根据关键词查询相关软件包

3.5 查询软件包组

yum grouplist [包组名] 
yum groupinfo <包组名>

3.6 安装软件

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

3.7 升级软件

yum update     //连内核一起升级
yum upgrade    //只更新软件包,不更新内核
yum groupupdate

3.8 卸载软件

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

NFS共享存储服务

一、NFS 网络文件系统

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

RPC,远程过程调用,即rpcbind 软件包

二、使用NFS发布共享资源

2.1 安装nfs-utls、rpcbind软件包

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

2.2 创建共享目录

[root@localhost ~]# mkdir /opt/abc
[root@localhost ~]# vi /etc/exports
/opt/abc    192.168.7.0/24(rw,sync,no_root_squash)
共享目录 用户   开放的地址(权限)
/var/ftp/pub    192.168.4.11(ro) 192.168.4.110(rw)

ro 只能读,不允许更改。
rw读写,sync是服务器和客户机开启同步,
no_root_squash 表示可以是root身份访问服务器。

2.3 启动NFS服务程序

[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# netstat -anpt |grep rpcbind

2.4 showmount -e 验证

[root@localhost ~]# showmount -e

2.5 手动挂载NFS共享目录(在客户机上操作)

2.6 fstab自动挂载设置

_netdev 网络型设备

当目标服务端宕机时,无法进行所有操作,就需要强制挂载

2.7 强制卸载NFS

umount -if /mnt

三、项目

NSF(共享存储服务)

server∶192.168.40.11  (需要安装rpcbind和nfs软件包)
client1∶192.168.40.12   预装apache 
client2∶192.168.40.13   预装apache

nfs-utils来实现nfs的共享发布与访问,题圆依赖rpc(远程过程调用),充当nfs客户端与服务器的中介,完成远程到本地的映射过程。

项目需求∶利用nfs存储服务来实现制作两个不同的网页,将这两个网页分别作为两个网站的主页。

服务器:

yum -y install nfs-utils rpcbind

创建共享文件夹:

[root@server1 ~]# mkdir /opt/web1
[root@server1 ~]# mkdir /opt/web2
[root@server1 ~]# cd /opt/web1
[root@server1 web1]# vi index.html
<html><title>web1</title><body><hl>this is the web1!</h1></body></html>
[root@server1 web1]# cp index.html /opt/web2
[root@server1 web1]# cd /opt/web2
[root@server1 web2]# vi index.html
<html><title>web2</title><body><h1>this is the web2!</h1></body>×/html>

发布共享文件夹:

[root@server1 ~]# vi /etc/exports
/opt/web1 192.168.40.12(ro)
/opt/web2 192.168.40.13(ro)

启动NFS服务:

[root@server1 ~]# systemctl start nfs
[root@server1 ~]# systemctl start rpcbind

客户机1:

[root@client1 ~] yum -y install httpd
查看发布的NFS共享目录

[root@client1 ~] showmount -e 192.168.40.11
Export list for 192.168.40.11:
/opt/web2 192.168.40.13
/opt/web1 192.168.40.12

挂载NFS共享目录(及创造一条路径)

[root@client1 ~]# mount 192.168.40.11:/opt/web1 /var/www/html/ 
[root@client1 ~]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/sda5               xfs        51G  4.6G   47G    9% /
devtmpfs                devtmpfs  898M     0  898M    0% /dev
tmpfs                   tmpfs     912M     0  912M    0% /dev/shm
tmpfs                   tmpfs     912M  9.0M  903M    1% /run
tmpfs                   tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sr0                iso9660   4.3G  4.3G     0  100% /mnt
/dev/sda2               xfs       5.0G   37M  5.0G    1% /home
/dev/sda1               xfs      1014M  174M  841M   18% /boot
tmpfs                   tmpfs     183M   12K  183M    1% /run/user/42
tmpfs                   tmpfs     183M     0  183M    0% /run/user/0
192.168.40.11:/opt/web1 nfs4       51G  4.5G   47G    9% /var/www/html

查看文件状态

[root@client1 ~]# cd /var/www/html/ 
[root@client1 html]# ls -lh
总用量 4.0K
-rw-r--r-- 1 root root 70 10月 30 00:58 index.html

客户机2:

[root@client2 ~] yum -y install httpd
查看发布的NFS共享目录

showmount -e 192.168.40.11
Export list for 192.168.40.11:
/opt/web2 192.168.40.13
/opt/web1 192.168.40.12

挂载NFS共享目录(及创造一条路径)

[root@client2 ~]# mount 192.168.40.11:/opt/web2 /var/www/html/
[root@client2 ~]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/sda5               xfs        51G  4.6G   47G    9% /
devtmpfs                devtmpfs  898M     0  898M    0% /dev
tmpfs                   tmpfs     912M     0  912M    0% /dev/shm
tmpfs                   tmpfs     912M  9.1M  903M    1% /run
tmpfs                   tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda2               xfs       5.0G   33M  5.0G    1% /home
/dev/sda1               xfs      1014M  174M  841M   18% /boot
tmpfs                   tmpfs     183M  4.0K  183M    1% /run/user/42
tmpfs                   tmpfs     183M   40K  183M    1% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0  100% /mnt
192.168.40.11:/opt/web2 nfs4       51G  4.5G   47G    9% /var/www/html

查看文件状态

[root@client2 ~]# cd /var/www/html/
[root@client2 html]# ls -lh
总用量 4.0K
-rw-r--r--. 1 root root 70 10月 30 01:00 index.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值