• memcached程序端口监控脚本


    线上memcached服务器启动了很多实例,端口很多,需要对这些端口进行监控,并在端口关闭的情况下自启动。监控脚本如下:

    [root@memcache2 ~]# ps -ef|grep /usr/bin/memcached|grep -v grep
    root      6139     1  0  2016 ?        04:49:49 /usr/bin/memcached -d -m 512 -p 11212 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6184     1  0  2016 ?        00:29:25 /usr/bin/memcached -d -m 512 -p 11411 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6198     1  0  2016 ?        00:29:24 /usr/bin/memcached -d -m 512 -p 11412 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6214     1  0  2016 ?        00:30:17 /usr/bin/memcached -d -m 512 -p 11413 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6229     1  0  2016 ?        00:29:19 /usr/bin/memcached -d -m 512 -p 11521 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6244     1  0  2016 ?        00:29:49 /usr/bin/memcached -d -m 512 -p 11522 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6259     1  0  2016 ?        00:09:27 /usr/bin/memcached -d -m 512 -p 11211 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6274     1  0  2016 ?        00:09:22 /usr/bin/memcached -d -m 512 -p 11213 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6289     1  0  2016 ?        00:29:54 /usr/bin/memcached -d -m 512 -p 11221 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root      6304     1  0  2016 ?        00:29:16 /usr/bin/memcached -d -m 512 -p 11222 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root     12514     1  0 13:00 ?        00:00:00 /usr/bin/memcached -d -m 512 -p 11321 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root     12758     1  0 13:02 ?        00:00:00 /usr/bin/memcached -d -m 512 -p 11322 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11322.pid
    root     24085     1  0  2016 ?        00:31:33 /usr/bin/memcached -d -m 512 -p 11311 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11311.pid
    root     24100     1  0  2016 ?        00:31:55 /usr/bin/memcached -d -m 512 -p 11312 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11312.pid
    root     24115     1  0  2016 ?        00:31:51 /usr/bin/memcached -d -m 512 -p 11313 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11313.pid
    root     24740     1  0  2016 ?        00:03:20 /usr/bin/memcached -d -m 512 -p 11811 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11811.pid
    root     24755     1  0  2016 ?        00:03:19 /usr/bin/memcached -d -m 512 -p 11812 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11812.pid
    root     24770     1  0  2016 ?        00:03:18 /usr/bin/memcached -d -m 512 -p 11813 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11813.pid
    root     24785     1  0  2016 ?        00:03:18 /usr/bin/memcached -d -m 512 -p 11814 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11814.pid
    root     24800     1  0  2016 ?        00:03:19 /usr/bin/memcached -d -m 512 -p 11815 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11815.pid
    root     24815     1  0  2016 ?        00:03:14 /usr/bin/memcached -d -m 512 -p 11816 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11816.pid
    root     24830     1  0  2016 ?        00:03:17 /usr/bin/memcached -d -m 512 -p 11817 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11817.pid
    root     24845     1  0  2016 ?        00:03:17 /usr/bin/memcached -d -m 512 -p 11818 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11818.pid
    root     24860     1  0  2016 ?        00:03:14 /usr/bin/memcached -d -m 512 -p 11819 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11819.pid
    root     24875     1  0  2016 ?        00:03:18 /usr/bin/memcached -d -m 512 -p 11820 -u root -c 4096 -P /var/lib/memcache/logs/memcached_11820.pid
    [root@memcache2 ~]# ps -ef|grep /usr/bin/memcached|grep -v grep|awk -F" " '{print $13}' > /root/memcache_port.list 
    
    [root@memcache2 ~]# cat /root/memcache_port.list
    11212
    11411
    11412
    11413
    11521
    11522
    11211
    11213
    11221
    11222
    11321
    11322
    11311
    11312
    11313
    11811
    11812
    11813
    11814
    11815
    11816
    11817
    11818
    11819
    11820
    
    [root@memcache2 ~]# cat memcache_port.sh              //脚本权限是755
    #!/bin/bash
    for i in `cat /root/memcache_port.list`
    do
      NUM=$(/usr/sbin/lsof -i:$i|wc -l)
      if [ $NUM -eq 0 ];then
        /usr/bin/memcached -d -m 512 -p $i -u root -c 4096 -P /var/lib/memcache/logs/memcached_$i.pid
      else
        echo "$i is ok"
      fi
    done
    
    [root@memcache2 ~]# crontab -l
    * * * * * /bin/bash -x /root/memcache_port.sh > /dev/null 2>&1
  • 相关阅读:
    uva 804WAWAWA--不想看了以后再说
    uva10129 play on words
    tree--
    打印素数表orz
    DeepFM模型
    国内常用镜像链接
    Thompson(汤普森)采样
    知识图谱简介
    显式反馈和隐式反馈
    RNN之LSTM及双向LSTM
  • 原文地址:https://www.cnblogs.com/kevingrace/p/6277781.html
Copyright © 2020-2023  润新知