您好,serverfault 社区,
我有一个中型 VPS,上面运行着 2 个 Magento 安装、一些静态页面以及几个 WordPress / Joomla 安装 - 全部是个人网站和项目 - 总体来说没有什么特别花哨的东西,流量也极大。
我的 VPS 规格:
内存:12288 MB,CPU 核心:4 × 2.4 Ghz,操作系统:CentOS,附加功能:WHM / cPanel
总体来说,速度一直都很快,我没什么可抱怨的,但是最近我注意到网站加载速度变慢了,更具体地说,所有网站都需要 MySQL 数据库。
我向某人寻求建议,他告诉我这很可能与我的数据库的增长和/或错误的 my.cnf 配置文件有关。
我当前的 my.cnf 如下所示:
[mysqld]
open_files_limit=64000
local-infile=0
query_cache_size=512M
query_cache_limit=2M
default-storage-engine=MyISAM
innodb_file_per_table=1
thread_cache_size=4
join_buffer_size=4M
key_buffer_size=128M
table_cache=640
log-slow-queries=/home/mysql-slow-queries.log
long_query_time=1
建议我运行 mysqltuner,我按照以下输出操作:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.5.32-cll
[OK] Operating on 64-bit architecture
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 165M (Tables: 1034)
[--] Data in InnoDB tables: 92M (Tables: 1101)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 372K (Tables: 55)
[!!] Total fragmented tables: 25
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 4h 39m 42s (571K q [34.034 qps], 15K conn, TX: 786M, RX: 113M)
[--] Reads / Writes: 54% / 46%
[--] Total buffers: 800.0M global + 6.6M per thread (151 max threads)
[OK] Maximum possible memory usage: 1.8G (14% of installed RAM)
[OK] Slow queries: 0% (2/571K)
[OK] Highest usage of available connections: 7% (12/151)
[OK] Key buffer size / total MyISAM indexes: 128.0M/40.3M
[OK] Key buffer hit rate: 96.5% (548K cached / 18K reads)
[OK] Query cache efficiency: 93.2% (440K cached / 472K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 7K sorts)
[!!] Joins performed without indexes: 946
[OK] Temporary tables created on disk: 11% (2K on disk / 22K total)
[OK] Thread cache hit rate: 99% (63 created / 15K connections)
[!!] Table cache hit rate: 0% (634 open / 268K opened)
[OK] Open file limit used: 1% (980/64K)
[OK] Table locks acquired immediately: 99% (121K immediate / 121K locks)
[OK] InnoDB data size / buffer pool: 93.0M/128.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Adjust your join queries to always utilize indexes
Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
join_buffer_size (> 4.0M, or always use indexes with joins)
table_cache (> 640)
提供此输出后,建议我应用以下更改:
thread_cache_size=16
query_cache_size=1024M
join_buffer_size=8M
table_cache=4096
我的问题:
我得到的建议安全吗?我还没有应用它们,但从我读过的其他与 my.cnf 相关的帖子来看,它们似乎有点过头了。
我认为,如果将当前的 my.cnf 文件与我在网上偶然发现的其他 my.cnf 文件进行比较,它会显得“小巧”。您认为我遗漏了什么具体内容吗?
我绝对不是专家或系统管理员,而只是一名业余爱好者,因此如果有人能分享一些关于如何改进/增强我当前配置的见解,我将不胜感激。非常感谢。
答案1
将 kernel.shmmax 调整为 10G(更改/etc/sysctl.conf, 跑步sysctl -p /etc/sysctl.conf)
是的,它看起来很安全,会多占用大约 2G 的内存,但也取决于其他选项
可以安全地应用更改,重新加载服务器,然后运行 mysqltuner,检查此字符串:
[确定] 最大可能的内存使用量:1.8G(已安装 RAM 的 14%)