yum仓库相关

20 篇文章 0 订阅

yum仓库搭建

安装createrepo

yum install createrepo

创建yum仓库目录,上传rpm包到yum仓库目录

mkdir -p /yum
cd /yum

上传rpm包到/yum

初始化yum仓库

[root@m01 yum]# createrepo  .
Spawning worker 0 with 3 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

每次加入新的rpm包,更新yum仓库

createrepo --update .

发布yum仓库

可以使用httpd nginx ftp 等发布yum仓库,此处省略一万行

yum客户端

安装yum源优先级插件

yum install yum-plugin-priorities.noarch

启用插件

cat /etc/yum/pluginconf.d/priorities.conf

[main]
enabled = 1

修改yum源优先级

自己的yum源优先级设置为1
cat my-base.repo

[my-base]
name=Server
baseurl=http://10.0.0.61
enable=1
gpgcheck=0
priority=1

其它yum源(如 CentOS-Base.repo)修改优先级为2

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2
#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority=2

priority 数字越小优先级越高

同步公网yum源

nginx配置

nginx源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

nginxyum配置

vim nginxyum.conf

server {
    listen       80;
    server_name  localhost;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    location / {
        root   /usr/share/nginx/html;
    }
}

创建yum源目录

mkdir -p /usr/share/nginx/html/centos /usr/share/nginx/html/epel/7 /usr/share/nginx/html/zabbix

rsync同步排除

vim /usr/share/nginx/html/rsync_exclude.txt

atomic/
configmanagement/
cr/
cloud/
dotnet/
fasttrack/
isos/
nfv/
opstools/
paas/
rt/
sclo/
storage/
virt/

rsync同步centos源

nohup /usr/bin/rsync -zaP --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://mirrors.tuna.tsinghua.edu.cn/centos/7.6.1810 /usr/share/nginx/html/centos/ &

rsync同步epel源

nohup /usr/bin/rsync -zaP rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/ &

rsync同步zabbix源

nohup /usr/bin/rsync -zaP rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64 /usr/share/nginx/html/zabbix/4.0/rhel/7/ &
nohup /usr/bin/rsync -zaP rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/x86_64  /usr/share/nginx/html/non-supported/rhel/7/ &
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/source/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/source/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/source/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/
mkdir -p /usr/share/nginx/html/docker-ce/linux/centos/7/source/
mkdir -p /usr/share/nginx/html/nginx
mkdir -p /usr/share/nginx/html/php
mkdir -p /usr/share/nginx/html/centos/
mkdir -p /usr/share/nginx/html/epel/7/
mkdir -p /usr/share/nginx/html/epel/8/Everything
mkdir -p /usr/share/nginx/html/zabbix/4.0/rhel/7/
mkdir -p /usr/share/nginx/html/zabbix/4.0/rhel/8/
mkdir -p /usr/share/nginx/html/non-supported/rhel/7/
mkdir -p /usr/share/nginx/html/non-supported/rhel/8/

定时同步

crontab -e

00 21 * * * /usr/bin/rsync -zrLptgoDP --delete --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://mirrors.tuna.tsinghua.edu.cn/centos/7 /usr/share/nginx/html/centos/ &> /tmp/centos.log
30 21 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/ &> /tmp/epel7.log
30 21 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/epel/8/Everything/x86_64 /usr/share/nginx/html/epel/8/Everything/ &> /tmp/epel8.log
00 22 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64 /usr/share/nginx/html/zabbix/4.0/rhel/7/ &> /tmp/zabbix.log
00 22 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/8/x86_64 /usr/share/nginx/html/zabbix/4.0/rhel/8/ &> /tmp/zabbix8.log
30 22 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/x86_64  /usr/share/nginx/html/non-supported/rhel/7/ &> /tmp/zabbix_non-supported.log
30 22 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/x86_64 /usr/share/nginx/html/non-supported/rhel/8/ &> /tmp/zabbix8_non-supported.log
00 23 * * * /bin/bash /server/scripts/rsync_docker-ce.sh &> /tmp/docker-ce.log
00 00 * * * /bin/bash /server/scripts/down_php.sh &> /tmp/php.log
00 01 * * * /bin/bash /server/scripts/down_nginx.sh &> /tmp/nginx.log
00 12 * * * /usr/bin/rsync -zrLptgoDP --delete --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://mirrors.tuna.tsinghua.edu.cn/centos/7 /usr/share/nginx/html/centos/ &> /tmp/centos7.log
30 12 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64 /usr/share/nginx/html/epel/7/ &> /tmp/epel7.log
30 12 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/epel/8/Everything/x86_64 /usr/share/nginx/html/epel/8/Everything/ &> /tmp/epel8.log
00 13 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64 /usr/share/nginx/html/zabbix/4.0/rhel/7/ &> /tmp/zabbix.log
00 13 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/8/x86_64 /usr/share/nginx/html/zabbix/4.0/rhel/8/ &> /tmp/zabbix8.log
30 13 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/x86_64  /usr/share/nginx/html/non-supported/rhel/7/ &> /tmp/zabbix_non-supported.log
30 13 * * * /usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/x86_64  /usr/share/nginx/html/non-supported/rhel/8/ &> /tmp/zabbix8_non-supported.log
00 14 * * * /bin/bash /server/scripts/rsync_docker-ce.sh &> /tmp/docker-ce.log
00 18 * * * /bin/bash /server/scripts/down_php.sh &> /tmp/php.log
00 19 * * * /bin/bash /server/scripts/down_nginx.sh &> /tmp/nginx.log

