構建局域網YUM倉庫

  • 修改yum源爲阿里雲源
  • 檢驗阿里雲源是否正常
yum repolist

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
  • 安裝相關軟件
yum install  wget gcc* createrepo yum-utils -y
- yum-utils           reposync同步工具
- createrepo            編輯yum庫工具
- plugin-priorities   控制yum源更新優先級工具
  • 建立本地目錄
mkdir -p /mirror/7
同步到本地目錄
reposync -p /mirror/7           # 同步整個源使用這個
reposync -r base -p /mirror/7   # 這裏同步base目錄到本地
注:系統自動建立相關目錄,並下載,時間較長請耐心等待。能夠用  repo -r --repoid=repoid指定要查詢的repo id,能夠指定多個
更新新的rpm包
reposync -np /mirror/7
建立索引
createrepo -po /mirror/7/base/ /mirror/7/base/
createrepo -po /mirror/7/extras/ /mirror/7/extras/
createrepo -po /mirror/7/updates/ /mirror/7/updates/
更新源數據
createrepo --update /mirror/7/base
createrepo --update /mirror/7/extras
createrepo --update /mirror/7/updates
  • 建立定時任務腳本
vim /mirror/7/script/centos_yum_update.sh
#!/bin/bash
DATE=$(date +%F)
LogFile=/var/log/aliyumrepo_${DATE}.log
function log_error() {
    echo -e "\033[31m [ERROR] $@ \033[0m"
    echo "ERROR $@"  >> $LogFile
}
function log_info() {
    echo -e "\033[32m [INFO] $@ \033[0m"
    echo "INFO $@"  >> $LogFile
}
function log_warn() {
    echo -e "\033[33m [WARN] $@ \033[0m"
    echo "WARN $@"  >> $LogFile
}
log_info "${DATE} 正在同步..."
reposync -np /mirror/7 &>/dev/null
if [ $? -eq 0 ];then
    createrepo --update /mirror/7/base
    createrepo --update /mirror/7/extras
    createrepo --update /mirror/7/updates
    log_info "${DATE} aliyum_yum update successful"
else
    log_error "${DATE} aliyum_yum update failed"
fi
  • 將腳本加入到定時任務中
  • 安裝nginx開啓目錄權限保證本地機器能夠直接本地yum源
yum install nginx -y
找到nginx配置文件,並修改nginx配置文件:
vim nginx.conf
    server {
        listen       80;
        server_name  localhost;
        root         /mirror/7;         # 這裏是yum源存放目錄      
        location / {
            autoindex on;               # 打開目錄瀏覽功能
            autoindex_exact_size off;   # on、off:以可讀的方式顯示文件大小
            autoindex_localtime on;     # on、off:是否以服務器的文件時間做爲顯示的時間
            charset utf-8,gbk;          # 展現中文文件名
            index index.html;
        }
}
  • 在客戶端修改yum源,並指向本地搭建的yum源主機
    • 注:若是開啓祕鑰驗證,則須要祕鑰文件,此處使用的ftp共享,固然nginx也是一樣的方式,只更換url便可。
vim ftp.repo
[base]
name=CentOS-$releasever - Base - mirror.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/base/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates - mirror.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/updates/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras - mirrors.template.com
baseurl=ftp://10.10.10.1/yum-mirror/7/extras/
enabled=1
gpgkey=ftp://10.10.10.1/yum-mirror/7/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgcheck=0
相關文章
相關標籤/搜索