视频加载失败

【Linux】nginx 离线安装

1506 字
8 分钟
【Linux】nginx 离线安装

资源下载#

nginx-1.20.1.tar.gz(下载链接中包含gcc、g++、pcre、libtool、nginx)

链接:https://pan.baidu.com/s/1Niv33uZa4gj0viYFrnBTBQ

提取码:0b91

安装步骤#

安装gcc#

Terminal window
rpm -Uvh *.rpm --nodeps --force

结果

Terminal window
[root@doris54 gcc]# rpm -Uvh *.rpm --nodeps --force
warning: cpp-4.8.5-16.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zlib-1.2.7-17.el7 ################################# [ 6%]
2:mpfr-3.1.1-4.el7 ################################# [ 13%]
3:libmpc-1.0.1-3.el7 ################################# [ 19%]
4:openssl-libs-1:1.0.2k-8.el7 ################################# [ 25%]
5:cpp-4.8.5-16.el7 ################################# [ 31%]
6:zlib-devel-1.2.7-17.el7 ################################# [ 38%]
7:kernel-headers-3.10.0-693.el7 ################################# [ 44%]
8:glibc-headers-2.17-196.el7 ################################# [ 50%]
9:glibc-devel-2.17-196.el7 ################################# [ 56%]
10:gcc-4.8.5-16.el7 ################################# [ 63%]
11:openssl-devel-1:1.0.2k-8.el7 ################################# [ 69%]
12:openssl-1:1.0.2k-8.el7 ################################# [ 75%]
13:openssl098e-0.9.8e-29.el7.centos.################################# [ 81%]
Cleaning up / removing...
14:openssl-1:1.0.2k-19.el7 ################################# [ 88%]
15:openssl-libs-1:1.0.2k-19.el7 ################################# [ 94%]
16:zlib-1.2.7-18.el7 ################################# [100%]
[root@doris54 gcc]#

安装g++#

Terminal window
rpm -Uvh *.rpm --nodeps --force

结果

Terminal window
[root@doris54 gcc-c++]# rpm -Uvh *.rpm --nodeps --force
warning: autogen-libopts-5.18-5.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:pkgconfig-1:0.27.1-4.el7 ################################# [ 5%]
2:zlib-1.2.7-17.el7 ################################# [ 10%]
3:libcom_err-1.42.9-10.el7 ################################# [ 15%]
4:openssl-libs-1:1.0.2k-8.el7 ################################# [ 20%]
5:ntpdate-4.2.6p5-25.el7.centos.2 ################################# [ 25%]
6:zlib-devel-1.2.7-17.el7 ################################# [ 30%]
7:libsepol-devel-2.5-6.el7 ################################# [ 35%]
8:libselinux-devel-2.5-11.el7 ################################# [ 40%]
9:libverto-devel-0.2.5-4.el7 ################################# [ 45%]
10:libstdc++-devel-4.8.5-16.el7 ################################# [ 50%]
11:keyutils-libs-devel-1.5.8-3.el7 ################################# [ 55%]
12:krb5-devel-1.15.1-8.el7 ################################# [ 60%]
13:autogen-libopts-5.18-5.el7 ################################# [ 65%]
14:ntp-4.2.6p5-25.el7.centos.2 ################################# [ 70%]
15:openssl-devel-1:1.0.2k-8.el7 ################################# [ 75%]
16:gcc-c++-4.8.5-16.el7 ################################# [ 80%]
17:openssl-1:1.0.2k-8.el7 ################################# [ 85%]
18:openssl098e-0.9.8e-29.el7.centos.################################# [ 90%]
19:tcl-1:8.5.13-8.el7 ################################# [ 95%]
Cleaning up / removing...
20:libcom_err-1.42.9-17.el7 ################################# [100%]
[root@doris54 gcc-c++]#

验证gcc、g++是否安装成功,执行命令:#

Terminal window
gcc -v

结果

Terminal window
[root@doris54 gcc-c++]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
[root@doris54 gcc-c++]#

**安装PCRE,先把pcre解压出来,tar -zxvf pcre-8.35.tar.gz,解压出来之后就要开始安装了#

Terminal window
cd pcre-8.35
./configure
make
make install

安装libtool,先解压libtool:tar -zxvf libtool-2.4.2.tar.gz,解压出来之后就要开始安装了#

Terminal window
cd libtool-2.4.2
./configure
make
make install

安装nginx,先把nginx解压出来 tar -zxvf nginx-1.20.1.tar.gz,解压出来之后就要开始安装了**#

Terminal window
cd nginx-1.20.1
./configure
make
make install

启动nginx: nginx安装目录地址 -c nginx配置文件地址 ,安装后的路径好像会被变到/usr/local里面#

