programing

워드프레스를 위한 MariaDB 최적화

randomtip 2022. 12. 21. 22:55
반응형

워드프레스를 위한 MariaDB 최적화

2개의 CPU 코어와 1GB의 RAM을 탑재한 서버가 있습니다.서버는 워드프레스 사이트를 하나만 실행합니다.내 서버 스택은 LEMP입니다.워드프레스 사이트를 개설한 지 2주 만에 mysql 튜너를 실행했습니다.결과는 다음과 같습니다.

[!!] Maximum reached memory usage: 884.8M (89.15% of installed RAM)
[!!] Maximum possible memory usage: 1.4G (139.86% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[!!] Slow queries: 15% (629K/4M)
[OK] Highest usage of available connections: 9% (19/200)
[OK] Aborted connections: 0.75%  (4103/548857)
[!!] name resolution is active : a reverse name resolution is made for each new connection and can reduce performance

여기 제 것이 있습니다.my.cnf배열

 [mysql]

# CLIENT #
port                           = 3306
socket                         = /var/lib/mysql/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /var/lib/mysql/mysql.sock
pid-file                       = /var/lib/mysql/mysql.pid

# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000

# DATA STORAGE #
datadir                        = /var/lib/mysql/

# BINARY LOGGING #
log-bin                        = /var/lib/mysql/mysql-bin
expire-logs-days               = 14
sync-binlog                    = 1

# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 200
thread-cache-size              = 20
open-files-limit               = 65535
table-definition-cache         = 1024
table-open-cache               = 2048

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 64M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table          = 1
innodb-buffer-pool-size        = 624M

# LOGGING #
log-error                      = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes  = 1
slow-query-log                 = 1
slow-query-log-file            = /var/lib/mysql/mysql-slow.log

이러한 문제를 해결하기 위해 구성을 최적화하려면 어떻게 해야 합니까?

매우 나쁜 설정이 하나 있습니다.

innodb-buffer-pool-size        = 624M

WP와 MySQL을 모두 포함하는 작은 1GB 서버에 저장하시겠습니까?그것을 2억으로 변경해 주세요.교환을 주의해 주세요.스와핑이 있는 경우는, 한층 더 내립니다.스왑하면 대량의 I/O가 발생하므로 설정을 축소하는 것이 좋습니다.여기서부터 시작합시다.

tmp-table-size                 = 32M  -> 8M
max-heap-table-size            = 32M  -> 8M
query-cache-type               = 0    -- good
query-cache-size               = 0    -- good
max-connections                = 200  -> 50
thread-cache-size              = 20
open-files-limit               = 65535
table-definition-cache         = 1024 -> 200
table-open-cache               = 2048 -> 300

느린 로그가 켜졌나요?다음으로 나타내는 최악의 쿼리를 나타냅니다.mysqldumpslow -s t또는pt-query-digest.

여기 또 다른 팁이 있어요.이 중요한 테이블에는 현재 형편없는 인덱스가 있습니다.이러한 인덱스는 다음과 같은 이점이 있습니다.

CREATE TABLE wp_postmeta (
    post_id …,
    meta_key …,
    meta_value …,
    PRIMARY KEY(post_id, meta_key),
    INDEX(meta_key)
) ENGINE=InnoDB;

WORDPRESS가 듣고 있습니까?

이유는 다음과 같습니다.

  • AUTO_INCREMENT아깝다
  • 이것이 훨씬 더 나은 PK입니다.
  • 필요한 경우 191을 사용합니다(5.6.3~5.7.6).
  • 클러스터된 PK용 InnoDB

상세: http://mysql.rjweb.org/doc.php/index_cookbook_mysql#speeding_up_wp_postmeta

언급URL : https://stackoverflow.com/questions/43515478/optimizing-mariadb-for-wordpress

반응형