一、通过rc.local该文件实现开机自启
 
1:编写测试脚本
[root@host1 ~]# vim test.sh
#!/bin/bash
/bin/echo $(/bin/date +%F_%T) >> /tmp/test.log
##开机启动打印当前时间输出到test.log文本里
 
2:测试脚本完成之后,更改rc.local配置文件
[root@host1 ~]# vim /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
 
touch /var/lock/subsys/local
/bin/bash /tmp/test.sh >/dev/null 2>/dev/null ##加上这一段配置,让其开机执行
 
保存退出
 
3:在centos7中,/etc/rc.d/rc.local没有执行权限,需要授权,然后就可以重启机器验证就行了
[root@host1 ~]# chmod +x /etc/rc.d/rc.local
 
 
4:重启之后查看结果
[root@host1 ~]# cat /tmp/test.log
2019-06-02_16:44:53
 
 
二、通过chkcongfig开机启动服务来实现
 
1:在/etc/init.d/编辑一个测试脚本
[root@host1 ~]# vim /etc/init.d/test
#!/bin/bash
# chkconfig: 3 88 88
 
/bin/bash /tmp/test.sh >/dev/null 2>/dev/null
 
保存退出
 
2:赋予执行权限
[root@host1 ~]# chmod 755 /etc/init.d/test
 
 
3:加入开机启动服务列表
[root@host1 ~]# chkconfig --add test
 
4:查看开机启动服务列表
[root@host1 ~]# chkconfig --list
 
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
 
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
 
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
test 0:关 1:关 2:关 3:开 4:关 5:关 6:关
 
5:重启系统之后查看结果
[root@host1 ~]# cat /tmp/test.log
2019-06-02_16:44:53
2019-06-02_16:48:45

Linux配置开机自启动的两种方法的更多相关文章

  1. 配置 yum 源的两种方法

    配置 yum 源的两种方法 由于 redhat的yum在线更新是收费的,如果没有注册的话不能使用,如果要使用,需将redhat的yum卸载后,重启安装,再配置其他源,以下为详细过程:  1.删除red ...

  2. Linux系统实现虚拟内存有两种方法:交换分区(swap分区)和交换文件

    Linux系统实现虚拟内存有两种方法:交换分区(swap分区)和交换文件 交换文件 查看内存:free -m , -m是显示单位为MB,-g单位GB 创建一个文件:touch /root/swapfi ...

  3. Linux 下操作GPIO(两种方法,驱动和mmap)(转载)

    目前我所知道的在Linux下操作GPIO有两种方法: 1.编写驱动,这当然要熟悉Linux下驱动的编写方法和技巧,在驱动里可以使用ioremap函数获得GPIO物理基地址指针,然后使用这个指针根据io ...

  4. Linux 下操作gpio(两种方法,驱动和mmap)

    目前我所知道的在linux下操作GPIO有两种方法: 1.  编写驱动,这当然要熟悉linux下驱动的编写方法和技巧,在驱动里可以使用ioremap函数获得GPIO物理基地址指针,然后使用这个指针根据 ...

  5. 20155212 C语言实现linux下pwd命令的两种方法

    20155212 C语言实现linux下pwd命令的两种方法 学习pwd命令 通过man pwd命令查看 pwd [OPTION],一般不加参数 -P显示当前目录的物理路径 -L显示当前目录的连接路径 ...

  6. spring security实现动态配置url权限的两种方法

    缘起 标准的RABC, 权限需要支持动态配置,spring security默认是在代码里约定好权限,真实的业务场景通常需要可以支持动态配置角色访问权限,即在运行时去配置url对应的访问角色. 基于s ...

  7. linux 设置开机启动项两种方式

    原文链接:http://blog.csdn.net/karchar/article/details/52489572 有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务. 在解问题之前 ...

  8. Linux小技巧之:两种方法统计访问web网站的前10个IP

    获得访问前10位的IP地址: 10.46.170.7 218.202.70.147 77.72.83.87 5.39.217.107 185.197.74.234 185.197.74.231 第二种 ...

  9. linux 开机自启动的两种方式

    方法 1 – 使用 rc.local sudo vi /etc/rc.local 在文件最后加上: sh /root/script.sh & 如果是 CentOS,我们修改的是文件 /etc/ ...

随机推荐

  1. arm下dlsym返回的符号地址居然不是偶对齐的。

    我们都知道在写汇编函数过程都会偶对齐,而gcc编译器都会将函数编译为cpu字长对齐的地址.arm指令集是固定32位指令长度,thumb指令集是固定16位指令长度, 但是运行在arm下的程序,dlsym ...

  2. objc反汇编分析,手工逆向libsystem_blocks.dylib

    上一篇<block函数块为何物?>介绍了在函数中定义的block函数块的反汇编实现,我在文中再三指出__block变量和block函数块自始还都是stack-based的,还不完全适合在离 ...

  3. ansible start canal

    - name: Start canal server shell: source /etc/profile && nohup /opt/canal/bin/startup.sh

  4. nvidia gtx1050在kali linux系统下安装显卡驱动,且可以使用x-setting切换显卡

    转自:https://www.zzhsec.com/255.html 1.更换源[使用中科大或者官方源都可以] 下面使用中科大的源 root@Andy:/home/dnt# vi /etc/apt/s ...

  5. linux basic

    一:date 语法: 打印日期:date [OPTION].....  [+FORMAT] 设定日期:date [MMDDhhmm] [[cc][YY][.ss] 创建带实时日期的文件 touch $ ...

  6. 在Kubernetes上运行有状态应用:从StatefulSet到Operator

    一开始Kubernetes只是被设计用来运行无状态应用,直到在1.5版本中才添加了StatefulSet控制器用于支持有状态应用,但它直到1.9版本才正式可用.本文将介绍有状态和无状态应用,一个通过K ...

  7. c#-PropertyChangingEventArgs

    MSDN 解释连接:https://msdn.microsoft.com/zh-cn/library/system.eventargs.aspx#inheritanceContinued[Serial ...

  8. UVA439 骑士的移动 Knight Moves

    #include<bits/stdc++.h> using namespace std; char a,c; int b,d; ][]; ]={,,,-,,-,-,-}; ]={,-,,, ...

  9. 获取Zabbix 中资源的使用率

    import pymysql as MySQLdb import time import datetime import xlsxwriter # zabbix数据库信息: zdbhost = 'xx ...

  10. Spring Data JPA 条件查询的关键字

    Spring Data JPA 为此提供了一些表达条件查询的关键字,大致如下: And --- 等价于 SQL 中的 and 关键字,比如 findByUsernameAndPassword(Stri ...