公司场景需求:离线服务器上安装一个nginx服务
系统版本:CentOS 7.6
方法一:
使用tar包,二进制安装 略
方法二:
rpm方式
安装rpm包时,应该大家都遇到过缺少依赖包的问题,一个一个安装依赖文件,让人头疼。
这里给大家介绍一种很方便的安装方法
使用yumdownloader命令离线安装 nginx rpm服务包
1.首先找一个可以连接外网的服务器
可以ping通百度域名,确定可以上外网 [root@243-ceshi /]# ping www.baidu.com PING www.baidu.com icmp_seq=1 ttl=53 time=23.5 ms icmp_seq=2 ttl=53 time=22.8 ms icmp_seq=3 ttl=53 time=27.3 ms
2.安装插件
[root@localhost ~]# yum install yum-utils
3.创建一个存放rpm包的目录
[root@localhost ~]# mkdir /rpm
4.下载nginx rpm相关文件
[root@localhost rpm]# yumdownloader --resolve --destdir=/rpm nginx
5.查看rpm目录下的文件
[root@243-ceshi rpm]# ls centos-indexhtml-7-9.el7.centos.noarch.rpm nginx-mod-http-image-filter-1.16.1-3.el7.x86_64.rpm gd-2.0.35-27.el7_9.x86_64.rpm nginx-mod-http-perl-1.16.1-3.el7.x86_64.rpm gperftools-libs-2.6.1-1.el7.x86_64.rpm nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64.rpm libXpm-3.5.12-1.el7.x86_64.rpm nginx-mod-mail-1.16.1-3.el7.x86_64.rpm nginx-1.16.1-3.el7.x86_64.rpm nginx-mod-stream-1.16.1-3.el7.x86_64.rpm nginx-all-modules-1.16.1-3.el7.noarch.rpm openssl11-libs-1.1.1g-2.el7.x86_64.rpm nginx-filesystem-1.16.1-3.el7.noarch.rpm
nginx最新版本的相关依赖文件全在都rpm目录下了
6.把rpm目录下文件移到内网服务器的/rpm目录下
[root@243-ceshi /]# scp -r /rpm root@192.168.1.168:/rpm root@192.168.1.168's password: centos-indexhtml-7-9.el7.centos.noarch.rpm 100% 92KB 19.7MB/s 00:00 gd-2.0.35-27.el7_9.x86_64.rpm 100% 146KB 22.7MB/s 00:00 gperftools-libs-2.6.1-1.el7.x86_64.rpm 100% 272KB 26.2MB/s 00:00 libXpm-3.5.12-1.el7.x86_64.rpm 100% 55KB 17.6MB/s 00:00 nginx-1.16.1-3.el7.x86_64.rpm 100% 563KB 31.4MB/s 00:00 nginx-all-modules-1.16.1-3.el7.noarch.rpm 100% 20KB 8.2MB/s 00:00 nginx-filesystem-1.16.1-3.el7.noarch.rpm 100% 21KB 9.0MB/s 00:00 nginx-mod-http-image-filter-1.16.1-3.el7.x86_64.rpm 100% 30KB 12.0MB/s 00:00 nginx-mod-http-perl-1.16.1-3.el7.x86_64.rpm 100% 39KB 14.3MB/s 00:00 nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64.rpm 100% 29KB 11.9MB/s 00:00 nginx-mod-mail-1.16.1-3.el7.x86_64.rpm 100% 57KB 16.6MB/s 00:00 nginx-mod-stream-1.16.1-3.el7.x86_64.rpm 100% 85KB 18.1MB/s 00:00 openssl11-libs-1.1.1g-2.el7.x86_64.rpm 100% 1485KB 40.6MB/s 00:00
7.进入离线服务器安装
[root@localhost /]# cd /rpm [root@localhost rpm]# rpm -ivh * --nodeps --force 警告:nginx-1.16.1-3.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 352c64e5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:openssl11-libs-1:1.1.1g-2.el7 ################################# [ 8%] 2:nginx-filesystem-1:1.16.1-3.el7 ################################# [ 15%] 3:libXpm-3.5.12-1.el7 ################################# [ 23%] 4:gd-2.0.35-27.el7_9 ################################# [ 31%] 5:gperftools-libs-2.6.1-1.el7 ################################# [ 38%] 6:centos-indexhtml-7-9.el7.centos ################################# [ 46%] 7:nginx-mod-http-image-filter-1:1.1################################# [ 54%] 8:nginx-mod-http-perl-1:1.16.1-3.el################################# [ 62%] 9:nginx-mod-http-xslt-filter-1:1.16################################# [ 69%] 10:nginx-mod-mail-1:1.16.1-3.el7 ################################# [ 77%] 11:nginx-all-modules-1:1.16.1-3.el7 ################################# [ 85%] 12:nginx-1:1.16.1-3.el7 ################################# [ 92%] 13:nginx-mod-stream-1:1.16.1-3.el7 ################################# [100%]
8.启动nginx服务
[root@localhost rpm]# systemctl start nginx [root@localhost rpm]# systemctl status nginx ● nginx.service - The nginx HTTP and reverse proxy server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since 四 2021-01-21 15:24:46 CST; 5s ago Process: 127308 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 127303 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 127300 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 127318 (nginx) Tasks: 7 Memory: 7.8M CGroup: /system.slice/nginx.service ├─127318 nginx: master process /usr/sbin/nginx ├─127319 nginx: worker process ├─127320 nginx: worker process ├─127322 nginx: worker process ├─127323 nginx: worker process ├─127324 nginx: worker process └─127325 nginx: worker process 1月 21 15:24:46 vrgv systemd[1]: Starting The nginx HTTP and reverse proxy server... 1月 21 15:24:46 vrgv nginx[127303]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 1月 21 15:24:46 vrgv nginx[127303]: nginx: configuration file /etc/nginx/nginx.conf test is successful 1月 21 15:24:46 vrgv systemd[1]: Started The nginx HTTP and reverse proxy server.
离线安装nginx服务及依赖文件完成