CentOS上搭建局域网(包括本地)YUM源

文章目录

  • 搭建前准备
    • 创建rpm存放目录
    • 准备rpm包
      • 方式一
      • 方式二
  • 创建repo库
    • 安装createrepo命令
    • 制作repo仓库
    • 制作repo文件
  • OpenResty安装
  • 配置nginx.conf文件
  • 配置repo文件
  • 检查

搭建前准备

创建rpm存放目录

[root@localhost ~]# mkdir -p /data1/centos/8

准备rpm包

方式一

使用reposync同步镜像库到本地。

方式二

挂载镜像文件,操作步骤如下:

  1. 查看可用设备
[root@localhost ~]# lsblk
NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0                          11:0    1   3.5G  0 rom  /mnt
sda                           8:0    0     8G  0 disk
├─sda1                        8:1    0   500M  0 part /boot
└─sda2                        8:2    0   7.5G  0 part
  ├─VolGroup-lv_root (dm-0) 253:0    0   5.6G  0 lvm  /
  └─VolGroup-lv_swap (dm-1) 253:1    0     2G  0 lvm  [SWAP]
sdb                           8:16   0 133.3G  0 disk /data1
  1. 挂载设备
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
  1. 拷贝rpm包
[root@localhost ~]# cp -R /mnt/AppStream/Packages/* /data1/centos/8/
[root@localhost ~]# cp /mnt/Packages/* /data1/centos/6/

创建repo库

安装createrepo命令

[root@localhost ~]# rpm -ivh /data1/centos/8/createrepo_c-0.11.0-3.el8.x86_64.rpm
error: Failed dependencies:
	createrepo_c-libs = 0.11.0-3.el8 is needed by createrepo_c-0.11.0-3.el8.x86_64
	libcreaterepo_c.so.0()(64bit) is needed by createrepo_c-0.11.0-3.el8.x86_64
	libdrpm.so.0()(64bit) is needed by createrepo_c-0.11.0-3.el8.x86_64
[root@localhost ~]# rpm -ivh /data1/centos/8/drpm-0.3.0-14.el8.x86_64.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:drpm-0.3.0-14.el8                ################################# [100%]
[root@localhost ~]# rpm -ivh /data1/centos/8/createrepo_c-libs-0.11.0-3.el8.x86_64.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:createrepo_c-libs-0.11.0-3.el8   ################################# [100%]
[root@localhost ~]# rpm -ivh /data1/centos/8/createrepo_c-0.11.0-3.el8.x86_64.rpm
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:createrepo_c-0.11.0-3.el8        ################################# [100%]

制作repo仓库

[root@localhost ~]# createrepo /data1/centos/8/

制作repo文件

[root@localhost ~]# yum clean all
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# mkdir repo_bak
[root@localhost yum.repos.d]# mv *.repo repo_bak/
[root@localhost yum.repos.d]# touch CentOS-Base.repo

CentOS-Base.repo文件内容如下

[base]
name=CentOS-$releasever - Base
baseurl=///data1/centos/8
enabled=1
gpgcheck=0

如果顺利使用yum repolist命令会有如下输出

[root@localhost yum.repos.d]# yum repolist
CentOS-8 - Base                                                                                                                             216 MB/s | 7.4 MB     00:00
Last metadata expiration check: 0:00:01 ago on Fri 10 Apr 2020 10:10:48 PM CST.
repo id                                                                        repo name                                                                              status
base                                                                           CentOS-8 - Base                                                                        6,774

到这里本地的yum源已经可以使用,下面将借助OpenResty搭建局域网yum源

OpenResty安装

OpenResty编译安装

配置nginx.conf文件

[root@localhost ~]# cd /usr/local/openresty/nginx/conf/
[root@localhost conf]# mkdir online
[root@localhost conf]# cp nginx.conf mime.types online/
[root@localhost online]# mv nginx.conf repo.conf

将repo.conf中location内容修改下面代码块中内容

        location / {
            root   /data1;
            autoindex on;
        }

配置repo文件

修改CentOS-Base.repo文件中baseurl

[root@localhost online]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#baseurl=/data1/centos/8
baseurl=http://192.168.3.9:80/centos/$releasever
enabled=1
gpgcheck=0

检查

可以安装一个包,或者按下面方式检查

[root@localhost online]# yum clean all
5 files removed
[root@localhost online]# yum makecache
CentOS-8 - Base                                                                                                                             171 MB/s | 7.4 MB     00:00
Last metadata expiration check: 0:00:02 ago on Fri 10 Apr 2020 10:32:16 PM CST.
Metadata cache created.
[root@localhost online]# yum repolist
Last metadata expiration check: 0:00:11 ago on Fri 10 Apr 2020 10:32:16 PM CST.
repo id                                                                        repo name                                                                              status
base                                                                           CentOS-8 - Base                                                                        6,774

你可能感兴趣的:(CentOS上搭建局域网(包括本地)YUM源)