Centos 配置开机启动项

  Linux system  部署新的服务,初次启动服务都是通过command的方式手工启动,时间久了之后重启系统或有别的人员维护系统【不熟悉环境、业务】,可能造成服务未启动、业务受影响,排查起来维护成本较高,且影响业务连续性。因此,设置新增业务为开机启动,显得十分必要,作者本身也是深有体会。本文着重介绍,如何为新增服务设置开启启动。

设置开机启动方式一

#ntsysv 【quit 】 =--图形界面查看、设置开机启动项

快捷键
CTRL+V 下翻
空格键 选中
tab
quit 命令退出图形界面

Centos  配置开机启动项

设置开机启动方式二

#chkconfig --list ----chkconfig 类似 MSConfig

Centos  配置开机启动项

Linux System Mode

Linux一般会有7个Mode(可由init N来切换,init0为关机,init 6为重启系统)
0 - 停机
1 - 单用户模式
2 - 多用户,但是没有NFS ,不能使用网络
3 - 完全多用户模式
4 - 打酱油的,没有用到
5 - X11 图形化登录的多用户模式
6 - 重新启动 (如果将默认启动模式设置为6,Linux将会不断重启)

Chkconfig 语法格式

     chkconfig --add <name>
     chkconfig --del <name>
     chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

配置示例:

设置IPtables开机启动或关闭

---注意一下linux有5个启动模式,分别对应不同的权限

chkconfig --list | grep iptables

iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

#chkconfig iptables --level 3 off/on ----给3打开或关闭开启启动

chkconfig --list | grep iptables

iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

chkconfig iptables off

chkconfig --list | grep iptables

iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

Linux服务器,服务管理--systemctl命令详解,设置开机自启动
syetemclt就是service和chkconfig这两个命令的整合,在CentOS 7就开始被使用了。
摘要: systemctl 是系统服务管理器命令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

任务 旧指令 新指令

使某服务自动启动 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

猜你喜欢

转载自blog.51cto.com/13637805/2336870