yum本地源搭建记录
参考:https://www.vos.cn/os/387.html
https://www.wanpeng.life/1903.html
1、安装工具
yum install screen wget -y
yum install yum-utils createrepo -y
2、开始下载
安装源
yum install epel-release -y
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
查看源列表
yum repolist
创建目录(其实这步可以省,文件夹会自动创建)
mkdir -p /home/html/{base,centosplus,extras,updates}
下载
下载所有,不指定--repoid
reposync -g -l -d -m --newest-only --download-metadata --download_path=/home/html/
下载指定仓库:
reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/home/html/
reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/home/html/
reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/home/html/
reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/home/html/
reposync -g -l -d -m --repoid=epel --newest-only --download-metadata --download_path=/home/html/
reposync -g -l -d -m --repoid=docker-ce-stable --newest-only --download-metadata --download_path=/home/html/
-g 删除公钥校验不通过的包
-d 删除本地有但是远程源没有的包
这两个会导致很多有用的包被删除,比如p7zip、nethogs
3、创建仓库
cd /home/html
ls|xargs -n1 echo createrepo
# 然后拷贝打印的命令进行执行
# base docker-ce-stable epel extras updates
#然后压缩
cd ..
tar cJvf html.tar.xz html/
# 或者轻度压缩
tar czvf html.tar.gz html/
# 或者不压缩
tar cvf html.tar html/
已上传到123云盘
https://www.123pan.com/s/xMzAjv-k47dv.html提取码:ChVh
4、文件服务器
启动文件服务器
python2(大部分系统自带)
cd /home/html
python -m SimpleHTTPServer 80
python3
cd /home/html
python3 -m http.server 80
5、客户端配置
包含:base docker-ce-stable epel extras updates
[base]
name=base
baseurl=http://192.168.31.197/base
enable=1
gpgcheck=0
proxy=_none_
[docker-ce-stable]
name=docker-ce-stable
baseurl=http://192.168.31.197/docker-ce-stable
enable=1
gpgcheck=0
proxy=_none_
[epel]
name=epel
baseurl=http://192.168.31.197/epel
enable=1
gpgcheck=0
proxy=_none_
[extras]
name=extras
baseurl=http://192.168.31.197/extras
enable=1
gpgcheck=0
proxy=_none_
[updates]
name=updates
baseurl=http://192.168.31.197/updates
enable=1
gpgcheck=0
proxy=_none_
可以用pyhton脚本生成
import os
def gen(name, addr):
return '''[%s]
name=%s
baseurl=http://%s/%s
enable=1
gpgcheck=0
proxy=_none_
''' % (name,name,addr,name)
if __name__ == "__main__":
html = "/home/package_dir/html"
addr = "192.168.31.89"
content = ""
for d in os.listdir(html):
if os.path.isdir(os.path.join(html, d)):
content += gen(d, addr)
with open("/etc/yum.repos.d/local.repo", "w") as f:
f.write(content)
6、优化
6.1、裁剪体积
下载的源中的包,绝大部分是用不到的,可以删除一些,基本上rpm包大小在30M以上的,都可以删除(少数除外),实际操作中,30M以上的,只保留了这几个:
[
{
"path": "/home/html/epel/Packages/g/golang-bin-1.19.10-1.el7.x86_64.rpm",
"name": "golang-bin-1.19.10-1.el7.x86_64.rpm",
"size": 112246734
},
{
"path": "/home/html/epel/Packages/c/chromium-116.0.5845.96-1.el7.x86_64.rpm",
"name": "chromium-116.0.5845.96-1.el7.x86_64.rpm",
"size": 78721720
},
{
"path": "/home/html/mysql56-community/mysql-community-server-5.6.51-2.el7.x86_64.rpm",
"name": "mysql-community-server-5.6.51-2.el7.x86_64.rpm",
"size": 69836204
},
{
"path": "/home/html/mysql56-community/mysql-community-embedded-devel-5.6.51-2.el7.x86_64.rpm",
"name": "mysql-community-embedded-devel-5.6.51-2.el7.x86_64.rpm",
"size": 69255060
},
{
"path": "/home/html/mysql56-community/mysql-community-embedded-devel-5.6.51-2.el7.i686.rpm",
"name": "mysql-community-embedded-devel-5.6.51-2.el7.i686.rpm",
"size": 65964768
},
{
"path": "/home/html/mysql56-community/mysql-community-test-5.6.51-2.el7.x86_64.rpm",
"name": "mysql-community-test-5.6.51-2.el7.x86_64.rpm",
"size": 60873572
},
{
"path": "/home/html/updates/Packages/kernel-3.10.0-1160.99.1.el7.x86_64.rpm",
"name": "kernel-3.10.0-1160.99.1.el7.x86_64.rpm",
"size": 54174680
},
{
"path": "/home/html/base/Packages/kernel-3.10.0-1160.el7.x86_64.rpm",
"name": "kernel-3.10.0-1160.el7.x86_64.rpm",
"size": 52709940
},
{
"path": "/home/html/epel/Packages/c/chromium-headless-116.0.5845.96-1.el7.x86_64.rpm",
"name": "chromium-headless-116.0.5845.96-1.el7.x86_64.rpm",
"size": 49613116
},
{
"path": "/home/html/mysql-tools-community/mysql-shell-8.0.34-1.el7.x86_64.rpm",
"name": "mysql-shell-8.0.34-1.el7.x86_64.rpm",
"size": 40307744
},
{
"path": "/home/html/epel/Packages/r/rust-doc-1.72.1-1.el7.x86_64.rpm",
"name": "rust-doc-1.72.1-1.el7.x86_64.rpm",
"size": 40136368
},
{
"path": "/home/html/epel/Packages/a/apptainer-1.2.3-1.el7.x86_64.rpm",
"name": "apptainer-1.2.3-1.el7.x86_64.rpm",
"size": 39570249
},
{
"path": "/home/html/docker-ce-stable/Packages/containerd.io-1.6.24-3.1.el7.x86_64.rpm",
"name": "containerd.io-1.6.24-3.1.el7.x86_64.rpm",
"size": 35551084
},
{
"path": "/home/html/updates/Packages/java-1.8.0-openjdk-headless-1.8.0.382.b05-1.el7_9.x86_64.rpm",
"name": "java-1.8.0-openjdk-headless-1.8.0.382.b05-1.el7_9.x86_64.rpm",
"size": 34752068
},
{
"path": "/home/html/epel/Packages/r/rust-std-static-1.72.1-1.el7.x86_64.rpm",
"name": "rust-std-static-1.72.1-1.el7.x86_64.rpm",
"size": 34294892
},
{
"path": "/home/html/epel/Packages/p/python36-cryptography-vectors-2.3-1.el7.noarch.rpm",
"name": "python36-cryptography-vectors-2.3-1.el7.noarch.rpm",
"size": 32090756
},
{
"path": "/home/html/epel/Packages/r/rust-1.72.1-1.el7.x86_64.rpm",
"name": "rust-1.72.1-1.el7.x86_64.rpm",
"size": 31779556
}
]
其实这里面有几个也不需要保留
6.2、新增mysql
之前下载的时候没有添加mysql源,后面补上
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-release-el7-5.noarch.rpm
# 重新下载(增量下载)
reposync -l -m --newest-only --download-metadata --download_path=/home/html/
# 重新创建库
cd /home/html
ls|xargs -n1 createrepo
7、定制特定软件的源
yum install screen wget -y
yum install yum-utils createrepo -y
mkdir source
cd source
yumdownloader --resolve --alldeps --destdir=./ docker-ce docker-ce-cli
yumdownloader --resolve --alldeps --destdir=./ rpcbind
yumdownloader --resolve --alldeps --destdir=./ nfs-utils
yumdownloader --resolve --alldeps --destdir=./ ipvsadm
yumdownloader --resolve --alldeps --destdir=./ ipset
yumdownloader --resolve --alldeps --destdir=./ sysstat
yumdownloader --resolve --alldeps --destdir=./ conntrack-tools
yumdownloader --resolve --alldeps --destdir=./ libseccomp
不要一起下载,一起下载时没有对应的源没法下载的包会被忽略。实测,在kylin v10上有 --alldeps选项(下载所有依赖,即使已安装),centos7上没有,所以centos7使用yumdownloader可能会漏包
使用repotrack 参考:https://zhuanlan.zhihu.com/p/662529601
113 repotrack -p ./ docker-ce docker-ce-cli
118 repotrack -p ./ rpcbind
119 repotrack -p ./ nfs-utils
120 repotrack -p ./ ipvsadm
121 repotrack -p ./ ipset
122 repotrack -p ./ sysstat
123 repotrack -p ./ conntrack
124 repotrack -p ./ libseccomp
126 repotrack -p ./ conntrack-tools
创建索引
createrepo ./
tar czvf ../centos7-rpms-amd64.tar.gz ./*