记录在Centos7上通过nginx+createrepo搭建本地yum仓库,及遇到的问题
需求:在公司服务器中只有一台服务器有网,其余服务器在利用yum安装依赖库时比较麻烦。
解决办法:在有网的服务器上利用nginx+createrepo搭建一个本地可用的yum仓.
1. 安装yumdownloade:
yum install -y yum-utils
2. 下载rpm包到指及其依赖包到指定文件夹(以wget为例):
yumdownloader wget --resolve --destdir=/usr/local/offline4rpm
1. 安装createrepo:
yum -y install createrepo
2. 创建本地yum仓库:
createrepo /usr/local/offline4rpm
3. yum仓库变动后需要进行更新:
createrepo --update /usr/local/offline4rpm
1. 准备工作
开放端口(以9920为例):
-
firewall-cmd --zone=
public --
add-port=
9920/tcp --permanent
-
firewall-cmd --reload
关闭selinux
-
vim /etc/selinux/config
-
# 修改以下
-
SELINUX=disabled
2. 安装nginx
下载nginx:
-
wget http:
//nginx.org/download/nginx-1.14.2.tar.gz
-
tar zxvf nginx-
1.14.2.tar.gz
编译安装nginx:
-
cd nginx
-1.14
.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
-
-
make && make install
3. 配置nginx:
-
vim /usr/
local/nginx_offline4rpm/conf/nginx_offline4rpm.conf
-
-
# nginx_offline4rpm.conf内容如下
-
events {
-
accept_mutex on;
-
worker_connections
4096;
-
}
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
sendfile on;
-
-
server {
-
listen
9920 default_server;
-
listen [::]:
9920 default_server;
-
server_name
192.168.
0.
39;
# localhost
-
location / {
-
root /usr/
local/Offline4rpm;
-
autoindex on;
-
}
-
}
-
}
4. 运行nginx发布yum仓库:
/usr/local/nginx_offlien4rpm/sbin/nginx -c /usr/local/nginx_offlien4rpm/conf/nginx_offline4rpm.conf
查看端口是否监听:
netstat -ntlp |grep 9920
1. 备份yum仓配置文件:
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/*.repo.bk
2. 配置客户端
-
vim /etc/yum.repos.d/offline4rpm.repo
-
-
[offline4rpm]
-
name=offline4rpm
-
baseurl=http:
//192.168.0.39:9920
-
enabled=
1
-
gpgcheck=
0
3. 测试
-
yum clean all
-
yum
list
能够显示下载的rpm包则配置成功。
4. yum清除缓存的命令
-
# 清除缓存目录下的软件包
-
yum clean packages
-
-
# 清除缓存目录下的headers
-
yum clean headers
-
-
# 清除缓存目录下的软件包及headers
-
yum clean all
转载:https://blog.csdn.net/zhifangyou7864/article/details/105101451
查看评论