多版本YUM倉庫搭建

服務器:CentOS7

YUM源:阿里雲

空間要求:CentOS6+CentOS7  50G,考慮後期更新預留,LVS空間100G

1、在服務器配置CentOS7的yum源和CentOS6的yum源

#Centos7
[base7] name
=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 [updates7] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 [extras7] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 [epel7] name=CentOS-7-epel-cmiot.local baseurl=https://mirrors.aliyun.com/epel/7/x86_64/ gpgcheck=0
#Centos6
[base6] name
=CentOS-6 - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/os/x86_64/ http://mirrors.aliyuncs.com/centos/6/os/x86_64/ http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 [updates6] name=CentOS-6 - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/updates/x86_64/ http://mirrors.aliyuncs.com/centos/6/updates/x86_64/ http://mirrors.cloud.aliyuncs.com/centos/6/updates/x86_64/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 [extras6] name=CentOS-6 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/6/extras/x86_64/ http://mirrors.aliyuncs.com/centos/6/extras/x86_64/ http://mirrors.cloud.aliyuncs.com/centos/6/extras/x86_64/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6 [epel6] name=CentOS-6-epel-cmiot.local baseurl=https://mirrors.aliyun.com/epel/6/x86_64/ gpgcheck=0

2、檢查yum的可用性,並查看yum的repoid

 3、安裝repo同步工具和必要軟件包

yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

4、創建yum軟件包目錄並向阿里同步,時間較久。

mkdir -p /mirror/Aliyun/CentOS/6
reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 --repoid=epel6 -p /mirror/Aliyun/CentOS/6

mkdir -p /mirror/Aliyun/CentOS/7
reposync -n --repoid=extras7 --repoid=updates7 --repoid=base7 --repoid=epel7 -p /mirror/Aliyun/CentOS/7

5、創建索引

createrepo -po /mirror/Aliyun/CentOS/6/base6/ /mirror/Aliyun/CentOS/6/base6/
createrepo -po /mirror/Aliyun/CentOS/6/epel6/ /mirror/Aliyun/CentOS/6/epel6/
createrepo -po /mirror/Aliyun/CentOS/6/extras6/ /mirror/Aliyun/CentOS/6/extras6/
createrepo -po /mirror/Aliyun/CentOS/6/updates6/ /mirror/Aliyun/CentOS/6/updates6/
createrepo -po /mirror/Aliyun/CentOS/7/base7/ /mirror/Aliyun/CentOS/7/base7/
createrepo -po /mirror/Aliyun/CentOS/7/epel7/ /mirror/Aliyun/CentOS/7/epel7/
createrepo -po /data/website/centos/7/extras7 /data/website/centos/7/extras7
createrepo -po /mirror/Aliyun/CentOS/7/updates7/ /mirror/Aliyun/CentOS/7/updates7/

6、安裝nginx並配置

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root         /mirror ;   #這裏是yum源存放目錄      
        location / {
            autoindex on;        #打開目錄瀏覽功能
            autoindex_exact_size off;  # off:以可讀的方式顯示文件大小
            autoindex_localtime on; # on、off:是否以服務器的文件時間作爲顯示的時間
            charset utf-8,gbk; #展示中文文件名
            index index.html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

7、創建更新軟件包的定時任務

0 1 * * * /mirror/update.sh
#!/bin/bash
reposync -n --repoid=extras6 --repoid=updates6 --repoid=base6 --repoid=epel6 -p /mirror/Aliyun/CentOS/6
reposync -n --repoid=extras7 --repoid=updates7 --repoid=base7 --repoid=epel7 -p /mirror/Aliyun/CentOS/7
createrepo --update /mirror/Aliyun/CentOS/6/base6/
createrepo --update /mirror/Aliyun/CentOS/6/epel6/
createrepo --update /mirror/Aliyun/CentOS/6/extras6/
createrepo --update /mirror/Aliyun/CentOS/6/updates6/
createrepo --update /mirror/Aliyun/CentOS/7/base7/
createrepo --update /mirror/Aliyun/CentOS/7/epel7/
createrepo --update /mirror/Aliyun/CentOS/7/extras7/
createrepo --update /mirror/Aliyun/CentOS/7/updates7/

8、配置客戶端yum文件使用

[base]
name=CentOS-$releasever - Base
baseurl=http://10.150.203.8/Aliyun/CentOS/$releasever/base$releasever
gpgcheck=1
gpgkey=http://10.150.203.8/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever

[updates]
name=CentOS-$releasever - Updates
baseurl=http://10.150.203.8/Aliyun/CentOS/$releasever/updates$releasever
gpgcheck=1
gpgkey=http://10.150.203.8/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever

[extras]
name=CentOS-$releasever - Extras
baseurl=http://10.150.203.8/Aliyun/CentOS/$releasever/extras$releasever
gpgcheck=1
gpgkey=http://10.150.203.8/Aliyun/CentOS/RPM-GPG-KEY-CentOS-$releasever

[epel]
name=CentOS-$releasever - epel
baseurl=http://10.150.203.8/Aliyun/CentOS/$releasever/epel$releasever
gpgcheck=0
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章