热点新闻
03-自建yum仓库(手把手教你搭建内网yum源)
2023-07-15 08:33  浏览:186  搜索引擎搜索“错改B2B”
温馨提示:为防找不到此信息,请务必收藏信息以备急用! 联系我时,请说明是在错改B2B看到的信息,谢谢。
展会发布 展会网站大全 报名观展合作 软文发布

1 环境

1.1 相关依赖

yum install -y wget make cmake gcc gcc-c++ yum install -y pcre-devel lib zlib-devel

1.2 yum 用到的工具

yum install yum-plugin-downloadonly yum -y install createrepo yum install yum-utils

2 安装nginx

我们用容器启动,流程如下:

  • docker-compose.yml文件

version: "3" services: nginx-02: image: "nginx" restart: on-failure ports: - 80:80 volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - /data/yum/centos/7/os:/usr/share/nginx/html restart: always

  • nginx.conf

# gzip设置 gzip on; gzip_vary on; gzip_comp_level 6; gzip_buffers 16 8k; gzip_min_length 1000; gzip_proxied any; gzip_disable "msie6"; #gzip_http_version 1.0; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; server { listen 80; server_name web80; location / { root /usr/share/nginx/html; index index.html index.htm; add_header Cache-Control no-store; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }

3. 同步外网源数据

以同步epel源为例

  • 将repo文件全部清除(非必要,不冲突即可)

  • 安装epel源(如果有可以忽略)

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm

打开生成的epel.repo文件,我们可以看见它默认使用的库是epel库,我们下边同步这个库

  • 同步epel源的 epel

reposync -r epel -p /data/yum/centos/7/os/

需要等一段时间,毕竟有十多个G的数据

  • 我们可看到/data/yum/centos/7/os/ 下多了 epel 这个目录

4. 初始化

createrepo /data/yum/centos/7/os

5. 使用

[liubei_epel] name=liubei_epel baseurl=http://liubei.xxx.com/ enabled=1 gpgcheck=0

6. 定时同步

6.1 同步脚本

创建定义脚本如下 /data/script/yum-update.sh

#!/bin/bash datetime=`date +"%Y-%m-%d"` exec > /var/log/yum-update.log reposync -d -r base -p /data/yum/centos/7/os/ ###########同步镜像源######################## if [ $? -eq 0 ];then createrepo --update /opt/yum/centos/7/os echo "SUCESS: $datetime epel update successful" else echo "ERROR: $datetime epel update failed" fi

6.2 定时任务

说明:每周日凌晨两点更新。

# crontab -e

定时任务如下:

0 2 * * 7 /bin/bash /data/script/yum-update.sh

8. 模拟后期添加新源

以k8s源为例

  • 添加yum源

# cat> /etc/yum.repos.d/kubernetes.repo <<EOF [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF

  • 同步数据

reposync -r kubernetes -p /data/yum/centos/7/os/

  • 更新yum源仓库

createrepo --update /opt/yum/centos/7/os







发布人:8012****    IP:117.173.23.***     举报/删稿
展会推荐
让朕来说2句
评论
收藏
点赞
转发