Nginx+Center OS 7.2 开机启动设置(转载)
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=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.设置开机启动
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
转载于:https://my.oschina.net/u/3054299/blog/868069
- 点赞
- 收藏
- 分享
- 文章举报
- Nginx+Center OS 7.2 开机启动设置(转载)
- Nginx+Center OS 7.2 开机启动设置(转载)
- Nginx+Center OS 7.2 开机启动设置(转载)
- Nginx+Center OS 7.2 开机启动设置(转载)
- Nginx+Center OS 7.2 开机启动设置
- Nginx+Center OS 7.2 开机启动设置
- Centos7 Nginx开机启动设置(转载)
- Linux(Centos)下设置nginx开机启动
- Linux(CentOS)下设置开机自动启动和chkconfig管理(nginx为例)
- windows下设置Nginx开机自动启动
- centos6.9下设置nginx服务开机自动启动
- 设置Nginx开机自动启动(centos6.8上亲测可用)
- 设置nginx开机自动启动方法
- 3分钟叫你Linux下设置nginx开机启动
- centos设置nginx开机启动
- nginx设置成服务并开机自动启动
- Mac 通过 Homebrew 安装 nginx 并设置开机启动配置
- CentOS下设置nginx开机自动启动和chkconfig管理
- nginx 设置服务,开机启动
- Linux/Centos7设置nginx开机自启动