centos 7上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度。关于Systemd的详情介绍在这里

Systemd服务文件以.service结尾,比如现在要建立nginx为开机启动,如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令

 systemcel enable nginx.service

设置开机启动即可。
在这里我是用源码编译安装的,所以要手动创建nginx.service服务文件。
开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:

/lib/systemd/system/

1.在系统服务目录里创建nginx.service文件

vi /lib/systemd/system/nginx.service

编辑如下内容

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

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

保存退出。

2.设置开机启动

启动nginx服务

systemctl start nginx.service 

设置开机自启动

systemctl enable nginx.service

停止开机自启动

systemctl disable nginx.service

查看服务当前状态

systemctl status nginx.service

重新启动服务

systemctl restart nginx.service 

查看所有已启动的服务

systemctl list-units --type=service

原址:https://blog.csdn.net/qq_36441027/article/details/80636526

CentOS7+Nginx设置Systemctl restart nginx.service服务的更多相关文章

  1. 重启ssh服务出现Redirecting to /bin/systemctl restart sshd.service

    转自:https://blog.csdn.net/caijunfen/article/details/70599138 CentOs 重启ssh服务的命令如下: # service sshd rest ...

  2. centos7也支持service命令启动服务吗,对于centos7 中的systemctl和旧的service命令的区别和联系

    一.centos7也支持service命令启动服务吗 CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服 ...

  3. Centos7下的systemctl命令与service和chkconfig

    博主使用的操作系统是最新的CentOS 7,所以可能和网上一些老的博文有一定出入,那是因为版本更新的原因. 这里写图片描述1 service service命令用于对系统服务进行管理,比如启动(sta ...

  4. 安装和启动tftp-server服务器及可能出现Redirecting to /bin/systemctl restart xinetd.service问题的解决方式

    安装和启动tftp-server服务器及可能出现Redirecting to /bin/systemctl restart xinetd.service问题的解决方式 1)首先,检查服务器已安装的tf ...

  5. 阿里云报错Redirecting to /bin/systemctl restart sshd.service

    转:http://blog.csdn.net/caijunfen/article/details/70599138 云服务器 ECS Linux CentOS 7 下重启服务不再通过 service  ...

  6. 【linux】CentOS 6 使用cron定时任务,报错:Redirecting to /bin/systemctl restart crond.service

    在centos7上,执行cron定时任务的相关命令,反馈如下: 定时任务执行,反馈是: Redirecting to /bin/systemctl restart crond.service 原因: ...

  7. Linux Redirecting to /bin/systemctl restart iptables.service

    方案 一 1.昨天碰到一个错误,linux下输入命令:service iptables restart时,总会报下面一个提示很简单,这句话的意思就是让你重定向到systemctl然后再启用,白话就是说 ...

  8. Redirecting to /bin/systemctl restart mysql. service Failed to restart mysql.service: Unit not found.

    使用如下命令操作mysql即可: systemctl restart mysqld.service systemctl start mysqld.service systemctl stop mysq ...

  9. 把ngnix注册为linux服务 将Nginx设置为linux下的服务 并设置nginx开机启动

    一.创建服务脚本 vim /etc/init.d/nginx 脚本内容如下 #! /bin/sh# chkconfig: - 85 15 PATH=/usr/local/nginx/sbin/ DES ...

随机推荐

  1. 关于web开发中,图片加载失败替换为默认图片

    页面上有用户自定义图片的时候经常会出现用户定义的图片特别是站外图片被删除或无法访问,因此,需要判断图片是否能成功被加载,否则自动换成“无法找到图片”之类的系统图片. document.body.onl ...

  2. 用MVC5+EF6+WebApi 做一个小功能(二) 项目需求整理

    在一个项目开始前,需求整理大概要占到整个项目周期15%甚至30%的比重,可以说需求理得越清楚,后续开发中返工几率越小.在一个项目中,开发新功能的花费的精力要远远小于修改功能的精力,这基本是一个共识.老 ...

  3. Java基本——数据类型

    一.创建一个简单的Java应用程序 public class Code { public static void main(String[]args) { System.out.println(&qu ...

  4. 不依赖AIDL的跨进程通信

    http://blog.csdn.net/lmj623565791/article/details/38461079 如果知道AIDL和binder的原理,可以简单写一个不依赖AIDL的跨进程通信 不 ...

  5. LOJ1070(SummerTrainingDay05-B 矩阵快速幂)

    Algebraic Problem Given the value of a+b and ab you will have to find the value of an+bn. a and bnot ...

  6. 数据库概念:码 键 Key & 范式 Normal Form

    参考资料 数据库管理系统原理与设计(Database Mangement System 3rd) 百度 wiki 术语对照 码 = 键 = Key 码约束 = Key Constraints 码约束 ...

  7. thymeleaf标签使用方法总结

    https://blog.csdn.net/quuqu/article/details/52511933 常用th标签https://www.cnblogs.com/suncj/p/4030393.h ...

  8. css3统一元素的宽和高

    通常我们设置元素的宽和高样式经常会出现一些问题,比如以下css的设置: 比如以下的代码: <!DOCTYPE html> <html> <head> <met ...

  9. java持有对象【1】容器类及ArrayList

    如果一个程序只包含固定数量的且其生命周期都是已知的对象,那么这是一个非常简单的程序.  ----------java编程思想第十一章引言 java有许多方式引用对象,例如学过的数组,他是编译器支持的类 ...

  10. 团队项目个人进展——Day09

    一.昨天工作总结 冲刺第九天,把地图和界面整合了一下 二.遇到的问题 地图的样式和一些公共样式有冲突 三.今日工作规划 团队共同整合程序,做出第一阶段的成品.