日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Redhat7.4 同步阿里云镜像rpm包并自建本地yum仓库

發(fā)布時間:2023/12/8 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Redhat7.4 同步阿里云镜像rpm包并自建本地yum仓库 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

環(huán)境介紹

操作系統(tǒng)IP地址主機名備注
Redhat7.4192.168.10.21yum-server?
Redhat7.4192.168.10.22jump01?

環(huán)境準備

1. 查看系統(tǒng)版本

[root@yum-server ~]# cat /etc/redhat-release?

Red Hat Enterprise Linux Server release 7.4 (Maipo)

2. 關(guān)閉防火墻

[root@yum-server ~]# systemctl stop ebtables firewalld

[root@yum-server ~]# systemctl disable ebtables firewalld

3. 關(guān)閉selinux

[root@yum-server ~]# sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux?

[root@yum-server ~]# setenforce 0

操作步驟

1. 備份系統(tǒng)自帶的yum源

[root@yum-server ~]# tar -zcvf Centos-bak.tar.gz /etc/yum.repos.d/*

2. 修改yum源為阿里云yum源

[root@yum-server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@yum-server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

或者

[root@yum-server ~]# curl -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@yum-server ~]# curl -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo ?

3. 檢測阿里云倉庫源是否正常

[root@yum-server?~]#?yum?repolistLoaded?plugins:?fastestmirror,?product-id,?search-disabled-repos,?subscription-managerThis?system?is?not?registered?with?an?entitlement?server.?You?can?use?subscription-manager?to?register.Loading?mirror?speeds?from?cached?hostfile?*?base:?mirrors.aliyun.com?*?extras:?mirrors.aliyun.com?*?updates:?mirrors.aliyun.comrepo?id?????????????????????????????????????????repo?name???????????????????????????????????????????????????????????????statusbase/$releasever/x86_64?????????????????????????CentOS-$releasever?-?Base?-?mirrors.aliyun.com??????????????????????????10,019epel/x86_64?????????????????????????????????????Extra?Packages?for?Enterprise?Linux?7?-?x86_64??????????????????????????13,341extras/$releasever/x86_64???????????????????????CentOS-$releasever?-?Extras?-?mirrors.aliyun.com???????????????????????????435updates/$releasever/x86_64??????????????????????CentOS-$releasever?-?Updates?-?mirrors.aliyun.com????????????????????????2,500repolist:?26,295?

4. 安裝相關(guān)需要軟件

[root@yum-server ~]# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

yum-utils:reposync同步工具

createrepo:編輯yum庫工具

plugin-priorities:控制yum源更新優(yōu)先級工具,這個工具可以用來控制進行yum源檢索的先后順序,建議可以用在client端。

注:由于很多人喜歡最小化安裝,上邊軟件是一些常用環(huán)境。

?

5. 創(chuàng)建本地目錄

[root@yum-server ~]# mkdir /mirrors/

6. 同步到本地目錄

[root@yum-server ~]# reposync -r base -p /mirrors/

注:不用擔心沒有創(chuàng)建相關(guān)目錄,系統(tǒng)自動創(chuàng)建相關(guān)目錄,并下載,時間較長請耐心等待。

可以用 repo -r --repoid=repoid指定要查詢的repo id,可以指定多個(# reposync -r base -p /mirror #這里同步base目錄到本地)

?

7. 創(chuàng)建索引

createrepo語法:

格式:createrepo -po? 源目錄? 索引元數(shù)據(jù)的輸出位置目錄

[root@yum-server ~]# createrepo -po /mirrors/base/? /mirrors/base/

[root@yum-server ~]# createrepo -po /mirrors/epel/? /mirrors/epel/

8. 更新源數(shù)據(jù)

[root@yum-server ~]# createrepo --update /mirrors/base

[root@yum-server ~]# createrepo --update /mirrors/epel

[root@yum-server ~]# createrepo --update /mirrors/extras

[root@yum-server ~]# createrepo --update /mirrors/updates

9. 創(chuàng)建定時任務(wù)腳本

[root@yum-server ~]# vim /mirrors/centos_yum_update.sh

#!/bin/bash

echo 'Updating Aliyum Source'

DATETIME=`date +%F_%T`

exec > /var/log/aliyumrepo_$DATETIME.log

???? reposync -np /mirrors

if [ $? -eq 0 ];then

????? createrepo --update /mirrors/base

????? createrepo --update /mirrors/extras

????? createrepo --update /mirrors/updates

????? createrepo --update /mirrors/epel

????? echo "SUCESS: $DATETIME aliyum_yum update successful"

? else

????? echo "ERROR: $DATETIME aliyum_yum update failed"

fi

10. 給腳本添加執(zhí)行權(quán)限

[root@yum-server ~]# chmod a+x /mirrors/centos_yum_update.sh

11. 將腳本加入到定時任務(wù)中

[root@yum-server ~]# crontab -e

# Updating Aliyum Source

00 22 * * 6? /bin/bash /mirrors/centos_yum_update.sh

解釋:每月第一個周六的22點更新阿里云yum源

12. 安裝nginx,提供

[root@yum-server ~]# yum -y install nginx

13. 配置nginx的服務(wù),讓其家目錄為:/mirrors

[root@yum-server ~]# vim /etc/nginx/nginx.conf?

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

events {

??? worker_connections 1024;

}

http {

??? include /etc/nginx/mime.types;

??? default_type application/octet-stream;

??? 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;

??? keepalive_timeout 65;

??? gzip on;

??? include /etc/nginx/conf.d/*.conf;

}

server {

??? listen 80;

??? server_name localhost;

??? root /mirrors;

??? index index.html index.htm;

??? #charset koi8-r;

??? #access_log /var/log/nginx/yum.access.log main;

??? location / {

??????? autoindex on;

??????? autoindex_exact_size off;

??????? autoindex_localtime on;

??????? charset utf-8,gbk;

??? }

??? #error_page 404 /404.html;

??? # redirect server error pages to the static page /50x.html

??? #

??? error_page 500 502 503 504 /50x.html;

??? location = /50x.html {

??????? root /usr/share/nginx/html;

??? }

}

14. 啟動nginx服務(wù)

[root@yum-server ~]# systemctl restart nginx

[root@yum-server ~]# systemctl enable nginx

客戶端測試

1. 修改客戶端yum源,并指向本地搭建的yum源主機

[root@jump01 ~]# vim /etc/yum.repos.d/centos_local.repo?

[base]

name=base

baseurl=http://192.168.10.21/base/

failovermethod=priority

enabled=1

gpgcheck=0

[extras]

name=extras

baseurl=http://192.168.10.21/extras/

failovermethod=priority

enabled=1

gpgcheck=0


[updates]

name=updates

baseurl=http://192.168.10.21/updates/

failovermethod=priority

enabled=1

gpgcheck=0


[epel]

name=epel

baseurl=http://192.168.10.21/epel/

failovermethod=priority

enabled=1

gpgcheck=0


2. 生成yum緩存

[root@jump01 ~]# yum makecache?

3. 安裝memcached測試

[root@jump01 ~]# yum -y install memcached

總結(jié)

以上是生活随笔為你收集整理的Redhat7.4 同步阿里云镜像rpm包并自建本地yum仓库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。