实验环境:Red Hat 8.0
1.本地源配置
确保本地或虚拟机已经挂载镜像文件
# mount /dev/cdrom /mnt //挂载镜像到本地文件 # cd /etc/yum.repos.d/ # vi redhat.repo //yum配置文件,添加以下内容,注意所有代码靠紧左边,不然格式会错误 [BaseOS] name=BaseOS baseurl=file:///mnt/BaseOS enabled=1 //启用yum源,0为不启用,1为启用 gpgcheck=0 //检查GPG-KEY,0为不检查,1为检查 [AppStream] name=AppStream baseurl=file:///mnt/AppStream enabled=1 gpgcheck=0 :wq # yum clean all //清除yum缓存 # yum makecache //缓存本地yum源
在RHEL8中把软件源分成了两部分
- 一个是BaseOS:以传统 RPM 包的形式提供底层核心 OS 内容
- 一个是AppStream:提供您可能希望在给定用户空间中运行的所有应用程序。
测试,随意安装一个服务,没有弹出错误提示,并成功安装
# yum -y install samba
如果是redhat8之前的版本配置本地源,只需要定义一个库即可
[test] name=test baseurl=file:///mnt enabled=1 gpgcheck=0
2.网络源配置
请先确保本机能够上网
实验前先备份自己的系统repo文件
# cd /etc/yum.repos.d/ # mkdir bak # mv redhat.repo bak/
获取repo文件
# wget http://mirrors.aliyun.com/repo/Centos-8.repo
有些系统最小化安装可能没有wget指令,需自行安装或者使用curl指令下载
# curl -O(大写O) http://mirrors.aliyun.com/repo/Centos-8.repo
这里提供两个国内源的地址:
http://mirrors.aliyun.com/repo/Centos-8.repo
http://mirrors.163.com/.help/CentOS8-Base-163.repo
更新yum源
# yum clean all # yum makecache
装软件测试,没有弹出错误提示,网络源成功
# yum -y install nginx
启动服务
# systemctl enable --now nginx
这句代码是redhat8的新特性,systemctl start nginx /systemctl enable nginx的集合体,启动并设置开机自启动