Linux开机启动三种方式

版权声明:商业使用请与博主联系 https://blog.csdn.net/NetRookieX/article/details/89185154

有的时候,我们开机启动一些命令或者是一段脚本,又或者是开机启动自定义的服务。
下面归纳了三种实现的方式。

方式1-开机启动命令

vim /etc/rc.local				#添加你想执行的命令
chmod +x /etc/rc.d/rc.local		#使文件生效

方式2-开机启动脚本

  • 将脚本添加至/etc/profile.d/目录下
  • 无需执行权限

方式3-注册系统服务

cd /etc/rc.d/init.d/
vim test				#设服务名为test
	#!/bin/sh
	#chkconfig: 35 20 80		#运行级别,启动优先权和关闭优先权
	#description: test enable	#脚本描述
	#下面填写你想执行的脚本
	date > /root/test_enable.txt
chown root.root /etc/rc.d/init.d/test		#改变所有者
chmod 755 /etc/rc.d/init.d/mysqld			#所有用户都可以执行,只有root可修改
chkconfig --add test			#将test加入linux启动管理体系
chkconfig test on				#设置开机启动
  • 注意:脚本前三行是必须有的,否则会报错

猜你喜欢

转载自blog.csdn.net/NetRookieX/article/details/89185154