一、准备工作
- 两台CentOS服务器。一台为本地yum源服务端,一台为客户端(测试yum服务端安装情况)
序号 IP地址 作用 备注 01 192.168.0.1 yum源服务端 将镜像上传到此处 02 192.168.0.2 客户端 - 下载CentOS-7-x86_64-Everything-2207-02.iso操作系统镜像文件至服务端。
镜像文件下载地址,链接: https://pan.baidu.com/s/1mtd8Vs7qdJioAJBa0Ar8MA?pwd=9qx7 提取码: 9qx7。
二、制作本机yum源
- 将操作系统本机自带的yum源备份
# 创建备份文件夹 mkdir -p /root/yum.repos.d # 将linux操作系统自带yum源文件备份至/root/yum.repos.d/文件夹 mv /etc/yum.repos.d/* /root/yum.repos.d/
- 创建新的yum源文件,这里的baseurl为本地文件目录,一会制作远端yum源的时候需要修改为http地址。
cat << EOF > /etc/yum.repos.d/localhost_centos.repo
[localhost_centos]
name=localhost_centos
baseurl=file:///opt/software/centos
gpgcheck=0
enabled=1
EOF
- baseurl
- 随便找一个目录将ios文件挂载至/opt/software/centos/,并将文件全部拷贝至centos目录
# 以只读方式将iso文件挂载至 /mnt/下
mount -o loop /opt/software/CentOS-7-x86_64-Everything-2207-02.iso /mnt/
# 拷贝/mnt/下的所有文件至/opt/software/centos/
cp -r /mnt/* /opt/software/centos/
# 卸载挂载点
umout /mnt/
- 制作本地yum源,通过以下两个命令,可以看到自建的yum仓库已经存在。
yum clean all && yum repolist
- 在服务端机器,运行yum命令安装http服务,后即可将yum源做成远端yum源
# 安装nginx服务,如果这里在我下载的本地iso文件yum源里没有nginx安装包,可以安装tomcat作为http发布服务器,tomcat作为http发布服务的教程大家自行查找 yum -y install nginx
找到server文件将nginx的主目录配置成/opt/software/,如下图:
# 检查nginx配置文件是否正确,如果正确显示nginx: the configuration file /etc/nginx/nginx.conf syntax is ok;nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx -t
# 启动nginx服务
systemctl start nginx
# 将nginx开机自启
systemctl enable nginx
# 显示nginx启动状态
systemctl status nginx
三、制作远端yum源
在客户端运行以下命令。
# 创建备份文件夹
mkdir -p /root/yum.repos.d
# 将linux操作系统自带yum源文件备份至/root/yum.repos.d/文件夹
mv /etc/yum.repos.d/* /root/yum.repos.d/
# 新建localhost_centos.repo yum源文件
cat << EOF > /etc/yum.repos.d/localhost_centos.repo
[localhost_centos]
name=localhost_centos
baseurl=http://192.168.0.1/centos
gpgcheck=0
enabled=1
EOF
yum clean all && yum repolist
# 安装vim nginx lrzsz chrony,测试yum源安装效果。
yum -y install vim nginx lrzsz chrony
发现可以通过本地制作的yum源安装软件包,yum源安装完成。