CentOS 7.4搭建本地YUM仓库
  C3KwzfU39uKz 2023年11月13日 20 0

系统环境:

操作系统:CentOS Linux release 7.4.1708 (Core)

服务器IP:192.168.8.23

客户端IP:192.168.8.24

1)修改yum源为阿里云源

#备份系统自带的yum源

[root@localhost ~]# cd /etc/yum.repos.d

[root@localhost yum.repos.d]# mkdir bak

[root@localhost yum.repos.d]# mv *.repo bak

2)修改为阿里云yum源

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

CentOS 7.4搭建本地YUM仓库_nginx

3)检验阿里云源是否正常

#清除缓存

[root@localhost yum.repos.d]# yum clean all

#生成缓存

[root@localhost yum.repos.d]# yum makecache

[root@localhost yum.repos.d]# yum repolist

CentOS 7.4搭建本地YUM仓库_nginx_02

4)安装相关软件

[root@localhost yum.repos.d]# yum install -y wget make cmake gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel createrepo yum-utils

yum-utils:reposync同步工具

createrepo:编辑yum库工具

plugin-priorities:控制yum源更新优先级工具,这个工具可以用来控制进行yum源检索的先后顺序,建议可以用在client端。

注:由于很多人喜欢最小化安装,上边软件是一些常用环境。

5)根据源标识同步源到指定目录

#创建同步目录

[root@localhost yum.repos.d]# mkdir -p /data/yum

#同步到本地目录

[root@localhost yum.repos.d]# reposync -p /data/yum

CentOS 7.4搭建本地YUM仓库_yum源_03

注:不用担心没有创建相关目录,系统自动创建相关目录,并下载,时间较长请耐心等待(大约20分钟,大约30多G)。

可以用 repo -r --repoid=repoid指定要查询的repo id,可以指定多个(reposync -r base -p /data/yum     #这里同步base目录到本地)

#更新新的rpm包(可以略过)

[root@localhost yum.repos.d]# reposync -np /data/yum

注:时间同样较长,请耐心等待。

6)创建索引

[root@localhost yum.repos.d]# createrepo -po /data/yum/base/ /data/yum/base/

[root@localhost yum.repos.d]# createrepo -po /data/yum/extras/ /data/yum/extras/

[root@localhost yum.repos.d]# createrepo -po /data/yum/updates/ /data/yum/updates/

[root@localhost yum.repos.d]# createrepo -po /data/yum/epel/ /data/yum/epel/

#更新源数据

[root@localhost yum.repos.d]# createrepo --update /data/yum/base/

[root@localhost yum.repos.d]# createrepo --update /data/yum/extras/

[root@localhost yum.repos.d]# createrepo --update /data/yum/updates/

[root@localhost yum.repos.d]# createrepo --update /data/yum/epel/

7)安装Nginx服务

[root@localhost yum.repos.d]# yum -y install nginx

CentOS 7.4搭建本地YUM仓库_nginx_04

8)配置Nginx

[root@localhost yum.repos.d]# vim /etc/nginx/nginx.conf

  1. user nginx;
  2.     worker_processes auto;
  3.     error_log /var/log/nginx/error.log;
  4.     pid /run/nginx.pid;
  5.     include /usr/share/nginx/modules/*.conf;
  6. events    {
  7.     worker_connections 1024;
  8.     }
  9. http    {
  10.     log_format main    '$remote_addr - $remote_user [$time_local] "$request" '
  11.             '$status $body_bytes_sent "$http_referer" '
  12.             '"$http_user_agent" "$http_x_forwarded_for"';
  13.     access_log /var/log/nginx/access.log main;
  14.     sendfile on;
  15.     tcp_nopush on;
  16.     tcp_nodelay on;
  17.     keepalive_timeout 65;
  18.     types_hash_max_size 2048;
  19.     include /etc/nginx/mime.types;
  20.     default_type application/octet-stream;
  21.     include /etc/nginx/conf.d/*.conf;
  22.     server {
  23.     listen 80;
  24.     server_name localhost;
  25.     location / {
  26.     root    /data/yum;
  27.     autoindex on; #打开目录浏览功能
  28.     autoindex_exact_size off; #off:以可读的方式显示文件大小
  29.     autoindex_localtime on; #on、off:是否以服务器的文件时间作为显示的时间
  30.     charset utf-8,gbk; #展示中文文件名
  31.     index index.html;
  32.     }
  33.     error_page 404 /404.html;
  34.     location = /40x.html {
  35.     }
  36.     error_page 500 502 503 504 /50x.html;
  37.     location = /50x.html {
  38.     }
  39. }
  40. }

9)启动Nginx服务

[root@localhost yum.repos.d]# systemctl start nginx

#浏览器访问服务器IP

CentOS 7.4搭建本地YUM仓库_yum源_05

10)在客户端修改yum源,并指向本地yum源

[root@localhost ~]# cd /etc/yum.repos.d

#备份yum源

[root@localhost yum.repos.d]# mkdir back

[root@localhost yum.repos.d]# mv *.repo back

[root@localhost yum.repos.d]# vim CentOS-7-Base.repo

  1. [base]
  2. name=CentOS-$releasever - Base - mirror.template.com
  3. baseurl=http://192.168.8.23/base/
  4. path=/
  5. enabled=1
  6. gpgcheck=0

  7. [updates]
  8. name=CentOS-$releasever - Updates - mirror.template.com
  9. baseurl=http://192.168.8.23/updates/
  10. path=/
  11. enabled=1
  12. gpgcheck=0

  13. [extras]
  14. name=CentOS-$releasever - Extras - mirrors.template.com
  15. baseurl=http://192.168.8.23/extras/
  16. path=/
  17. enabled=1
  18. gpgcheck=0

  19. [epel]
  20. name=CentOS-$releasever - epel - mirrors.template.com
  21. baseurl=http://192.168.8.23/epel/
  22. failovermethod=priority
  23. enabled=1
  24. gpgcheck=0

[root@localhost yum.repos.d]# yum clean all

[root@localhost yum.repos.d]# yum repolist

CentOS 7.4搭建本地YUM仓库_yum源_0611)客户端测试
[root@localhost yum.repos.d]# yum -y install lrzsz

CentOS 7.4搭建本地YUM仓库_CentOS_07

至此,本地YUM仓库搭建完毕。

  • 输入编号:5832,直达文章
  • 输入m|M,直达目录列表
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读
  4koL3J55wyKx   2023年11月13日   35   0   0 icogitCentOS
  9E2BTpjt8nym   2023年12月06日   34   0   0 WindowsgitCentOS
C3KwzfU39uKz