2017-06-01 149 views
0

我有一個MariaDB RDS設置在VPC中。 RDS不可公開訪問。因此,爲了訪問RDS,我決定在相同的VPC中生成EC2並配置HAProxy。無法通過HaProxy連接到RDS

HAProxy的是工作的罰款,並偵聽端口3306。然而,當我試圖通過HAProxy的連接到RDS,我收到此錯誤信息:

ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2

這裏是我的haproxy.cfg

global 
    log /dev/log local0 
    log /dev/log local1 notice 
    chroot /var/lib/haproxy 
    stats socket /run/haproxy/admin.sock mode 660 level admin 
    stats timeout 30s 
    user haproxy 
    group haproxy 
    daemon 

    # Default SSL material locations 
    ca-base /etc/ssl/certs 
    crt-base /etc/ssl/private 

    # Default ciphers to use on SSL-enabled listening sockets. 
    # For more information, see ciphers(1SSL). This list is from: 
    # https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ 
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS 
    ssl-default-bind-options no-sslv3 

defaults 
    log  global 
    mode tcp 
    option tcplog 
    option dontlognull 
    timeout connect 5000 
    timeout client 50000 
    timeout server 50000 
    errorfile 400 /etc/haproxy/errors/400.http 
    errorfile 403 /etc/haproxy/errors/403.http 
    errorfile 408 /etc/haproxy/errors/408.http 
    errorfile 500 /etc/haproxy/errors/500.http 
    errorfile 502 /etc/haproxy/errors/502.http 
    errorfile 503 /etc/haproxy/errors/503.http 
    errorfile 504 /etc/haproxy/errors/504.http 

listen rds 
    bind 0.0.0.0:3306 
    mode tcp 
    option mysql-check user haproxy_check 
    balance roundrobin 
    server rds test.dkd20slksdfkl.ap-southeast-1.rds.amazonaws.com:3306 check 

如果你想知道,我做編輯/etc/default/haproxy,並把ENABLED=1

回答

0

我設法通過刪除check選項成功連接到RDS。我不知道爲什麼,但也許是因爲沒有其他RDS來負載均衡,因此check選項會帶來問題。

+0

這表明檢查沒有成功,所以HAProxy接受傳入連接並立即關閉它,因爲沒有可用的健康後端。使用'選項日誌健康檢查',檢查你的HAProxy日誌,或通過統計UI或統計套接字檢查後端健康狀況會使這個問題變得明顯。 –

+0

感謝您的建議。到目前爲止,連接是好的,我會繼續監控。如果我再看到問題,我將啓用運行狀況檢查日誌。 –