首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >CentOS7下的YUM源服务器最全搭建步骤,希望看了有所收获

CentOS7下的YUM源服务器最全搭建步骤,希望看了有所收获

作者头像
老K博客
发布2024-11-04 09:40:22
发布2024-11-04 09:40:22
1.1K0
举报
文章被收录于专栏:老K博客老K博客

环境要求

代码语言:javascript
复制
'环境准备,修改hostname,关闭防火墙,disabled selinux' 
[root@edenluo ~]# hostnamectl set-hostname --static yum-server
[root@edenluo ~]# systemctl disable firewalld --now
[root@edenluo ~]# sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux

二、配置服务器端yum

1、安装yum源工具
代码语言:javascript
复制
[root@edenluo ~]# yum -y install epel-release.noarch     # nginx需要epel源
[root@edenluo ~]# yum -y install nginx    # 安装nginx
[root@edenluo ~]# yum -y yum-utils    # 安装repository管理工具
2、配置nginx
代码语言:javascript
复制
[root@edenluo nginx]# cd /etc/nginx/
[root@edenluo nginx]# cp nginx.conf{,.bak}    # 备份!备份!备份!
[root@edenluo nginx]# vim nginx.conf
    server {
        listen       80;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }
        # 在server段加入以下三段内容
        autoindex on;              # 表示:自动在index.html的索引打开
        autoindex_exact_size on;   # 表示:如果有文件,则显示文件的大小
        autoindex_localtime on;    # 表示:显示更改时间,以当前系统的时间为准

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    
[root@edenluo nginx]# nginx -t     # 检测一下nginx语法是否有错
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@edenluo nginx]# systemctl enable nginx.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

[root@edenluo nginx]# systemctl enable nginx.service --now  # 启动nginx,设为开机自启
[root@edenluo nginx]# curl -I http://localhost    # 访问本地,状态码返回200,服务正常
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Sun, 05 Jul 2020 09:48:05 GMT
Content-Type: text/html
Content-Length: 4833
Last-Modified: Fri, 16 May 2014 15:12:48 GMT
Connection: keep-alive
ETag: "53762af0-12e1"
Accept-Ranges: bytes
3、配置nginx页面目录
代码语言:javascript
复制
[root@edenluo nginx]# cd /usr/share/nginx/html/
[root@edenluo html]# mkdir -p CentOS-YUM/Aliyun/{version_8,version_7}/64bit
[root@edenluo html]# tree /usr/share/nginx/html/CentOS-YUM/
/usr/share/nginx/html/CentOS-YUM/
└── Aliyun
    ├── version_8
    │   └── 64bit
    └── version_7
        └── 64bit

5 directories, 0 files
代码语言:javascript
复制
[root@edenluo html]# cd CentOS-YUM/
[root@edenluo CentOS-YUM]# vim index.html
ALL of the packages in the below:



version_8


These packagers using for Centos 8


version_7


These packagers using for Centos 7


