IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    init 管理 ssh 服务

    Kumu\'s Blog发表于 2014-11-25 00:00:00
    love 0

    RHEL 6 / CentOS 6 开始使用 upstart 管理服务,而 RHEL 5 / CentOS 5 则使用传统的 SysV 进程管理,最新的 CentOS 7 则使用的是 Systemd。

    为防止进程意外退出,可以使用 init 来管理监控指定的程序,如防止 ssh 意外退出,方法如下:

    一、RHEL 5 / CentOS 5

    在 /etc/inittab 中加入如下字段:

    ssh:2345:respawn:/usr/sbin/sshd -f /etc/ssh/sshd_config -D # 管理 ssh 服务
    

    加入以上配置之后,执行 init q 即可生效。

    可以查看手册 man 5 inittab :

    ...
    id:runlevels:action:process
    ...
    respawn # 关于 action respawn 的介绍
    The  process  will  be  restarted  whenever  it terminates (e.g.getty).
    ...
    

    二、RHEL 6 / CentOS 6

    在 /etc/init/ 下创建 .conf 结尾的文件,如创建 ssh.conf, cat /etc/init/ssh.conf 内容如下:

    #!/bin/bash
    
    # ssh
    #
    # This service starts sshd
    
    start on runlevel [2345]
    stop on runlevel [!RUNLEVEL]
    
    # kill timeout 30
    console output
    respawn
    exec /usr/sbin/sshd -f /etc/ssh/sshd_config -D
    

    执行 init 3 生效, 3 是当前的运行级别, 通过 initctl list 可以查看当前 init 监控管理的服务。



沪ICP备19023445号-2号
友情链接