MySQL、Redis、Nginx配置优化

文章目录


一、MySQL

  • mysql.cnf
bash 复制代码
[mysqld]
binlog_cache_size = 128K
thread_stack = 256K
join_buffer_size = 2048K
max_heap_table_size = 512M

default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 100G
table_open_cache = 384
sort_buffer_size = 1024K
net_buffer_length = 4K
read_buffer_size = 1024K
read_rnd_buffer_size = 768K
myisam_sort_buffer_size = 32M
thread_cache_size = 128
tmp_table_size = 512M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp = true
max_connections = 1000
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 600000
slow_query_log=1
long_query_time=3
early-plugin-load = ""

innodb_buffer_pool_size = 512M
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 8
innodb_write_io_threads = 8

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

二、Redis

  • redis.conf
bash 复制代码
# 最大内存 128 MB
maxmemory 134217728
# 最大连接数
maxclients 10000
# 绑定IP 外网可访问改为 0.0.0.0 , 外网不可访问改为 127.0.0.1
bind 0.0.0.0
# 外网可访问改为 no , 外网不可访问改为 yes
protected-mode no
# 绑定端口号
port 6379
# 密码, 空表示没有密码
requirepass mimapassword
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
loglevel notice
logfile "/etc/redis/redis.log"
databases 9
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

三、Nginx

  • nginx.conf
bash 复制代码
worker_processes auto;								# 开启业务进程数, 建议设置为CPU总核心数
worker_rlimit_nofile 51200;							# 打开文件数的总和

events
	{
		use epoll;									# 使用epoll模型
		worker_connections 51200;					# 客户端最大连接数
		multi_accept on;							# 同时接受多个连接请求
	}

http
	{
		include mime.types;							# 引入http mime类型
		default_type application/octet-stream;		# 默认文件类型
		client_header_buffer_size 32k;				# 接收用户请求中HTTP header部分时分配的内存buffer大小
		large_client_header_buffers 4 32k;			# 请求中的HTTP header超过client_header_buffer_size时生效
		client_max_body_size 500m;					# 允许客户端请求的最大单文件字节数
		client_body_buffer_size 512k;				# 缓冲用户端请求的最大字节数
		proxy_connect_timeout 300;					# 和后端服务器连接超时时间
		proxy_read_timeout 300;						# 连接成功后, 后端服务器响应超时时间
		proxy_send_timeout 300;						# 后端服务器数据回传超时时间
		proxy_buffer_size 32k;						# 保存用户头信息的缓冲区大小
		proxy_buffers 4 64k;						# proxy_buffers缓冲区
		proxy_busy_buffers_size 128k;				# 高负荷下缓冲大小(proxy_buffers*2)
		proxy_temp_file_write_size 128k;			# 缓存文件夹大小
		# 当其中一台返回错误码时, 可以分配到下一台服务器程序继续处理
		proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; # 111
		# 限制并发连接数以及下载带宽
		limit_conn_zone $binary_remote_addr zone=perip:10m;
		limit_conn_zone $server_name zone=perserver:10m;

		sendfile on;								# 开启高效文件传输模式
		tcp_nopush on;								# 防止网络阻塞
		tcp_nodelay on;								# 防止网络阻塞
		keepalive_timeout 300;						# 客户端连接保持活动的超时时间

		# FastCGI配置, 改善网站的性能
		fastcgi_connect_timeout 300;
		fastcgi_send_timeout 300;
		fastcgi_read_timeout 300;
		fastcgi_buffer_size 64k;
		fastcgi_buffers 4 64k;
		fastcgi_busy_buffers_size 128k;
		fastcgi_temp_file_write_size 256k;
		fastcgi_intercept_errors on;

		# gzip压缩配置
		gzip on;
		gzip_min_length 1k;
		gzip_buffers 4 16k;
		gzip_http_version 1.1;
		gzip_comp_level 2;
		gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
		gzip_vary on;
		gzip_proxied expired no-cache no-store private auth;
		gzip_disable "MSIE [1-6]\.";

		# 虚拟主机, 可以配置多个
		server
			{
				listen 8080;								# Nginx监听端口号

				# 设置静态内容服务
				location /test/base/ {
					alias /usr/share/nginx/html/base/;
				}

				# 设置反向代理
				location /test/base/api/ {
					proxy_pass http://1192.168.1.11:8080/base/api/;
				}

				# 设置Nginx状态模块
				location /nginx_status {
					stub_status on;
					access_log off;
					allow 127.0.0.1;
					deny all;
				}

				# 未匹配uri禁止访问
				location ~ /\.
				{
					deny all;
				}
			}
}
  • mime.types
