#零 修订记录
序号 | 修订内容 | 修订时间 |
---|---|---|
1 | 新增 | 2021/2/21 |
2 | 新增centos6.9 域名源 | 2021/8/12 |
3 | 新增centos7 本地文件源 | 2022/6/27 |
一 摘要
本文主要介绍搭建内网yum 源,以centos8.1 内网系统源为例。使用nginx 作为web 服务器。
二 环境信息
##(一)软件信息
[root@10-3-170-32 ~]# createrepo --version
createrepo 0.9.9
[root@10-3-170-32 ~]#
[root@10-3-170-32 ~]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0
[root@10-3-170-32 ~]#
(二) 操作系统
[dev@10-3-170-32 ~]$ cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
[dev@10-3-170-32 ~]$
三 实施
(一) 制作centos8.1具体实施
3.1.1 将centos 8.1 系统盘上传到服务器上
使用xshell 等软件上传到服务器。
3.1.2 新增挂载目录,并将系统盘挂载到该目录
[root@10-3-170-32 mnt]# rm -rf centos81/
[root@10-3-170-32 mnt]# mkdir /mnt/centos81
[root@10-3-170-32 mnt]# cd centos81/
[root@10-3-170-32 centos81]# pwd
/mnt/centos81
[root@10-3-170-32 centos81]# mount /home/yunwei/software/centos/CentOS-8.1.1911-x86_64-dvd1.iso /mnt/centos81/
mount: /dev/loop0 写保护,将以只读方式挂载
检查挂载是否成功
root@10-3-170-32 mnt]# cd centos81/
[root@10-3-170-32 centos81]# ll
总用量 12
dr-xr-xr-x 4 root root 2048 1月 4 2020 AppStream
dr-xr-xr-x 4 root root 2048 1月 4 2020 BaseOS
dr-xr-xr-x 3 root root 2048 1月 4 2020 EFI
dr-xr-xr-x 3 root root 2048 1月 4 2020 images
dr-xr-xr-x 2 root root 2048 1月 4 2020 isolinux
-r--r--r-- 1 root root 87 1月 4 2020 media.repo
-r--r--r-- 1 root root 664 1月 4 2020 TRANS.TBL
[root@10-3-170-32 centos81]# df -h | grep centos81
/dev/loop0 7.1G 7.1G 0 100% /mnt/centos81
[root@10-3-170-32 centos81]#
3.1.3 centos8.1 文件复制到本机
[root@10-3-170-32 localyum]# cp -r /mnt/centos81/ /data/localyum/
3.1.4 createrepo /data/localyum/centos81/
createrepo /data/localyum/centos81/
3.1.5 nginx 配置文件
centos81.mirror.digital.com 这个用你对应的域名
[root@10-3-170-32 conf.d]# cat centos81mirror.conf
server {
listen 80;
server_name centos81.mirror.digital.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /data/localyum/centos81;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
重启nginx
[root@10-3-170-32 conf.d]# /usr/local/nginx/sbin/nginx -s reload
3.1.6 repo 文件参考配置
[base]
name=CentOSBase
baseurl=http://centos81.mirror.digital.com
gpgcheck=0
enabled=1
(二) 制作centos6.9 本地yum源
centos 6.9 有8.1 唯一的区别是centos 6.9 是两张盘
[root@10-3-170-32 localyum]# mkdir /mnt/centos691
[root@10-3-170-32 localyum]# mkdir /mnt/centos692
挂载
[root@10-3-170-32 tmp]# mount CentOS-6.9-x86_64-bin-DVD1.iso /mnt/centos691
mount: /dev/loop0 写保护,将以只读方式挂载
[root@10-3-170-32 tmp]# mount CentOS-6.9-x86_64-bin-DVD2.iso /mnt/centos692
复制
[root@10-3-170-32 centos691]# cp -r /mnt/centos691/. /data/localyum/centos69/
[root@10-3-170-32 centos691]# cp -r /mnt/centos692/. /data/localyum/centos69/
合并
[root@10-3-170-32 centos69]# cat /mnt/centos691/TRANS.TBL /mnt/centos691/TRANS.TBL | sort > /data/localyum/centos69/TRANS.TBL
[root@10-3-170-32 centos69]#
其余同centos8.1
(三) 制作centos7 本地yum源(非nginx 模式)
将系统文件传到机器上,然后挂载,然后传到本地目录(这一步可以不要)
[root@localhost ~]# mkdir /mnt/centos76
[root@localhost ~]# mount /home/yunwei/software/CentOS-7-x86_64-Everything-1810.iso /mnt/centos76/
mount: /dev/loop0 is write-protected, mounting read-only
[root@localhost ~]# mkdir /data/localyum
mkdir: cannot create directory ‘/data/localyum’: No such file or directory
[root@localhost ~]# mkdir -p /data/localyum
[root@localhost ~]# cp -r /mnt/centos76/ /data/localyum/
[root@localhost ~]# cd /data/localyum/
[root@localhost localyum]# ll
total 0
drwxr-xr-x. 8 root root 254 Jun 27 10:32 centos76
配置 Yum 文件
备份原有yum 文件
[root@localhost yum.repos.d]# mkdir /etc/yum.repos.d/bak
[root@localhost yum.repos.d]# mv /etc/yum.repos.d/* /etc/yum.repos.d/bak/
mv: cannot move ‘/etc/yum.repos.d/bak’ to a subdirectory of itself, ‘/etc/yum.repos.d/bak/bak’
[root@localhost yum.repos.d]# ll
编辑新的yum 文件
[localyum]
name=localyum
baseurl=file:///data/localyum/centos76/
enabled=1
gpgcheck=0
然后就可以了
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: localyum
[root@localhost yum.repos.d]# yum install telnet
Loaded plugins: fastestmirror
Determining fastest mirrors
localyum | 3.6 kB 00:00:00
(1/2): localyum/group_gz | 166 kB 00:00:00
(2/2): localyum/primary_db