你好,游客! 登陆或注册 | 首 页 | 同城博客 | 搜 索 | 帮 助 | 无图版
  • 首 页
  • 技术讨论
  • 生活人生
  • 经济大观
  • 时尚动态
  • 舞文弄墨
  • 情感天地
  • 原创文学
  • 体育竞技
  • 旅游杂记
  • 随想杂谈

 

  承德人博客 » 技术讨论 » 服务器优化——Sysctl, Apache, MySQL篇

 
0
服务器优化——Sysctl, Apache, MySQL篇
作者: admin 发表日期: 2007-05-14 复制链接 收藏

最近踩过这里的人:
出处 菜鸟油 ( http://www.noobu.com ) 作者:沧蓝 欢迎转载,转载请注明出处与作者,谢谢 WzlS^bZ  
<推荐> 本文的完美排版/最后更新修正版本:http://www.noobu.com/0510_apache_mysql_sysctl_tweak.html <推荐> bk0Y  
33,;i E  
 ;fj9 n-  
@7 )Z  
人们常说,服务器的负载能力,很大程度上取决于系统管理员的配置和优化能力。这个是对的,相同的硬件、不同的软件配置,会造成截然不同的效果。下面我将给大家介绍一下如何优化 sysctrl, Apache 以及 MySQL 。请注意,所有配置均为取决于个人,请根据自己的实际情况做调整。 Ou? r {$(b  
T6,V  
,;7`{Nab  
配置Sysctl @uoT{E[  
EZ..^M3  
编辑此文件: #>@<n3rq  
fVG$8tB  
nano -w /etc/sysctl.conf l_bL,-|E8  
lt{lH at1  
j p!  
如果该文件为空,则输入以下内容,否则请根据情况自己做调整: j.<:00<  
A<mj8qz  
# Controls source route verification Sjw2 j#Q  
# Default should work for all interfaces  AQB1gzE  
net.ipv4.conf.default.rp_filter = 1 g@<sU0B  
# net.ipv4.conf.all.rp_filter = 1 f-vZ2+HP  
# net.ipv4.conf.lo.rp_filter = 1 #L_@ s d  
# net.ipv4.conf.eth0.rp_filter = 1 F5<"ktnI  
nw~/~eM5=  
# Disables IP source routing b^uP^](J  
# Default should work for all interfaces l5{(z;xM  
net.ipv4.conf.default.accept_source_route = 0 Zx}N Fcn  
# net.ipv4.conf.all.accept_source_route = 0 AeNyZ[40T  
# net.ipv4.conf.lo.accept_source_route = 0 P3+)pOE-SI  
# net.ipv4.conf.eth0.accept_source_route = 0 80{#bb  
e#l*/G*,  
# Controls the System Request debugging functionality of the kernel 4 ?9soc  
kernel.sysrq = 0 gGtep*k  
anHBy SI3  
# Controls whether core dumps will append the PID to the core filename. 7sQ]w   
# Useful for debugging multi-threaded applications. ^4u3Q  
kernel.core_uses_pid = 1 Z]mM  
GN htnB  
# Increase maximum amount of memory allocated to shm 09}f\/  
# Only uncomment if needed! ,Az`6PW  
# kernel.shmmax = 67108864 veYsctK~  
L|]w3}ZT@  
# Disable ICMP Redirect Acceptance .oi}SG  
# Default should work for all interfaces Z ,|1G6f@  
net.ipv4.conf.default.accept_redirects = 0 D&z'tf5  
# net.ipv4.conf.all.accept_redirects = 0 SQ~N X)  
# net.ipv4.conf.lo.accept_redirects = 0 1c<CEq:?e%  
# net.ipv4.conf.eth0.accept_redirects = 0 O?j98H Sya  
F$6])F  
# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets K\^&_#MG  
# Default should work for all interfaces #czyr@  
net.ipv4.conf.default.log_martians = 1 (2O} B.6  
# net.ipv4.conf.all.log_martians = 1 @ V7ooo!  
# net.ipv4.conf.lo.log_martians = 1 (jo(bbpj  
# net.ipv4.conf.eth0.log_martians = 1 :bM$;  
3I>S:|=K  
# Decrease the time default value for tcp_fin_timeout connection _ntW}})K  
net.ipv4.tcp_fin_timeout = 25 px [1#*  
G"U>fwFuK  
# Decrease the time default value for tcp_keepalive_time connection llZ"uTK\M  
net.ipv4.tcp_keepalive_time = 1200 t0asW5f  
vY0V{u?J  
# Turn on the tcp_window_scaling }*}`)rj,  
net.ipv4.tcp_window_scaling = 1 LHHDt<+B  
$p6Xa;j$9  
# Turn on the tcp_sack  Sj{rvW  
net.ipv4.tcp_sack = 1 yz2oS|0'  
S9"y@F <  
# tcp_fack should be on because of sack dVmAMQk.g  
net.ipv4.tcp_fack = 1 ]g-qWSKU  
l#vw L 15  
# Turn on the tcp_timestamps Yq hz(&*)  
net.ipv4.tcp_timestamps = 1 x+:,b~Skk  
VF!kr1n!  
# Enable TCP SYN Cookie Protection |e-+xX|;  
net.ipv4.tcp_syncookies = 1 X @jYQ.  
7F9g:r/^  
# Enable ignoring broadcasts request 2hA66ar{$  
net.ipv4.icmp_echo_ignore_broadcasts = 1 H"RF[bX(  
;Y XrG  
# Enable bad error message Protection [qD<U%Hi  
net.ipv4.icmp_ignore_bogus_error_responses = 1 RJs G]`  
;3?J#e6;  
# Make more local ports available M^Ay,jK!  
# net.ipv4.ip_local_port_range = 1024 65000 3k[<4-  
5b4V/d* '  
# Set TCP Re-Ordering value in kernel to ‘5′ OO+#KyU   
net.ipv4.tcp_reordering = 5 ne24QZ~}  
$`dNl#G,  
# Lower syn retry rates DMZ aMY|  
net.ipv4.tcp_synack_retries = 2 c7Qa !w  
net.ipv4.tcp_syn_retries = 3 ~ 2oP,  
uW'4 Kt  
# Set Max SYN Backlog to ‘2048′ jz7ltoP  
net.ipv4.tcp_max_syn_backlog = 2048 +4nR&1z$  
>MY.Fr#.m  
# Various Settings "?&bh@P&  
net.core.netdev_max_backlog = 1024 !!O{ ppM  
`(suRp8 !  
# Increase the maximum number of skb-heads to be cached |&'] ms5J  
net.core.hot_list_length = 256 E!l1a5qB  
NRF%Qd8I/2  
# Increase the tcp-time-wait buckets pool size `0sk2fn  
net.ipv4.tcp_max_tw_buckets = 360000 m1i$> 9,  
8%f! X51  
# This will increase the amount of memory available for socket input/output queues &'\+Z  
net.core.rmem_default = 65535 6mpUk.M"  
net.core.rmem_max = 8388608 E9 -'!I!  
net.ipv4.tcp_rmem = 4096 87380 8388608 :"IH*7xp  
net.core.wmem_default = 65535 (HKm2JuFG  
net.core.wmem_max = 8388608 # |[@Due  
net.ipv4.tcp_wmem = 4096 65535 8388608 .tsB$,/  
net.ipv4.tcp_mem = 8388608 8388608 8388608 a Z, Wa-k  
net.core.optmem_max = 40960 ~J:lC u  
[_1G\z_iE  
如果希望屏蔽别人 ping 你的主机,则加入以下代码: @$G K<jl  
t]%R4ymV  
# Disable ping requests ohk =7d.'  
net.ipv4.icmp_echo_ignore_all = 1 <:-&yDh u  
uGWk(qn  
编辑完成后,请执行以下命令使变动立即生效: c[q3O**  
0g4cyK~n]  
/sbin/sysctl -p !>j- j  
/sbin/sysctl -w net.ipv4.route.flush=1 B4=gMVp1  
nr;/:[F  
MySQL优化 q9^r2OO  
akoILX~u  
编辑MySQL的配置文件: $MHc4FE[  
6 ?cV1:jh  
nano /etc/my.cnf 'yqp   
fpUX @b  
输入以下内容: N?p $-{  
F7d f  
[mysqld] [z?XVl<  
connect_timeout=15 SU^/qF%8  
interactive_timeout=100 aG!!z>  
join_buffer_size=1M 5m/r,d^H  
key_buffer=128M %u#pl=k}  
max_allowed_packet=16M L/shF}<  
max_connections=500 l\bBc, %jt  
max_connect_errors=10 nHhg#wR  
myisam_sort_buffer_size=64M tG6 o^  
read_buffer_size=1M SFuzH)+VO  
read_rnd_buffer_size=768K UJQ!~g.y]  
sort_buffer_size=1M 4&?%"2  
table_cache=1024 >_R5Li  
thread_cache_size=100 {8E hC/=  
thread_concurrency=4 #<)u%)`  
wait_timeout=300 e-Eoe_k  
query_cache_size=32M #T+%$q [:  
query_cache_limit=1M norWNm(n  
query_cache_type=1 $U<xrN>O  
skip-innodb ,1od]]>(O  
!\CoJ.5=  
请注意,以上配置适用于512M~1024M内存,如内存更大的话请自行做调整。给项目增加内存会加快速度,但是使用过多的内存而导致启用swap的话,会极大的导致系统效率下降。其中 thread_concurrency 这项配置,单CPU的话请设置为2,双CPU的话请设置为4。 " GgK,d}%  
eEXer>Rm   
Apache优化 ~c+0SuJ  
{p+7QlgK  
以下优化适用于 Apache 1.3 系列,如果你用的是 2.0 系列的话,请自行做调整和判断。 JZ'`. yK:  
UuW"  
确认 Apache 的配置文件位置并开始编辑: "^yTH/m  
g!i\ AMG?  
locate httpd.conf L@XhgQ  
nano -w /path/to/httpd.conf \|RP-8  
](vOH#E  
httpd.conf的文件有许多内容,笔者就拿出需要做优化的: }mzM'9JH  
8lh{ R  
KeepAlive On xQT`sK+  
MaxKeepAliveRequests 1000 615, P/  
KeepAliveTimeout 3 8&\<p7}=h  
S;[9 hI+  
MinSpareServers 8 wM8Gz.9,  
MaxSpareServers 13 21_>|EKp  
?aR)dQ  
MaxRequestsPerChild 50 x>THyY[sq  
Nz %{T  
将 KeepAliveTimeout 设定到较小的数字将有助于减少服务器上的无用等待链接,一定程度上能增加服务器负载。 z'GYU=  
]U.1z  
另外,下面这条不算优化,但是是Apache安全相关: , g\%P5  
7m3| 2Qv  
ServerSignature Off P0WI QG+  
ServerTokens ProductOnly / V}>v  
No#1Ikw  
将 ServerSignature 关闭,并增加 ServerTokens ProductOnly 可以使常人无法检测到Apache的实际版本号,有助于Apache的安全。 r6k0=6i  
j}}:&>;  
以上所做的这些优化在某种程度上会增强服务器的负载性能。但请注意,最佳的配置是实践出来的。
欢迎到 admin 的个人主页看更多内容 阅读全文 (349) | 回复 (2) | 推送
qq (2008-03-06)回复:  
免烧砖机
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒

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

反应釜
搪瓷反应釜
造粒机
造粒
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)回复:  
免烧砖机
球磨机
选矿设备
选矿设备
真空砖机
加气块
天车
电子衡器
电子秤
衡器
电子吊秤
地磅
电子汽车衡
免烧砖机
制砖机
免烧砖机
真空砖机
免烧制砖机
球磨机
选矿设备
防爆电动葫芦
电动葫芦
风湿病 排名在 需加强
类风湿性关节炎
强直性脊柱炎
风湿
类风湿
风湿性关节炎
肝癌晚期治疗
肝硬化腹水
肝硬化治疗
肝癌晚期治疗
肝癌治疗
肝硬化
旅游规划
旅游策划
隔声
搪玻璃反应釜
冷凝器
搪瓷储罐
反应釜
搪瓷反应釜
造粒机
造粒

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

反应釜
搪瓷反应釜
造粒机
造粒
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护栏
静脉曲张
精索静脉曲张
静脉曲张
糖尿病足
脉管炎
静脉炎
动脉硬化闭塞症

用户名:

搜索

系统公告

小调查

新加入

  • jttnaq
  • mhkkqj
  • pgspnwr
  • ofunamu
  • qjrnd
  • 尤米尼斯
  • 德明泉

朋友圈分类

  • » 影视音乐
  • » 置业安居
  • » 车行天下
  • » 星座情缘
  • » 体育联盟
  • » 职业交流
  • » 技术联盟
  • » 同城对碰
  • » 生活休闲
  • » 商业金融
  • » 原创空间
Powered by LxBlog v5.3 Code © 2003-07 PHPWind.com Corporation
Time 0.120867 second(s),query:5 Gzip enabled contact us