旌旗博客

2011-11-02

本地连接消失了

Filed under: I.T. — rocky @ 00:47

前几天家里的台式机系统中的"本地连接"突然就消失了,新出来一个"本地连接2",无法上网。症状为:DHCP分配不到地址,设静态IP地址后,能访问接在同一交换机上的另一网络设备的samba服务,但ping网关路由器不通。发现有时候重启之后"本地连接"又出来了,就一切正常了,但得靠运气,不太靠谱。今天运气不好,重启两次都没管用,仔细检查,发现"本地连接2"的MAC地址都是0,于是随便填了一个,然后就一切太平了。

2010-12-30

PHP的mysql模块引起的3221225477错误解决

Filed under: I.T. — rocky @ 20:49

在windows上,MySQL 5.1中的libmySQL.dll与PHP 5.2.14中的php_mysql模块不兼容,导致3221225477 (0xC0000005)进程退出错误,可以将PHP安装包中的libmySQL.dll复制到apache的bin目录中,重新启动服务就可解决。

2010-08-12

Patch for anonymous’ comments bug on drupal

Filed under: I.T. — 标签: — rocky @ 17:15

  You may allow anonymous post comments on drupal system by granting those rights to anonymous roles. But there is a bug which preventing the anonymous’ comments to display with the posts or in the comment block. You could apply the patch below to fix the bug. It should work for version 6.16 to 6.19.

Index: modules/comment/comment.admin.inc
===================================================================
--- modules/comment/comment.admin.inc    (revision 281)
+++ modules/comment/comment.admin.inc    (revision 282)
@@ -57,7 +57,7 @@
     array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'),
     array('data' => t('Operations'))
   ));
-  $result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, n.title as node_title FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.status = %d'. tablesort_sql($form['header']['#value']), 50, 0, NULL, $status);
+  $result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, n.title as node_title FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.status = %d'. tablesort_sql($form['header']['#value']), 50, 0, NULL, $status);
 
   // build a table listing the appropriate comments
   $destination = drupal_get_destination();
@@ -215,7 +215,7 @@
  *   The comment do be deleted.
  */
 function comment_delete($cid = NULL) {
-  $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
+  $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid));
   $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
 
   $output = '';
@@ -287,7 +287,7 @@
   comment_invoke_comment($comment, 'delete');
 
   // Delete the comment's replies
