Too many open files in system
BSD:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/configtuning-kernel-limits.html
LINUX:
http://www.cs.wisc.edu/condor/condorg/linux_scalability.html
BSD:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/configtuning-kernel-limits.html
LINUX:
http://www.cs.wisc.edu/condor/condorg/linux_scalability.html
编写的php_fork脚本,都是使用文件存储,这次改为MySQL,执行之后就发现MySQL连接错误,因为使用exit()退出子进程,导致系统回收资源,关闭了数据库连接。
正确方法是使用:kill -9 避免垃圾回收。(http://php.net/manual/en/function.pcntl-fork.php)
$pid = pcntl_fork();
if ( $pid == 0 ) {
// This is the child process. Do something here.
// Instead of calling exit(), we use posix_kill()
posix_kill(getmypid(),9);
}
此外,使用成熟的类库是很好的编程习惯,能最大限度的避免问题(别人都测试过了)。比如PHP_FORK:(http://www.phpclasses.org/browse/package/1136.html)
// 以下这些是Linux 0.11 内核中定义的信号。
#define SIGHUP 1 // Hang Up — 挂断控制终端或进程。
#define SIGINT 2 // Interrupt — 来自键盘的中断。
#define SIGQUIT 3 // Quit — 来自键盘的退出。
#define SIGILL 4 // Illeagle — 非法指令。
#define SIGTRAP 5 // Trap — 跟踪断点。
#define SIGABRT 6 // Abort — 异常结束。
#define SIGIOT 6 // IO Trap — 同上。
#define SIGUNUSED 7 // Unused — 没有使用。
#define SIGFPE 8 // FPE — 协处理器出错。
#define SIGKILL 9 // Kill — 强迫进程终止。
#define SIGUSR1 10 // User1 — 用户信号1,进程可使用。
#define SIGSEGV 11 // Segment Violation — 无效内存引用。
#define SIGUSR2 12 // User2 — 用户信号2,进程可使用。
#define SIGPIPE 13 // Pipe — 管道写出错,无读者。
#define SIGALRM 14 // Alarm — 实时定时器报警。
#define SIGTERM 15 // Terminate — 进程终止。
#define SIGSTKFLT 16 // Stack Fault — 栈出错(协处理器)。
#define SIGCHLD 17 // Child — 子进程停止或被终止。
#define SIGCONT 18 // Continue — 恢复进程继续执行。
#define SIGSTOP 19 // Stop — 停止进程的执行。
#define SIGTSTP 20 // TTY Stop — tty 发出停止进程,可忽略。
#define SIGTTIN 21 // TTY In — 后台进程请求输入。
#define SIGTTOU 22 // TTY Out — 后台进程请求输出。
编辑 vmx 文件(例如:Linux 2.6.x kernel.vmx)
加入一行:
disk.locking = “FALSE”
迅雷会向WEB服务提交如下HTTP请求头:
POST / HTTP/1.1
Host: 58.61.39.206:80
Content-type: application/octet-stream
Content-Length: 140
Connection: Keep-Alive
Squid配置如下:
acl IP dstdom_regex [0-9]$
acl ROOT urlpath_regex ^/$
acl POST method POST
acl Octet_Stream req_mime_type application/octet-stream
http_access deny IP ROOT POST Octet_Stream
Smoothwall使用ez-ipupdate更新动态域名。
希网也使用ez-ipupdate的修改版作为Linux客户端:
http://www.3322.org/dyndnspage/client.html
只需把Smoothwall的ez-ipupdate替换为希网提供的专版即可。
使用附件替换以下两个文件:
1. web管理界面
/httpd/cgi-bin/ddns.cgi
2. ez-ipupdate
/usr/bin/ez-ipupdate
附件下载:
ddns.cgi
ez-ipupdate
1.分区
fdisk /dev/hdb
n -> 添加分区
p -> 主分区
1 -> 分区号
2.格式化ext3
mkfs.ext2 -j /dev/hdb1
3.临时挂载
mount /dev/hdb1 /path/to/
4.启动挂载
vim /etc/fstab
#
由于人人网(renren.com)和开心网(kaixin.com)对接,新建了个passport服务,用于统一验证,模拟登录的方式也改了,请看通行证登录原理:
1.应用提交验证信息给passport:
email/password
origURL/domain
2.passport分配全局SessionID:
XNESSESSIONID=c3b27ade6716;
3.passport验证帐号/密码
4.用户验证成功,Location 回应用的 callbackUrl:
http://login.renren.com/callback.do?t=ad34b89977d3a45a7bd0b49ea568ad436&origURL=http%3A%2F%2Fwww.renren.com%2FSysHome.do
5.应用的callbackUrl负责获取用户信息,并分配当前的UID:
xnsid=48863dc
6.跳转到应用的首页origURL
function xiaonei_login($email, $password){
$url = ‘http://passport.renren.com/PLogin.do’;
$opt = array(
// LOCATION(自动跳转1次)
CURLOPT_MAXREDIRS => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_AUTOREFERER => 1,
// POST(提交验证数据)
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => “email=$email&password=$password&origURL=http%3A%2F%2Fwww.renren.com%2FSysHome.do&domain=renren.com”,
// COOKIE(保存cookie)
CURLOPT_COOKIEJAR => ‘./cookie’,
CURLOPT_COOKIEFILE => ‘./cookie’,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt_array($ch, $opt);
curl_exec($ch);
curl_close($ch);
}
流程:Apache日志分析,解析GET的URL参数,生成CSV后,使用LOAD INFILE导入数据库;
问题:字段错位
一行数据(1,2,3),导入后成了(1,23,NULL);
原因:分隔符和字段值中的宽字节字符组合成了新字符;
相当于命中了宽字节编码漏洞:
高字节范围129-254的ASCII编码可以和基础字符编码组成一个非法宽字节字符。
造成漏洞的高字节编码范围:0xC0-0xFE
安全的生成CSV文件的方法:
过滤宽字符函数:
function safe_string($string){
if( strlen($string) > 2 &&
//攻击发生在字符串的最后两个字节,倒数第二个字节ASCII码大于129,倒数第一个字节ASCII码小于127.
(ord(substr($string,-2,1)) >= 129 && ord(substr($string,-1,1))<127) ){
$string = substr($string, 0, -1);
return safe_string($string);
}
return $string;
}
示例代码:
$value = mysql_real_escape_string(safe_string($value));
“$value”,”$value”
倒入这样的CSV就万无一失了,不会出现字段对齐问题。
http://getfirebug.com/lite.html
IE 也可以使用firebug,添加到收藏夹:FileBug