Cấu hình Nginx, PHP, MariaDB này dành cho máy chủ có sức mạnh trung bình trở lên (từ 4 CPU và 8 GB RAM trở lên), các bạn có thể tự mình tinh chỉnh lại cho hợp lý hơn.
Tối ưu Nginx
Sửa tập tin /etc/nginx/nginx.conf.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log crit;
pid /run/nginx.pid;
worker_rlimit_nofile 100000;
events {
worker_connections 4096;
use epoll;
multi_accept on;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
keepalive_timeout 32;
keepalive_requests 100000;
reset_timedout_connection on;
gzip on;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_static on;
gzip_min_length 1400;
gzip_buffers 32 8k;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_proxied any;
gzip_types text/plain text/css text/xml application/javascript application/x-javascript application/xml application/xml+rss application/ecmascript application/json image/svg+xml;
client_body_buffer_size 256k;
client_body_in_file_only off;
client_body_timeout 10;
client_header_timeout 10;
send_timeout 2;
client_header_buffer_size 64k;
large_client_header_buffers 4 256k;
client_max_body_size 128m;
connection_pool_size 512;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
fastcgi_buffering on;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
}
Sau đó khởi động lại Nginx.
systemctl restart nginx.service
Tối ưu PHP
Sửa tập tin etc/php.ini.
memory_limit = 8192M
Sửa tập tin /etc/php-fpm.d/www.conf.
pm = dynamic
pm.max_children = 12
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 9
Khởi động lại PHP-FPM:
systemctl restart php-fpm.service
Tối ưu MariaDB
Sửa tập tin /etc/my.cnf, thêm nội dung sau.
[mysqld]
basedir = /usr
bind_address = 127.0.0.1
datadir = /var/lib/mysql
max_connect_errors = 1000000
pid_file = /run/mysqld/mysqld.pid
port = 3306
socket = /run/mysqld/mysqld.sock
tmpdir = /tmp
user = mysql
key_buffer_size = 4G
join_buffer_size = 32M
read_buffer_size = 32M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
table_cache = 16000
thread_concurrency = 32
tmp_table_size = 2G
max_heap_table_size = 2G
myisam_sort_buffer_size = 512M
max_connections = 10000
query_cache_limit = 32M
query_cache_size = 2G
query_cache_type = 1
connect_timeout = 60
thread_cache_size = 256
default_storage_engine = InnoDB
innodb_buffer_pool_instances = 4
innodb_buffer_pool_size = 4G
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 0
innodb_flush_method = O_DIRECT
innodb_log_buffer_size = 32M
innodb_log_file_size = 1G
innodb_sort_buffer_size = 16M
innodb_stats_on_metadata = 0
innodb_read_io_threads = 64
innodb_write_io_threads = 64
low_priority_updates = 1
concurrent_insert = 2
back_log = 512
thread_stack = 192K
interactive_timeout = 300
wait_timeout = 600
table_definition_cache = 40000
table_open_cache = 40000
open_files_limit = 60000
ft_min_word_len = 3
disable_log_bin = 1
log_error = /var/lib/mysql/mysql_error.log
log_queries_not_using_indexes = 0
long_query_time = 5
slow_query_log = 0
slow_query_log_file = /var/lib/mysql/mysql_slow.log
[mysqldump]
quick
quote_names
max_allowed_packet = 2G
Nhớ khởi động lại MariaDB:
systemctl restart mariadb.service
Memcached
Nếu bạn có sử dụng Memcached, sửa tập tin /etc/sysconfig/memcached.
PORT="11211"
USER="memcached"
MAXCONN="163840"
CACHESIZE="8192"
OPTIONS="-l 127.0.0.1 -U 0"
Khởi động lại Memcached.
systemctl restart memcached.service
Chúc các bạn thành công!
Bình luận