mysql - 将 Mysql 和 My.cnf 优化为 16g Ram 和 8 核 CPU? [30-80并发用户,高峰时200-300]

标签 mysql optimization laravel-forge

自从我购买了 16GB 内存和 1 个核心服务器的服务器后,我还没有优化我的 MY.cnf 文件。

我不知道该怎么做,因为所有这些优化内容对我来说都是全新的。 服务器在正常时间大约有 60-80 个并发用户,在不正常时间有 20-40 个并发用户,然后有时在不同场合达到 200-300 左右的峰值。

我该怎么办?

这是我的 mysqltuner.pl:

 >>  MySQLTuner 1.7.4 - Major Hayden <major@mhtx.net>
 >>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

[--] Skipped version check for MySQLTuner script
Please enter your MySQL administrative login: forge
Please enter your MySQL administrative password: [OK] Currently running supporte                                                                                                                                                             d MySQL version 5.7.20-0ubuntu0.16.04.1
[OK] Operating on 64-bit architecture

-------- Log file Recommendations ----------------------------------------------                                                                                                                                                             --------------------
[--] Log file: /var/lib/mysql/crypto-boi.err(0B)
[!!] Log file /var/lib/mysql/crypto-boi.err doesn't exist
[!!] Log file /var/lib/mysql/crypto-boi.err isn't readable.

-------- Storage Engine Statistics ---------------------------------------------                                                                                                                                                             --------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +My                                                                                                                                                             ISAM +PERFORMANCE_SCHEMA
[--] Data in InnoDB tables: 514M (Tables: 66)
[OK] Total fragmented tables: 0

-------- Security Recommendations ----------------------------------------------                                                                                                                                                             --------------------


-------- CVE Security Recommendations ------------------------------------------                                                                                                                                                             --------------------
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION

-------- Performance Metrics ---------------------------------------------------                                                                                                                                                             --------------------
[--] Up for: 4m 0s (49K q [205.421 qps], 286 conn, TX: 38M, RX: 7M)
[--] Reads / Writes: 78% / 22%
[--] Binary logging is disabled
[--] Physical Memory     : 15.7G
[--] Max MySQL memory    : 2.0G
[--] Other process memory: 1.6G
[--] Total buffers: 1.5G global + 2.0M per thread (214 max threads)
[--] P_S Max memory usage: 72B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 1.6G (9.95% of installed RAM)
[OK] Maximum possible memory usage: 2.0G (12.54% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available
[OK] Slow queries: 0% (0/49K)
[OK] Highest usage of available connections: 2% (6/214)
[OK] Aborted connections: 0.35%  (1/286)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 37K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 283 sorts)
[!!] Joins performed without indexes: 187
[OK] Temporary tables created on disk: 4% (10 on disk / 227 total)
[OK] Thread cache hit rate: 97% (6 created / 286 connections)
[OK] Table cache hit rate: 75% (340 open / 453 opened)
[OK] Open file limit used: 0% (0/1K)
[OK] Table locks acquired immediately: 100% (102 immediate / 102 locks)

-------- Performance schema ------------------------------------------------------------------------
[--] Memory used by P_S: 72B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.2% (48M used / 268M cache)
[OK] Key buffer size / total MyISAM indexes: 256.0M/43.0K
[!!] Read Key buffer hit rate: 50.0% (6 cached / 3 reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[OK] InnoDB buffer pool / data size: 1.0G/514.4M
[!!] Ratio InnoDB log file size / InnoDB Buffer pool size (9.375 %): 48.0M * 2/1.0G should be equal 25%
[!!] InnoDB buffer pool <= 1G and Innodb_buffer_pool_instances(!=1).
[--] Number of InnoDB Buffer Pool Chunk : 8 for 8 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 99.82% (11564032 hits/ 11585189 total)
[!!] InnoDB Write Log efficiency: 54.07% (3734 hits/ 6906 total)
[OK] InnoDB log waits: 0.00% (0 waits / 10640 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.

-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.

-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
    Set up a Password for user with the following SQL statement ( SET PASSWORD FOR 'user'@'SpecificDNSorIp' = PASSWORD('secure_password'); )
    Restrict Host for user@% to user@SpecificDNSorIp
    MySQL started within last 24 hours - recommendations may be inaccurate
    Configure your accounts with ip or subnets only, then update your configuration with skip-name-resolve=1
    Adjust your join queries to always utilize indexes
    Read this before changing innodb_log_file_size and/or innodb_log_files_in_group: 
Variables to adjust:
    query_cache_size (=0)
    query_cache_type (=0)
    query_cache_limit (> 1M, or use smaller result sets)
    join_buffer_size (> 256.0K, or always use indexes with joins)
    innodb_log_file_size should be (=128M) if possible, so InnoDB total log files size equals to 25% of buffer pool size.
    innodb_buffer_pool_instances (=1)

这是我的 My.CNF

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = *
#
max_connections         = 300
key_buffer_size         = 256M
read_buffer_size = 1M
table_open_cache = 15000
thread_cache_size = 384
connect_timeout = 10
interactive_timeout = 7000
tmp_table_size = 256M
max_heap_table_size = 256M
query_cache_size = 0
query_cache_type = 0
innodb_buffer_pool_size = 1G

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 32M
#
#
expire_logs_days        = 10
max_binlog_size   = 100M
default_password_lifetime = 0

最佳答案

你有 514M 的 innodb 数据。在您的 innodb 存储需求增长之前不要管它。

您的 my.cnf/ini 应更改为:

#read_buffer_size=1M  # disabled to allow default to serve your needs
thread_cache_size=100 # from 384 to avoid OOM per V8 CAP at 100 threads_cached.

关机/重启。

在您忙碌至少 24 小时后重新发布当前 MySQLTuner 报告。

在 4 分钟内,与我们在一整天或一周后看到的相比,您的信息微不足道。

关于mysql - 将 Mysql 和 My.cnf 优化为 16g Ram 和 8 核 CPU? [30-80并发用户,高峰时200-300],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47389899/

相关文章:

mysql - Laravel - 违反完整性约束 : 1452

java - 启动 Activity 时,应用程序可能在其主线程上做了太多工作

SSH 权限被拒绝(公钥) - Laravel Forge

nginx - Forge/Nginx - 404 未找到

mysql - 如何查找与过滤条件中给定的每个值匹配的所有行?

php - PhpRunner 中的 IONCUBE 如何安装

mysql - 由于数据库凭据无效,kamailio 无法启动

php - 在类对象中创建一个静态成员并为特定功能调用该成员是个好主意吗

optimization - LLVM 和优化的 future

php - 从环境文件中删除后,Laravel Forge 继续通过 Mandrill 发送邮件