linux创建/etc/init.d/服务脚本

一、linux启动过程

1551426-20181222204258530-1038882260.jpg
1、开机自检(硬件、cpu、主板、内存等)
2、读硬盘的0柱面0磁道1扇区的前446byte,446字节中有引导程序(根据启动顺利把任务交给相应的硬件。1扇区总共512字节,只读446字节,剩下的66给4个分区,2个给分区结束标志)
3、grup引导菜单
4、加载内核kernel
5、启动init进程(第一个启动的进程ps -ef|grep init可查看,为1)
6、读取inittab文件,执行rc.sysinit rc等脚本
/etc/inittab (运行级别脚本,可以更改开机运行级别)
/etc/ec.d/rc.sysinit
/etc/rc.d/rc3.d (文本模式)
7、启动mingetty,进入系统登入界面
精简开机系统启动
作用:减少安全隐患,减少资源占用

二、创建服务脚本

过程:创建/etc/init.d/chen1脚本,给/etc/init.d/chen1添加权限,为了符合chkconfig的脚本格式,我们需要在/etc/init.d/chen1写开头文件。写完之后chen1添加成chkcinfig管理。脚本的使用chkconfig chenq1 on即可。2345级别若没设置,系统默认是被设置的。
例:运行设置的是运行级别三,那么关闭或者打开该服务后,级别三里面的链接文件会更改

[root@Chen rc3.d]# vim /etc/init.d/chen                (脚本必须要写在/etc/init.d/)
[root@Chen rc3.d]# chmod +x /etc/init.d/chen              (脚本授权)
[root@Chen rc3.d]# vim /etc/init.d/chen                   (把脚本信息写进去)
[root@Chen rc3.d]# cat /etc/init.d/chen                    (确认脚本信息)
# chkconfig: 3 67 22
# description: chen by chenqj at 1
echo i like you
[root@Chen rc3.d]# chkconfig --add chen                   (进行关联服务)
[root@Chen rc3.d]# chkconfig --list chen
chen            0:off   1:off   2:off   3:on    4:off   5:off   6:off
[root@Chen rc3.d]# ll /etc/rc.d/rc3.d/|grep chen
lrwxrwxrwx. 1 root root   14 Oct  4 06:40 S67chen -> ../init.d/chen
[root@Chen rc3.d]# chkconfig chen off
[root@Chen rc3.d]# chkconfig --list chen
chen            0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@Chen rc3.d]# ll /etc/rc.d/rc3.d|grep chen
lrwxrwxrwx. 1 root root   14 Oct  4 06:43 K22chen -> ../init.d/chen

Systemd 入门教程:命令篇

转载于:https://www.cnblogs.com/reaperhero/articles/10162401.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值