当前位置: 首页 > 图文教程 > 数据库 > MYSQL > 大家来优化 Sysctl、Apache、MySQL
服务器的负载能力,很大程度上取决于系统管理员的配置和优化能力。相同的硬件、不同的软件配置,会造成截然不同的效果。下面我将给大家介绍一下如何优化 sysctrl, Apache 以及 MySQL 。请注意,所有配置均为取决于个人,请根据自己的实际情况做调整。
配置Sysctl
编辑此文件:
nano -w /etc/sysctl.conf
如果该文件为空,则输入以下内容,否则请根据情况自己做调整:
| # Controls source route verification # Disables IP source routing # Controls the System Request debugging functionality of the kernel # Controls whether core dumps will append the PID to the core filename. # Increase maximum amount of memory allocated to shm # Disable ICMP Redirect Acceptance # Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets # Decrease the time default value for tcp_fin_timeout connection # Decrease the time default value for tcp_keepalive_time connection # Turn on the tcp_window_scaling # Turn on the tcp_sack # tcp_fack should be on because of sack # Turn on the tcp_timestamps # Enable TCP SYN Cookie Protection # Enable ignoring broadcasts request # Enable bad error message Protection # Make more local ports available # Set TCP Re-Ordering value in kernel to ‘5′ # Lower syn retry rates # Set Max SYN Backlog to ‘2048′ # Various Settings # Increase the maximum number of skb-heads to be cached # Increase the tcp-time-wait buckets pool size # This will increase the amount of memory available for socket input/output queues |
如果希望屏蔽别人 ping 你的主机,则加入以下代码:
| # Disable ping requests net.ipv4.icmp_echo_ignore_all = 1 |
编辑完成后,请执行以下命令使变动立即生效:
| /sbin/sysctl -p /sbin/sysctl -w net.ipv4.route.flush=1 |
MySQL优化
编辑MySQL的配置文件:
| nano /etc/my.cnf |
输入以下内容:
| [mysqld] |
请注意,以上配置适用于512M~1024M内存,如内存更大的话请自行做调整。给项目增加内存会加快速度,但是使用过多的内存而导致启用swap的话,会极大的导致系统效率下降。其中 thread_concurrency 这项配置,单CPU的话请设置为2,双CPU的话请设置为4。
Apache优化
以下优化适用于 Apache 1.3 系列,如果你用的是 2.0 系列的话,请自行做调整和判断。
确认 Apache 的配置文件位置并开始编辑:
| locate httpd.conf nano -w /path/to/httpd.conf |
httpd.conf的文件有许多内容,笔者就拿出需要做优化的:
| KeepAlive On MinSpareServers 8 MaxRequestsPerChild 50 |
将 KeepAliveTimeout 设定到较小的数字将有助于减少服务器上的无用等待链接,一定程度上能增加服务器负载。
另外,下面这条不算优化,但是是Apache安全相关:
| ServerSignature Off ServerTokens ProductOnly |
将 ServerSignature 关闭,并增加 ServerTokens ProductOnly 可以使常人无法检测到Apache的实际版本号,有助于Apache的安全。
以上所做的这些优化在某种程度上会增强服务器的负载性能。但请注意,最佳的配置是实践出来的。
评论 (0) All