DengQN·一个普通程序员;
【Crud Boy日常】nginx 部署记录
2024-06-06 18:29 116
#linux#nginx#运维

说明

  • 源码目录 /root/soft/nginx-1.26.1
  • 安装目录 /usr/sbin/nginx
  • 配置文件 /etc/nginx/nginx.conf
  • 日志目录 /var/log/nginx
  • 服务管理 /lib/systemd/system/nginx.service

安装依赖

yum install -y gcc make pcre pcre-devel zlib zlib-devel openssl openssl-devel

编译

  1. configure
bash 复制代码
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads

正常输出:

log 复制代码
checking for getaddrinfo() ... found
checking for PCRE2 library ... not found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/lib64/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/tmp/client_body"
  nginx http proxy temporary files: "/var/lib/nginx/tmp/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/tmp/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/tmp/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/tmp/scgi"
  1. make
bash 复制代码
make

正常输出:

log 复制代码
objs/src/stream/ngx_stream_upstream_zone_module.o \
objs/src/stream/ngx_stream_ssl_preread_module.o \
objs/ngx_stream_module_modules.o \
-shared
sed -e "s|%%PREFIX%%|/usr/share/nginx|" \
        -e "s|%%PID_PATH%%|/run/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/etc/nginx/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/var/log/nginx/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: 离开目录“/root/soft/nginx-1.26.1”

安装

将会安装到/usr/share/nginx

bash 复制代码
make install

正常输出:

log 复制代码
test -d '/var/log/nginx' \
        || mkdir -p '/var/log/nginx'
test -d '/usr/lib64/nginx/modules' \
        || mkdir -p '/usr/lib64/nginx/modules'
test ! -f '/usr/lib64/nginx/modules/ngx_mail_module.so' \
        || mv '/usr/lib64/nginx/modules/ngx_mail_module.so' \
                '/usr/lib64/nginx/modules/ngx_mail_module.so.old'
cp objs/ngx_mail_module.so '/usr/lib64/nginx/modules/ngx_mail_module.so'
test ! -f '/usr/lib64/nginx/modules/ngx_stream_module.so' \
        || mv '/usr/lib64/nginx/modules/ngx_stream_module.so' \
                '/usr/lib64/nginx/modules/ngx_stream_module.so.old'
cp objs/ngx_stream_module.so '/usr/lib64/nginx/modules/ngx_stream_module.so'
make[1]: 离开目录“/root/soft/nginx-1.26.1”

配置服务

创建文件 /lib/systemd/system/nginx.service

bash 复制代码
[Unit]
Description=nginx service
After=network.target 
   
[Service] 
Type=forking 
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true
[Install] 
WantedBy=multi-user.target

执行

刷新并启动,enable 为开机自启

bash 复制代码
systemctl daemon-reload
systemctl start nginx
systemctl enable nginx

正常情况:

bash 复制代码
[root@localhost nginx-1.26.1]# systemctl start nginx
[root@localhost nginx-1.26.1]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost nginx-1.26.1]# ps -ef | grep nginx
30960     1  0 16:28 ?        00:00:00 nginx: master process /usr/sbin/nginx
30961 30960  0 16:28 ?        00:00:00 nginx: worker process
30962 30960  0 16:28 ?        00:00:00 nginx: worker process
30963 30960  0 16:28 ?        00:00:00 nginx: worker process
30964 30960  0 16:28 ?        00:00:00 nginx: worker process
30965 30960  0 16:28 ?        00:00:00 nginx: worker process
30966 30960  0 16:28 ?        00:00:00 nginx: worker process
30967 30960  0 16:28 ?        00:00:00 nginx: worker process
30968 30960  0 16:28 ?        00:00:00 nginx: worker process
31013 21622  0 16:28 pts/1    00:00:00 grep --color=auto nginx
[root@localhost nginx-1.26.1]#