通过HTTP方式自建CentOS系列Yum源

前言:

 由于CentOS 6.x 系列在2020年11月30日官方就已经停止维护更新了,刚开始一些国内的开源镜像站都还能用,但是后面也就基本都失效了,因为自己还一直在用CentOS 6.x,所以必须得自建一个Yum源来自给自足。

CentOS停止维护时间:
 CentOS 6 停止维护更新日期2020年11月30日
 CentOS 7 停止维护更新日期2024年6月30日
 CentOS 8 停止维护更新日期2029年5月31日

环境:

 CentOS 6.9

操作:

1.下载http软件包

 目前阿里的CentOS 6的Yum源大部分的包也都没了,只有一部分包还可以用,下载http暂时可以先用阿里云Yum源下载,如果阿里云现在能够满足你们,直接用这个也可以,因为我需要的很多包阿里云里没有,所以我还是得自建一个

[root@test ~]# mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.bak     //备份

[root@test ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-6.10 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-6.10 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.10 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.10 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.10/contrib/$basearch/
gpgcheck=1
enabled=0

[root@test ~]# yum clean all

[root@test ~]# yum makecache

[root@test ~]# yum repolist
...
仓库标识                               仓库名称                                                                  状态
base                                   CentOS-6.10 - Base - mirrors.aliyun.com                                   6,713
extras                                 CentOS-6.10 - Extras - mirrors.aliyun.com                                    47
updates                                CentOS-6.10 - Updates - mirrors.aliyun.com                                1,193
repolist: 7,953

2.部署http

[root@test ~]# yum -y install httpd

3.上传下载好的Yum源包

 这里上传的Yum资源是我之前官方还没停止更新维护的时候下载的,使用的是reposync工具下载到本地。

下载yum源至本地方法

[root@test ~]# yum search reposync      //通过yum搜索reposync命令检索出所需的安装包

[root@test ~]# yum -y install yum-utils    //安装

[root@test ~]# yum repolist    //通过yum repolist列出当前yum源(为了查看要下载的yum源的repo id)
repo id                                      repo name                                                          status
base                                   CentOS-6.10 - Base - mirrors.aliyun.com                   6,713
extras                                 CentOS-6.10 - Extras - mirrors.aliyun.com                   47
updates                                CentOS-6.10 - Updates - mirrors.aliyun.com            1,193
repolist: 7,953

开始下载:
  reposync --repoid=仓库ID --download-Metadata -p 下载存放路径

[root@test ~]# reposync --repoid=base --download-Metadata -p /var/www/html/centos/6/
[root@test ~]# reposync --repoid=extras --download-Metadata -p /var/www/html/centos/6/
[root@test ~]# reposync --repoid=updates --download-Metadata -p /var/www/html/centos/6/

 下载完成之后就可以直接使用或者以后需要的时候拿出来自建Yum源。

[root@test ~]# ll /var/www/html/centos/6/  
centos6.zip

[root@test ~]# unzip /var/www/html/centos/6/centos6.zip    //将压缩文件centos6.zip在当前目录下解压缩。

[root@test ~]# ll /var/www/html/centos/6/centos6/
总用量 12
drwxrwxrwx 5 root root 4096 2月   2 10:41 base
drwxrwxrwx 5 root root 4096 2月   2 10:41 extras
drwxrwxrwx 5 root root 4096 2月   2 10:43 updates

[root@test ~]# mv /var/www/html/centos/6/centos6/* /var/www/html/centos/6/    //移动到centos/6下,方便后续操作

[root@test ~]# ll /var/www/html/centos/6/
总用量 12
drwxrwxrwx 5 root root 4096 2月   2 10:41 base
drwxrwxrwx 5 root root 4096 2月   2 10:41 extras
drwxrwxrwx 5 root root 4096 2月   2 10:43 updates

4.配置http.conf

[root@test ~]# vim /etc/httpd/conf/httpd.conf
......
<Directory "/var/www/html">
...
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all        //添加(为了防止访问时报错:You don’t have permission to access / on this server)

</Directory>
.......
<VirtualHost *:6666>         //添加以下虚拟主机,配置端口,根目录
    ServerAdmin 127.0.0.1
    DocumentRoot /var/www/html
    ServerName 127.0.0.1
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

[root@test ~]# /etc/init.d/httpd restart

5.关闭selinux、添加iptables规则

[root@test ~]# vim /etc/sysconfig/selinux
...
SELINUX=disabled

[root@test ~]# vim /etc/sysconfig/iptables
...
-A INPUT -p tcp -m tcp --dport 6666 -j ACCEPT

[root@test ~]# /etc/init.d/iptables restart

Web访问:

在这里插入图片描述

6.使用createrepo来创建repo

[root@test ~]# yum -y install createrepo      //安装createrepo

[root@test ~]# createrepo /var/www/html/centos/6/base/     //创建base源repo
Spawning worker 0 with 6713 pkgs
Workers Finished
Gathering worker results

Saving Primary Metadata
Saving file lists Metadata
Saving other Metadata
Generating sqlite DBs
sqlite DBs complete

[root@test ~]# createrepo /var/www/html/centos/6/extras/     //创建extras源repo

[root@test ~]# createrepo /var/www/html/centos/6/updates/     //创建updates源repo

[root@test ~]#  ll /var/www/html/centos/6/base/
总用量 2184
-rwxrwxrwx 1 root root  248263 1月  27 13:58 47bb3f2a77d01bd38e462765ebd67f8890af8c4ea75ab1b9ba192926db7e552b-c6-x86_64-comps.xml.gz
-rwxrwxrwx 1 root root 1508980 1月  27 13:58 5a045ecddfcca9dcbf1c28b6543e740de844ff4ef221e70308e7ad6decaea417-c6-x86_64-comps.xml
drwxrwxrwx 2 root root  471040 1月  27 14:03 Packages
drwxr-xr-x 2 root root    4096 2月   2 10:46 repodata

[root@test ~]#  ll /var/www/html/centos/6/extras/
总用量 2184
-rwxrwxrwx 1 root root  248263 1月  27 14:03 47bb3f2a77d01bd38e462765ebd67f8890af8c4ea75ab1b9ba192926db7e552b-c6-x86_64-comps.xml.gz
-rwxrwxrwx 1 root root 1508980 1月  27 14:03 5a045ecddfcca9dcbf1c28b6543e740de844ff4ef221e70308e7ad6decaea417-c6-x86_64-comps.xml
drwxrwxrwx 2 root root  471040 1月  27 14:08 Packages
drwxr-xr-x 2 root root    4096 2月   2 10:46 repodata

[root@test ~]#  ll /var/www/html/centos/6/updates/
总用量 2188
-rwxrwxrwx 1 root root  248263 1月  27 14:08 47bb3f2a77d01bd38e462765ebd67f8890af8c4ea75ab1b9ba192926db7e552b-c6-x86_64-comps.xml.gz
-rwxrwxrwx 1 root root 1508980 1月  27 14:08 5a045ecddfcca9dcbf1c28b6543e740de844ff4ef221e70308e7ad6decaea417-c6-x86_64-comps.xml
drwxrwxrwx 2 root root  471040 1月  27 14:12 Packages
drwxr-xr-x 2 root root    4096 2月   2 10:47 repodata

7.其他主机配置自建的Yum源

[root@centos6 ~]# mv /etc/yum.repos.d/CentOS-Base.repo  /etc/yum.repos.d/CentOS-Base.repo.bak     //备份

[root@centos6 ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=centos6
enabled=1
baseurl=http://xxxxxxxxxxx:6666/centos/6/base
gpgcheck=0

[extras]
name=centos6
enabled=1
baseurl=http://xxxxxxxxxxx:6666/centos/6/extras
gpgcheck=0

[updates]
name=Centos6
enabled=1
baseurl=http://xxxxxxxxxxx:6666/centos/6/updates
gpgcheck=0

[root@centos6 ~]# yum clean all

[root@centos6 ~]# yum makecache

[root@centos6 ~]# yum repolist
仓库标识                                                 仓库名称                                                状态
base                                                     centos6                                                 6,713
extras                                                   centos6                                                 6,713
updates                                                  Centos6                                                 6,713
repolist: 20,139

[root@centos6 ~]# yum -y install  psmisc
...
已安装:
  psmisc.x86_64 0:22.6-24.el6

完毕!

 

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native