安装本地yum源报错 关于yum源配置出错的问题



文章插图
安装本地yum源报错 关于yum源配置出错的问题

文章插图
概述
由于网络限制,部分服务器不给阿里源访问权限了,那就只能搭建一下集团的私有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.confyum clean all && yum makecache yum repolist-- 安装依赖yum -y installyum-utilscreaterepo plugin-priorities 这里用蓝鲸平台调用系统初始化脚本输出日志如下:
2、安装nginx(手动执行脚本)
yum install -y nginx
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 -
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_formatmain'$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.logmain;sendfileon;tcp_nopushon;tcp_nodelayon;keepalive_timeout65;types_hash_max_size 2048;include/etc/nginx/mime.types;default_typeapplication/octet-stream;include /etc/nginx/conf.d/*.conf;server {listen80;server_namemirrors.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_page500 502 503 504/50x.html;location = /50x.html {roothtml;}}}=======================================================================systemctl restart nginx--测试nginx访问地址:http://nginx_IP地址/>>nginx访问:
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 ];thencreaterepo --update /data/centos/7/base/basecreaterepo --update /data/centos/7/base/extrascreaterepo --update /data/centos/7/base/updatescreaterepo --update /data/centos/7/base/epelecho "SUCESS: $DATETIME aliyum_yum update successful" >>/var/log/aliyumrepo_$DATETIME.logelseecho "ERROR: $DATETIME aliyum_yum update failed" >> /var/log/aliyumrepo_$DATETIME.logfi==============================================================================-- 设定定时任务(crontab -e)30 1 * * 6 /bin/bash /home/scripts/yum_update.sh6、客户端配置yum源
【安装本地yum源报错 关于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
后面会分享更多devops和DBA方面流程,感兴趣的朋友可以关注下~