Linux网络服务----yum仓库的部署和NFS服务

目录

  • 一、yum仓库部署服务
    • 1、yum软件仓库的部署
      • 1>yum概述
      • 2>准备安装源
    • 2、使用yum工具管理软件包
      • 1>yum工具概述
      • 2>软件包,软件组查询及安装卸载
    • 3>本地yum仓库
    • 4>远程ftp yum仓库
  • 二、NFS共享存储服务
    • 1、使用NFS发布共享资源
    • 2、客户端访问NFS共享
    • 3、构建NFS实验

一、yum仓库部署服务

1、yum软件仓库的部署

1>yum概述

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

2>准备安装源

  • 软件仓库的提供方式:
    FTP服务:ftp://...
    HTTP服务:http://...
    本地目录:file://...
  • RPM软件包的来源
    centos发布的rpm包合集
    第三方组织发布的rpm包集合
    用户自定义的rpm包集合

2、使用yum工具管理软件包

1>yum工具概述

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

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

2>软件包,软件组查询及安装卸载

Yum update 既更新软件包,同时更新系统内核
Yum upgrade 只更新软件包
Yum install 软件包 —安装
Yum remove 软件包 —卸载
Yum list —查看软件列表
Yum clean all —清理缓存
Yum info 软件包 —查看软件包详细信息
Yum whatprovides 文件或目录 ----查看文件或者目录归属于哪个软件包安装的
yum grouplist 包组名
yum groupinfo 包组名

3>本地yum仓库

挂载光盘

[root@localhost yum.repos.d]# df -Th
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs       296G  4.0G  292G    2% /
devtmpfs                devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G    0% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G    1% /run
tmpfs                   tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               xfs       973M  179M  795M   19% /boot
tmpfs                   tmpfs     378M  4.0K  378M    1% /run/user/42
tmpfs                   tmpfs     378M   24K  378M    1% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0  100% /mnt  ##光盘挂载

移走原来的yum源

