在 Debian 系统中,如果是后面安装的服务,如 httpd、mysqld、postfix 等,安装后系统默认不会自动启动的。就算手动启动了服务,只要服务器重启后,系统仍然不会自动启动服务。此时,我们就需要在安装后做个设置,让系统自动启动这些服务,避免不必要的损失和麻烦。
chkconfig 命令主要用来更新(启动或停止)和查询系统服务的运行级信息。其实命令很简单的,可以输入 chkconfig -h 获得帮助。如要将 mysqld 设置为开机自动启动: chkconfig mysqld on
如要取消 mysqld 的开机自动启动: chkconfig mysqld off 。要设置或取消某个服务自动启动,只需要最后的参数 on 和 off 即可。
把某个服务添加进 chkconfig 列表中,则现需要使用 chkconfig --add 参数将其添加进去: chkconfig --add mysqld
从系统启动项列表删除一个服务,使用 chkconfig --del 选项从启动列表删除它: chkconfig --del mysqld
如果要查询当前所有自动启动的服务,可以直接输入: chkconfig
此时 iptables 服务0~6均为 off,则说明不会在系统启动的时候自动启动。我们输入 chkconfig iptables on 后,再次检查输出结果变为:
这个时候2~5都是 on,就表明会自动启动了。图中0~6指定读系统服务要在哪一个执行等级中开启或关毕等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
Debian 系统服务命令合并为 systemctl
以 iptables 服务为例介绍,新命令: systemctl 动作 服务名.servicesystemctl start iptables.service //启动 iptables
systemctl stop iptables.service //停止 iptables
systemctl restart iptables.service //重新启动 iptables
systemctl status iptables.service //查看 iptables 服务状态
systemctl enable iptables.service //开机启动 iptables
systemctl disable iptables.service //取消开机启动 iptables