主题
OpenEuler 22.03 LTS-SP4 源码编译安装nginx1.28.0
一、版本约束
软件的不同版本,在使用起来都有可能带来不可预知的影响,因此需要统一整理,固定下来,不允许轻易变更。
在Nginx开源版官网,点击右侧download可以看到各个版本的Nginx,其中Mainline是抢先的主干版本(版本号是奇数),Stable是稳定版(版本号是偶数)
系统环境,软件版本
- OpenEuler22.03 LTS SP4
- nginx: 1.28.0
二、软件安装路径
部署路径
/home/application/nginx
静态代码路径
/home/application/nginx/html
日志路径
/home/application/nginx/logs
配置文件路径
- [主配置文件]
/home/application/nginx/conf/nginx.conf
- [从配置文件]
/home/application/nginx/conf.d/*
- [主配置文件]
ssl证书路径
/home/application/nginx/cert
三、安装
3.1 下载
bash
wget http://nginx.org/download/nginx-1.28.0.tar.gz
3.2 安装依赖
安装依赖包,NGINX是C语言写的,pcre-devel支持正则表达式,openssl 开启加密
bash
yum -y install gcc pcre-devel openssl-devel tar make zlib zlib-devel
3.3 创建nginx用户
bash
useradd -s /sbin/nologin nginx -M
3.4 指定安装目录
TIP
启用 HTTP/2 模块;启用 SSL 模块;启用 Stub Status 模块;启用4 层TCP/UDP 代理模块;启用 Gzip 静态模块
bash
## 创建 nginx 工作目录
mkdir /home/application/nginx
tar -xf nginx-1.28.0.tar.gz
cd nginx-1.28.0
./configure --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_v2_module --with-http_ssl_module --with-http_stub_status_module --with-stream --with-http_gzip_static_module --pid-path=/home/application/nginx/nginx.pid
3.5 编译安装
bash
make && make install
3.6 服务启动
3.6.1 编写 nginx.service 文件
TIP
这里 service 文件定义了 pid 文件路径,那么nginx.conf 中也必须需要这样定义 pid 的路径!
bash
cat >> /lib/systemd/system/nginx.service < 'EOF'
[Unit]
Description=The NGINX HTTP and reverse proxy server
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStart=/home/application/nginx/sbin/nginx
ExecReload=/home/application/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
3.6.2 修改 nginx.conf 主配置文件
bash
....
user nginx;
pid /run/nginx.pid;
...
3.6.3 服务启动
bash
systemctl daemon-reload
systemctl enable nginx
systemctl start nginx
四、平滑升级步骤
4.1 下载
bash
wget https://nginx.org/download/nginx-1.29.1.tar.gz
4.2 解压
bash
tar xf nginx-1.29.1.tar.gz
4.3 查看原先使用的模块
bash
[root@nginx ~]# nginx -V
nginx version: nginx/1.28.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream
4.4 编译安装
bash
cd nginx-1.29.1
./configure --prefix=/home/application/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream
make
4.5 复制启动文件
bash
mv /home/application/nginx/sbin/nginx /home/application/nginx/sbin/nginx-old
cp nginx-1.29.1/objs/nginx /home/application/nginx/sbin/
4.6 平滑升级
bash
make upgrade
4.7 查看版本
bash
/home/application/nginx/sbin/ -v