小言_互联网的博客

记录在Centos7上通过nginx+createrepo搭建本地yum仓库,及遇到的问题

366人阅读  评论(0)

记录在Centos7上通过nginx+createrepo搭建本地yum仓库,及遇到的问题

需求:在公司服务器中只有一台服务器有网,其余服务器在利用yum安装依赖库时比较麻烦。

解决办法:在有网的服务器上利用nginx+createrepo搭建一个本地可用的yum仓.


  • 利用yumdownloade下载rpm包和相关依赖

    1. 安装yumdownloade:

yum install -y yum-utils

 

    2. 下载rpm包到指及其依赖包到指定文件夹(以wget为例):

yumdownloader wget --resolve --destdir=/usr/local/offline4rpm
  • 利用createrepo创建安装包元数据信息

    1. 安装createrepo:

yum -y install createrepo

    2. 创建本地yum仓库:

createrepo /usr/local/offline4rpm

    3. yum仓库变动后需要进行更新:

createrepo --update /usr/local/offline4rpm
  • 利用nginx发布yum仓库到局域网中

    1. 准备工作

    开放端口(以9920为例):


  
  1. firewall-cmd --zone= public -- add-port= 9920/tcp --permanent
  2. firewall-cmd --reload

    关闭selinux


  
  1. vim /etc/selinux/config
  2. # 修改以下
  3. SELINUX=disabled

    2. 安装nginx

    下载nginx:


  
  1. wget http: //nginx.org/download/nginx-1.14.2.tar.gz
  2. tar zxvf nginx- 1.14.2.tar.gz

    编译安装nginx:


  
  1. cd nginx -1.14 .2
  2. ./configure --prefix= /usr/local/nginx_offline4rpm/ -- with-http_v2_module -- with-http_ssl_module -- with-http_sub_module -- with-http_stub_status_module -- with-http_gzip_static_module -- with-pcre
  3. make && make install

    3. 配置nginx:


  
  1. vim /usr/ local/nginx_offline4rpm/conf/nginx_offline4rpm.conf
  2. # nginx_offline4rpm.conf内容如下
  3. events {
  4. accept_mutex on;
  5. worker_connections 4096;
  6. }
  7. http {
  8. include mime.types;
  9. default_type application/octet-stream;
  10. sendfile on;
  11. server {
  12. listen 9920 default_server;
  13. listen [::]: 9920 default_server;
  14. server_name 192.168. 0. 39; # localhost
  15. location / {
  16. root /usr/ local/Offline4rpm;
  17. autoindex on;
  18. }
  19. }
  20. }

    4. 运行nginx发布yum仓库:

/usr/local/nginx_offlien4rpm/sbin/nginx -c /usr/local/nginx_offlien4rpm/conf/nginx_offline4rpm.conf

    查看端口是否监听:

netstat -ntlp |grep 9920
  • 客户端配置指向yum仓库

    1. 备份yum仓配置文件:

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/*.repo.bk

    2. 配置客户端


  
  1. vim /etc/yum.repos.d/offline4rpm.repo
  2. [offline4rpm]
  3. name=offline4rpm
  4. baseurl=http: //192.168.0.39:9920
  5. enabled= 1
  6. gpgcheck= 0

   3. 测试


  
  1. yum clean all
  2. yum list

   能够显示下载的rpm包则配置成功。

    4. yum清除缓存的命令


  
  1. # 清除缓存目录下的软件包
  2. yum clean packages
  3. # 清除缓存目录下的headers
  4. yum clean headers
  5. # 清除缓存目录下的软件包及headers
  6. yum clean all

 


转载:https://blog.csdn.net/zhifangyou7864/article/details/105101451
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场