常用命令操作
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf启动nginx
/usr/local/nginx/sbin/nginx -s stop停止nginx
/usr/local/nginx/sbin/nginx -s reload重启nginx
netstat -tunlp查看端口占用
netstat -tunlpgrep

nginx的配置文件为安装目录下的nginx目录中的nginx.conf,默认端口为80,启动后出现如下页面即为启动成功

开机自启#

编写自启服务#

Terminal window
vim /usr/lib/systemd/system/nginx.service
Terminal window
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

设置nginx命令#

.bash_profile
[root@node1 sbin]# vi ~/.bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
# 在原有的PATH 后加 :/usr/local/nginx/sbin
PATH={mathJaxContainer[0]}HOME/bin:/usr/local/nginx/sbin
export PATH
[root@node1 sbin]# source ~/.bash_profile
[root@node1 sbin]# nginx -v
nginx version: nginx/1.18.0

设置开机自启#

Terminal window
root@node1 ~]# systemctl enable --now nginx.service
[root@node1 ~]# ps -ef |grep nginx
root 879 1 0 16:17 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 881 879 0 16:17 ? 00:00:00 nginx: worker process
root 1738 1645 0 16:20 pts/0 00:00:00 grep --color=auto nginx
[root@node1 ~]#

启动命令#

Terminal window
# nginx start
sudo systemctl start nginx
# nginx stop
sudo systemctl stop nginx
# nginx reload
sudo systemctl reload nginx
# nginx status
sudo systemctl status nginx

银河麒麟 V10 SP3 aarch64 离线安装(RPM 方式)#

适用环境:银河麒麟 V10 SP3 aarch64(ARM 鲲鹏架构),服务器无外网,需离线安装 nginx。

为什么不能用 x86_64 的 RPM 包?#

nginx 官方 CentOS 的 aarch64 rpm 包不要直接装 ky10,glibc、openssl 版本不一样,大概率装不上、启动异常。必须用麒麟官方适配的 ky10 版本包。

必下核心包#

以下三个包版本号必须完全一致(都是 p12),不能混用不同补丁版本:

包名架构说明
nginx-1.21.5-5.p12.ky10.aarch64.rpmaarch64主程序,必选
nginx-filesystem-1.21.5-5.p12.ky10.noarch.rpmnoarch目录、配置文件结构,必选
nginx-all-modules-1.21.5-5.p12.ky10.noarch.rpmnoarch全套模块(stream、ssl、http2 等),生产推荐带上

可选(非必须):nginx-help-1.21.5-5.p12.ky10.noarch.rpm 帮助文档,服务器可以不下载。

常见报错:依赖缺失#

直接执行以下命令会报依赖错误:

Terminal window
rpm -ivh nginx-filesystem-1.21.5-5.p12.ky10.noarch.rpm nginx-1.21.5-5.p12.ky10.aarch64.rpm nginx-all-modules-1.21.5-5.p12.ky10.noarch.rpm

错误信息:

  • libprofiler.so.0() 被 nginx 需要
  • nginx-mod-http-image-filter、nginx-mod-http-perl、nginx-mod-http-xslt-filter、nginx-mod-mail、nginx-mod-stream 被 nginx-all-modules 需要

报错原因:nginx-all-modules 是元包,依赖所有单独模块包;还缺 libprofiler.so.0 这个系统依赖包(来自 gperftools-libs)。

解决方案#

方案 A:一次性装所有 RPM(本地包齐全时)#

把目录里所有 nginx 相关 RPM 一次性装进去:

Terminal window
rpm -ivh \
nginx-filesystem-1.21.5-5.p12.ky10.noarch.rpm \
nginx-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-all-modules-1.21.5-5.p12.ky10.noarch.rpm \
nginx-mod-http-image-filter-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-mod-http-perl-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-mod-http-xslt-filter-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-mod-mail-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-mod-stream-1.21.5-5.p12.ky10.aarch64.rpm

执行完上面这条,如果还报 libprofiler.so.0 缺失,需要额外安装 gperftools-libs:

Terminal window
# 去麒麟官方更新站下载
https://update.cs2c.com.cn/NS/V10/V10SP3-2403/os/adv/lic/updates/aarch64/Packages/gperftools-libs-*.ky10.aarch64.rpm
# 安装
rpm -ivh gperftools-libs-*.rpm

方案 B:精简安装(不装 all-modules,按需装模块)#

如果不需要全套模块,不要安装 nginx-all-modules,只装主程序 + filesystem + 需要的模块(大多数场景只需要 stream):

Terminal window
# 只装基础 nginx + stream 模块(常用 TCP 反向代理)
rpm -ivh \
nginx-filesystem-1.21.5-5.p12.ky10.noarch.rpm \
nginx-1.21.5-5.p12.ky10.aarch64.rpm \
nginx-mod-stream-1.21.5-5.p12.ky10.aarch64.rpm

