데이터 베이스 MySQL 튜토리얼 High Availability with mysqlnd_ms on Percona XtraDB Cluster_MySQL

High Availability with mysqlnd_ms on Percona XtraDB Cluster_MySQL

Jun 01, 2016 pm 01:06 PM

This is the second part of my series on High Availability with mysqlnd_ms. In my first post, “Simple MySQL Master HA with mysqlnd_ms,” I showed a simple HA solution using asynchronous MySQL replication. This time we will see how to leverage an all-primary cluster where you can write to all nodes. In this post I usedPercona XtraDB Cluster, but you should also be able to do the same with MySQL NDB Cluster or Tungsten Replicator.

To start with, here is the mysqlnd_ms configuration I used:mysqlnd_ms_mm.ini.  All of these files are available from myGithub repository. Below, I have three Percona XtraDB Cluster nodes, all defined as masters and no slaves. I’ve configured a roundrobin filter where all connections will happen on the first node, in this case192.168.56.44 . In case the first node fails, the second node will be used and so forth until no more nodes are available. Another interesting configuration option here is the loop_before_master strategy whereby if connection or a statement to the current server fails, it will be retried silently on the remaining nodes before returning an error to the user, more on this below.

JavaScript
{ "primary": { "master": { "master_1": { "host": "192.168.56.44", "port": "3306" }, "master_2": { "host": "192.168.56.43", "port": "3306" }, "master_3": { "host": "192.168.56.42", "port": "3306" } }, "slave": { }, "filters": { "roundrobin": [ ] }, "failover": { "strategy": "loop_before_master", "remember_failed": true } } }
로그인 후 복사

{

  "primary":{

    "master":{

      "master_1":{

        "host":"192.168.56.44",

        "port":"3306"

      },

      "master_2":{

        "host":"192.168.56.43",

        "port":"3306"

      },

      "master_3":{

        "host":"192.168.56.42",

        "port":"3306"

      }

    },

    "slave":{},

    "filters":{"roundrobin":[]},

    "failover":{"strategy":"loop_before_master","remember_failed":true}

  }

}

Similar to my previous post, I also used a custom INI file for PHP to use, this time aptly namedmaster-master.ini :

mysqlnd_ms.enable = 1mysqlnd_ms.disable_rw_split = 1mysqlnd_ms.multi_master = 1mysqlnd_ms.force_config_usage = 1mysqlnd_ms.config_file = /home/revin/git/demo-me/phpugph201407/mysqlnd_ms_mm.ini
로그인 후 복사

mysqlnd_ms.enable=1

mysqlnd_ms.disable_rw_split=1

mysqlnd_ms.multi_master=1

mysqlnd_ms.force_config_usage=1

mysqlnd_ms.config_file=/home/revin/git/demo-me/phpugph201407/mysqlnd_ms_mm.ini

A new addition to this configuration ismysqlnd_ms.multi_master , when enabled it would allow you to use all nodes or just one and treat the others as passive. The PHP script I used this time is calledmaster-master.php , it is largely similar tomaster-slave-ng.phpwith a few differences:

  1. There is no need for /tmp/PRIMARY_HAS_FAILED  sentinel as all nodes were writable.
  2. There is no need for /*ms=master*/  SQL hint when validating a connection from connect_mysql function since all nodes acts as master.

So here is a quick test, first with roundrobin filter, after 4 INSERTs, I shutdown192.168.56.44  which sends my connection to the next server in the configuration,192.168.56.43 . When I started back 192.168.56.44  again, the script resumed connections there. Pretty cool right?

[revin@forge phpugph201407]$ php -c master-master.ini master-master.phpLast value 3564 from host 192.168.56.44 via TCP/IP and thread id 19Last value 3565 from host 192.168.56.44 via TCP/IP and thread id 20Last value 3566 from host 192.168.56.44 via TCP/IP and thread id 21Last value 3567 from host 192.168.56.44 via TCP/IP and thread id 22Warning: connect_mysql(): MySQL server has gone away in /home/revin/git/demo-me/phpugph201407/master-master.php on line 63Warning: connect_mysql(): Error while reading greeting packet. PID=23464 in /home/revin/git/demo-me/phpugph201407/master-master.php on line 63ERRROR: 192.168.56.43 via TCP/IP [2006] MySQL server has gone away on line 30Last value 0 from hostand thread id 0Last value 3568 from host 192.168.56.43 via TCP/IP and thread id 1552Last value 3569 from host 192.168.56.43 via TCP/IP and thread id 1553[...]Last value 3584 from host 192.168.56.43 via TCP/IP and thread id 1568Last value 3585 from host 192.168.56.44 via TCP/IP and thread id 18
로그인 후 복사

[revin@forgephpugph201407]$php-cmaster-master.inimaster-master.php

Lastvalue3564fromhost192.168.56.44viaTCP/IPandthreadid19

Lastvalue3565fromhost192.168.56.44viaTCP/IPandthreadid20

Lastvalue3566fromhost192.168.56.44viaTCP/IPandthreadid21

Lastvalue3567fromhost192.168.56.44viaTCP/IPandthreadid22

Warning:connect_mysql():MySQLserverhasgoneawayin/home/revin/git/demo-me/phpugph201407/master-master.phponline63

Warning:connect_mysql():Errorwhilereadinggreetingpacket.PID=23464in/home/revin/git/demo-me/phpugph201407/master-master.phponline63

ERRROR:192.168.56.43viaTCP/IP[2006]MySQLserverhasgoneawayonline30

Lastvalue0fromhost  andthreadid0

Lastvalue3568fromhost192.168.56.43viaTCP/IPandthreadid1552

Lastvalue3569fromhost192.168.56.43viaTCP/IPandthreadid1553

[...]

Lastvalue3584fromhost192.168.56.43viaTCP/IPandthreadid1568

Lastvalue3585fromhost192.168.56.44viaTCP/IPandthreadid18

Here’s another test using the random filter which allows you to write to all nodes, on my mysqlnd_ms_mm.ini above, I just changedroundrobin  torandom . As you can see, all three nodes were being used, of course in random, at the same time you will also see when I shutdown 192.168.56.44  around where the connect_mysql  errors and then the server was used again near the bottom after a started it back up. Still pretty cool right?

[revin@forge phpugph201407]$ php -c master-master.ini master-master.phpLast value 3590 from host 192.168.56.42 via TCP/IP and thread id 2060Last value 3591 from host 192.168.56.43 via TCP/IP and thread id 1569Last value 3592 from host 192.168.56.43 via TCP/IP and thread id 1570Warning: connect_mysql(): MySQL server has gone away in /home/revin/git/demo-me/phpugph201407/master-master.php on line 63Warning: connect_mysql(): Error while reading greeting packet. PID=23919 in /home/revin/git/demo-me/phpugph201407/master-master.php on line 63ERRROR: 192.168.56.43 via TCP/IP [2006] MySQL server has gone away on line 30Last value 0 from hostand thread id 0Last value 3593 from host 192.168.56.42 via TCP/IP and thread id 2061Last value 3594 from host 192.168.56.42 via TCP/IP and thread id 2062Last value 3595 from host 192.168.56.42 via TCP/IP and thread id 2063Last value 3596 from host 192.168.56.42 via TCP/IP and thread id 2064Last value 3597 from host 192.168.56.43 via TCP/IP and thread id 1576Last value 3598 from host 192.168.56.43 via TCP/IP and thread id 1577Last value 3599 from host 192.168.56.43 via TCP/IP and thread id 1578Last value 3600 from host 192.168.56.43 via TCP/IP and thread id 1579Last value 3601 from host 192.168.56.42 via TCP/IP and thread id 2065Last value 3602 from host 192.168.56.43 via TCP/IP and thread id 1581Last value 3603 from host 192.168.56.43 via TCP/IP and thread id 1582Last value 3604 from host 192.168.56.42 via TCP/IP and thread id 2066Last value 3605 from host 192.168.56.44 via TCP/IP and thread id 19Last value 3606 from host 192.168.56.43 via TCP/IP and thread id 1583Last value 3607 from host 192.168.56.44 via TCP/IP and thread id 21
로그인 후 복사

[revin@forgephpugph201407]$php-cmaster-master.inimaster-master.php

Lastvalue3590fromhost192.168.56.42viaTCP/IPandthreadid2060

Lastvalue3591fromhost192.168.56.43viaTCP/IPandthreadid1569

Lastvalue3592fromhost192.168.56.43viaTCP/IPandthreadid1570

Warning:connect_mysql():MySQLserverhasgoneawayin/home/revin/git/demo-me/phpugph201407/master-master.phponline63

Warning:connect_mysql():Errorwhilereadinggreetingpacket.PID=23919in/home/revin/git/demo-me/phpugph201407/master-master.phponline63

ERRROR:192.168.56.43viaTCP/IP[2006]MySQLserverhasgoneawayonline30

Lastvalue0fromhost  andthreadid0

Lastvalue3593fromhost192.168.56.42viaTCP/IPandthreadid2061

Lastvalue3594fromhost192.168.56.42viaTCP/IPandthreadid2062

Lastvalue3595fromhost192.168.56.42viaTCP/IPandthreadid2063

Lastvalue3596fromhost192.168.56.42viaTCP/IPandthreadid2064

Lastvalue3597fromhost192.168.56.43viaTCP/IPandthreadid1576

Lastvalue3598fromhost192.168.56.43viaTCP/IPandthreadid1577

Lastvalue3599fromhost192.168.56.43viaTCP/IPandthreadid1578

Lastvalue3600fromhost192.168.56.43viaTCP/IPandthreadid1579

Lastvalue3601fromhost192.168.56.42viaTCP/IPandthreadid2065

Lastvalue3602fromhost192.168.56.43viaTCP/IPandthreadid1581

Lastvalue3603fromhost192.168.56.43viaTCP/IPandthreadid1582

Lastvalue3604fromhost192.168.56.42viaTCP/IPandthreadid2066

Lastvalue3605fromhost192.168.56.44viaTCP/IPandthreadid19

