公司服务器属于内网环境,并且未挂载虚拟机镜像,需要人工将镜像文件上传至服务器并挂载,但是由于iso镜像文件很大,为每台服务器都进行同样的操作不但占用过多的磁盘空间并且操作过于繁琐,故采用nginx方式搭建局域网yum源仓库。
一、挂载镜像文件
- 因为是内网环境,需要手动上传iso镜像文件
- 挂载镜像文件
# mount CentOS-7.6-x86_64-DVD-1810.iso /mnt/
二、安装Nginx
2.1、关闭防火墙
# systemctl stop firewalld
# systemctl disable firewalld
# setenforce 0
# vi /etc/selinux/config
- 将SELINUX修改为disabled
SELINUX=disabled
2.2、安装依赖包
# yum -y install gcc make pcre-devel openssl-devel
2.3、创建nginx用户
# useradd nginx
2.4、上传并解压nginx源码包
2.5、安装nginx
- 编译并安装
# ./configure --prefix=/usr/local/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
2.6、启动nginx
- 启动nginx服务
# /usr/local/nginx/sbin/nginx
- 查看nginx信息
# /usr/local/nginx/sbin/nginx -V
三、修改nginx.conf
# vi /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
autoindex on;
root /mnt;
#root html;
#index index.html index.htm;
}
- 重新加载nginx
# /usr/local/nginx/sbin/nginx -s reload
四、配置repo
- 进入/etc/yum.repos.d目录下,配置yum源
# cd /etc/yum.repos.d/
# rm -rf *.repo
# vi CentOS.repo
[CentOS]
name=CentOS
baseurl=http://ip:port/
gpgcheck=0
enabled=1
- 清空缓存及查看现有的yum源
# yum clean all
# yum makecache
# yum repolist