Redhat7.4 同步阿里云镜像rpm包并自建本地yum仓库
環境介紹
| 操作系統 | IP地址 | 主機名 | 備注 |
| Redhat7.4 | 192.168.10.21 | yum-server | ? |
| Redhat7.4 | 192.168.10.22 | jump01 | ? |
環境準備
1. 查看系統版本
[root@yum-server ~]# cat /etc/redhat-release?
Red Hat Enterprise Linux Server release 7.4 (Maipo)
2. 關閉防火墻
[root@yum-server ~]# systemctl stop ebtables firewalld
[root@yum-server ~]# systemctl disable ebtables firewalld
3. 關閉selinux
[root@yum-server ~]# sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux?
[root@yum-server ~]# setenforce 0
操作步驟
1. 備份系統自帶的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. 安裝相關需要軟件
[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源更新優先級工具,這個工具可以用來控制進行yum源檢索的先后順序,建議可以用在client端。
注:由于很多人喜歡最小化安裝,上邊軟件是一些常用環境。
?
5. 創建本地目錄
[root@yum-server ~]# mkdir /mirrors/
6. 同步到本地目錄
[root@yum-server ~]# reposync -r base -p /mirrors/
注:不用擔心沒有創建相關目錄,系統自動創建相關目錄,并下載,時間較長請耐心等待。
可以用 repo -r --repoid=repoid指定要查詢的repo id,可以指定多個(# reposync -r base -p /mirror #這里同步base目錄到本地)
?
7. 創建索引
createrepo語法:
格式:createrepo -po? 源目錄? 索引元數據的輸出位置目錄
[root@yum-server ~]# createrepo -po /mirrors/base/? /mirrors/base/
[root@yum-server ~]# createrepo -po /mirrors/epel/? /mirrors/epel/
8. 更新源數據
[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. 創建定時任務腳本
[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. 給腳本添加執行權限
[root@yum-server ~]# chmod a+x /mirrors/centos_yum_update.sh
11. 將腳本加入到定時任務中
[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的服務,讓其家目錄為:/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服務
[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
總結
以上是生活随笔為你收集整理的Redhat7.4 同步阿里云镜像rpm包并自建本地yum仓库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Boot使用Commons
- 下一篇: 淘宝精灵图循环