Magento webserver临时报告在1-2分钟内丢失了错误代码4的mysq连接

时间:2016-09-04 11:51:25

标签: php mysql magento nginx

目前,我正在使用两台服务器:带有magento 1.7的webserver,nginx,php-fpm,用于缓存的redis,以及一个带有5.5.32版本的mysql数据库服务器。 有时会在1-2分钟内继续发生,网络服务器报告错误: SQLSTATE [HY000] [2003]无法连接到lib / Zend / Db / Adapter / Pdo / Mysql.php(96)上'remoteserverip'(4)上的MySQL服务器。 但我用mysql命令检查它连接远程数据库服务器,没关系。 我搜索了谷歌和stackoverflow,没有报道这样的问题。

如我所见,两台服务器的CPU和内存不会过载,http 80连接大约为500。 我也改变了网络服务器:

# cat /etc/sysctl.conf 
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).

# Disable IPv6 autoconf 
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 0


#file.file-max = 20000000
fs.file-max = 20000000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_fin_timeout = 15
#net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 6

net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000

vm.overcommit_memory = 1
net.core.somaxconn = 3096

和nginx设置:

user  nginx;
worker_processes  32;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 65535;

events {
    worker_connections  65535;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    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 off;
    server_tokens off;

        #Adjust client timeouts
        #client_max_body_size 50M;
        client_body_buffer_size 20k;
        client_body_timeout 12;
        client_header_timeout 12;
        keepalive_timeout 30;
        send_timeout 10;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;

        #Adjust output buffers
        fastcgi_buffers 256 16k;
        fastcgi_buffer_size 128k;
        fastcgi_connect_timeout 3s;
        fastcgi_send_timeout 300s;
        fastcgi_read_timeout 300s;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        server_names_hash_bucket_size 100;



    gzip on;
    gzip_static on;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_min_length 1100; 
    #gzip_buffers 16 8k; 
    gzip_buffers 4 32k;   
    gzip_http_version 1.1;
    gzip_comp_level 6; 
    gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_vary on;
    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    open_file_cache max=5000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors off; 
    keepalive_requests 100000;
    reset_timedout_connection on;
    include /etc/nginx/conf.d/*.conf;

}

用于DB服务器:

# cat /etc/sysctl.conf 
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1

# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

# Controls the default maxmimum size of a mesage queue
kernel.msgmnb = 65536

# Controls the maximum size of a message, in bytes
kernel.msgmax = 65536

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296

# Disable IPv6 autoconf 
net.ipv6.conf.all.autoconf = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.eth0.autoconf = 0
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.eth0.accept_ra = 0
fs.file-max = 200000

# Increase system IP port limits to allow for more connections

net.ipv4.ip_local_port_range = 1024 65000

#net.ipv4.tcp_window_scaling = 0

# number of packets to keep in backlog before the kernel starts dropping them 
#net.ipv4.tcp_max_syn_backlog = 1280

# increase socket listen backlog
#net.core.somaxconn = 3240000
#net.ipv4.tcp_max_tw_buckets = 1440000

# Increase TCP buffer sizes
#net.core.rmem_default = 8388608
#net.core.rmem_max = 16777216
#net.core.wmem_max = 16777216
#net.ipv4.tcp_rmem = 4096 87380 16777216
#net.ipv4.tcp_wmem = 4096 65536 16777216
#net.ipv4.tcp_congestion_control = cubic

#Solve TIME_WAIT
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000 

和mysql connection_timeout:

mysql> show variables like "%conn%";
+--------------------------+-----------------+
| Variable_name            | Value           |
+--------------------------+-----------------+
| character_set_connection | utf8            |
| collation_connection     | utf8_general_ci |
| connect_timeout          | 60              |
| init_connect             |                 |
| max_connect_errors       | 10              |
| max_connections          | 14000           |
| max_user_connections     | 0               |
+--------------------------+-----------------+

首先,我认为这是db服务器不稳定,但mysql远程命令连接正常,只是php mysql_connect报告丢失了连接。 我还更改了sysctl的一些net.ipv4变量,但没有工作。 你能告诉我如何追踪这样的问题吗? 是否有任何其他调整mysql和Web服务器设置。 提前谢谢。

0 个答案:

没有答案