yum源优先级_yum仓库_同步公网yum源

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/ &

定时同步

crontab -e

00 21 * * * /usr/bin/rsync -zaP --delete --exclude-from /usr/share/nginx/html/rsync_exclude.txt rsync://mirrors.tuna.tsinghua.edu.cn/centos/7.6.1810 /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/epel.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
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
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

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/

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 .

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容