Linux下Nginx编译安装后的开机自启动设置

简介: Linux下Nginx编译安装后的开机自启动设置

一、查看当前Nginx启动状态

[root@node1 sbin]# ps -ef |grep nginx
root      39424      1  0 14:01 ?        00:00:00 nginx: master process ./nginx
nobody    39425  39424  0 14:01 ?        00:00:00 nginx: worker process
root      40313   1884  0 15:41 pts/0    00:00:00 grep --color=auto nginx

二、而配置Nginx相关服务文件

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

三 、设置nginx命令

[root@node1 sbin]# cat  ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH={
   mathJaxContainer[0]}HOME/bin:/usr/local/nginx/sbin


export PATH
[root@node1 sbin]# source ~/.bash_profile 
[root@node1 sbin]# nginx -v
nginx version: nginx/1.18.0
[root@node1 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@node1 ~]# systemctl enable --now  nginx.service
[root@node1 ~]# ps -ef |grep nginx
root        879      1  0 16:17 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody      881    879  0 16:17 ?        00:00:00 nginx: worker process
root       1738   1645  0 16:20 pts/0    00:00:00 grep --color=auto nginx
[root@node1 ~]#

五、测试开机启动

[root@node1 ~]# systemctl status nginx
● nginx.service - nginx
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-05-08 16:17:54 CST; 45s ago
  Process: 872 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 879 (nginx)
    Tasks: 2 (limit: 12404)
   Memory: 2.5M
   CGroup: /system.slice/nginx.service
           ├─879 nginx: master process /usr/local/nginx/sbin/nginx
           └─881 nginx: worker process

May 08 16:17:54 node1 systemd[1]: Starting nginx...
May 08 16:17:54 node1 systemd[1]: Started nginx.
相关文章
|
27天前
|
安全 Linux iOS开发
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
117 6
Nessus Professional 10.10 Auto Installer for RHEL 10, AlmaLinux 10, Rocky Linux 10 - Nessus 自动化安装程序
|
27天前
|
消息中间件 Kafka Linux
Linux下安装Kafka 3.9.1
本文介绍Kafka 3.9.1版本的安装与配置,包括通过ZooKeeper或KRaft模式启动Kafka。涵盖环境变量设置、日志路径修改、集群UUID生成、存储格式化及服务启停操作,适用于Linux环境下的部署实践。
178 0
|
3月前
|
网络协议 关系型数据库 Linux
【App Service Linux】在Linux App Service中安装 tcpdump 并抓取网络包
在App Service for Linux环境中,无法像Windows一样直接使用网络排查工具抓包。本文介绍了如何通过TCPDUMP在Linux环境下抓取网络包,包括SSH进入容器、安装tcpdump、执行抓包命令及下载分析文件的完整操作步骤。
177 5
|
3月前
|
弹性计算 安全 Linux
阿里云服务器ECS安装宝塔Linux面板、安装网站(新手图文教程)
本教程详解如何在阿里云服务器上安装宝塔Linux面板,涵盖ECS服务器手动安装步骤,包括系统准备、远程连接、安装命令执行、端口开放及LNMP环境部署,手把手引导用户快速搭建网站环境。
|
NoSQL Java Linux
linux 安装 neo4j简介
Neo4j是高性能NoSQL图形数据库,利用图结构存储数据。推荐使用JDK 11配合Neo4j 3.x版本。下载3.5.9版,通过`curl`命令在Linux上获取tar.gz文件,然后解压。配置`neo4j.conf`,调整内存设置,开启远程访问。执行`./bin/neo4j start`启动,通过`http://服务器IP:7474`访问,默认凭据是username: neo4j, password: neo4j,登录后应更改密码。
1367 1
|
存储 缓存 Ubuntu
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(二)
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(二)
342 0
|
Ubuntu 安全 Unix
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(一)
【嵌入式开发】 Linux Kernel 下载 配置 编译 安装 及 驱动简介(一)
426 0