-  $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
+  $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c LEFT JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid);
   while ($comment = db_fetch_object($result)) {
     $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
     _comment_delete_thread($comment);
Index: modules/comment/comment.module
===================================================================
--- modules/comment/comment.module    (revision 281)
+++ modules/comment/comment.module    (revision 282)
@@ -936,7 +936,7 @@
 
     if ($cid && is_numeric($cid)) {
       // Single comment view.
-      $query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
+      $query = 'SELECT c.cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.status FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d';
       $query_args = array($cid);
       if (!user_access('administer comments')) {
         $query .= ' AND c.status = %d';
@@ -957,7 +957,7 @@
     else {
       // Multiple comment view
       $query_count = 'SELECT COUNT(*) FROM {comments} c WHERE c.nid = %d';
-      $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
+      $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
 
       $query_args = array($nid);
       if (!user_access('administer comments')) {

2009-01-12

Make cronolog work with Nginx

Filed under: I.T. — 标签: — rocky @ 23:02

I got two solutions from here: http://pjkh.com/articles/2007/03/15/nginx-and-cronolog/.

But I am not satisfied with the second solution because of some wrong placement with a few log records. I would like use this:

mv /var/log/nginx/access_log /var/log/nginx/access_log.processing -f;
mv /var/log/nginx/error_log /var/log/nginx/error_log.processing -f;
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`;
/usr/bin/perl /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -LogFile=/var/log/nginx/access_log.processing -update
cat /var/log/nginx/access_log.processing | /usr/local/sbin/cronolog /var/log/nginx/%Y/%m/%d/access_log;
cat /var/log/nginx/error_log.processing | /usr/local/sbin/cronolog /var/log/nginx/%Y/%m/%d/error_log;
rm /var/log/nginx/access_log.processing /var/log/nginx/error_log.processing -f;

2008-11-29

coolplayer youtube-support-bug fix

Filed under: I.T. — 标签: — rocky @ 19:18

进入coolplayer的后台设置页面:http://xxxx/wp-admin/options- general.php?page=coolplayer/options.php,将“RPC 服务器地址”设置为 http://rocky.blog.kingtch.com/wp-content/plugins/coolplayer/rpc.php 即可。

如果你想使用自己的rpc,可以从这里下载coolplayer- youtube-patch.zip,解压后将rpc.php覆盖原来目录/wp-content/plugins /coolplayer/下的rpc.php文件即可。

fix coolcode plugin for WP 2.6.5

Filed under: I.T. — 标签: — rocky @ 17:44

Coolcode is a cool plugin which is made by andot. Now it is not compatible with WP 2.6.5. Ifix it, and you can download new version from here.

2008-11-28

Fix Nginx “411 Length Required” Problem

Filed under: I.T. — 标签:, , — rocky @ 16:28
When using POST method to request via Nginx 0.6.33 without any post body data, you may get this error: 411 Length Required. 

Download nginx-0.6.33-length_required patch
Save the attachment and run this command in the root path of nginx 0.6.33 source code:
patch ./src/http/ngx_http_request.c<nginx-0_6_33-length_required.patch
Then "make && make install && sudo /sbin/service nginx restart" and enjoy your AJAX function.

2008-07-23

自动阻止SYN、DoS攻击

Filed under: I.T. — 标签:, — rocky @ 13:51

除了告警敦促人工处理SYN、DoS攻击,可以将嫌疑犯先抓起来再说:

netstat -na | grep :80 |awk '{print $5}'|awk -F '::ffff:' '{print $2}' | grep ':' | awk -F: '{print $1}' | sort | uniq -c | sort -r | awk -F' ' '{if ($1 > 50) print $2}' | sed 's/^.*$/iptables -I RH-Firewall-1-INPUT 1 -p tcp -m tcp -s & --dport 80 --syn -j REJECT/' | sh

该脚本基于的基础是认为从一个IP过来的连接数过大(超过50个),则该IP可能在进行攻击。实际上可能误杀掉一些只能通过代理服务器访问的大公司用户,或者某些有点贪心的网络爬虫。可以在脚本中加入一些白名单以防止误杀,如:

netstat -na | grep :80 |awk '{print $5}'|awk -F '::ffff:' '{print $2}' | grep ':' | awk -F: '{print $1}' | sort | uniq -c | sort -r | awk -F' ' '{if ($1 > 50) print $2}' | grep -v xxx.xxx.xxx.xxx | sed 's/^.*$/iptables -I RH-Firewall-1-INPUT 1 -p tcp -m tcp -s & --dport 80 --syn -j REJECT/' | sh


2008-05-16

自动短信提醒进行服务器状态告警

Filed under: I.T. — 标签:, — rocky @ 16:22

定时启动的脚本:

df | grep “/var” | awk ‘{ print $5 }’ | awk -F”%” ‘{print $1}’ | awk ‘{ if ($1 > 90){print “alert.sh \”139xxxxxxxx\” \”insufficient disk space on /var. “,$1,”\””} }’ | csh
ps -ef | grep httpd | grep -v cronolog | grep -v grep | grep -v root | wc -l | awk ‘{ if ($1 > 3000){print “alert.sh \”139xxxxxxxx\” \”apache process “, $1,”\””} }’ | csh
echo ‘show processlist’ | mysql | grep -v Id | grep -v processlist | wc -l | awk ‘{ if ($1 > 3000){print “alert.sh \”139xxxxxxxx\” \”mysql process “, $1,”\””} }’ | csh

alert.sh 脚本:

echo $2
echo -e “From:monitor<>\nReply-to:support <support.labs@etentec.com>\nSubject:$2\n\n$2\n.” | /usr/sbin/sendmail $1@139.com

一个监视服务器状态的shell脚本

Filed under: I.T. — 标签:, — rocky @ 14:03

#! /bin/bash

for1
do
    clear
    date
    echo -n ‘httpd process:             ‘;ps -ef | grep httpd | grep -v cronolog | grep -v grep | grep -v root | wc -l
    echo -n ‘http connection:   ‘;netstat -an | grep :80 | grep ESTABLISHED | wc -l
    echo -n ‘mysql process:             ‘;echo ‘show processlist’ | mysql | grep -v Id | grep -v processlist | wc -l
    echo -n ‘mysql connection:  ‘;netstat -an | grep 3306 | grep ESTABLISHED | wc -l
    echo ‘tcp connection stats:’;netstat -n | awk ‘/^tcp/ {++S[$NF]} END {for(a in S) print ”   “,a, S[a]}’
    echo ‘sorted ESTABLISHED connections: ‘;netstat -na|grep ESTABLISHED|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n
    echo ‘sorted SYN connections: ‘; netstat -na|grep SYN|awk ‘{print $5}’|awk -F: ‘{print $1}’|sort|uniq -c|sort -r +0n
    sleep 5
done

  1. ; ; []
Older Posts »

Powered by WordPress