在windows上搭建鏡像yum站的方法(附bat腳本)


方法一:支持rsync的網站 

對於常用的centos、Ubuntu、等使用官方yum源在 http://mirrors.ustc.edu.cn 都存在鏡像。

  同時 http://mirrors.ustc.edu.cn 網站又支持 rsync 協議, 可以通過rsync實現 鏡像yum源。

 _______________________________________________________________
|         University of Science and Technology of China         |
|           Open Source Mirror  (mirrors.ustc.edu.cn)           |
|===============================================================|
|                                                               |
| Debian primary mirror in China mainland (ftp.cn.debian.org),  |
|     also mirroring a great many OSS projects & Linux distros. |
|                                                               |
| Currently we don't limit speed. To prevent overload, Each IP  |
| is only allowed to start upto 2 concurrent rsync connections. |
|                                                               |
| This site also provides http/https/ftp access.                |
|                                                               |
| Supported by USTC Network Information Center                  |
|          and USTC Linux User Group (http://lug.ustc.edu.cn/). |
|                                                               |
|    Sync Status:  https://mirrors.ustc.edu.cn/status/          |
|           News:  https://servers.ustclug.org/                 |
|        Contact:  lug@ustc.edu.cn                              |
|                                                               |
|_______________________________________________________________|

在windows上使用rsync需要用到 cwRsync  下載地址是 https://www.itefix.net/dl/cwRsync_5.5.0_x86_Free.zip;

  其官網為 https://www.itefix.net/cwrsync 

使用rsync的時候需要編寫腳本,設置要同步的內容

 

其中centos7_base.bat腳本內容 供大家參考:

@echo off
SETLOCAL

SET CWRSYNCHOME=%~dp0

IF NOT EXIST %CWRSYNCHOME%home\%USERNAME%\.ssh MKDIR  %CWRSYNCHOME%home\%USERNAME%\.ssh

SET CWOLDPATH=%PATH%

SET PATH=%CWRSYNCHOME%bin;%PATH%

rsync  -av --delete rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/    /cygdrive/f/yum/nginx/html/centos/7/os/x86_64/

方法二:使用wget命令下載不支持rsync協議的源

由於線上跑的系統還有CentOS5.4、6.4、6.5、6.5、6.6、6.8,而各鏡像站維護的最早的版本已經是6.9,所以需要爬archive站點的rpm包來自建yum倉庫。

# wget -r -p -np -k http://archives.fedoraproject.org/pub/archive/epel/5Server/x86_64/

# wget -r -p -np -k http://archives.fedoraproject.org/pub/epel/6Server/x86_64/

-c, --continue resume getting a partially-downloaded file. 斷點續傳
-nd, --no-directories don't create directories. 不創建層級目錄,所有文件下載到當前目錄
-r, --recursive specify recursive download. 遞歸下載
-p, --page-requisites get all images, etc. needed to display HTML page.
下載頁面所有文件,使頁面能在本地打開
-k, --convert-links make links in downloaded HTML or CSS point to local files.
轉換鏈接指向本地文件
-np, --no-parent don't ascend to the parent directory. 不下載父級目錄的文件
-o, --output-file=FILE log messages to FILE. 指定日志輸出文件
-O, --output-document=FILE write documents to FILE. 指定文件下載位置
-L, --relative follow relative links only. 只下載相對鏈接,如果頁面嵌入其他站點不會被下載

windows上wget命令使用方法

  下載:http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe

  官網:http://gnuwin32.sourceforge.net/packages/wget.htm

  安裝

        雙擊即可安裝,安裝到目錄:D:\GnuWin32

    

  修改環境變量

    右鍵計算機 -> 屬性 -> 高級系統設置 -> 環境變量 -> 系統變量  GNU_HOME=D:\GnuWin32\bin

    

    添加path變量,在cmd中可以使用wget命令。  PATH=;%GNU_HOME%

    

c:\>wget -V
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = D:\GnuWin32/etc/wgetrc
GNU Wget 1.11.4

Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://www.gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

最初由 Hrvoje Niksic <hniksic@xemacs.org> 編寫。
Currently maintained by Micah Cowan <micah@cowan.name>.

提供web服務

 同時提供web服務需要用到nginx 

   nginx 下載 頁面 http://nginx.org/en/download.html

附: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;
        location / {
            autoindex  on;
            root   html;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  repo.zabbix.com;
        location / {
            autoindex  on;
            root   html/zabbix;
            index  index.html index.htm;
        }
    } 
    server {
        listen       80;
        server_name  sp.repo.webtatic.com mirror.webtatic.com;
        location / {
            autoindex  on;
            root   html/webtatic;
            index  index.html index.htm;
        }
    }
}

最后使用瀏覽器訪問

  

在linux服務器中設置解析

[root@m01 ~]# cat /etc/hosts
127.0.0.1    localhost localhost.localdomain localhost4 localhost4.localdomain4
::1          localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.1     mirrors.aliyuncs.com mirrors.aliyun.com repo.zabbix.com

附件:

附件1、  cwrsync + 全部 bat 腳本  https://files.cnblogs.com/files/clsn/cwRsync.rar

附件2、  nginx + 配置文件  https://files.cnblogs.com/files/clsn/nginx.zip

 

特別感謝:國強哥提供wget命令使用

               此文章出自慘綠少年,轉載請注明     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM