方式一:

 # 在/etc/rc.d/rc.local文件中追加启动命令,该文件追加后,会随着机器自动后,自动运行文件中的命令
# vim /etc/rc.d/rc.local # 权限问题:在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限(如遇权限问题,请执行此命令)
# chmod +x /etc/rc.d/rc.local

方式二:

Centos 系统服务脚本目录:

 # /usr/lib/systemd/  
有系统(system)和用户(user)之分,
如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:
 # /lib/systemd/system/  
反之,用户登录后才能运行的程序,存在用户(user)里
服务以.service结尾。
这边以nginx开机运行为例
 
1.建立服务文件
 # vim /lib/systemd/system/nginx.service  
 [Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/www/lanmps/init.d/nginx start
ExecReload=/www/lanmps/init.d/nginx restart
ExecStop=/www/lanmps/init.d/nginx stop
PrivateTmp=true [Install]
WantedBy=multi-user.target
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]服务安装的相关设置,可设置为多用户
 
2.保存目录
以754的权限保存在目录:
 # /lib/systemd/system  
3.设置开机自启动
 # systemctl enable nginx.service  

4.其他命令

使某服务自动启动
chkconfig --level 3 httpd  on 
systemctl enable httpd.service
使某服务不自动启动
chkconfig --level 3 httpd off
systemctl disable httpd.service
检查服务状态
service httpd status
systemctl status httpd.service (服务详细信息) 
systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务
chkconfig --list
systemctl list-units --type=service
启动某服务
service httpd start
systemctl start httpd.service
停止某服务
service httpd stop
systemctl stop httpd.service
重启某服务
service httpd restart
systemctl restart httpd.service

启动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://www.cnblogs.com/yanglang/p/10523095.html

CentOS7设置开机自启动方式的更多相关文章

  1. CentOS7设置开机自启动命令大全

    任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd  on              systemctl enable httpd.service 使某服务不自 ...

  2. [CentOS7] 设置开机启动方式(图形界面或命令行)

    由于CenOS之前一直都是通过修改inittab文件来修改开机启动模式,于是 通过 vim /etc/inittab 打开inittab来查看 如上所示,CentOS 7由于使用systemd而不是i ...

  3. CentOS7设置开机启动方式(图形界面/命令行界面)

    CentOS 7由于使用systemd而不是init,所以不能通过修改inittab文件来修改开机启动模式. 先使用ctrl+alt+f2切换到命令行模式,然后输入命令:systemctl set-d ...

  4. redis的安装与设置开机自启动

    redis 的安装配置: 可以直接去官网下载((https://redis.io/download) 解压文件到指定目录下  tar zxvf redis-5.0.7.tar.gz -C  /opt/ ...

  5. Fedora 16设置开机自启动程序与Ubuntu的区别

    Ubuntu设置开机自启动脚本的方法是:修改/etc/init.d/rc.local这个文件,添加需要启动的程序即可,相关函数如下: void SetSysAutoBoot() { ] = {}; ; ...

  6. linux_设置开机自启动程序脚本

    设置开机自启动

  7. Linux服务器,服务管理--systemctl命令详解,设置开机自启动

    Linux服务器,服务管理--systemctl命令详解,设置开机自启动 syetemclt就是service和chkconfig这两个命令的整合,在CentOS 7就开始被使用了. 摘要: syst ...

  8. CentOS 6下 Oracle11gR2 设置开机自启动

    [1] 更改/etc/oratab # This file is used by ORACLE utilities. It is created by root.sh # and updated by ...

  9. Ubuntu14.04设置开机自启动脚本

    方法一.编辑rc.loacl脚本  Ubuntu开机之后会执行/etc/rc.local文件中的脚本,所以我们可以直接在/etc/rc.local中添加启动脚本.在 exit 0 前面添加好脚本代码, ...

随机推荐

  1. EM13C添加agent记录两个报错

    错误一:ADF_FACES-60097:For more information, please see the server's error log for an entry beginning w ...

  2. Oracle 10g&11g安装卸载Oracle Label Security

    Oracle Label Securit简介   Oracle Label Security是内置于数据库引擎中的过程与约束条件集,该数据引擎实施对在单个表或整个模式上的"行"级访 ...

  3. Linux下查看哪些进程占用的CPU、内存资源

    1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10个进程 ps auxw|head -1;ps a ...

  4. 201871010124 王生涛《面向对象程序设计JAVA》第一周学习总结

    项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://edu.cnblogs.com/campus/xbsf/ ...

  5. python直接赋值、浅拷贝、深拷贝的区别

    一:直接赋值 赋值,就是对象的引用,给对象起别名. i = 8j = iprint("值是:",i, "地址:",id(i))print("值是:&q ...

  6. 配置SQL Server维护计划-定时备份

    目录 创建维护计划 创建任务 配置维护计划的依赖环境 还原数据库 创建维护计划 打开SQL Server 2014 Management Studio,用SQL Server管理员账户登录. 展开Ma ...

  7. 基于TCP协议的socket套接字编程

    目录 一.什么是Scoket 二.套接字发展史及分类 2.1 基于文件类型的套接字家族 2.2 基于网络类型的套接字家族 三.套接字工作流程 3.1 服务端套接字函数 3.2 客户端套接字函数 3.3 ...

  8. Linux 小工具

    1. 截图工具 shutter 安装 sudo add-apt-repository ppa:shutter/ppa sudo apt-get update sudo apt-get install ...

  9. Unity 利用Cinemachine快速创建灵活的相机系统

    在第一或第三人称ACT和FPS游戏中,相机的运动需求是多种多样的,Unity内置的Cinemachine包可以助你快速实现不同相机功能,例如范围追踪,边界设置等. 例如,考虑这样一个功能,这在很多游戏 ...

  10. 使用openpyxl模块进行封装,高效处理excel测试数据

    from openpyxl import load_workbook from scripts.handle_config import conf from scripts.constants imp ...