CentOS 6.9自建開源鏡像站
IP | OS | Nginx版本 | Rsync版本 | 清華大學開源軟件鏡像站 |
192.168.1.146 | CentOS 6.9 x86_64 | 1.10.2 | 3.0.6 | https://mirrors.tuna.tsinghua.edu.cn/ |
備註:同步的上遊yum源必須要支持rsync協議,否則不能使用rsync進行同步。國內的很多開源鏡像站都不支持rsync,這裏以清華大學開源軟件鏡像站為例。
2、 安裝前準備:
(1)服務器時間校對
(2)配置epel源
3、 安裝配置Nginx:
(1)安裝Nginx:# yum -y install nginx
(2)創建軟件包存放目錄:# mkdir -pv /mirror/{centosplus,extras,os,updates,epel}
(3)配置Nginx:
# cd /etc/nginx/conf.d
# cp default.conf default.conf.bak
# vim default.conf
server {
listen 80;
server_name localhost;
root /mirror/;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
(4)檢查Nginx配置文件語法,並啟動Nginx:# nginx -t # service nginx start
(5)檢查Nginx監聽的80端口:# ss -tnlp | grep :80 # pidof nginx
(6)瀏覽器中訪問站點:192.168.1.146
4、 同步清華大學開源軟件鏡像站:
(1)安裝相關軟件包:# yum -y install rsync createrepo
(2)查看每個源下的軟件包:
# rsync --list-only rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/centosplus/x86_64/Packages/
# rsync --list-only rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/extras/x86_64/Packages/
# rsync --list-only rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/os/x86_64/Packages/
# rsync --list-only rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/updates/x86_64/Packages/
# rsync -r --list-only rsync://mirrors.tuna.tsinghua.edu.cn/epel/6Server/x86_64/Packages/
(3)編寫同步腳本:
# mkdir -pv /scripts
# vim /scripts/yum_rsync.sh
#!/bin/bash
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/centosplus/x86_64/Packages/ /mirror/centosplus && /usr/bin/createrepo /mirror/centosplus
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/extras/x86_64/Packages/ /mirror/extras && /usr/bin/createrepo /mirror/extras
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/os/x86_64/Packages/ /mirror/os && /usr/bin/createrepo /mirror/os
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/centos/6.9/updates/x86_64/Packages/ /mirror/updates && /usr/bin/createrepo /mirror/updates
/usr/bin/rsync -avz rsync://mirrors.tuna.tsinghua.edu.cn/epel/6Server/x86_64/Packages/ /mirror/epel && /usr/bin/createrepo /mirror/epel
# chmod +x /scripts/yum_rsync.sh
(4)編寫定時任務:每天淩晨12點開始執行同步腳本
# crontab -e --> 0 0 * * * /scripts/yum_rsync.sh
備註:同步耗時較長,且保證磁盤有足夠大的容量
同步時可以通過# top命令查看rsync進程:
同步前目錄結構及磁盤容量:
同步後目錄結構及磁盤容量:
5、 其它服務器(例如:192.168.1.145)配置自建的yum源進行軟件包下載安裝測試:
(1)創建yum源的repo配置文件:
# cd /etc/yum.repos.d
# mv CentOS-Base.repo CentOS-Base.repo.bak
# vim CentOS-Base.repo
[base]
name=Marion - CentOS-$releasever - Base
baseurl=http://192.168.1.146/os
enabled=1
gpgcheck=0
[centosplus]
name=Marion - CentOS-$releasever - Centosplus
baseurl=http://192.168.1.146/centosplus
enabled=1
gpgcheck=0
[extras]
name=Marion - CentOS-$releasever - Extras
baseurl=http://192.168.1.146/extras
enabled=1
gpgcheck=0
[updates]
name=Marion - CentOS-$releasever - Updates
baseurl=http://192.168.1.146/updates
enabled=1
gpgcheck=0
# vim epel.repo
[epel]
name=Marion - CentOS-$releasever - EPEL
baseurl=http://192.168.1.146/epel
enabled=1
gpgcheck=0
(2)清除當前yum緩存:# yum clean all
(3)重新生成yum緩存:# yum makecache
(4)顯示可用的yum源:# yum repolist
(5)測試base源:# yum -y install httpd # yum info httpd
(6)測試epel源:# yum -y install nginx # yum info nginx
CentOS 6.9自建開源鏡像站