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

相关推荐
醉颜凉16 分钟前
银河麒麟桌面操作系统V10 SP1:取消安装应用的安全授权认证
运维·安全·操作系统·国产化·麒麟·kylin os·安全授权认证
C++忠实粉丝1 小时前
Linux环境基础开发工具使用(2)
linux·运维·服务器
康熙38bdc1 小时前
Linux 环境变量
linux·运维·服务器
存储服务专家StorageExpert2 小时前
DELL SC compellent存储的四种访问方式
运维·服务器·存储维护·emc存储
大G哥3 小时前
记一次K8S 环境应用nginx stable-alpine 解析内部域名失败排查思路
运维·nginx·云原生·容器·kubernetes
妍妍的宝贝3 小时前
k8s 中微服务之 MetailLB 搭配 ingress-nginx 实现七层负载
nginx·微服务·kubernetes
醉颜凉3 小时前
银河麒麟桌面操作系统修改默认Shell为Bash
运维·服务器·开发语言·bash·kylin·国产化·银河麒麟操作系统
苦逼IT运维4 小时前
YUM 源与 APT 源的详解及使用指南
linux·运维·ubuntu·centos·devops
仍有未知等待探索4 小时前
Linux 传输层UDP
linux·运维·udp
zeruns8024 小时前
如何搭建自己的域名邮箱服务器?Poste.io邮箱服务器搭建教程,Linux+Docker搭建邮件服务器的教程
linux·运维·服务器·docker·网站