1、准备编译安装环境
[root@node1 ~]# yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel nettools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
2、下载源码包
下载地址:http://nginx.org/en/download.html
[root@node1 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@node1 ~]# tar -zxf nginx-1.18.0.tar.gz -C /usr/local/src/
[root@node1 ~]# cd /usr/local/src/nginx-1.18.0/
3、安装
3.1、根据参数生成Makefile
[root@node1 nginx-1.18.0]# ./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
–prefix=/apps/nginx 指定安装路径
3.2、编译安装
[root@node1 nginx-1.18.0]# make
[root@node1 nginx-1.18.0]# make install
[root@node1 nginx-1.18.0]# useradd nginx -s /sbin/nologin -u 2000
[root@node1 nginx-1.18.0]# chown nginx:nginx -R /apps/nginx/
3.3、验证版本及编译参数
[root@node1 nginx-1.18.0]# /apps/nginx/sbin/nginx -V
nginx version: nginx/1.18.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=/apps/nginx --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
3.4、创建nginx自启动脚本
[root@node1 nginx-1.18.0]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /apps/nginx/logs/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /apps/nginx/logs/nginx.pid)"
[Install]
WantedBy=multi-user.target
3.5、验证自启动脚本
[root@node1 nginx-1.18.0]# systemctl daemon-reload
[root@node1 nginx-1.18.0]# systemctl start nginx
[root@node1 nginx-1.18.0]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@node1 nginx-1.18.0]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-01-28 17:20:13 CST; 41s ago
Docs: http://nginx.org/en/docs/
Main PID: 4583 (nginx)
CGroup: /system.slice/nginx.service
├─4583 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
└─4584 nginx: worker process
Jan 28 17:20:13 node1 systemd[1]: Starting nginx - high performance web server...
Jan 28 17:20:13 node1 systemd[1]: Can't open PID file /apps/nginx/logs/nginx.pid (yet?) after start: No such file or directory
Jan 28 17:20:13 node1 systemd[1]: Started nginx - high performance web server.