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. 参考文档

相关推荐
荣--5 小时前
一键部署不是为了省时间 —— 它是把"买来的 PaaS"变成"自己的平台"的拐点
运维·zabbix·工程化·一键部署·平台化·边界设计
江华森6 小时前
动手实战学 Docker — 从零到集群编排完全指南
运维
Avan_菜菜1 天前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
SelectDB2 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
XIAOHEZIcode3 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220704 天前
如何搭建本地yum源(上)
运维
ping某5 天前
为什么 Nginx 明明监听了 80,转发后端时却用了 4xxxx 端口?
后端·nginx
大树887 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠7 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质7 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务