CentOS 6.9自建开源镜像站

前端之家收集整理的这篇文章主要介绍了CentOS 6.9自建开源镜像站前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、 演示环境:

IP

OS

Nginx@H_403_31@版本

Rsync@H_403_31@版本

@H_403_31@清华大学开源软件镜像站

192.168.1.146

CentOS 6.9 x86_64

1.10.2

3.0.6

https://mirrors.tuna.tsinghua.edu.cn/

@H_403_31@备注:同步的上游yum@H_403_31@源必须要支持rsync@H_403_31@协议,否则不能使用rsync@H_403_31@进行同步。国内的很多开源镜像站都不支持rsync@H_403_31@,这里以清华大学开源软件镜像站为例。

2、 安装前准备:

(1)@H_403_31@服务器时间校对

(2)@H_403_31@配置epel@H_403_31@源

3、 安装配置Nginx

(1)@H_403_31@安装Nginx@H_403_31@:# yum -y install Nginx

(2)@H_403_31@创建软件包存放目录:# mkdir -pv /mirror/{centosplus,extras,os,updates,epel}

(3)@H_403_31@配置Nginx@H_403_31@:

# 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)@H_403_31@检查Nginx@H_403_31@配置文件语法,并启动# Nginx -t # service Nginx start

(5)@H_403_31@检查Nginx@H_403_31@监听的80@H_403_31@端口:# ss -tnlp | grep :80 # pidof Nginx

(6)@H_403_31@浏览器中访问站点192.168.1.146

4、 同步清华大学开源软件镜像站:

(1)@H_403_31@安装相关软件包:# yum -y install rsync createrepo

(2)@H_403_31@查看每个源下的软件包:

# 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)@H_403_31@编写同步脚本:

# 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)@H_403_31@编写定时任务:每天凌晨12@H_403_31@点开始执行同步脚本

# crontab -e --> 0 0 * * * /scripts/yum_rsync.sh

@H_403_31@备注:同步耗时较长,且保证磁盘有足够大的容量

@H_403_31@同步时可以通过# top@H_403_31@命令查看rsync@H_403_31@进程:

同步前目录结构及磁盘容量:

同步后目录结构及磁盘容量:

5、 其它服务器(例如:192.168.1.145)配置自建的yum源进行软件包下载安装测试:

(1)@H_403_31@创建yum@H_403_31@源的repo@H_403_31@配置文件

# 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

[extras]

name=Marion - CentOS-$releasever - Extras

baseurl=http://192.168.1.146/extras

[updates]

name=Marion - CentOS-$releasever - Updates

baseurl=http://192.168.1.146/updates

gpgcheck=0


# vim epel.repo

[epel]

name=Marion - CentOS-$releasever - EPEL

baseurl=http://192.168.1.146/epel

gpgcheck=0

(2)@H_403_31@清除当前yum@H_403_31@缓存:# yum clean all

(3)@H_403_31@重新生成# yum makecache

(4)@H_403_31@显示可用的yum@H_403_31@源:# yum repolist

(5)@H_403_31@测试base@H_403_31@源:# yum -y install httpd # yum info httpd

(6)@H_403_31@测试epel@H_403_31@源:# yum -y install Nginx # yum info Nginx

原文链接:https://www.f2er.com/centos/374999.html

猜你在找的CentOS相关文章