首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >16 and和8核的最佳Apache & MySQL配置

16 and和8核的最佳Apache & MySQL配置
EN

Server Fault用户
提问于 2013-12-19 19:15:11
回答 1查看 6.2K关注 0票数 -1

我的服务器出问题了。我有一个高峰,我的服务器负载非常高。

我有3台服务器,一台用于前端,一台用于数据库(mysql),一台用于交付映像(这一台没有问题)

以下是我目前的配置和1500名访问者的平均负载:

服务器1(前端):

代码语言:javascript
复制
load average: 143.08, 120.50, 66.99
CentOS 6.3
Apache/2.2.15
8 x Intel(R) Xeon(R) CPU E5645  @ 2.40GHz
16GB RAM

httpd.conf

代码语言:javascript
复制
PidFile run/httpd.pid
Timeout 60
KeepAlive Off
MaxKeepAliveRequests 1000
KeepAliveTimeout 15

<IfModule prefork.c>
  ServerLimit       520

  StartServers           16
  MinSpareServers         5
  MaxSpareServers        20
  MaxClients            500
  MaxRequestsPerChild  1000
</IfModule>

<IfModule worker.c>
  ServerLimit           520

  StartServers           16 
  MaxClients            500
  MinSpareThreads        25
  MaxSpareThreads        75 
  ThreadsPerChild        25
  MaxRequestsPerChild     0
</IfModule>

ExtendedStatus On
UseCanonicalName Off
HostnameLookups Off

ErrorLog logs/error_log
LogLevel warn

ServerSignature On


IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

服务器2 (MySQL my.cnf)

代码语言:javascript
复制
load average: 12.84, 23.39, 22.85
CentOS 6.4
MYSQL 5.5.34
8 x Intel(R) Xeon(R) CPU E5645  @ 2.40GHz
16GB RAM

my.cnf

代码语言:javascript
复制
[mysqld]
port=3306
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

max_connections = 2000

key_buffer = 384M
query_cache_type=1
query_cache_size=512M
query_cache_limit=4M

innodb_buffer_pool_size = 8G
slow_query_log=1
slow_query_log_file=log-slow-queries.log
thread_cache_size=8
table_cache=128k
tmp_table_size=256M
max_heap_table_size=256M

init_connect='SET collation_connection = latin1_swedish_ci'
init_connect='SET NAMES latin1'
character-set-server=latin1
collation-server=latin1_swedish_ci
skip-character-set-client-handshake

log-error=/var/log/mysqld.error.log

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

mysqltuner输出

代码语言:javascript
复制
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.34-log
[OK] Operating on 64-bit architecture

-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
[--] Data in InnoDB tables: 3G (Tables: 57)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[!!] Total fragmented tables: 57

-------- Security Recommendations  -------------------------------------------
[OK] All database users have passwords assigned

-------- Performance Metrics -------------------------------------------------
[--] Up for: 5h 11m 15s (4M q [241.514 qps], 537K conn, TX: 11B, RX: 2B)
[--] Reads / Writes: 87% / 13%
[--] Total buffers: 9.1G global + 2.8M per thread (2000 max threads)
[OK] Maximum possible memory usage: 14.5G (46% of installed RAM)
[OK] Slow queries: 1% (55K/4M)
[OK] Highest usage of available connections: 37% (756/2000)
[OK] Key buffer size / total MyISAM indexes: 384.0M/96.0K
[OK] Key buffer hit rate: 100.0% (46K cached / 0 reads)
[!!] Query cache efficiency: 0.0% (0 cached / 2M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 480K sorts)
[OK] Temporary tables created on disk: 16% (112K on disk / 684K total)
[OK] Thread cache hit rate: 83% (87K created / 537K connections)
[OK] Table cache hit rate: 99% (2K open / 2K opened)
[OK] Open file limit used: 0% (19/264K)
[OK] Table locks acquired immediately: 100% (7M immediate / 7M locks)
[OK] InnoDB data size / buffer pool: 3.6G/8.0G

应用程序详细信息

PHP5.4 Symfony 1.2数据库大小: 6GB

你能帮帮我吗?

EN

回答 1

Server Fault用户

发布于 2013-12-19 22:01:28

我在这里看到的主要问题是前端服务器的负载平均值很高。MySQL服务器可以做得更好,但也没有那么糟糕。Apache服务器经常成为瓶颈。在不知道应用程序正在做什么的情况下,很难解决这个问题。一般性建议可如下:

  1. 在前端服务器上设置Munin,这将包括Apache的度量标准。有了这些信息,您将更容易调优Apache。Munin还将帮助您确定负载平均增加的频率和时间。
  2. 分析Apache和应用程序日志。什么是最沉重和最频繁的请求?可能存在一些与应用程序相关的问题(比如使用PHP提供静态文件)。
  3. 考虑切换到nginx/php而不是Apache。Apache是非常好的but服务器,但是nginx成为了许多不需要特定Apache特性的现代设置的标准。

考虑MySQL优化。您只有96.0K的MyISAM索引,而384.0M的密钥缓冲池。您可以安全地减少这个参数。您还可以使用Percona的pt查询摘要检查您的慢速查询,它非常方便。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/562567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档