CentOS 7以上版本Nginx开机自启
Nginx+Center OS 7.x 开机启动设置
centos 7以上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度。关于Systemd的详情介绍在这里。
Systemd服务文件以.service结尾,比如现在要建立nginx为开机启动,如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令
|
1
|
systemcel enable nginx.service |
设置开机启动即可。
在这里我是用源码编译安装的,所以要手动创建nginx.service服务文件。
开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:
|
1
|
/lib/systemd/system/ |
1.在系统服务目录里创建nginx.service文件
|
1
|
vi /lib/systemd/system/nginx.service |
内容如下
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[Unit]Description=nginxAfter=network.target [Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true [Install]WantedBy=multi-user.target |
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
保存退出。
2.设置开机启动
|
1
|
systemctl enable nginx.service |
3.其他命令
启动nginx服务
|
1
|
systemctl start nginx.service |
设置开机自启动
|
1
|
systemctl enable nginx.service |
停止开机自启动
|
1
|
systemctl disable nginx.service |
查看服务当前状态
|
1
|
systemctl status nginx.service |
重新启动服务
|
1
|
systemctl restart nginx.service |
查看所有已启动的服务
|
1
|
systemctl list-units --type=service |
4.Systemd 命令和 sysvinit 命令的对照表

5.Sysvinit 运行级别和 systemd 目标的对应表

原文地址:http://www.dohooe.com/2016/03/03/352.html?utm_source=tuicool&utm_medium=referral
CentOS 7以上版本Nginx开机自启的更多相关文章
- Linux下设置Nginx开机自启
1.本地环境 [root@dev ~]#cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) 2.在/etc/init.d创建ngi ...
- Centos8 Nginx 开机自启配
第一步:创建 service文件 vim /lib/systemd/system/nginx.service /lib 与 /usr/lib 我这里配置时是一样的,在那个文件夹配置都可以 第二步:编写 ...
- Linux(CentOS)系统下设置nginx开机自启动
Nginx 是一个很强大的高性能Web和反向代理服务器.下面介绍在linux下安装后,如何设置开机自启动.首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:vi ...
- Nginx开机自启
编写service脚本: vim /usr/lib/systemd/system/nginx.service 将以下内容复制到nginx.service文件中 ps:我的nginx目录是/usr/lo ...
- linux tomcat开机自启/nginx开机自启
修改/etc/rc.d/rc.local文件,修改完成后需执行以下指令才能正常自启动 chmod +x /etc/rc.d/rc.local #!/bin/bash # THIS FILE IS AD ...
- nginx的开机自启、server命令启动、nginx.conf配置
1.将Nginx设置为开机自动启动 a.当上面6步完成之后,说明安装已经完全成功了,但是每次开机我们面临的一个问题,就是每次都要执行命令(1: cd /usr/local/nginx/sbin/ ...
- CentOS 7.4安装Nginx 1.14.0
一.安装所需环境 1.gcc 安装 yum install gcc-c++
- (2)Ngixn 编译安装设置开机自启
设置nginx开机自启 #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 ...
- CentOS环境部署(Nginx+Mariadb+Java+Tomcat)
1.安装nginx 安装 yum install nginx 启动 yum install nginx 开机自启 sudo systemctl enable nginx 2.安装mariadb 安装 ...
随机推荐
- BZOJ2795&2890&3647[Poi2012]A Horrible Poem——hash
题目描述 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节.如果字符串B是字符串A的循环节,那么A可以由B重复若干次得到. 输入 第一行一个正整数n (n<= ...
- APICloud之封装webApp
注册用户 https://www.apicloud.com/ 使用步骤 进入开发控制台 创建应用 选择webApp 根据自己的情况填写信息,然后创建即可 应用创建后的界面 端设置 app界面设置 证书 ...
- Codeforces Round #418 (Div. 2) B. An express train to reveries
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Hard Rock
Ilya is a frontman of the most famous rock band on Earth. Band decided to make the most awesome musi ...
- day30 item系列
item 会将数据操作类似于字典的操作具体用到的方法 __getitem__(self, item): __setitem__(self, key, value): __delitem__(self, ...
- mysql case when 判断null
select name,case WHEN m.NAME is null THEN '' else m.NAME end NAME1 from sys_users
- MT【73】求函数表达式
评:由关系式求表达式最经典的莫过于已知$f(x+y)=f(x)f(y)$利用柯西法求得 $f(x)=[f(1)]^x$
- 【BZOJ1802】[AHOI2009]checker(动态规划)
[BZOJ1802][AHOI2009]checker(动态规划) 题面 BZOJ 洛谷 题解 首先自己观察一波,发现如果有相邻两个格子都是红色的话,那么显然可以在任意位置都存在一个跳棋.可以让两个位 ...
- A1010. Radix
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- 斯坦福大学公开课机器学习:梯度下降运算的特征缩放(gradient descent in practice 1:feature scaling)
以房屋价格为例,假设有两个特征向量:X1:房子大小(1-2000 feets), X2:卧室数量(1-5) 关于这两个特征向量的代价函数如下图所示: 从上图可以看出,代价函数是一个又瘦又高的椭圆形轮廓 ...