Please replace the file and fill in the f    ollowing content:
Way: /etc/yum.repos.d/CentOS-Base.repo
代码语言:javascript
复制
  Web Server
  

        html {
        background-image:url(img/html-background.png);
        background-color: white;
        font-family: "DejaVu Sans", "Liberation Sans", sans-serif;
        font-size: 0.85em;
        line-height: 1.25em;
        margin: 0 4% 0 4%;
        }

        body {
        border: 10px solid #fff;
        margin:0;
        padding:0;
        background: #fff;
        }

        /* Links */

        a:link { border-bottom: 1px dotted #ccc; text-decoration: none; color: #204d92; }
        a:hover { border-bottom:1px dotted #ccc; text-decoration: underline; color: green; }
        a:active {  border-bottom:1px dotted #ccc; text-decoration: underline; color: #204d92; }
        a:visited { border-bottom:1px dotted #ccc; text-decoration: none; color: #204d92; }
        a:visited:hover { border-bottom:1px dotted #ccc; text-decoration: underline; color: green; }

        .logo a:link,
        .logo a:hover,
        .logo a:visited { border-bottom: none; }

        .mainlinks a:link { border-bottom: 1px dotted #ddd; text-decoration: none; color: #eee; }
        .mainlinks a:hover { border-bottom:1px dotted #ddd; text-decoration: underline; color: white; }
        .mainlinks a:active { border-bottom:1px dotted #ddd; text-decoration: underline; color: white; }
        .mainlinks a:visited { border-bottom:1px dotted #ddd; text-decoration: none; color: white; }
        .mainlinks a:visited:hover { border-bottom:1px dotted #ddd; text-decoration: underline; color: white; }

        /* User interface styles */

        #header {
        margin:0;
        padding: 0.5em;
        background: #204D8C url(img/header-background.png);
        text-align: left;
        }

        .logo {
        padding: 0;
        /* For text only logo */
        font-size: 1.4em;
        line-height: 1em;
        font-weight: bold;
        }

        .logo img {
        vertical-align: middle;
        padding-right: 1em;
        }

        .logo a {
        color: #fff;
        text-decoration: none;
        }

        p {
        line-height:1.5em;
        }

        h1 {
                margin-bottom: 0;
                line-height: 1.9em; }
        h2 {
                margin-top: 0;
                line-height: 1.7em; }

        #content {
        clear:both;
        padding-left: 30px;
        padding-right: 30px;
        padding-bottom: 30px;
        border-bottom: 5px solid #eee;
        }

    .mainlinks {
        float: right;
        margin-top: 0.5em;
        text-align: right;
    }

    ul.mainlinks > li {
    border-right: 1px dotted #ddd;
    padding-right: 10px;
    padding-left: 10px;
    display: inline;
    list-style: none;
    }

    ul.mainlinks > li.last,
    ul.mainlinks > li.first {
    border-right: none;
    }

  







    
         Home 
         Wiki 
         Mailing Lists
         Mirror List
         IRC
         Forums
         Bugs 
         Donate
    

        
                
        





        CentOS-YUM 所有的包

        按照系统版本选择版本下载
        CentOS8 版本


        以上包适用于 Centos 8


        CentOS7 版本


        以上包适用于 Centos 7


        请替换该文件并填写以下内容:
        替换文件: /etc/yum.repos.d/CentOS-Base.repo

        CentOS 官网  

        ,

         mirror network,SIGs,wiki, IRC Chat, Email Lists, Forums, Bugs Database , FAQ.
4、替换yum源文件# 备份原来的官方yum源
代码语言:javascript
复制
[root@edenluo CentOS-YUM]# cd /etc/yum.repos.d/
[root@edenluo yum.repos.d]# mv ./* /tmp/
代码语言:javascript
复制
[root@edenluo yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo    # 下载aliyun的centos7的yum源
[root@edenluo yum.repos.d]# vim yum.reposync.sh    # 同步脚本
#!/usr/bin/bash
reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/

/usr/bin/sed -i "s/7/8/g" `grep 7 -rl /etc/yum.repos.d/CentOS-Base.repo`

reposync -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_8/64bit/

/usr/bin/sed -i "s/8/7/g" `grep 6 -rl /etc/yum.repos.d/CentOS-Base.repo`  #还原

[root@edenluo yum.repos.d]# chmod +x yum.reposync.sh   # 要给执行权限
[root@edenluo yum.repos.d]# ll
total 8
-rw-r--r-- 1 root root 2523 Jun 16  2018 CentOS-Base.repo
-rwxr-xr-x 1 root root  303 Jul  5 19:02 yum.reposync.sh
[root@edenluo yum.repos.d]# sh yum.reposync.sh
# 等待同步完成
# 同步完成,查看文件大小,合计27G
[root@edenluo CentOS-YUM]# du -ch Aliyun/
9.0G    Aliyun/version_7/64bit/base/Packages
9.0G    Aliyun/version_7/64bit/base
616M    Aliyun/version_7/64bit/extras/Packages
616M    Aliyun/version_7/64bit/extras
3.6G    Aliyun/version_7/64bit/updates/Packages
3.6G    Aliyun/version_7/64bit/updates
14G     Aliyun/version_7/64bit
14G     Aliyun/version_7
9.0G    Aliyun/version_8/64bit/base/Packages
9.0G    Aliyun/version_8/64bit/base
616M    Aliyun/version_8/64bit/extras/Packages
616M    Aliyun/version_8/64bit/extras
3.6G    Aliyun/version_8/64bit/updates/Packages
3.6G    Aliyun/version_8/64bit/updates
14G     Aliyun/version_8/64bit
14G     Aliyun/version_8
27G     Aliyun/
27G     total

5、建立yum源仓库

代码语言:javascript
复制
'因为建仓最终的目的也是可供client来进行检索的,所以得每个Packages目录都要建成仓库,所以建仓的时候,目录指到最底层的Packages,而-np更新的时候只用指定到64bit的目录就可以了,否则会重复建立base、extras、updates三个目录进行下载
[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/base/Packages/
Spawning worker 0 with 10070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/extras/Packages/
Spawning worker 0 with 397 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/updates/Packages/
Spawning worker 0 with 884 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_8/64bit/base/Packages/
Spawning worker 0 with 10070 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_8/64bit/updates/Packages/
Spawning worker 0 with 884 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@edenluo ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_8/64bit/extras/Packages/
Spawning worker 0 with 397 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@edenluo ~]# tree -d /usr/share/nginx/html/CentOS-YUM/Aliyun/          # 建仓完成后,会自动生成一个repodata目录
/usr/share/nginx/html/CentOS-YUM/Aliyun/
├── version_8
│   └── 64bit
│       ├── base
│       │   └── Packages
│       │       └── repodata
│       ├── extras
│       │   └── Packages
│       │       └── repodata
│       └── updates
│           └── Packages
│               └── repodata
└── version_7
    └── 64bit
        ├── base
        │   └── Packages
        │       └── repodata
        ├── extras
        │   └── Packages
        │       └── repodata
        └── updates
            └── Packages
                └── repodata

22 directories
代码语言:javascript
复制
'可以写一个更新yum源的脚本,然后写一个计划任务,定期更新yum源(reposync -np 就是更新新的rpm包)
#!/usr/bin/bash
reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/
echo "centos7 is sync complate"
/usr/bin/sed -i "s/7/8/g" `grep 7 -rl /etc/yum.repos.d/CentOS-Base.repo`

reposync -np /usr/share/nginx/html/CentOS-YUM/Aliyun/version_8/64bit/
echo "centos6 is sync complate"
/usr/bin/sed -i "s/8/7/g" `grep 6 -rl /etc/yum.repos.d/CentOS-Base.repo`

三、配置客户端yum

代码语言:javascript
复制
# 备份原来的yum源
[root@edenluo ~]# cd /etc/yum.repos.d/
[root@edenluo yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo
[root@edenluo yum.repos.d]# mkdir back
[root@edenluo yum.repos.d]# mv CentOS-* back/
[root@edenluo yum.repos.d]# mv epel* back/
[root@edenluo yum.repos.d]# ls
back
代码语言:javascript
复制
[root@edenluo yum.repos.d]# vim CentOS-Base.repo   # 需要8,就使用8,需要7,就使用7,也可以使用yum-plugin-priorities工具来控制优先级,加上priority=1(2|3|4都可以)来控制优先级
[Aliyun_7_base]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/base/Packages
gpgcheck=0
enable=1

[Aliyun_7_extras]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/extras/Packages
gpgcheck=0
enable=1

[Aliyun_7_updates]
name=source_from_localserver
baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/updates/Packages
gpgcheck=0
enable=1

# [Aliyun_8_base]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_8/4bit/base/Packages
# gpgcheck=0
# enable=1
#
# [Aliyun_8_extras]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_8/74bit/extras/Packages
# gpgcheck=0
# enable=1
#
# [Aliyun_8_updates]
# name=source_from_localserver
# baseurl=http://192.168.57.133/CentOS-YUM/Aliyun/version_8/74bit/updates/Packages
# gpgcheck=0
# enable=1
[root@edenluo yum.repos.d]# yum clean all
[root@edenluo yum.repos.d]# yum makecache
代码语言:javascript
复制
# 安装软件来测试一下
[root@edenluo yum.repos.d]# yum -y install net-tools
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================
 Package            Arch            Version                             Repository              Size
=====================================================================================================
Installing:
 net-tools          x86_64          2.0-0.25.20131004git.el7            Aliyun_7_base          306 k

Transaction Summary
=====================================================================================================
Install  1 Package

Total download size: 306 k
Installed size: 917 k
Downloading packages:
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                 | 306 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : net-tools-2.0-0.25.20131004git.el7.x86_64                                         1/1
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                         1/1

Installed:
  net-tools.x86_64 0:2.0-0.25.20131004git.el7

Complete!

本文共 421 个字数,平均阅读时长 ≈ 2分钟

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024年11月03日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境要求
  • 二、配置服务器端yum
    • 1、安装yum源工具
    • 2、配置nginx
    • 3、配置nginx页面目录
    • 4、替换yum源文件# 备份原来的官方yum源
  • 三、配置客户端yum
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档