美文网首页
Centos7多台内网服务器共享同一本地yum源

Centos7多台内网服务器共享同一本地yum源

作者: Habit_1027 | 来源:发表于2023-05-09 11:37 被阅读0次

    一、步骤

    1.1 共享源服务器(192.168.100.111),配置本地yum源

    1.2 为共享源配置对外访问的地址(我这里用nginx)

    1.3 其他内网服务器配置共享源的地址

    二、共享源配置本地yum源

    2.1 创建目录,备份原yum源文件

    mkdir /data/{centos-yum.bak,centos,centos-images}
    
    mv /etc/yum.repos.d/* /data/centos-yum.bak/
    

    2.2 上传镜像到服务器上

    mv CentOS-7-x86_64-DVD-1810.iso /data/centos-images/
    

    2.3 挂载镜像

    mount -o loop -t iso9660 /data/centos-images/CentOS-7-x86_64-DVD-1810.iso  /data/centos
    
    #取消挂载
    umount /data/centos
    

    2.4 创建repo文件

    vim /etc/yum.repos.d/my.repo
    [my]
    name=my
    baseurl=file:///data/centos
    enabled=1
    gpgcheck=0
    

    2.5制作cache

    yum clean all
    yum makecache
    

    2.6 详情

    [root@omnis-server data]# pwd
    /data
    [root@omnis-server data]# ls
     centos  centos-images  centos-yum.bak 
    [root@omnis-server data]# cd centos
    [root@omnis-server centos]# pwd
    /data/centos
    [root@omnis-server centos]# ls
    CentOS_BuildTag  EFI  EULA  GPL  images  isolinux  LiveOS  Packages  repodata  RPM-GPG-KEY-CentOS-7  RPM-GPG-KEY-CentOS-Testing-7  TRANS.TBL
    [root@omnis-server centos]#
    

    三、为共享源提供对外访问地址

    这里以nginx方式提供访问该地址

    [root@omnis-server conf.d]# more yum_share.conf 
    server {
        listen 8888;
        server_name 192.168.100.111;
      
        location / {
            root /data/centos;
        }
    }
    
    
    [root@omnis-server nginx]# more nginx.conf
    #user  nobody;worker_processes  1;
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        include  yum_share.conf;
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
       ......
       ......
       ......
    

    配置完了之后,我们就得到了访问192.168.100.111服务器yum源的地址:http://192.168.100.111:8888/,启动nginx(此处需关闭防火墙或开启8888端口)
    开放防火墙端口的命令:
    firewall-cmd --zone=public --add-port=8888/tcp --permanent
    firewall-cmd --reload

    四、其它服务器配置

    4.1 备份原yum源配置

    mv /etc/yum.repos.d /etc/yum.repos.d.bak
    mkdir /etc/yum.repos.d
    

    4.2 创建本地yum源配置文件

    [root@localhost~]# vi /etc/yum.repos.d/CentOS-local.repo
    [base-local]
    name=CentOS-local
    baseurl=http://192.168.100.111:8888/
    enabled=1
    gpgcheck=0
    

    4.3 更新yum源配置

    yum clean all
    yum makecache
    

    4.4 测试yum安装软件

    yum install -y  lrzsz  tree unzip zip
    

    相关文章

      网友评论

          本文标题:Centos7多台内网服务器共享同一本地yum源

          本文链接:https://www.haomeiwen.com/subject/yaersdtx.html