[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir aa
[root@localhost yum.repos.d]# mv *.repo aa
[root@localhost yum.repos.d]# ls
aa
[root@localhost yum.repos.d]# yum -y install httpd
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
There are no enabled repos.
 Run "yum repolist all" to see the repos you have.
 To enable Red Hat Subscription Management repositories:
     subscription-manager repos --enable 
 To enable custom repositories:
     yum-config-manager --enable   ##yum仓库没了,安装不了软件包

重新写入本地yum仓库

vim new.repo
[base]
name=base
baseurl=file:///mnt
enabled=1
gpgcheck=0
yum clean all   
yum list
[root@localhost yum.repos.d]# yum -y install httpd   #测试可以安装
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-88.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-88.el7.centos,它被软件包 httpd-2.4.6-88.el7.centos.x86_64 需要
--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-88.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 httpd-tools.x86_64.0.2.4.6-88.el7.centos 将被 安装
---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=============================================================================================
 Package               架构             版本                            源              大小
=============================================================================================
正在安装:
 httpd                 x86_64           2.4.6-88.el7.centos             base           2.7 M
为依赖而安装:
 httpd-tools           x86_64           2.4.6-88.el7.centos             base            90 k
 mailcap               noarch           2.1.41-2.el7                    base            31 k

事务概要
=============================================================================================
安装  1 软件包 (+2 依赖软件包)

总下载量:2.8 M
安装大小:9.6 M
Downloading packages:
---------------------------------------------------------------------------------------------
总计                                                          81 MB/s | 2.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : mailcap-2.1.41-2.el7.noarch                                              1/3 
  正在安装    : httpd-tools-2.4.6-88.el7.centos.x86_64                                   2/3 
  正在安装    : httpd-2.4.6-88.el7.centos.x86_64                                         3/3 
  验证中      : httpd-tools-2.4.6-88.el7.centos.x86_64                                   1/3 
  验证中      : mailcap-2.1.41-2.el7.noarch                                              2/3 
  验证中      : httpd-2.4.6-88.el7.centos.x86_64                                         3/3 

已安装:
  httpd.x86_64 0:2.4.6-88.el7.centos                                                         

作为依赖被安装:
  httpd-tools.x86_64 0:2.4.6-88.el7.centos           mailcap.noarch 0:2.1.41-2.el7          

完毕!

4>远程ftp yum仓库

  • FTP端口号:20和21 —21:用于连接服务器
    —20:数据传输
    准备网络安装源(服务器端)
[root@localhost ~]# mount /dev/sr0 /mnt
[root@localhost /]# yum -y install vsftp*  ##安装vsftp包
[root@localhost /]# cd /var
[root@localhost var]# ls
account  cache  db     ftp    gopher    lib    lock  mail  opt       run    target  www
adm      crash  empty  games  kerberos  local  log   nis   preserve  spool  tmp     yp
[root@localhost var]# cd ftp
[root@localhost ftp]# ls
pub
[root@localhost ftp]# mkdir centos7   ##创建一个放仓库的文件夹
[root@localhost ftp]# cp -rf /mnt/* /var/ftp/centos7/ &  #复制软件包到ftp仓库
[root@localhost ftp]# mkdir other
[root@localhost ftp]# createrepo -g /mnt/repodata/repomd.xml other/ #建立yum索引环境
[root@localhost ftp]# systemctl start vsftpd   #开启ftp服务

客户端配置

[root@localhost ~]# yum -y install ftp   #测试访问ftp服务
[root@localhost ~]#ftp 192.168.100.20
[root@localhost ~]#vim abc.repo                          #配置repo仓库文件
[base]  
name=centos7
baseurl=ftp://192.168.100.20/centos7
enabled=1
gpgcheck=1
gpgkey=ftp://192.168.100.20/centos7/RPM-GPG-KEY-CentOS-7

[other]
name=other.Packages
baseurl=ftp://192.168.200.20/other
enabled=1
gpgcheck=0

[root@localhost yum.repos.d]# yum -y install httpd   #测试可以安装

二、NFS共享存储服务

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

1、使用NFS发布共享资源

  • 安装nfs-utils,rpcbind软件包
  • 设置共享目录
[root@localhost opt]# mkdir wwwroot
[root@localhost opt]# vim /etc/exports
/opt/wwwroot  192.168.197.171(rw,sync,no_root_squash)

2、客户端访问NFS共享

  • 安装rpcbind软件包,并启动rpcbind服务
    若要正常访问NFS共享资源,客户机中也需要安装rpcbind软件包,并启动rpcbind服务
    为了可以使用showmount查询工具,建议将nfs-utils软件包也一并装上
    使用 “showmount -e 服务器地址”可以查看NFS服务器端共享了那些目录
  • 手动挂载NFS共享目录
  • 自动挂载设置
[root@localhost opt]# vim /etc/fstab
192.168.197.171:/opt/wwwroot /var/www/html      nfs     defaults,_netdev        0 0

  • 强制卸载NFS
    如果客户端正在挂载使用,服务器端NFS服务突然停掉了,那么在客户端就会出现df -h命令卡死的现象
    此时使用umount命令是无法直接卸载的,需要加上-lf才能卸载,出现卡死现象时,需要重新打开一个终端,执行 cat/etc/rc.local命令,查看挂载点然后使用umount命令卸载,其中-l表示解除正在繁忙的文件系统,-f表示强制

3、构建NFS实验

服务端:

[root@localhost ~]# df -Th                  ##添加一块硬盘作共享
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs       295G  4.1G  291G    2% /
devtmpfs                devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G    0% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G    1% /run
tmpfs                   tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  179M  836M   18% /boot
tmpfs                   tmpfs     378M  4.0K  378M    1% /run/user/42
tmpfs                   tmpfs     378M   24K  378M    1% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
/dev/sdb1               xfs        20G   33M   20G    1% /mnt
[root@localhost /]# setenforce 0
[root@localhost /]# iptables -F     ## 关闭防火墙
[root@localhost /]# yum -y install rpcbind nfs-utils   ##安装两个相关的软件包
[root@localhost /]# vim /etc/exports     ##写入共享配置文文件
/mnt    192.168.20.0/24(rw,sync,no_root_squash)   ##允许哪个网段可以查看共享的空间
[root@localhost /]# systemctl start nfs-utils     ##开启两个服务
[root@localhost /]# systemctl start rpcbind
[root@localhost /]# systemctl enable nfs-utils
[root@localhost /]# systemctl enable rpcbind
[root@localhost /]# showmount -e     ##查看提供的服务
Export list for localhost.localdomain:
/mnt 192.168.20.0/24

客户端:

[root@localhost ~]#yum -y install httpd       #安装一个apache服务做实验
[root@localhost ~]# setenforce 0   ##关闭防火墙
[root@localhost ~]# iptables -F
[root@localhost ~]# mount 192.168.20.20:/mnt /var/www/html   ##将共享空间挂载到要用的服务目录里面(也就是做实验的apache文件)   手动挂载
[root@localhost ~]# df -Th    
文件系统                类型      容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root xfs       295G  4.1G  291G    2% /
devtmpfs                devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G    0% /dev/shm
tmpfs                   tmpfs     1.9G   13M  1.9G    1% /run
tmpfs                   tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  179M  836M   18% /boot
tmpfs                   tmpfs     378M   36K  378M    1% /run/user/0
/dev/sr0                iso9660   4.3G  4.3G     0  100% /run/media/root/CentOS 7 x86_64
192.168.20.20:/mnt      nfs4       20G   32M   20G    1% /var/www/html   ##查看,已经挂载


[root@localhost www]# vim /etc/fstab   
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=451ccd23-f0c9-4858-9910-bdb53cff4e48 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
192.168.20.20:/mnt      /var/www/html   nfs     defaults,_netdev 0 0    ##自动挂载
[root@localhost www]# mount -a
[root@localhost www]# cd /var/www/html    #写一个网页验证
[root@localhost html]# ls
[root@localhost html]# vim index.html

text01...web

[root@localhost html]# systemctl start httpd ##开启httpd服务
[root@localhost /]# cd /mnt   ##回到服务端 查看客户端写的一个网页文件
[root@localhost mnt]# ls
index.html
[root@localhost mnt]# cat index.html 

text01...web

用浏览器打开客户端写的网页即可看到网页

你可能感兴趣的:(linux,内核,文件系统,网络)