Lastvalue3606fromhost192.168.56.43viaTCP/IPandthreadid1583

Lastvalue3607fromhost192.168.56.44viaTCP/IPandthreadid21

So here are some issues I’ve observed during these tests:

  1. remember_failed  during failover does not work as advertised. Supposedly, a failed node should not be used again for every connection request but in my test, this is not the case. See more fromthis bug. This means that if you have 2 out of 3 failed nodes in this scenario the overhead would be too big when testing both connections. Perhaps some sort of in memory shared TTL can be used to overcome this? I’m not sure.
  2. If you look closely around line 7 on my last output above the error displayed is kind of misleading. In particular it saysERRROR:192.168.56.43viaTCP/IP , whereby it was not 192.168.56.43  that failed, it was192.168.56.43 . This is because under the hood, immediately after failure the next node will be cycled to, this is especially true since we have loop_before_master configured. I sure do have a bug on the script that should capture the host_info  properly, but this is something to always keep in mind so you don’t keep scratching your head.

So we’ve seen these two forms of possibilities and they definitely have use cases and advantages. On the other hand because of the issues we have found so far(I’ve reported 4 bugs on the PHP bugs database during the course of these tests including onecrashing), I recommend to make sure you test seriously before putting this on production.

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Alter Table 문을 사용하여 MySQL에서 테이블을 어떻게 변경합니까? Alter Table 문을 사용하여 MySQL에서 테이블을 어떻게 변경합니까? Mar 19, 2025 pm 03:51 PM

이 기사는 MySQL의 Alter Table 문을 사용하여 열 추가/드롭 테이블/열 변경 및 열 데이터 유형 변경을 포함하여 테이블을 수정하는 것에 대해 설명합니다.

MySQL 연결에 대한 SSL/TLS 암호화를 어떻게 구성합니까? MySQL 연결에 대한 SSL/TLS 암호화를 어떻게 구성합니까? Mar 18, 2025 pm 12:01 PM

기사는 인증서 생성 및 확인을 포함하여 MySQL에 대한 SSL/TLS 암호화 구성에 대해 설명합니다. 주요 문제는 자체 서명 인증서의 보안 영향을 사용하는 것입니다. [문자 수 : 159]

MySQL에서 큰 데이터 세트를 어떻게 처리합니까? MySQL에서 큰 데이터 세트를 어떻게 처리합니까? Mar 21, 2025 pm 12:15 PM

기사는 MySQL에서 파티셔닝, 샤딩, 인덱싱 및 쿼리 최적화를 포함하여 대규모 데이터 세트를 처리하기위한 전략에 대해 설명합니다.

인기있는 MySQL GUI 도구는 무엇입니까 (예 : MySQL Workbench, Phpmyadmin)? 인기있는 MySQL GUI 도구는 무엇입니까 (예 : MySQL Workbench, Phpmyadmin)? Mar 21, 2025 pm 06:28 PM

기사는 MySQL Workbench 및 Phpmyadmin과 같은 인기있는 MySQL GUI 도구에 대해 논의하여 초보자 및 고급 사용자를위한 기능과 적합성을 비교합니다. [159 자].

드롭 테이블 문을 사용하여 MySQL에서 테이블을 어떻게 드롭합니까? 드롭 테이블 문을 사용하여 MySQL에서 테이블을 어떻게 드롭합니까? Mar 19, 2025 pm 03:52 PM

이 기사에서는 Drop Table 문을 사용하여 MySQL에서 테이블을 떨어 뜨리는 것에 대해 설명하여 예방 조치와 위험을 강조합니다. 백업 없이는 행동이 돌이킬 수 없으며 복구 방법 및 잠재적 생산 환경 위험을 상세하게합니다.

외국 키를 사용하여 관계를 어떻게 표현합니까? 외국 키를 사용하여 관계를 어떻게 표현합니까? Mar 19, 2025 pm 03:48 PM

기사는 외국 열쇠를 사용하여 데이터베이스의 관계를 나타내고 모범 사례, 데이터 무결성 및 피할 수있는 일반적인 함정에 중점을 둡니다.

JSON 열에서 인덱스를 어떻게 생성합니까? JSON 열에서 인덱스를 어떻게 생성합니까? Mar 21, 2025 pm 12:13 PM

이 기사에서는 PostgreSQL, MySQL 및 MongoDB와 같은 다양한 데이터베이스에서 JSON 열에서 인덱스를 작성하여 쿼리 성능을 향상시킵니다. 특정 JSON 경로를 인덱싱하는 구문 및 이점을 설명하고 지원되는 데이터베이스 시스템을 나열합니다.

일반적인 취약점 (SQL 주입, 무차별 적 공격)에 대해 MySQL을 어떻게 보호합니까? 일반적인 취약점 (SQL 주입, 무차별 적 공격)에 대해 MySQL을 어떻게 보호합니까? Mar 18, 2025 pm 12:00 PM

기사는 준비된 명령문, 입력 검증 및 강력한 암호 정책을 사용하여 SQL 주입 및 무차별 적 공격에 대한 MySQL 보안에 대해 논의합니다 (159 자)

See all articles