nginx的安装002

时间:2024-06-02 08:17:03

   之前001讲述了nginxyum安装现在讲一下nginx如何本地离线安装


操作系统:

CentOS Stream 9

操作步骤:

首先访问nginx官网,下载。

用wget命令下载,

[root@localhost ~]# wget -c https://nginx.org/download/nginx-1.26.0.tar.gz
-bash: wget:未找到命令
[root@localhost ~]# yum -y install wget
CentOS Stream 9 - BaseOS                                 3.8 kB/s | 6.7 kB     00:01    
CentOS Stream 9 - BaseOS                                 372 kB/s | 8.1 MB     00:22    
CentOS Stream 9 - AppStream                              3.9 kB/s | 6.5 kB     00:01    
CentOS Stream 9 - AppStream                               34 kB/s |  19 MB     09:39    A
CentOS Stream 9 - Extras packages                        2.2 kB/s | 4.8 kB     00:02    
依赖关系解决。
=========================================================================================
 软件包          架构              版本                       仓库                  大小
=========================================================================================
安装:
 wget            x86_64            1.21.1-7.el9               appstream            789 k

事务概要
=========================================================================================
安装  1 软件包

总下载:789 k
安装大小:3.1 M
下载软件包:
wget-1.21.1-7.el9.x86_64.rpm                              62 kB/s | 789 kB     00:12    
-----------------------------------------------------------------------------------------
总计                                                      51 kB/s | 789 kB     00:15     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                          1/1 
  安装    : wget-1.21.1-7.el9.x86_64                                                 1/1 
  运行脚本: wget-1.21.1-7.el9.x86_64                                                 1/1 
  验证    : wget-1.21.1-7.el9.x86_64                                                 1/1 

已安装:
  wget-1.21.1-7.el9.x86_64                                                               

完毕!
[root@localhost ~]# wget -c https://nginx.org/download/nginx-1.26.0.tar.gz
--2024-05-31 21:15:56--  https://nginx.org/download/nginx-1.26.0.tar.gz
正在解析主机 nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:5c0:2600::6, ...
正在连接 nginx.org (nginx.org)|3.125.197.172|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1244118 (1.2M) [application/octet-stream]
正在保存至: “nginx-1.26.0.tar.gz”

nginx-1.26.0.tar.gz    100%[=========================>]   1.19M  14.5KB/s  用时 62s     

2024-05-31 21:17:02 (19.5 KB/s) - 已保存 “nginx-1.26.0.tar.gz” [1244118/1244118])

[root@localhost ~]# 

解压并进入

[root@localhost ~]# tar xf nginx-1.26.0.tar.gz
[root@localhost ~]# cd nginx-1.26.0
[root@localhost nginx-1.26.0]# 

下载安装所依赖环境

[root@localhost nginx-1.26.0]# yum -y install gcc gcc-c++ make autoconf pcre-devel zlib-devel openssl-devel
上次元数据过期检查:0:09:07 前,执行于 2024年05月31日 星期五 21时14分21秒。
依赖关系解决。
=========================================================================================
 软件包                       架构         版本                    仓库             大小
=========================================================================================
安装:
 autoconf                     noarch       2.69-38.el9             appstream       681 k
 gcc                          x86_64       11.4.1-3.el9            appstream        32 M
 gcc-c++                      x86_64       11.4.1-3.el9            appstream        13 M
 make                         x86_64       1:4.3-8.el9             baseos          536 k
 
 perl-Pod-Perldoc             noarch       3.28.01-461.el9         appstream        87 k
 perl-Pod-Simple              noarch       1:3.42-4.el9            appstream       225 k
 perl-Pod-Usage               noarch       4:2.01-4.el9            appstream        41 k
 perl-Scalar-List-Utils       x86_64       4:1.56-462.el9          appstream        71 k
 perl-SelectSaver             noarch       1.02-481.el9            appstream        11 k
 perl-Socket                  x86_64       4:2.031-4.el9           appstream        56 k
 perl-Storable                x86_64 

选择安装路径

[root@localhost nginx-1.26.0]# ./configure --prefix=/usr/local/nginx --with-debug --with-stream ; echo $?
checking for OS
 + Linux 5.14.0-427.el9.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
'''
...
Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

0

预编译

[root@localhost nginx-1.26.0]# grep -c processor /proc/cpuinfo
4
[root@localhost nginx-1.26.0]# make -j `grep -c processor /proc/cpuinfo`
make -f objs/Makefile
make[1]: 进入目录“/root/nginx-1.26.0”
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_log.o \
	src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_palloc.o \
	src/core/ngx_palloc.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_array.o \
	src/core/ngx_array.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_list.o \
	src/core/ngx_list.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_hash.o \
	src/core/ngx_hash.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_buf.o \
	src/core/ngx_buf.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \
	-o objs/src/core/ngx_queue.o \
	src/core/ngx_queue.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/event/quic -I src/os/unix -I objs \

正式编译

[root@localhost nginx-1.26.0]# make install ; echo $?
make -f objs/Makefile install
make[1]: 进入目录“/root/nginx-1.26.0”
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
	'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
	'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
	'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
	|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
make[1]: 离开目录“/root/nginx-1.26.0”
0
[root@localhost nginx-1.26.0]# 
离开安装编译 nginx 的目录 ,查看安装后的目录
[root@localhost nginx-1.26.0]# cd
[root@localhost ~]# ls -lhrt /usr/local/nginx/
总用量 4.0K
drwxr-xr-x 2 root root   19  5月 31 22:09 sbin
drwxr-xr-x 2 root root 4.0K  5月 31 22:09 conf
drwxr-xr-x 2 root root    6  5月 31 22:09 logs
drwxr-xr-x 2 root root   40  5月 31 22:09 html
[root@localhost ~]# 

检测配置语法,并启动nginx

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# /usr/local/nginx/sbin/nginx

查看端口和进程

[root@localhost ~]# ss -tulanp | grep nginx
tcp   LISTEN 0      511          0.0.0.0:80        0.0.0.0:*     users:(("nginx",pid=11524,fd=6),("nginx",pid=11523,fd=6),("nginx",pid=11522,fd=6),("nginx",pid=11521,fd=6),("nginx",pid=11520,fd=6))
tcp   LISTEN 0      511             [::]:80           [::]:*     users:(("nginx",pid=11524,fd=7),("nginx",pid=11523,fd=7),("nginx",pid=11522,fd=7),("nginx",pid=11521,fd=7),("nginx",pid=11520,fd=7))
[root@localhost ~]# ps axu | grep nginx
root       11520  0.0  0.0  10112  2080 ?        Ss   19:23   0:00 nginx: master processnginx
nginx      11521  0.0  0.1  14388  5536 ?        S    19:23   0:00 nginx: worker process
nginx      11522  0.0  0.1  14388  4768 ?        S    19:23   0:00 nginx: worker process
nginx      11523  0.0  0.1  14388  5024 ?        S    19:23   0:00 nginx: worker process
nginx      11524  0.0  0.1  14388  5024 ?        S    19:23   0:00 nginx: worker process
root       20660  0.0  0.0   6636  2176 pts/1    R+   22:18   0:00 grep --color=auto nginx
[root@localhost ~]# 

操作结果: