Linux离线安装Nginx

Linux离线安装Nginx

参考:https://blog.csdn.net/qq_33381971/article/details/123328191
https://www.cnblogs.com/rainbow-tan/p/16448004.html

1.环境部署

(1)网络环境:

# yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

(2)离线环境:

下载依赖包:
https://download.csdn.net/download/lqh_linux/87738988
把nginxpackage.tar.gz放在/home目录下

# tar zxvf nginxpackage.tar.gz

配置本地源:

# cd /etc/yum.repos.d/
# mkdir bak
# mv *.repo bak/
# cat nginx.repo 
[docker]
name=docker
baseurl=file:///home/nginxpackage/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# createrepo -d /home/nginxpackage/
# yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

2.下载安装Nginx

官网直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html

或者:https://nginx.org/download/nginx-1.24.0.tar.gz

把下载的nginx-1.24.0.tar.gz放在/home目录下

# cd /home
# mkdir nginx
# tar zxvf nginx-1.24.0.tar.gz
#  cd nginx-1.24.0
# ./configure --prefix=/home/nginx --with-http_stub_status_module --with-http_ssl_module
# make
# make install

3.把Nginx添加到systemctl

# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/home/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /home/nginx/logs/nginx.pid
ExecStartPre=/home/nginx/sbin/nginx -t
ExecStart=/home/nginx/sbin/nginx
ExecReload=/home/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
#  systemctl daemon-reload
[root@localhost sbin]# systemctl start nginx 
[root@localhost sbin]# systemctl enable nginx 
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost sbin]# systemctl status nginx 
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2023-04-28 14:58:07 CST; 2min 36s ago
 Main PID: 17884 (nginx)
   CGroup: /system.slice/nginx.service
           ├─17884 nginx: master process /home/nginx/sbin/nginx
           └─17885 nginx: worker process

428 14:58:07 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
428 14:58:07 localhost.localdomain nginx[17880]: nginx: the configuration file /home/nginx/conf/nginx.conf syntax is ok
428 14:58:07 localhost.localdomain nginx[17880]: nginx: configuration file /home/nginx/conf/nginx.conf test is successful
428 14:58:07 localhost.localdomain systemd[1]: Failed to parse PID from file /home/nginx/logs/nginx.pid: Invalid argument
428 14:58:07 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.

验证:
Linux离线安装Nginx_第1张图片

你可能感兴趣的:(linux,bash,运维)