日历

2008 11.21 Fri
      1
2345678
9101112131415
16171819202122
23242526272829
30      
«» 2008 - 11 «»

文章搜索

日志文章

2007年05月14日

服务器优化——Sysctl, Apache, MySQL篇

出处 菜鸟油 ( http://www.noobu.com ) 作者:沧蓝 欢迎转载,转载请注明出处与作者,谢谢 rD_\NgVAs  
<推荐> 本文的完美排版/最后更新修正版本:http://www.noobu.com/0510_apache_mysql_sysctl_tweak.html <推荐> sH_B*cr3  
?cur}`  
% H/V iC  
lD9QS ;  
人们常说,服务器的负载能力,很大程度上取决于系统管理员的配置和优化能力。这个是对的,相同的硬件、不同的软件配置,会造成截然不同的效果。下面我将给大家介绍一下如何优化 sysctrl, Apache 以及 MySQL 。请注意,所有配置均为取决于个人,请根据自己的实际情况做调整。 (p v6V2i  
nI _UL  
;)Fc@OXN>  
配置Sysctl hEhvA6f,  
j"5 $m@lgn  
编辑此文件: 2'U+QK@  
a 8}!9kL  
nano -w /etc/sysctl.conf =wquFA!c  
zvOSQxGQ  
~0V,B1a  
如果该文件为空,则输入以下内容,否则请根据情况自己做调整: 9s2 N!bx  
ydMfV-  
# Controls source route verification @+&QNI06S  
# Default should work for all interfaces =bh.V@*  
net.ipv4.conf.default.rp_filter = 1 -F&*>?I  
# net.ipv4.conf.all.rp_filter = 1 ' }T6dS  
# net.ipv4.conf.lo.rp_filter = 1 Sp\ 7  
# net.ipv4.conf.eth0.rp_filter = 1 eUEO~M2&U{  
U}:e-   
# Disables IP source routing j6#RV@ p`  
# Default should work for all interfaces ~@ML>z 7  
net.ipv4.conf.default.accept_source_route = 0 q%hxU.h  
# net.ipv4.conf.all.accept_source_route = 0 cwBf((~  
# net.ipv4.conf.lo.accept_source_route = 0 |P`:NAf2  
# net.ipv4.conf.eth0.accept_source_route = 0 f{ER]U  
3fhlMOm  
# Controls the System Request debugging functionality of the kernel U`)o$4Bq  
kernel.sysrq = 0 , Vr'F  
4 t< mX  
# Controls whether core dumps will append the PID to the core filename. xZ(f_Oy  
# Useful for debugging multi-threaded applications. \iM  
kernel.core_uses_pid = 1 /d-d8n  
.F@0`*#rE~  
# Increase maximum amount of memory allocated to shm RqE|h6/  
# Only uncomment if needed! < (<IRCR  
# kernel.shmmax = 67108864 a534@U4,  
Y=YIz>u  
# Disable ICMP Redirect Acceptance 5&N55? G6  
# Default should work for all interfaces e9@7GaL`"S  
net.ipv4.conf.default.accept_redirects = 0 ,+hH|$  
# net.ipv4.conf.all.accept_redirects = 0 uIb,n 5  
# net.ipv4.conf.lo.accept_redirects = 0 |)W N%#v  
# net.ipv4.conf.eth0.accept_redirects = 0 WPu{ ]<pl  
>4@/x{{  
# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets FEzjP$  
# Default should work for all interfaces rj> _L  
net.ipv4.conf.default.log_martians = 1 =vc8u&L2  
# net.ipv4.conf.all.log_martians = 1 xhmrep6+<  
# net.ipv4.conf.lo.log_martians = 1 !Ey=  
# net.ipv4.conf.eth0.log_martians = 1 i9 Tq h  
"x P2GZ  
# Decrease the time default value for tcp_fin_timeout connection a/v!W@Zz}  
net.ipv4.tcp_fin_timeout = 25 gvLzE&V}  
<yq kJ  
# Decrease the time default value for tcp_keepalive_time connection q }'ww  
net.ipv4.tcp_keepalive_time = 1200 S pqbr@j  
j[e<CGZ  
# Turn on the tcp_window_scaling 4,)EG1  
net.ipv4.tcp_window_scaling = 1 -)Zp"  
a(Fx1`}  
# Turn on the tcp_sack iT2{3 t  
net.ipv4.tcp_sack = 1 }\$CU N  
>=+: lD  
# tcp_fack should be on because of sack &h<\jqN/  
net.ipv4.tcp_fack = 1 hq|I%>y  
9(AY7]6  
# Turn on the tcp_timestamps =euMOs  
net.ipv4.tcp_timestamps = 1 \Aq$h:<  
AdgZau[Y6  
# Enable TCP SYN Cookie Protection Q*54!^l+_r  
net.ipv4.tcp_syncookies = 1 ;#XF.l,u  
>z|bQW#2  
# Enable ignoring broadcasts request K 3.z>.F'h  
net.ipv4.icmp_echo_ignore_broadcasts = 1 ' TO/i:{\  
B".3NQ  
# Enable bad error message Protection aHkt K/  
net.ipv4.icmp_ignore_bogus_error_responses = 1 U7xKu75G1  
r*kz`cJ  
# Make more local ports available UWW'[gEP1  
# net.ipv4.ip_local_port_range = 1024 65000 _ 5/3RN  
f3SAK!V+s  
# Set TCP Re-Ordering value in kernel to ‘5′ 4hWFgk  
net.ipv4.tcp_reordering = 5 h3(B7n7  
`{&l _  
# Lower syn retry rates F$HL \y  
net.ipv4.tcp_synack_retries = 2 ]htx9ds=  
net.ipv4.tcp_syn_retries = 3 D6:"k 2  
v03 ^  
# Set Max SYN Backlog to ‘2048′ )%bY2 pk  
net.ipv4.tcp_max_syn_backlog = 2048 zJTSg  
5[A4K%EL  
# Various Settings ,S7M4ajVZB  
net.core.netdev_max_backlog = 1024 j12khp?  
qdwjg8fo4Z  
# Increase the maximum number of skb-heads to be cached ''wF%q  
net.core.hot_list_length = 256 f/]g@/`  
k1_ 3\JO"6  
# Increase the tcp-time-wait buckets pool size B#K 2?Et!t  
net.ipv4.tcp_max_tw_buckets = 360000 $jNp-5+Q;  
j:J{m0  
# This will increase the amount of memory available for socket input/output queues 4&^BcWqA*f  
net.core.rmem_default = 65535 jl~ ?I*Gr  
net.core.rmem_max = 8388608 |T^c(RpOE  
net.ipv4.tcp_rmem = 4096 87380 8388608 w|WehNGr  
net.core.wmem_default = 65535 1U;p+k5c  
net.core.wmem_max = 8388608 gv,8Wo  
net.ipv4.tcp_wmem = 4096 65535 8388608 K\`>'C2_V  
net.ipv4.tcp_mem = 8388608 8388608 8388608 isR|K9qf^  
net.core.optmem_max = 40960 h$~ \to$C  
'vUx4s  
如果希望屏蔽别人 ping 你的主机,则加入以下代码: #DFfySH)A  
CDTM<0`%  
# Disable ping requests q:/<^|  
net.ipv4.icmp_echo_ignore_all = 1 Au-h#YV  
xLmgr72D  
编辑完成后,请执行以下命令使变动立即生效: -*T<^G;rK  
BQfq]ti  
/sbin/sysctl -p [|!A3o  
/sbin/sysctl -w net.ipv4.route.flush=1 "bC1dl<  
',Q|g^rF]  
MySQL优化 B<" `<oG@|  
1}VaBsEV  
编辑MySQL的配置文件: =, XCjiBeC  
(\:Rnl  
nano /etc/my.cnf z5@XFaQ  
^J^,@ Hf_  
输入以下内容: L;V 8c  
e-dkvPr  
[mysqld] u^MKqI  
connect_timeout=15 5]O{tS j  
interactive_timeout=100 $PJ==N  
join_buffer_size=1M M+ [ho]  
key_buffer=128M vr;`h/  
max_allowed_packet=16M ,X!6|l8  
max_connections=500 G+dq */  
max_connect_errors=10 wfo,r 7  
myisam_sort_buffer_size=64M v3r3$(Hr  
read_buffer_size=1M =E9\fRGU  
read_rnd_buffer_size=768K +byOThuE  
sort_buffer_size=1M bYsX?0T!p  
table_cache=1024 t/;2rIx>  
thread_cache_size=100 C8m9H8Qm  
thread_concurrency=4 >jt2vU@t.  
wait_timeout=300 o]1BWwtY&  
query_cache_size=32M .!3e$mhV  
query_cache_limit=1M Qu|CXUk  
query_cache_type=1 ZDW9H6ux  
skip-innodb :8`A  
9,?~dx  
请注意,以上配置适用于512M~1024M内存,如内存更大的话请自行做调整。给项目增加内存会加快速度,但是使用过多的内存而导致启用swap的话,会极大的导致系统效率下降。其中 thread_concurrency 这项配置,单CPU的话请设置为2,双CPU的话请设置为4。  yXU.PSG*  
{;{U@Z  
Apache优化 -`faXFW'  
(4FVemgy  
以下优化适用于 Apache 1.3 系列,如果你用的是 2.0 系列的话,请自行做调整和判断。 6*Z7JiQ 0  
BgXZr,?  
确认 Apache 的配置文件位置并开始编辑: C~2!@<y  
CzBYH   
locate httpd.conf u IXA{89  
nano -w /path/to/httpd.conf |u>V> PN  
*q 6XK_  
httpd.conf的文件有许多内容,笔者就拿出需要做优化的: i%o%bib#  
X,49(-~\  
KeepAlive On #aX#gh}1  
MaxKeepAliveRequests 1000 KtaoOe  
KeepAliveTimeout 3 ]zYIblpde  
[l-o*@  
MinSpareServers 8 Ovx *  
MaxSpareServers 13 '@Uu/~;h  
+JI,6)Ry  
MaxRequestsPerChild 50 l0'Yq%Nf  
>12jUm)  
将 KeepAliveTimeout 设定到较小的数字将有助于减少服务器上的无用等待链接,一定程度上能增加服务器负载。 Milp"L?B%  
JLm3qIC  
另外,下面这条不算优化,但是是Apache安全相关: :WRD<D_4  
v(;yy{>8"  
ServerSignature Off ~+{*KPiD  
ServerTokens ProductOnly yhgGvyD  
*m]Y6  
将 ServerSignature 关闭,并增加 ServerTokens ProductOnly 可以使常人无法检测到Apache的实际版本号,有助于Apache的安全。 fK:4jl-r  
B{\Y~>]Pj  
以上所做的这些优化在某种程度上会增强服务器的负载性能。但请注意,最佳的配置是实践出来的。

类别: 无分类 |  评论(2) |  浏览(360) |  收藏
qq 2008年03月06日 Says:
免烧砖机
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒

反应釜
搪瓷反应釜
冷凝器
搪玻璃反应釜

反应釜
搪瓷反应釜
造粒机
造粒
Thermal fogger
fogging machine


Thermal fogger
fogging machine
wedding dress
bridesmaid dress
bridesmaid dress
flower girl dress
wedding dresses
wholesale wedding dress
wedding dress factory

偏头痛
护栏
道路护栏
pvc护栏
静脉曲张
精索静脉曲张
静脉曲张
糖尿病足
脉管炎
静脉炎
动脉硬化闭塞症
qq 2008年03月06日 Says:
免烧砖机
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒

反应釜
搪瓷反应釜
冷凝器
搪玻璃反应釜

反应釜
搪瓷反应釜
造粒机
造粒
Thermal fogger
fogging machine


Thermal fogger
fogging machine
wedding dress
bridesmaid dress
bridesmaid dress
flower girl dress
wedding dresses
wholesale wedding dress
wedding dress factory

偏头痛
护栏
道路护栏
pvc护栏
静脉曲张
精索静脉曲张
静脉曲张
糖尿病足
脉管炎
静脉炎
动脉硬化闭塞症
发表评论