bash 复制代码
types {
    text/html                                        html htm shtml;
    text/css                                         css;
    text/xml                                         xml;
    image/gif                                        gif;
    image/jpeg                                       jpeg jpg;
    application/javascript                           js;
    application/atom+xml                             atom;
    application/rss+xml                              rss;

    text/mathml                                      mml;
    text/plain                                       txt;
    text/vnd.sun.j2me.app-descriptor                 jad;
    text/vnd.wap.wml                                 wml;
    text/x-component                                 htc;

    image/avif                                       avif;
    image/png                                        png;
    image/svg+xml                                    svg svgz;
    image/tiff                                       tif tiff;
    image/vnd.wap.wbmp                               wbmp;
    image/webp                                       webp;
    image/x-icon                                     ico;
    image/x-jng                                      jng;
    image/x-ms-bmp                                   bmp;

    font/woff                                        woff;
    font/woff2                                       woff2;

    application/java-archive                         jar war ear;
    application/json                                 json;
    application/mac-binhex40                         hqx;
    application/msword                               doc;
    application/pdf                                  pdf;
    application/postscript                           ps eps ai;
    application/rtf                                  rtf;
    application/vnd.apple.mpegurl                    m3u8;
    application/vnd.google-earth.kml+xml             kml;
    application/vnd.google-earth.kmz                 kmz;
    application/vnd.ms-excel                         xls;
    application/vnd.ms-fontobject                    eot;
    application/vnd.ms-powerpoint                    ppt;
    application/vnd.oasis.opendocument.graphics      odg;
    application/vnd.oasis.opendocument.presentation  odp;
    application/vnd.oasis.opendocument.spreadsheet   ods;
    application/vnd.oasis.opendocument.text          odt;
    application/vnd.openxmlformats-officedocument.presentationml.presentation
                                                     pptx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                                     xlsx;
    application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                                     docx;
    application/vnd.wap.wmlc                         wmlc;
    application/wasm                                 wasm;
    application/x-7z-compressed                      7z;
    application/x-cocoa                              cco;
    application/x-java-archive-diff                  jardiff;
    application/x-java-jnlp-file                     jnlp;
    application/x-makeself                           run;
    application/x-perl                               pl pm;
    application/x-pilot                              prc pdb;
    application/x-rar-compressed                     rar;
    application/x-redhat-package-manager             rpm;
    application/x-sea                                sea;
    application/x-shockwave-flash                    swf;
    application/x-stuffit                            sit;
    application/x-tcl                                tcl tk;
    application/x-x509-ca-cert                       der pem crt;
    application/x-xpinstall                          xpi;
    application/xhtml+xml                            xhtml;
    application/xspf+xml                             xspf;
    application/zip                                  zip;

    application/octet-stream                         bin exe dll;
    application/octet-stream                         deb;
    application/octet-stream                         dmg;
    application/octet-stream                         iso img;
    application/octet-stream                         msi msp msm;

    audio/midi                                       mid midi kar;
    audio/mpeg                                       mp3;
    audio/ogg                                        ogg;
    audio/x-m4a                                      m4a;
    audio/x-realaudio                                ra;

    video/3gpp                                       3gpp 3gp;
    video/mp2t                                       ts;
    video/mp4                                        mp4;
    video/mpeg                                       mpeg mpg;
    video/quicktime                                  mov;
    video/webm                                       webm;
    video/x-flv                                      flv;
    video/x-m4v                                      m4v;
    video/x-mng                                      mng;
    video/x-ms-asf                                   asx asf;
    video/x-ms-wmv                                   wmv;
    video/x-msvideo                                  avi;
}
相关推荐
苹果酱05671 小时前
Golang的文件解压技术研究与应用案例
java·vue.js·spring boot·mysql·课程设计
hu_yuchen1 小时前
从单机到微服务的转型之路
redis·mysql·微服务
warrah1 小时前
redis——岁月云实战
数据库·redis·缓存
秀儿y1 小时前
Redis-十大数据类型
数据库·redis·缓存·oracle
知识的宝藏2 小时前
Django models中的增删改查与MySQL SQL的对应关系
sql·mysql·django·django models
路在脚下@2 小时前
MySQL的索引失效的原因有那些
数据库·mysql
记得开心一点嘛2 小时前
Nginx与Tomcat之间的关系
java·nginx·tomcat
ascarl20102 小时前
【Nginx系列】---Nginx配置tcp转发
运维·tcp/ip·nginx
新子-存在了2 小时前
linux中 mysql备份
linux·运维·mysql
liutaiyi82 小时前
Redis可视化工具 RDM mac安装使用
redis·后端·macos