2017-01-10 6 views
0

postgres 데이터베이스에 대한로드 균형 조정을 설정하려고합니다. 우리에게는 포스트그레스 마스터와 노예가 있습니다. 부하 분산을 위해 HA 프록시를 구성했습니다. 간단한로드 균형 조정이 정상적으로 작동합니다.HAproxy를 사용하여 postgres master에게 경로 요청을 수행하는 방법

이 데이터베이스는 bitbucket에 사용됩니다.

bitbucket가로드 밸런서를 통해 데이터베이스에 데이터를 쓰고있을 때 마스터를 때리는 것이 좋지만 읽기 모드 인 슬레이브를 치면 문제가 발생하여 데이터베이스를 업데이트 할 수 없습니다.

어떻게하면 요청을 postgres 마스터로 라우팅 할 수 있는지 HAproxy라고 말할 수 있습니다.

* 마스터와 슬레이브에서 실행될 pg_stat_replication에서 *를 선택하고 요청을 스트리밍 마스터에 라우팅해야하는 출력을 기반으로 HAproxy를 사용하여 달성 할 수있는 방법이 있습니까?

덕분에, KARTHIK

답변

0

이 서버가 마스터 경우에만 성공 맞춤형 건강 검진을 사용하여 수행 할 수 있습니다. 다른 모든 종속 서버는 표시가 해제됩니다.

backend pgsql 
    mode tcp 
    option tcp-check 
    tcp-check send-binary 0000002C# length 
    tcp-check send-binary 00030000 # version 
    tcp-check send-binary 75736572 # 'user'.bytes.map { |c| c.to_s(16) } 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 6170706c69636174696f6e # 'application' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 6461746162617365 # 'database' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 706f737467726573 # 'postgres' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 00 # name/value terminator 
    tcp-check expect string R 
    tcp-check send-binary 51 # 'Q' 
    tcp-check send-binary 00000020 # length 
    tcp-check send-binary 73656c6563742070675f69735f696e5f7265636f7665727928293b # 'select pg_is_in_recovery();' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 58 # 'X' 
    tcp-check send-binary 00000004 # length 
    tcp-check expect string f 
    tcp-check expect string Z 
    server pg1 1.2.3.4:5432 check 
    server pg2 5.6.7.8:5432 check 

'TCP 체크'선 송신 및 그들의 documentation에 정의 된 포스트 그레스 클라이언트 프로토콜을 사용하여 이진 패킷을 수신하는

.

또한 기본에 실패 할 경우에만 사용되는 보조 '읽기 전용'백엔드를 사용할 수도 있습니다. 여기에 대한 추가 프론트 엔드/백엔드 구성이 있습니다.

frontend pgsql 
    mode tcp 
    bind *:5432 
    acl readonly.pgsql nbsrv(pgsql) eq 0 
    use_backend readonly.pgsql if readonly.pgsql 
    acl pgsql nbsrv(pgsql) gt 0 
    use_backend pgsql if pgsql 

<...primary backend...> 

backend readonly.pgsql 
    mode tcp 
    option tcp-check 
    tcp-check send-binary 0000002C# length 
    tcp-check send-binary 00030000 # version 
    tcp-check send-binary 75736572 # 'user'.bytes.map { |c| c.to_s(16) } 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 6170706c69636174696f6e # 'application' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 6461746162617365 # 'database' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 706f737467726573 # 'postgres' 
    tcp-check send-binary 00 # string terminator 
    tcp-check send-binary 00 # name/value terminator 
    tcp-check expect string R 
    tcp-check send-binary 58 # 'X' 
    tcp-check send-binary 00000004 # length 
    server pg1 1.2.3.4:5432 check 
    server pg2 5.6.7.8:5432 check 

노예를 '아래'로 표시하면 HAProxy 상태 검사를 잘 사용하는지 논쟁의 여지가 있습니다. 위는 작동하지만, HAProxy없이 이것을 수행하는 other ways이 있습니다.