您好,欢迎访问这里是深圳市硕远科技有限公司!
戴尔服务器价格_IBM联想配置_浪潮代理-深圳市硕远科技有限公司
联系我们
戴尔服务器价格_IBM联想配置_浪潮代理-深圳市硕远科技有限公司
邮箱:2324898850@qq.com
电话:400-080-6079
地址:深圳市龙华区河背工业区108创业园A301
当前位置:主页 > 新闻动态 > 行业新闻 >

行业新闻

超详细的私有yum仓库搭建及定时同步阿里云yum源

发布时间:2021-08-04 12:00:39浏览次数:

概述

由于网络限制,部分服务器不给阿里源访问权限了,那就只能搭建一下集团的私有yum仓库了,仅供参考。


一、共享yum源

YUM是“Yellow dog Updater, Modified”的缩写,是一个软件包管理器,YUM从指定的地方(相关网站的rpm包地址或本地的rpm路径)自动下载RPM包并且安装,能够很好的解决依赖关系问题。yum源就相当是一个目录项,当我们使用yum机制安装软件时,若需要安装依赖软件,则yum机制就会根据在yum源中定义好的路径查找依赖软件,并将依赖软件安装好。


YUM的基本工作机制如下:

1)服务器端:在服务器上面存放了所有的RPM软件包,然后以相关的功能去分析每个RPM文件的依赖性关系,将这些数据记录成文件存放在服务器的某特定目录内。

2)客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文件(可通过WWW或FTP方式),通过对服务器端下载的纪录数据进行分析,然后取得所有相关的软件,一次全部下载下来进行安装。


共享yum源就是在局域网内(或本地)搭建一个yum源,然后局域网内(或本地)所有的计算机在离线的环境下可以使用yum命令安装软件。



二、搭建私有yum仓库及定时同步阿里云yum到本地

1、本机配置阿里源(调用系统初始化脚本)

for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}_bak;donerm -rf /etc/yum.repos.d/*.repowget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo >/dev/null 2>&1sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf     yum clean all && yum makecache yum repolist-- 安装依赖yum -y install   yum-utils   createrepo plugin-priorities 

这里用蓝鲸平台调用系统初始化脚本输出日志如下:


超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程

2、安装nginx(手动执行脚本)

yum install -y nginx


超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程

3、同步公网镜像到本地私有仓库

用repoync 命令,Reposync用于将远程yum存储库同步到本地存储库,

-n:只下载最新的包

-p:下载包的路径:默认为当前目录

--建立私有yum存放目录mkdir -p /data/centos/7/{base,extras,updates,epel}--下载rpm包##这里同步的源文件就是上一步配置的yum源#/data/centos/7/ 为生成的本地yum仓库文件即rpm包所在路径nohup reposync -np  /data/centos/7   > /opt/yum.log 2>&1&--建库cd /data/centos/7/cd base && createrepo -p ./ && cd -cd extras && createrepo -p ./ && cd -cd updates && createrepo -p ./ && cd -cd epel && createrepo -p ./ && cd -


超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程

4、nginx配置

将yum仓库文件即rpm包所在路径设置为 nginx发布目录

# vim /etc/nginx/nginx.conf (核心在server段)=======================================================================user root;  #得用root用户,要不会报 open() "/data/centos/7/base" failed (13: Permission denied)worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;include /usr/share/nginx/modules/*.conf;events {    worker_connections 10240;}http {    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    include /etc/nginx/conf.d/*.conf;        server {    listen       80;    server_name  mirrors.xxx.com;    root         /data/centos/7/;   #这里是yum源存放目录    location / {        autoindex on;        #打开目录浏览功能        autoindex_exact_size off;  # off:以可读的方式显示文件大小        autoindex_localtime on; # on、off:是否以服务器的文件时间作为显示的时间        charset utf-8,gbk; #展示中文文件名        index index.html;    }    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }}}=======================================================================systemctl restart nginx--测试nginx访问地址:http://nginx_IP地址/

>>nginx访问:

超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程

5、设置定时同步阿里yum源

# vim /home/scripts/yum_update.sh==============================================================================#!/bin/bashecho 'Updating Aliyum Source'DATETIME=`date +%F_%T`exec > /var/log/aliyumrepo_$DATETIME.logreposync -np /data/package/centos/7if [ $? -eq 0 ];then      createrepo --update /data/centos/7/base/base      createrepo --update /data/centos/7/base/extras      createrepo --update /data/centos/7/base/updates      createrepo --update /data/centos/7/base/epel    echo "SUCESS: $DATETIME aliyum_yum update successful" >>/var/log/aliyumrepo_$DATETIME.logelse    echo "ERROR: $DATETIME aliyum_yum update failed" >> /var/log/aliyumrepo_$DATETIME.logfi==============================================================================-- 设定定时任务(crontab -e)30 1 * * 6 /bin/bash /home/scripts/yum_update.sh    



6、客户端配置yum源

cat > /etc/yum.repos.d/mirrors-dfwlg.repo <<EOF[base]name=CentOS-$releasever - Base - mirror.dfwlg.combaseurl=http://xxx88/base/path=/enabled=1gpgcheck=0 [updates]name=CentOS-$releasever - Updates - mirror.dfwlg.combaseurl=http://xxx.88/updates/path=/enabled=1gpgcheck=0 [extras]name=CentOS-$releasever - Extras - mirrors.dfwlg.combaseurl=http://xxx.88/extras/path=/enabled=1gpgcheck=0 [epel]name=CentOS-$releasever - epel - mirrors.dfwlg.combaseurl=http://xxx.88/epel/failovermethod=priorityenabled=1gpgcheck=0EOF--刷新yum缓存yum clean all && yum makecache yum repolist


超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程


后面会分享更多devops和DBA方面流程,感兴趣的朋友可以关注下~

超详细的私有yum仓库搭建及定时同步阿里云yum源到本地教程

400-080-6079