⚠️ libprofiler.so.0 这个依赖是 nginx 主包本身的依赖,不是模块带来的,绕不开,仍需提前下好 gperftools-libs。

方案 C:本地 yum 自动解决依赖(机器可连外网时)#

把当前目录作为 yum 本地源,自动处理依赖:

Terminal window
# 先创建仓库元数据
createrepo .
# 使用本地源安装
yum localinstall *.rpm -y

前提:机器能访问麒麟在线源,yum 会自动拉取缺失的 gperftools-libs。纯断网离线环境不行,必须提前下好。

安装包下载地址#

银河麒麟官方更新站(V10 SP3 aarch64):

https://update.cs2c.com.cn/NS/V10/V10SP3-2403/os/adv/lic/updates/aarch64/Packages/

在该目录下搜索 nginx,下载所需 RPM 包。


安装后配置与验证#

1. 查看版本,确认识别成功#

Terminal window
nginx -v # 只看版本
nginx -V # 看编译参数、已加载的模块(检查 stream 等模块是否在)

2. 查看 nginx 服务状态 & 启停#

麒麟 V10 由 systemd 管理:

Terminal window
# 查看状态
systemctl status nginx
# 启动
systemctl start nginx
# 设置开机自启(生产必做)
systemctl enable nginx
# 重启(后续改配置用)
systemctl restart nginx
# 重载配置(不中断业务,改完配置优先用这个)
systemctl reload nginx

3. 检查配置文件语法(改配置前一定要跑)#

Terminal window
nginx -t

输出 test is successful 且显示 /etc/nginx/nginx.conf、/etc/nginx/conf.d/ 路径即正常。

4. 本地访问测试#

Terminal window
curl 127.0.0.1

能返回 nginx 默认欢迎页面 html,说明 web 服务正常。

5. 防火墙放行(外部访问需要)#

银河麒麟 V10 默认 firewalld:

Terminal window
# 放行 80 端口
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
# HTTPS 443 端口
firewall-cmd --add-service=https --permanent && firewall-cmd --reload

6. 常用目录备忘#

用途路径
配置文件/etc/nginx/
网页根目录/usr/share/nginx/html/
日志文件/var/log/nginx/(access.log、error.log)
pid 文件/run/nginx.pid

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
【Linux】nginx 离线安装
https://blog.huhaha.vip/posts/1c39c402/
作者
小王的博客
发布于
2024-06-16
许可协议
CC BY-NC-SA 4.0
相关文章智能推荐
1
【Linux】Libgdiplus安装
Linux在CentOS 7上安装libgdiplus的过程,以解决ASP.NET Core MVC项目在处理图片时遇到的The type initializer for ‘Gdip‘ threw an exception错误。首先,通过安装yum-utils和epel-release来获取必要的工具和仓库支持。
2
【Linux】Redis 离线安装
Linux在Linux环境下离线安装Redis的全过程。文章首先提供了Redis的下载链接及解压步骤,接着详细描述了编译和安装Redis的方法,包括解决编译过程中可能遇到的问题。随后,文章介绍了如何启动Redis服务,如何设置Redis的开机自启动,这些内容对离线环境下的Redis安装和管理非常有帮助。
3
【Linux】Nacos 问题
Linux本文《【Linux】Nacos 问题》详细记录了在Linux环境下遇到的Nacos服务连接问题及其解决方法。文章还介绍了如何配置Nacos服务的开机自启动,确保服务在系统重启后能够自动运行。这些内容对解决Nacos连接问题和提高系统稳定性非常有帮助。
4
【Linux】常用命令
Linux本文档《【Linux】常用命令》详细列出了Linux系统中常用的命令及其用法,涵盖了从基本命令、关机操作、文件和目录管理、文件搜索、文件系统的挂载与卸载、磁盘空间管理、文件权限设置、文件的特殊属性、打包和压缩文件、RPM包管理、YUM软件包升级器、DEB包管理、查看文件内容、文本处理、字符设置和文件格式转换等操作。
5
【Linux】RocketMQ 部署
Linux在Linux环境下部署RocketMQ的完整过程。文章详细说明了如何通过Docker部署RocketMQ,包括创建NameServer、Broker和RocketMQ Console的服务,并提供了相应的Docker命令和配置文件示例。
随机文章随机推荐

评论区

Profile Image of the Author
小王的博客
一个上了年纪的猿人.
分类
标签
最新动态
站点统计
文章
210
分类
15
标签
162
总字数
481,598
运行时长
0 天
最后活动
0 天前
站点信息
构建平台
Netlify CI
博客版本
Firefly v6.16.8
文章许可
CC BY-NC-SA 4.0
文章目录