Liunx使用nginx和http搭建yum-server仓库

文章目录

  • [1. yum-server的搭建方式](#1. yum-server的搭建方式)
  • [2. nginx搭建yum-server仓库](#2. nginx搭建yum-server仓库)
    • [2.1. 安装配置nginx](#2.1. 安装配置nginx)
    • [2.2 配置yum-server的rpm](#2.2 配置yum-server的rpm)
    • [2.3. 同步yum源相关包](#2.3. 同步yum源相关包)
      • [2.3.1 rsync同步源](#2.3.1 rsync同步源)
      • [3.3.1 reposync同步源](#3.3.1 reposync同步源)
    • [2.4. 配置客户端访问yum配置](#2.4. 配置客户端访问yum配置)
    • [2.5. 验证测试](#2.5. 验证测试)
  • [3. http服务搭建yum-server仓库](#3. http服务搭建yum-server仓库)
    • [3.1. 安装配置http](#3.1. 安装配置http)
    • [3.2 配置yum-server的rpm](#3.2 配置yum-server的rpm)
    • [3.3. 同步yum源相关包](#3.3. 同步yum源相关包)
    • [3.4. 配置客户端访问yum配置](#3.4. 配置客户端访问yum配置)
    • [3.5. 验证测试](#3.5. 验证测试)
  • [4. 疑问和思考](#4. 疑问和思考)
    • [4.1 配置多个yum-server仓库节点,该如何操作?](#4.1 配置多个yum-server仓库节点,该如何操作?)
    • [4.2 如何从公有云同步yum-server的rpm?](#4.2 如何从公有云同步yum-server的rpm?)
      • [4.2.1 rsync同步源](#4.2.1 rsync同步源)
      • [4.2.2 reposync同步源](#4.2.2 reposync同步源)
  • [5. 参考文档](#5. 参考文档)

探讨在linux环境下的搭建yum-server仓库,特别是使用nginx搭建yum-server提供yum服务。

1. yum-server的搭建方式

yum-server通常使用如下2种方式进行搭建,提供远程yum-server仓库服务

  • 使用nginx搭建yum源
  • 使用普通的http服务,搭建yum源

2. nginx搭建yum-server仓库

2.1. 安装配置nginx

ngx的安装本文不做介绍,可以网上获取,可以参考 LINUX安装nginx详细步骤

2.2 配置yum-server的rpm

nginx的配置如下

  • nginx.conf配置
bash 复制代码
cat nginx.conf
user  nobody;
worker_processes  8;

pid         log/nginx.pid;


events {
    use epoll;
    worker_connections  100000;
}
worker_rlimit_nofile 100000;

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    check_shm_size 100m;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

    sendfile          on;
    tcp_nopush        on;
    tcp_nodelay       on;

    keepalive_timeout  0;

    fastcgi_connect_timeout 30;
    fastcgi_send_timeout 30;
    fastcgi_read_timeout 30;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip              on;
    gzip_min_length   1k;
    gzip_buffers      4 16k;
    gzip_http_version 1.0;
    gzip_comp_level   2;
    gzip_types        text/plain application/x-javascript text/css application/xml text/javascript;
    gzip_vary         on;

    charset      utf-8;
    #代理公网源缓存配置
    proxy_cache_path /data1/cache/nginx levels=1:2 keys_zone=my_cache:500m;

    access_log   on;
    log_not_found off;

    error_page   400 403 405 408 /40x.html ;
    error_page   500 502 503 504 /50x.html ;

    #INCLUDE_APP
    include yum.conf.d/yum.nginx.conf;
}
  • yum.nginx.conf
bash 复制代码
server {
    listen 80;
    server_name  mirrors.xxx.com;
    error_log /data/log/tnginx_1_0_0-1.0/error.log;
    access_log /data/log/tnginx_1_0_0-1.0/yum-access.log;

    charset utf-8;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    client_max_body_size 512m;
    client_body_buffer_size 256k;
    proxy_connect_timeout 30;
    proxy_send_timeout 30;
    proxy_read_timeout 60;
    proxy_buffer_size 256k;
    proxy_buffers 4 256k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
    proxy_max_temp_file_size 128m;
    
    location / {
        root /data1/yum_data;
        autoindex on;
    }
}

定义/data1/yum_data位yum源的相关目录

2.3. 同步yum源相关包

可以从公有云进行同步,比如阿里云、腾讯云、清华等。

不同的厂商支持的同步协议不同,通常是用rsync和reposync两种类型,需要根据不同的协议选择对应的方式进行同步

  • 如果支持支持rsync, 就用常规的rsync方案同步.
  • 如果软件源不支持rsync, rpm的包可以用reposync工具同步

本次实例只 同步和拷贝epel的其中一个包,放到/var/www/html/ 目录
返回同步yum源相关包

2.3.1 rsync同步源

  1. 内部环境源
bash 复制代码
# 同步内部源
rsync -avzP epel/7/x86_64 xx.xx.xx.xx:/var/www/html/epel/7/
  1. 公有云源,支持rsync协议

中科大yum源:

rsync://mirrors.ustc.edu.cn/centos/7/os

bash 复制代码
# 同步公有云的源,中科大
rsync -avz rsync://rsync.mirrors.ustc.edu.cn/epel/7

3.3.1 reposync同步源

  1. 下载repo
  • 腾讯云
bash 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
  • 阿里云
bash 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  1. 同步源
bash 复制代码
 #reposync将根据刚下载的repo下载rpm包到指定文件夹/var/www/html/
reposync -r base /var/www/html/
reposync -r updates /var/www/html/
reposync -r epel /var/www/html/

2.4. 配置客户端访问yum配置

bash 复制代码
cat /etc/yum.repos.d/epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
failovermethod=priority
gpgcheck=0
enabled=1
baseurl=http://mirrors.xxx.com/epel/7/$basearch/

2.5. 验证测试

bash 复制代码
# 清理缓存
yum clean all
#缓存本地yum源中的软件包信息
yum makecache

# 查看所有可用的yum源
 yum repolist all

# 查看yum可以安装的组件
yum search all
yum list |grep epel

# 测试yum安装
yum install -y httpd
bash 复制代码
# 测试yum安装
yum install -y zabbix

说明已经能够正常安装

3. http服务搭建yum-server仓库

3.1. 安装配置http

bash 复制代码
# 安装httpd
yum install -y httpd

# 启动httpd服务
systemctl start httpd

# 检查80端口是否正常启动
netstat -ntlp|grep 80

3.2 配置yum-server的rpm

通过cat /etc/httpd/conf/httpd.conf服务默认的目录是DocumentRoot "/var/www/html"

bash 复制代码
cd /var/www/html

# 安装createrepo
yum install -y createrepo

# 初始化库
createrepo -pdo /var/www/html/ /var/www/html/ 

# 产看yum库,会创建目录repodata
ll

3.3. 同步yum源相关包

参考同步yum源相关包

3.4. 配置客户端访问yum配置

bash 复制代码
# 配置客户端访问yum配置
vim /etc/yum.repos.d/epel.repo 
[epel] 
name=Server
baseurl=http://xx.xx.xx.xx
#是否将该仓库做为软件包提供源
enabled=1
#是否进行gpg校验
gpgcheck=0

3.5. 验证测试

bash 复制代码
# 清理缓存
yum clean all
#缓存本地yum源中的软件包信息
yum makecache

# 查看所有可用的yum源
 yum repolist all

# 查看yum可以安装的组件
yum search all
yum list |grep epel

# 测试yum安装
yum install -y httpd
bash 复制代码
# 测试yum安装
yum install -y zabbix

说明已经能够正常安装

4. 疑问和思考

4.1 配置多个yum-server仓库节点,该如何操作?

不同yum节点配置rsync同步相关的配置即可

bash 复制代码
# 同步内部源
rsync -avzP epel/7/x86_64 xx.xx.xx.xx:/var/www/html/epel/7/

4.2 如何从公有云同步yum-server的rpm?

参考同步yum源相关包, 更多操作方法可以进一步扩展,参考相关公有云的官网

4.2.1 rsync同步源

  1. 公有云源,支持rsync协议

中科大yum源:

rsync://mirrors.ustc.edu.cn/centos/7/os

bash 复制代码
# 同步公有云的源,中科大
rsync -avz rsync://rsync.mirrors.ustc.edu.cn/epel/7

4.2.2 reposync同步源

  • 腾讯云
bash 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
  • 阿里云
bash 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
bash 复制代码
 #reposync将根据刚下载的repo下载rpm包到指定文件夹/var/www/html/
reposync -r base /var/www/html/
reposync -r updates /var/www/html/
reposync -r epel /var/www/html/

5. 参考文档

相关推荐
师傅别念了6 小时前
Nginx 反向代理配置指南,看完这篇就够了
nginx
Acrellea7 小时前
告别粗放式能耗管理!安科瑞EIOT平台助力产业园区智慧低碳运营
运维·安全·能源
Databuff7 小时前
五款主流 SSH 免费工具介绍
运维·ssh·运维开发
菜鸟学编程o7 小时前
Linux常见指令
linux·运维·服务器
pt10438 小时前
AIOps机器学习——当警报阈值被调高之后
运维·人工智能·自动化
迪康coolmu9 小时前
企业文件外发管控落地实践 —— 基于迪康端点安全一体化管理系统
运维·网络·经验分享·安全
见闻小天地10 小时前
四方电气DL300变频器面向雕铣机多工况的技术参数与适配验证
运维·人工智能·业界资讯
千舟软件10 小时前
【宿舍管理小程序】新生入住不靠纸质表
大数据·运维·服务器·科技·业界资讯
j7~11 小时前
【Linux网络加餐课】(篇八)网络版计算器(终篇):守护进程、标准 IO 重定向与部署打包
linux·运维·网络编程·tcp·守护进程·io重定向·部署打包
海宇服务12 小时前
零信任架构实战:基于海宇公安二要素认证即时版构建自动化号码发卡网关
运维·人工智能·架构·自动化