| 关键词: nbsp sshd 服务 start init exists etc PID True system |
近日,跳板机等数据库ssh、snmpd服务总是莫名其妙的上了西天。这叫研发等人着急啊。分析后发现可能是Linux系统自带的机制,杀掉一些服务。既然这样,那就上脚本你懂的。先想了下SHELL 脚本怎么写,后来考虑到刚学的python那就练练手呗。1、因为一些常见的服务有PID文件那就从判断是否不存在PID文件下手 (后来发现对于自己系统是个坑,稍后分析...)2、也“库以”从ps aux 过滤出对应进程下手脚本贴上你懂得:#!/usr/bin/python# -*- coding: utf-8 -*-import os'''a.判断系统常用服务是否为正常状态,若不正常则将其启动'''if os.path.exists(r'/var/run/crond.pid') != True: os.system('/etc/init.d/crond start 2>&1')if os.path.exists(r'/var/run/sshd.pid') != True: os.system('/etc/init.d/sshd start 2>&1')if os.path.exists(r'/var/run/syslogd.pid') != True: os.system('/etc/init.d/rsyslog start || /etc/init.d/syslog start 2>&1')if os.path.exists(r'/var/run/snmpd.pid') != True: os.system('/etc/init.d/snmpd start 2>&1')3.运行一段时候发现问题......<1>服务上西天时,PID文件竟然存在。比如snmp服务报:snmpd dead but pid file exists 坑爹报错<2>计划任务的服务,也上了西天.....这个如何是好...4.那成,最终解决方法:<2>[root@localhost ~]#screen[root@localhost ~]# while true ;sleep 60;do sshd=`netstat -ntlp | awk '{print $4}' | grep :22` ;if [[ $sshd = "" ]];then /etc/init.d/sshd start; fi;done<3>/etc/init.d/sshd stop[root@localhost ~]# while true ;sleep 60;do sshd=`netstat -ntlp | awk '{print $4}' | grep :22` ;if [[ $sshd = "" ]];then /etc/init.d/sshd start; fi;done正在启动 sshd: [确定]5.后续深夜12点,正打着游戏<卑鄙我>....此时手机铃声响了。xx, 中国区跳板机尼玛无法登陆啊。我擦嘞....60s后,SSHD服务还是木有起来。第二天上班,果断到机房重启SSHD服务。后排查是因为L2TP服务原因造成的,把原先的4G内存换成了8G。问题解决了..... |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|