Centos 7使用nginx实现挂载本地yum源

您所在的位置:网站首页 centos65挂载光盘 Centos 7使用nginx实现挂载本地yum源

Centos 7使用nginx实现挂载本地yum源

#Centos 7使用nginx实现挂载本地yum源| 来源: 网络整理| 查看: 265

前言:生产环境中由于一些安全问题,无法使用外网,只能在内网运行,无法访问外部yum源,这时候对于一些环境的安装及其不方便,故使用内部挂载yum源方式解决。

1、环境

操作系统版本

2、关闭selinux和防火墙 # 关闭selinux sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config # 关闭防火墙 systemctl stop firewalld.service systemctl disable firewalld.service 3、上传镜像到服务器并挂载 # 创建镜像存储目录,将镜像上传到该目录 mkdir -p /mnt/iso # 创建镜像挂载目录 mkdir -p /opt/centos # 挂载镜像 mount -t iso9660 /mnt/iso/CentOS-7-x86_64-DVD-1810.iso /opt/centos # 查看是否挂载成功 df -Th # 设置开机自动挂载 vi /etc/fstab /mnt/iso/CentOS-7-x86_64-DVD-1810.iso /opt/centos iso9660 loop 0 0

可以看到有/opt/centos表示挂载成功

4、安装nginx # 安装依赖 yum -y install gcc make pcre-devel openssl-devel # 创建用户和组 groupadd nginx useradd -M -s /sbin/nologin -g nginx nginx # 编译安装 ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-http_gzip_static_module --with-pcre make && make install # 修改配置文件 vi /etc/nginx/nginx.conf server { listen 10080; # 端口自行修改 server_name _; location / { autoindex on; root /opt/centos; #镜像挂载目录 } } # 检查nginx配置文件是否正确 /etc/nginx/sbin/nginx -t # 启动nginx /etc/nginx/sbin/nginx # 重新加载nginx /etc/nginx/sbin/nginx -s reload 5、配置yum源 # 备份原有repo配置 mkdir -p /etc/yum.repos.d/backup mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup # 创建本地yum配置文件 cd /etc/yum.repos.d vi local.repo [local] name=local baseurl=http://192.168.10.158:10080/ # 上面配置的nginx地址 enabled=1 gpgcheck=0 # 清空缓存 yum clean all yum makecache # 查看现有yum源 yum repolist

6、使用内网服务器配置内部yum源测试 # 备份原有repo配置 mkdir -p /etc/yum.repos.d/backup mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup # 创建本地yum配置文件 cd /etc/yum.repos.d vi local.repo [local] name=local baseurl=http://192.168.10.158:10080/ # 上面配置的nginx地址 enabled=1 gpgcheck=0 # 清空缓存 yum clean all yum makecache 7、下载文件测试 (1) 内部网络通信

(2) 下载文件 yum -y install unzip

使用的是本地源local进行下载

至此使用nginx实现本地yum源完成,大家觉得可以,请给个赞哟!谢谢!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3