DDR爱好者之家 Design By 杰米
memcached 进程启动及监控
1.memcached_inc.sh
设置路径,端口等讯息。
#!/bin/sh #config include HOST=$(hostname) SITE="mysite" PORT=11211 MEMCACHED_PID_FILE="/tmp/memcached.pid" MEMCACHED_DAEMON_PID_FILE="/tmp/memcached_daemon.pid" MEMCACHED="memcached -d -m 64 -p $PORT -u memcache -l 127.0.0.1 -P $MEMCACHED_PID_FILE" MEMCACHED_DAEMON_FILE="memcached_daemon.sh" ERROR_LOG_FILE="${ROOT}/memcached_${SITE}_${HOST}_${PORT}.log"
2.gm_memcached.sh
控制memcached 启动,停止,重启。
#!/bin/sh #memcached start and stop #$1 action ROOT=$(cd "$(dirname "$0")"; pwd) . ${ROOT}/memcached_inc.sh start() { if [ -f "$MEMCACHED_PID_FILE" ] && [ -s "$MEMCACHED_PID_FILE" ]; then printf "memcached already running\n" else printf "starting memcached\n" $MEMCACHED sleep 2 PID=$(cat $MEMCACHED_PID_FILE) printf "memcached is started PID:$PID\n" printf "starting memcached daemon\n" ${ROOT}/${MEMCACHED_DAEMON_FILE} & DAEMON_PID=$! echo ${DAEMON_PID} > ${MEMCACHED_DAEMON_PID_FILE} printf "memcached daemon is started PID:${DAEMON_PID}\n" fi } stop() { if [ -f "$MEMCACHED_DAEMON_PID_FILE" ] && [ -s "$MEMCACHED_DAEMON_PID_FILE" ]; then DAEMON_PID=$(cat $MEMCACHED_DAEMON_PID_FILE) rm -f ${MEMCACHED_DAEMON_PID_FILE} if [ ! -z ${DAEMON_PID} ]; then kill -9 ${DAEMON_PID} fi printf "memcached daemon is stopped\n" else printf "no memcached daemon running\n" fi sleep 1 if [ -f "$MEMCACHED_PID_FILE" ] && [ -s "$MEMCACHED_PID_FILE" ]; then PID=$(cat $MEMCACHED_PID_FILE) rm -f ${MEMCACHED_PID_FILE} if [ ! -z ${PID} ]; then kill -9 ${PID} fi printf "memcached is stopped\n" else printf "no memcached running\n" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 3 start ;; *) printf "Usage:$0 {start|stop|restart}\n" exit 1 esac exit 0
3.memcached_daemon.sh
监控memcached 进程,如进程失效则自动启动。
#!/bin/sh #memcached daemon ROOT=$(cd "$(dirname "$0")"; pwd) . ${ROOT}/memcached_inc.sh while : do if [ -f "$MEMCACHED_PID_FILE" ] && [ -s "$MEMCACHED_PID_FILE" ]; then PID=$(cat $MEMCACHED_PID_FILE) else PID="" fi if [ -z "$PID" ] || [ -z $(ps aux|awk '{print $2}' | grep "^$PID$") ]; then $MEMCACHED sleep 1 printf "[$(date +%Y-%m-%d' '%H:%M:%S)] ${SITE} ${HOST} memcached ${PORT} is restarted\n" $ERROR_LOG_FILE echo "Subject: ${SITE} ${HOST} memcached ${PORT} is restarted $(date +%Y-%m-%d' '%H:%M:%S)" | sendmail me@gmail.com fi sleep 5 done exit 0
使用方法:
./gm_memcached.sh start #启动memcached ./gm_memcached.sh stop #停止memcached ./gm_memcached.sh restart #重启memcached
shell 记录apache status并自动更新到数据库
1. 获取apache status
monitor_log.sh
#!/bin/bash #连接数 site_connects=$(netstat -ant | grep $ip:80 | wc -l) #当前连接数 site_cur_connects=$(netstat -ant | grep $ip:80 | grep EST | wc -l) #apache apache_speed=$(netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}') printf "[#start#]\n$(date '+%Y-%m-%d %H:%M:%S')\n" printf "connects:${site_connects}\n" printf "cur connects:${site_cur_connects}\n" printf "apache_speed:\n${apache_speed}\n[#end#]\n\n" exit 0
在终端设置crontab执行
* * * * * /home/fdipzone/monitor_log.sh /home/fdipzone/monitor.log
2. 将apache status log 写入数据库
save_monitor_log.php
<" ,".$key : $key; $insertval .= $insertval" ,'".mysql_escape_string(trim($val))."'" : "'".mysql_escape_string(trim($val))."'"; } $sqlstr = "insert into ".$this->_dbconfig['tabname']."($insertkey) values($insertval)"; $query = @mysql_query($sqlstr) or die(mysql_error()); $id = mysql_insert_id(); return $id"\r\n"); } } // class end "htmlcode">0 0 * * * php /home/fdipzone/save_monitor_log.php
table monitor_log structCREATE TABLE IF NOT EXISTS `monitor_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `site` varchar(20) NOT NULL, `connects` int(10) unsigned NOT NULL DEFAULT '0', `cur_connects` int(10) unsigned NOT NULL DEFAULT '0', `TIME_WAIT` int(10) unsigned NOT NULL DEFAULT '0', `CLOSE_WAIT` int(10) unsigned NOT NULL DEFAULT '0', `SYN_SENT` int(10) unsigned NOT NULL DEFAULT '0', `SYN_RECV` int(10) unsigned NOT NULL DEFAULT '0', `FIN_WAIT1` int(10) unsigned NOT NULL DEFAULT '0', `FIN_WAIT2` int(10) unsigned NOT NULL DEFAULT '0', `ESTABLISHED` int(10) unsigned NOT NULL DEFAULT '0', `LAST_ACK` int(10) unsigned NOT NULL DEFAULT '0', `CLOSING` int(10) unsigned NOT NULL DEFAULT '0', `addtime` datetime NOT NULL, PRIMARY KEY (`id`), KEY `connects` (`connects`), KEY `cur_connects` (`cur_connects`), KEY `TIME_WAIT` (`TIME_WAIT`), KEY `CLOSE_WAIT` (`CLOSE_WAIT`), KEY `SYN_SENT` (`SYN_SENT`), KEY `SYN_RECV` (`SYN_RECV`), KEY `FIN_WAIT1` (`FIN_WAIT1`), KEY `FIN_WAIT2` (`FIN_WAIT2`), KEY `ESTABLISHED` (`ESTABLISHED`), KEY `LAST_ACK` (`LAST_ACK`), KEY `CLOSING` (`CLOSING`), KEY `addtime` (`addtime`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月27日
2024年11月27日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]