安裝本地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方面流程,感興趣的朋友可以關注下~