線上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