|
出处 菜鸟油 ( http://www.noobu.com ) 作者:沧蓝 欢迎转载,转载请注明出处与作者,谢谢 A`nzqe#(1 <推荐> 本文的完美排版/最后更新修正版本:http://www.noobu.com/0510_apache_mysql_sysctl_tweak.html <推荐> O
#5`mo G;AJBs>Y} V|)nUsU tZygTvK/S 人们常说,服务器的负载能力,很大程度上取决于系统管理员的配置和优化能力。这个是对的,相同的硬件、不同的软件配置,会造成截然不同的效果。下面我将给大家介绍一下如何优化 sysctrl, Apache 以及 MySQL 。请注意,所有配置均为取决于个人,请根据自己的实际情况做调整。 8qwPk4 R'$1,ie \L"0Pmt[ 配置Sysctl zKFiCP
K Q+p9^_r 编辑此文件: emG1Wyl B3Ws)nF" nano -w /etc/sysctl.conf RY]jY | E f<vZ4 IU KNSMx<GP 如果该文件为空,则输入以下内容,否则请根据情况自己做调整: CJt(c,!z "LM[WcDX # Controls source route verification gP?.io9Oi # Default should work for all interfaces v dPb-z4 net.ipv4.conf.default.rp_filter = 1 O7yIFqI=/ # net.ipv4.conf.all.rp_filter = 1 _@O.EksY3r # net.ipv4.conf.lo.rp_filter = 1 oA4<AJ2 # net.ipv4.conf.eth0.rp_filter = 1 JxQGL{)
> aA-s{af # Disables IP source routing <,Fj}T- # Default should work for all interfaces +[Q`I*C net.ipv4.conf.default.accept_source_route = 0 4GexYDk'# # net.ipv4.conf.all.accept_source_route = 0 Im@Yx^gc # net.ipv4.conf.lo.accept_source_route = 0 hv )d # net.ipv4.conf.eth0.accept_source_route = 0 qKNHhXi 6QNO#!; # Controls the System Request debugging functionality of the kernel p&ZLd`
[ kernel.sysrq = 0 VX e7b 5>&C.+A 9 # Controls whether core dumps will append the PID to the core filename. bP{uZnOM2P # Useful for debugging multi-threaded applications. IvM>z03 kernel.core_uses_pid = 1 P;ovPyoO MzIn~[\ # Increase maximum amount of memory allocated to shm t#=FFQOt # Only uncomment if needed! %SwhNn # kernel.shmmax = 67108864 n4/Jx* K7]QgfpSZ # Disable ICMP Redirect Acceptance u-HBmL # Default should work for all interfaces m]'P3^<{P net.ipv4.conf.default.accept_redirects = 0 qp2&Z8S\D # net.ipv4.conf.all.accept_redirects = 0 q 1+{MPJ # net.ipv4.conf.lo.accept_redirects = 0 `_>44!M # net.ipv4.conf.eth0.accept_redirects = 0 48n 7<M;I y/!jC]!+c # Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets d`
4F # Default should work for all interfaces hbE~.[Y2r net.ipv4.conf.default.log_martians = 1 |&U{
z? # net.ipv4.conf.all.log_martians = 1 p((a(Q/ # net.ipv4.conf.lo.log_martians = 1 +F+M[ef<ws # net.ipv4.conf.eth0.log_martians = 1 (!%9# .?kq\.rQ # Decrease the time default value for tcp_fin_timeout connection (nAL;:$x2 net.ipv4.tcp_fin_timeout = 25 u(i=-PN_< -tfUkGdx;l # Decrease the time default value for tcp_keepalive_time connection @MO/LvD net.ipv4.tcp_keepalive_time = 1200 )3k?{1: rFaG-R # Turn on the tcp_window_scaling LVT:oIQ net.ipv4.tcp_window_scaling = 1 aK/fZ$Qc aa"3
Io # Turn on the tcp_sack U7Oa
13Qz net.ipv4.tcp_sack = 1 G.`},c;A- Lv#0-+]$Bt # tcp_fack should be on because of sack `]^W#6l net.ipv4.tcp_fack = 1 \*[DR R0 ea]qX6)UZ # Turn on the tcp_timestamps *V 4%&&{ net.ipv4.tcp_timestamps = 1 wl&T9O;? XRO(p`OE- # Enable TCP SYN Cookie Protection e ^oGiL~ net.ipv4.tcp_syncookies = 1 un4fnoc 4wkv#vi7!- # Enable ignoring broadcasts request g?Tev^D net.ipv4.icmp_echo_ignore_broadcasts = 1 /Ry%K4$ Ar[|M2| # Enable bad error message Protection /#
]eVD
net.ipv4.icmp_ignore_bogus_error_responses = 1 tjt^R$[ @ &+&@;2 # Make more local ports available vi
*A5 # net.ipv4.ip_local_port_range = 1024 65000 l)*(UZ" LXh}U>a9 # Set TCP Re-Ordering value in kernel to ‘5′
`YC7+`q net.ipv4.tcp_reordering = 5 8-NycG&) z4Zm% # Lower syn retry rates tiE|%jOzt net.ipv4.tcp_synack_retries = 2 P O 5Wi net.ipv4.tcp_syn_retries = 3 V~[b`&F
y;Cs#eo # Set Max SYN Backlog to ‘2048′ 8
E\zjT!#\ net.ipv4.tcp_max_syn_backlog = 2048 myR{}G 0 (wu # Various Settings mdEJ'];AH net.core.netdev_max_backlog = 1024 fV|uKs(W 8#yu.\N.xt # Increase the maximum number of skb-heads to be cached __'4Qt net.core.hot_list_length = 256 aE5-b ub c NUYKMo1ze # Increase the tcp-time-wait buckets pool size o'$"MC+ net.ipv4.tcp_max_tw_buckets = 360000 49Jnp>h dYrgL3' # This will increase the amount of memory available for socket input/output queues 9Vm1q!lE net.core.rmem_default = 65535 ZX:rqc net.core.rmem_max = 8388608 adP :{j net.ipv4.tcp_rmem = 4096 87380 8388608 -{cmi
,oy net.core.wmem_default = 65535 N
x&/p$d net.core.wmem_max = 8388608 m>vwpRBOA net.ipv4.tcp_wmem = 4096 65535 8388608 k)n
b<JW|r net.ipv4.tcp_mem = 8388608 8388608 8388608 2xLtJR4L net.core.optmem_max = 40960 ki'$P.v{$w (kLaXayn 如果希望屏蔽别人 ping 你的主机,则加入以下代码: T/'z,,Y f#!+l1GV # Disable ping requests s-"KABEE net.ipv4.icmp_echo_ignore_all = 1 uB
I/3aQ 3}H{4]*%_ 编辑完成后,请执行以下命令使变动立即生效: "] V\ Y! h vYRAQR: /sbin/sysctl -p be8T<F /sbin/sysctl -w net.ipv4.route.flush=1 sGu.G .}\8Y= MySQL优化 n&:ohOH% R0RxcBtG 编辑MySQL的配置文件: PB@IPnB- ?/o 8f7Z nano /etc/my.cnf E]mm^i`| G3Dg B! 输入以下内容: BY~Tc5 $P{`-Y }a [mysqld] lKsn6c,] connect_timeout=15 -P}A26qB interactive_timeout=100 6k
t,q0 join_buffer_size=1M xxur4@p! key_buffer=128M G[>NP#P max_allowed_packet=16M S"&Gutu3o max_connections=500 gF,=rT1:>r max_connect_errors=10 V[(fE=cIN~ myisam_sort_buffer_size=64M NF&Sv read_buffer_size=1M v*!N}1+J read_rnd_buffer_size=768K W_}j~[& sort_buffer_size=1M ],weqs table_cache=1024 or*{P=m+R thread_cache_size=100 f- XUto thread_concurrency=4 /Z6lnm7wJ wait_timeout=300 84WDR? query_cache_size=32M -W9DH^EL< query_cache_limit=1M Q/SO%E`E query_cache_type=1 ;d}>8w&tfy skip-innodb Z;G*wM" C$[iduS 请注意,以上配置适用于512M~1024M内存,如内存更大的话请自行做调整。给项目增加内存会加快速度,但是使用过多的内存而导致启用swap的话,会极大的导致系统效率下降。其中 thread_concurrency 这项配置,单CPU的话请设置为2,双CPU的话请设置为4。 h,$CJdDY] $_F_%m"\ Apache优化 Ga5s9wC u9 &$`N_G 以下优化适用于 Apache 1.3 系列,如果你用的是 2.0 系列的话,请自行做调整和判断。 RyK~"CWT Bug.>ln1 确认 Apache 的配置文件位置并开始编辑: QwX81*nx o6A$)m5V locate httpd.conf Kn->R9Tl nano -w /path/to/httpd.conf )'m;a_r` ML>M:Ik+ httpd.conf的文件有许多内容,笔者就拿出需要做优化的: h)Fc<,vwBE D\5+2 G KeepAlive On kFE9}0- MaxKeepAliveRequests 1000 {{G3^ysa KeepAliveTimeout 3 0JtM|Mg 9~`#aQG T MinSpareServers 8
ZY8.p MaxSpareServers 13 HsTY* ^V 1Z
~C3)T= MaxRequestsPerChild 50 '1DY5`i{ k}:;`ST 将 KeepAliveTimeout 设定到较小的数字将有助于减少服务器上的无用等待链接,一定程度上能增加服务器负载。 K3\a~_0 Ub
f5: 另外,下面这条不算优化,但是是Apache安全相关: +pgHCzwJE iPl,KjGk ServerSignature Off (hOD ServerTokens ProductOnly w tGS"L +x{o 将 ServerSignature 关闭,并增加 ServerTokens ProductOnly 可以使常人无法检测到Apache的实际版本号,有助于Apache的安全。 R\ 8[6H |BM#r fQ 以上所做的这些优化在某种程度上会增强服务器的负载性能。但请注意,最佳的配置是实践出来的。
|
一共有 2 条评论
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒
反应釜
搪瓷反应釜
冷凝器
搪玻璃反应釜
反应釜
搪瓷反应釜
造粒机
造粒
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护栏
静脉曲张
精索静脉曲张
静脉曲张
糖尿病足
脉管炎
静脉炎
动脉硬化闭塞症
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒
反应釜
搪瓷反应釜
冷凝器
搪玻璃反应釜
反应釜
搪瓷反应釜
造粒机
造粒
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护栏
静脉曲张
精索静脉曲张
静脉曲张
糖尿病足
脉管炎
静脉炎
动脉硬化闭塞症