<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[针对Web服务器总体优化]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Fri, 20 Apr 2007 08:57:21 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	一、文件系统 <br/>　　在fstab里加入noatime，如 <br/>　　#cat /etc/fstab <br/>　　/dev/sda1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/home &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ext3 &nbsp; &nbsp;noatime,defaults &nbsp; &nbsp; &nbsp; &nbsp;1 2 <br/>　　reboot或者重新mount生效 <br/>　　二、Tcp优化 <br/>　　在/etc/sysctl.conf里加入 <br/>　　net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv = 3 <br/>　　net.ipv4.tcp_syncookies = 1 #启用syncookies <br/>　　 &nbsp; &nbsp; &nbsp; &nbsp;net.ipv4.tcp_max_syn_backlog = 8192 #定义backlog队列容纳的最大半连接数 <br/>　　net.ipv4.tcp_fin_timeout = 30 <br/>　　net.ipv4.tcp_keepalive_time = 1800 <br/>　　net.ipv4.tcp_window_scaling = 0 <br/>　　net.ipv4.tcp_sack = 0 <br/>　　net.ipv4.tcp_timestamps = 0 <br/>　　[color=blue:b6bef7e40f]老实说，对于sysctl.conf究竟能不能用起来还真不知道，因为我是没用起来，虽然内核里面是支持的 = =b[/color:b6bef7e40f] <br/><br/>　　三、虚拟内存优化 <br/>　　/etc/sysctl.conf <br/>　　vm.lower_zone_protection = 100 <br/><br/>　　四、I/O调度器 <br/>　　在grub.conf的相应启动选项里加入elevator=deadline，如： <br/>　　kernel /vmlinuz-2.6.6 ro root=/dev/sda6 elevator=deadline <br/>　　这里用了Deadline的I/O调度器,它比系统默认的AnticipatoryI/O调度器更为小巧,在数据吞吐量非常大的数据库系统中表现得更有优势。 <br/><br/>　　五、内核源代码参数修改 <br/>　　修改/usr/src/linux/include/linux/posix_types.h <br/>　　#define __FD_SETSIZE 1024  65536 &nbsp;<br/>　　设置fd_set支持的最大数量 <br/>　　 &nbsp;<br/>　　修改/usr/src/linux/include/linux/fs.h <br/>　　#define INR_OPEN 1024  65536 <br/>　　#define NR_FILE 8192  65536 <br/>　　#define NR_RESERVED_FILES 10  128 <br/>　　设置最大打开文件数量（TCP连接数量） <br/><br/>　　修改/usr/src/linux/include/net/tcp.h <br/>　　#define TCP_TIMEWAIT_LEN (60*HZ)  1*HZ <br/>　　#define TCP_SYNACK_RETRIES &nbsp;5  3 &nbsp;<br/>　　设置在backlog队列里的半连接的重试次数，每次都会花相应的时间，本质上 <br/>　　也是减少重试时间 <br/><br/>　　make menuconfig中，去掉没用的选项，打开以下选项的开关： <br/>　　High Memory Support (支持4GB以上内存) <br/>　　Symmetric multi-processing support (支持多CPU) <br/>　　TCP syncookie support (可以防DOS) <br/>　　设置文件打开数等的其他方法(好处就是可以不重新编译内核) <br/>　　在 /etc/init.d/sshd里加入(统一加在. /etc/rc.d/init.d/functions行后面) <br/>　　[code:1:b6bef7e40f]ulimit -n 65535 >/dev/null 2>&1 <br/>　　ulimit -u 16384 >/dev/null 2>&1[/code:1:b6bef7e40f] <br/>　　重起sshd：nohup /etc/init.d/sshd restart & <br/>　　BTW：其实limits.conf不好，因为他需要root su - user遗传给普通用户 <br/>　　如果直接远程登陆是没效果的 <br/><br/>　　六、apache <br/>　　1、安装:采用worker线程工作模式 <br/>　　[code:1:b6bef7e40f]./configure --prefix=/prefix &nbsp;<br/>　　--enable-mods-shared=all &nbsp;<br/>　　--enable-deflate &nbsp;<br/>　　--with-mpm=worker[/code:1:b6bef7e40f][color=blue:b6bef7e40f]chmod +s /prefix/bin/httpd [/color:b6bef7e40f]#允许普通用户也可以启动apache <br/>　　2、配置：httpd.conf <br/>　　[code:1:b6bef7e40f]Timeout 60 <br/>　　KeepAlive On <br/>　　MaxKeepAliveRequests 150 <br/>　　KeepAliveTimeout &nbsp; 5 <br/><br/>　　StartServers &nbsp; &nbsp; &nbsp; &nbsp; 3 <br/>　　MaxClients &nbsp; &nbsp; &nbsp; &nbsp; 3200 &nbsp; #支持3200个客户端哦 <br/>　　ServerLimit &nbsp; &nbsp; &nbsp; &nbsp;32 <br/>　　MinSpareThreads &nbsp; &nbsp; 50 <br/>　　MaxSpareThreads &nbsp; &nbsp; 250 <br/>　　ThreadLimit &nbsp; 200 <br/>　　ThreadsPerChild &nbsp; &nbsp; 100 <br/>　　MaxRequestsPerChild 0 <br/><br/>　　#上面的几个参数对机器要求比较高，如果是比较差的机器，每台机1000个连接最多了，你可能要重新设置参数，我的机器是DELL 2850 <br/><br/>　　UseCanonicalName Off <br/>　　HostnameLookups Off <br/>　　ServerSignature Off[/code:1:b6bef7e40f]<br/><br/>　　备注：<br/>　　要apache支持3200个客户端，默认最大支持1024（64*16）个客户端，所以必须修改apache的源代码树下的server/mpm/worker/worker.c <br/>　　把 #define DEFAULT_THREAD_LIMIT 64 &nbsp;--> 128 #每个子进程中包含的线程数 <br/>　　 &nbsp; #define DEFAULT_SERVER_LIMIT 16 &nbsp;--> &nbsp;32 &nbsp;#最大的子进程总数 <br/><br/>　　注意，不要把这两个值设得太高，超过系统的处理能力，那就事与愿违了 <br/>　　现在我的机子能承受每天350W的访问量，高峰期的load最多到2左右 <br/><br/>　　Worker模式下所能同时处理的请求总数是由子进程总数乘以ThreadsPerChild值决定的，应该大于等于MaxClients <br/><br/>　　大家可以根据自己的实际情况调试一下的。祝大家愉快。 &nbsp; :)<br/><br/><br/>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] 针对Web服务器总体优化]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>