yum是一款软件包管理器,基于rpm包管理,可以从指定的位置自动下载rpm包,自动的处理依赖性关系,一次性安装所有的软件包,无需繁琐的一次次下载和安装
yum命令常用选项:
yum list all ###列出所有安装包
yum list installed ###列出已经安装的
yum list available ###列出没有安装的
yum remove software ###卸载软件
yum install software ###安装软件
yum search 关键字 ###搜索与关键字相关的软件
yum whatprovides 文件 ###搜索包含此文件的包
yum reinstall software ###从新安装软件
yum localinstall 第三方软件 ###安装第三方软件并解决依赖关系
yum info software ###查询软件信息
yum groups list ###列出软件组
yum groups install ###安装组
yum groups remove ###卸载组
yum groups info ###查看组信息
本地源配置
[root@foundation43 ~]# ostnamectl ##查看系统版本
Static hostname: foundation43.ilt.example.com
Icon name: computer-laptop
Chassis: laptop
Machine ID: 5dda1580e9474d0ab1a33787bad19b3b
Boot ID: cc6ec8b27bd44f3f8ac0e0aa20d25035
Operating System: Red Hat Enterprise Linux Server 7.2 (Maipo) ##系统版本
CPE OS Name: cpe:/o:redhat:enterprise_linux:7.2:GA:server
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
找到相应的iso文件挂载
[root@foundation43 ~]# cd /iso ##找到系统相对应的光盘
[root@foundation43 iso]# ll
total 11309056
-rw-rw-r-- 1 qemu qemu 3743416320 Apr 22 2016 rhel-server-7.0-x86_64-dvd.iso
-rw-rw-r-- 1 kiosk kiosk 4043309056 Jul 25 2016 rhel-server-7.2-x86_64-dvd.iso
-rw-rw-r-- 1 kiosk kiosk 3793747968 Sep 16 2017 rhel-server-7.3-x86_64-dvd.iso
[root@foundation43 iso]# mkdir /mnt/rhel7.2 ##创建一个挂在目录
[root@foundation43 iso]# mount rhel-server-7.2-x86_64-dvd.iso /mnt/rhel7.2
mount: /dev/loop0 is write-protected, mounting read-only ##挂在iso镜像至挂载目录
配置本地源
[root@foundation43 iso]# cd /etc/yum.repos.d/ ##切换至yum库配置文件目录
[root@foundation43 yum.repos.d]# mkdir repo.bak ##创建一个备份目录
[root@foundation43 yum.repos.d]# mv * repo.bak/ ##备份现有文件
[root@foundation43 yum.repos.d]# vim yum.repo ##创建新的repo文件
[rhel7.2] ##源名称
name=rhel7.2 ##源描述
baseurl=file:///mnt/rhel7.2 ##源地址
gpgcheck=0|1 ##是否检测源的gpgkey
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ##本机gpgkey文件,如果检测源的gpgkey需要此参数
#enabled=1 ##源是否生效,非必须
[root@foundation43 yum.repos.d]# yum clean all ##清理yum缓存
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel7.2
Cleaning up everything
共享源搭建
在本地源搭建成功后安装httpd
[root@foundation43 yum.repos.d]# yum install httpd ##安装apache
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-40.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-40.el7 for package: httpd-2.4.6-40.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-40.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-40.el7 rhel7.2 1.2 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 rhel7.2 103 k
apr-util x86_64 1.5.2-6.el7 rhel7.2 92 k
httpd-tools x86_64 2.4.6-40.el7 rhel7.2 82 k
Transaction Summary
================================================================================
Install 1 Package (+3 Dependent packages)
Total download size: 1.4 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------
Total 28 MB/s | 1.4 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/4
Installing : apr-util-1.5.2-6.el7.x86_64 2/4
Installing : httpd-tools-2.4.6-40.el7.x86_64 3/4
Installing : httpd-2.4.6-40.el7.x86_64 4/4
Verifying : httpd-tools-2.4.6-40.el7.x86_64 1/4
Verifying : apr-1.4.8-3.el7.x86_64 2/4
Verifying : apr-util-1.5.2-6.el7.x86_64 3/4
Verifying : httpd-2.4.6-40.el7.x86_64 4/4
Installed:
httpd.x86_64 0:2.4.6-40.el7
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-40.el7
Complete!
[root@foundation43 yum.repos.d]# systemctl start httpd.service ##重启服务
[root@foundation43 yum.repos.d]# systemctl enable httpd.service ##开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@foundation43 yum.repos.d]# systemctl stop firewalld.service ##关闭防火墙
[root@foundation43 yum.repos.d]# systemctl disable firewalld.service ##禁止防火墙开机启动
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@foundation43 yum.repos.d]# mkdir /var/www/html/rhel7.0 ##创建共享目录
[root@foundation43 yum.repos.d]# mount /iso/rhel-server-7.0-x86_64-dvd.iso /var/www/html/rhel7.0 ##挂载镜像至共享目录
浏览器访问ip地址/rhel7.0测试共享源,访问成功表示共享成功
客户端配置yum源
[root@desktop ~]# cd /etc/yum.repos.d/ ##移动至repo配置目录
[root@desktop yum.repos.d]# mkdir repo.bak ##创建备份目录
[root@desktop yum.repos.d]# mv * repo.bak ##备份文件
[root@desktop yum.repos.d]# vim yum.repo ##配置源
[rhel7.0]
name=rhel7.0
baseurl=http://172.25.254.43/rhel7.0 ##网络源路径
gpgcheck=0
[root@desktop yum.repos.d]# yum clean all ##清空缓存
Loaded plugins: langpacks
Cleaning repos: rhel7.0 ##当前的源
Cleaning up everything
[root@desktop yum.repos.d]# yum install zsh ##安装软件
Loaded plugins: langpacks
rhel7.0 | 4.1 kB 00:00
(1/2): rhel7.0/group_gz | 134 kB 00:00
(2/2): rhel7.0/primary_db | 3.4 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package zsh.x86_64 0:5.0.2-7.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
zsh x86_64 5.0.2-7.el7 rhel7.0 2.4 M
Transaction Summary
================================================================================
Install 1 Package
Total download size: 2.4 M
Installed size: 5.6 M
Is this ok [y/d/N]: y
Downloading packages:
zsh-5.0.2-7.el7.x86_64.rpm | 2.4 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : zsh-5.0.2-7.el7.x86_64 1/1
Verifying : zsh-5.0.2-7.el7.x86_64 1/1
Installed:
zsh.x86_64 0:5.0.2-7.el7
Complete!
配置成功后,通过网络源,安装软件成功