yum 本地仓库搭建这一篇就够了

2024-05-22 13:42:49 浏览数 (1)

环境:

操作系统:centos7.4 x64,2c4G,200G系统盘,500G数据盘。分区lvm格式,数据盘单独一个lv,挂载在 /data目录。

安装建库所需工具
代码语言:javascript复制
yum install -y yum-utils device-mapper-persistent-data lvm2 createrepo wget
加载几个常用的阿里源
epel源
代码语言:javascript复制
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
Docker 源
代码语言:javascript复制
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
查看yum仓库
代码语言:javascript复制
[root@yum-centos7 yum]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                 repo name                                        status
base                                    CentOS-7 - Base                                  10,097
base-ex                                 CentOS-7 - Base-ex                                  307
docker                                  docker-ce                                            63
epel                                    epel                                             13,501
kubernetes                              Kubernetes                                          442
repolist: 24,410
下载仓库
代码语言:javascript复制
reposync -r docker -p /yum
reposync -r epel -p /yum
reposync -r kubernetes -p /yum
reposync -r base-ex -p /yum

base光盘上有,用以下命令创建

代码语言:javascript复制
mount /dev/cdrom /mnt
mkdir -p /yum/base/Packages
cp /mnt/Packages/* /yum/base/Packages
创建 reopdata仓库,生成仓库信息
代码语言:javascript复制
createrepo /yum/kubernetes/
createrepo /yum/epel
createrepo /yum/base
createrepo /yum/extras
createrepo /yum/docker-ce-stable
配置repo

放一起也可以,分开放也可以

代码语言:javascript复制
yum clean all
yum makecache
yum install nginx -y
配置nginx
代码语言:javascript复制
grep -vE "#|^$" /etc/nginx/nginx.conf >/etc/nginx/nginx.conf.bak
mv /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
....
    server {
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name yum;
        root /yum;
    }
systemctl restart nginx
[root@yum-centos7 ~]# ss -ntulp |grep 80
tcp    LISTEN     0      128       *:80                    *:*                   users:(("nginx",pid=2839,fd=6),("nginx",pid=2838,fd=6),("nginx",pid=2837,fd=6))
tcp    LISTEN     0      128    [::]:80                 [::]:*                   users:(("nginx",pid=2839,fd=7),("nginx",pid=2838,fd=7),("nginx",pid=2837,fd=7))
通过浏览器访问

http://ip地址

替换repo文件
代码语言:javascript复制
sed -i 's#file:///yum#http://192.168.31.200#g' /etc/yum.repos.d/centos7.repo
[root@yum-centos7 ~]# cat /etc/yum.repos.d/centos7.repo
[base]
name=CentOS-$releasever - Base
baseurl=http://192.168.31.200/base
enabled=1
gpgcheck=0

[base-ex]
name=CentOS-$releasever - Base-ex
baseurl=http://192.168.31.200/extras
enabled=1
gpgcheck=0

[epel]
name=epel
baseurl=http://192.168.31.200/epel
enabled=1
gpgcheck=0

[docker]
name=docker-ce
baseurl=http://192.168.31.200/docker-ce-stable
enabled=1
gpgcheck=0

[k8s]
name=docker-ce
baseurl=http://192.168.31.200/kubernetes
enabled=1
gpgcheck=0
更新软件包
代码语言:javascript复制
createrepo --update /yum/kubernetes/
createrepo --update /yum/epel
createrepo --update /yum/base
createrepo --update /yum/extras
createrepo --update /yum/docker-ce-stable

0 人点赞