vim /server/scripts/rsync_docker-ce.sh

#!/bin/bash
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/stable           /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-x86_64/stable     /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/stable           /usr/share/nginx/html/docker-ce/linux/centos/7/source/
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/edge             /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-x86_64/edge       /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/ 
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/edge             /usr/share/nginx/html/docker-ce/linux/centos/7/source/
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/test             /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/  
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-x86_64/test       /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/          
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/test             /usr/share/nginx/html/docker-ce/linux/centos/7/source/    
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/x86_64/nightly          /usr/share/nginx/html/docker-ce/linux/centos/7/x86_64/  
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/debug-x86_64/nightly    /usr/share/nginx/html/docker-ce/linux/centos/7/debug-x86_64/    
/usr/bin/rsync -zaP --delete rsync://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/7/source/nightly          /usr/share/nginx/html/docker-ce/linux/centos/7/source/

base

cat CentOS-Base.repo 
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel

yum install epel-release
cat epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

zabbix(el7)

[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://192.168.0.128/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://192.168.0.128/zabbix/4.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://192.168.0.128/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

zabbix(el8)

[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://192.168.0.128/zabbix/4.0/rhel/8/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://192.168.0.128/non-supported/rhel/8/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

docker-ce

wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/gpg
wget https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' docker-ce.repo

nginx

cat nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://192.168.0.128/nginx/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

php

cat php.repo
[php7w]
name=php repo
baseurl=http://192.168.0.128/php/
gpgcheck=0
enabled=1

vim /server/scripts/down_nginx.sh

#!/bin/bash
cd /usr/share/nginx/html/nginx
/bin/yumdownloader nginx-*
wait
/bin/createrepo --update .

vim /server/scripts/down_php.sh

#!/bin/bash
cd /usr/share/nginx/html/php
/bin/yumdownloader *php7?w*
wait
/bin/createrepo --update .

#各种源使用说明

#base
mv CentOS-Base.repo{,.off}
curl -o /etc/yum.repos.d/CentOS-Base.repo http://192.168.0.128/CentOS-Base.repo

#epel
yum install epel-release
mv epel.repo{,.off}
curl -o /etc/yum.repos.d/epel.repo http://192.168.0.128/epel.repo

#https替换为http
sed 's#https#http#g' /etc/yum.repos.d/{CentOS-Base.repo,epel.repo} -i

#hosts解析
192.168.0.128 mirrors.tuna.tsinghua.edu.cn

#nginx
curl -o /etc/yum.repos.d/nginx.repo http://192.168.0.128/nginx.repo

#php
curl -o /etc/yum.repos.d/php.repo  http://192.168.0.128/php.repo

#docker
curl -o /etc/yum.repos.d/docker-ce.repo http://192.168.0.128/docker-ce.repo
yum install -y yum-utils device-mapper-persistent-data lvm2

#zabbix
rpm -ivh http://192.168.0.128/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
mv zabbix.repo{,.off}
curl -o /etc/yum.repos.d/zabbix.repo http://192.168.0.128/zabbix.repo

#pypi
yum install python-pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
cat .config/pip/pip.conf

mkdir -p ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
timeout=60
index-url=https://pypi.tuna.tsinghua.edu.cn/simple

[install]
trusted-host=https://pypi.tuna.tsinghua.edu.cn
EOF



#npm
npm config set registry https://registry.npm.taobao.org/

cat /root/.npmrc
registry=https://registry.npm.taobao.org/

yum仓库作为rsync服务器

vim /etc/rsyncd.conf

uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = true
list = true
[yum]
path = /usr/share/nginx/html

rsync://192.168.0.163/yum

mount挂载iso镜像

mount -o loop  CentOS-7-x86_64-DVD-1810.iso /mnt

开启yum缓存

vi /etc/yum.conf
在[main]部分中,添加或修改以下行来开启依赖缓存

keepcache=1

#缓存所有依赖
installonlypkgs=*
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wuxingge

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值