一、通过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

最新文章

  1. session过期返回登录页面跳出frame
  2. polymorphic-associations 多态关联实例 ruby on rails
  3. TOP/ORDER BY 顺序(转)
  4. Android 项目利用 Android Studio 和 Gradle 打包多版本APK
  5. BZOJ_1607_ [Usaco2008_Dec]_Patting_Heads_轻拍牛头_(筛数)
  6. TCP/IP-IP
  7. javascript 中的nextSibling和previousSibling使用注意事项
  8. uploadify在asp.net中的试用小结
  9. 多个UpdatePanel控件相互引发刷新的使用
  10. PHP实现仿Google分页效果的分页函数
  11. KindEditor富文本编辑器使用
  12. e.stopPropagation()兼容性处理
  13. 【repost】javascript callback
  14. Node.js 反序列化漏洞远程执行代码(CVE-2017-5941)
  15. javanio1----传统io
  16. The Attention Merchants
  17. 【转】Linux 高级的视角来查看Linux引导过程
  18. Nginx(十一)-- keepalived简介
  19. JS和webView的交互
  20. 用block将UIAlertView与UIActionSheet统一起来

热门文章

  1. nyoj 513-A+B Problem IV (java BigDecimal, stripTrailingZeros, toPlainString)
  2. 力扣(LeetCode)加一 个人题解
  3. oracle日期时间范围查询
  4. linux磁盘分区、格式化、挂载
  5. Android加载大量图片内存溢出解决办法
  6. 基于Galera Cluster多主结构的Mysql高可用集群
  7. requests请求库练习--GitHub登录
  8. Java 大小端转换(基于ByteBuffer)
  9. js贪吃蛇(构造函数)
  10. 把Git Repository建到U盘上去