MySQL 그룹 복제 구축 [단일 - 기본 모드]

42831 단어 mysql
이 글 은 my sql group replication 단일 쓰기 모드 (단일 - primary mode) 를 어떻게 배치 하 는 지 기록 합 니 다.
배치 방식 은 크게 다 중 쓰기 모드 의 배치 와 일치 합 니 다. 수정 해 야 할 것 은 my. cnf 에서 group replication 에 대한 설정 뿐 입 니 다.
다 중 쓰기 모드 의 배 치 는 다른 글 을 참고 합 니 다.
http://blog.csdn.net/d6619309/article/details/53691790
1. 환경 준비
  • CentOS5.6
  • mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz

  • 2. 배치
    우리 의 목 표 는 한 기계 에 3 개의 my sql 인 스 턴 스 를 설치 한 다음 my sql group replication 을 설정 하 는 것 입 니 다. 모드 는 single - primary mode 입 니 다.
    설치 디 렉 터 리 설명 은 다음 과 같 습 니 다.
    1) 인 스 턴 스 데이터 가 설 치 됩 니 다.
  • s1: /dba/mysql/data/s1
  • s2: /dba/mysql/data/s2
  • s3: /dba/mysql/data/s3

  • 2) mysql 5.7 압축 해제
    /dba/mysql/mysql-5.7

    2.1 다 중 인 스 턴 스 설치 (s1, s2, s3)
    테스트 와 테스트 를 고려 하여 우 리 는 직접 컴 파일 된 my sql 설치 패키지 로 간소화 설 치 를 합 니 다.
    cd /dba/mysql
    mkdir data
    mysql-5.7/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-5.7 --datadir=$PWD/data/s1
    mysql-5.7/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-5.7 --datadir=$PWD/data/s2
    mysql-5.7/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-5.7 --datadir=$PWD/data/s3

    2.2 s1 인 스 턴 스 배치
    2.2.1 인 스 턴 스 설정
    cd $PWD/data/s1
    touch s1.cnf
    vi s1.cnf
  • 메 인 설정 추가
  • [mysqld]
    
    # server configuration
    datadir=/dba/mysql/data/s1
    basedir=/dba/mysql/mysql-5.7/
    
    port=24801
    socket=/dba/mysql/data/s1/s1.sock
  • Replication 설정 추가
  • server_id=1
    gtid_mode=ON
    enforce_gtid_consistency=ON
    master_info_repository=TABLE
    relay_log_info_repository=TABLE
    binlog_checksum=NONE
    log_slave_updates=ON
    log_bin=binlog
    binlog_format=ROW

    대부분의 설정 은 group replication 을 열기 위해 설정 해 야 합 니 다. 자세 한 내용 은:
    http://mysqlhighavailability.com/mysqlha/gr/doc/limitations.html
  • group replication 설정 가입
  • transaction_write_set_extraction=XXHASH64
    loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
    loose-group_replication_start_on_boot=off
    loose-group_replication_local_address= "127.0.0.1:24901"
    loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
    loose-group_replication_bootstrap_group= off
    loose-group_replication_single_primary_mode=true
    loose-group_replication_enforce_update_everywhere_checks=false

    설정 설명:
    http://mysqlhighavailability.com/mysqlha/gr/doc/getting_started.html#group-replication
    다 중 쓰기 모드 설정 닫 기:
  • loose-group_replication_single_primary_mode=true
  • loose-group_replication_enforce_update_everywhere_checks=false

  • 2.2.2 시작 실례
    다음 명령 을 실행 하여 s1 인 스 턴 스 를 시작 합 니 다:
    nohup mysql-5.7/bin/mysqld --defaults-file=data/s1/s1.cnf >data/s1/nohup.out 2>data/s1/nohup.out &

    my sql 사용 자 는 data 디 렉 터 리 에 대한 읽 기와 쓰기 권한 을 가 져 야 합 니 다.
    2.2.3 사용자 권한 부여
    성공 적 으로 시작 한 후 mysql 에 로그 인 합 니 다:
    mysql -uroot -h127.0.0.1 -P24801 --skip-password

    로그 인 후 루트 로그 인 비밀 번 호 를 수정 하 는 것 을 권장 합 니 다. 다음 문 구 를 통 해 수정 하 십시오.
    SET SQL_LOG_BIN=0;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
    SET SQL_LOG_BIN=1;

    비밀번호 변경 ERROR 만 남:
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    암호 보안 정책 이 너무 높 아서 참조http://www.cnblogs.com/ivictor/p/5142809.html
    실행:
    set global validate_password_policy=0;

    그리고 비밀 번 호 를 설정 하면 됩 니 다.
    my sql 명령 행 에서 group replication 을 만 드 는 데 필요 한 사용자:
    SET SQL_LOG_BIN=0;
    CREATE USER rpl_user@'%';
    GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
    FLUSH PRIVILEGES;
    SET SQL_LOG_BIN=1;
    CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';

    2.2.4 오픈 그룹 복사
    my sql 명령 행 에서 실행:
    mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
    mysql> SHOW PLUGINS;
    +----------------------------+----------+--------------------+----------------------+-------------+
    | Name                       | Status   | Type               | Library              | License     |
    +----------------------------+----------+--------------------+----------------------+-------------+
    | binlog                     | ACTIVE   | STORAGE ENGINE     | NULL                 | PROPRIETARY |
    
    (...)
    
    | group_replication          | ACTIVE   | GROUP REPLICATION  | group_replication.so | PROPRIETARY |
    +----------------------------+----------+--------------------+----------------------+-------------+

    그룹 보이 기replication 플러그 인 설치 성공 확보
    다음 문장 을 실행 하고 group replication 을 시작 합 니 다.
    SET GLOBAL group_replication_bootstrap_group=ON;
    START GROUP_REPLICATION;
    SET GLOBAL group_replication_bootstrap_group=OFF;

    다음 문 구 를 실행 하고 group replication 이 성공 적 으로 시작 되 었 음 을 검증 합 니 다.
    mysql> SELECT * FROM performance_schema.replication_group_members;
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | group_replication_applier | 3c992270-c282-11e6-93bf-fa163ee40410 | ${yourhostname}  |       24801 | ONLINE       |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    1 row in set (0.00 sec)
    

    다음 테스트 용 라 이브 러 리 와 표를 만 듭 니 다:
    mysql> CREATE DATABASE test;
    Query OK, 1 row affected (0,00 sec)
    
    mysql> use test
    Database changed
    mysql> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL);
    Query OK, 0 rows affected (0,00 sec)
    
    mysql> INSERT INTO t1 VALUES (1, 'Luis');
    Query OK, 1 row affected (0,01 sec)
    
    mysql> SELECT * FROM t1;
    +----+------+
    | c1 | c2   |
    +----+------+
    |  1 | Luis |
    +----+------+
    1 row in set (0,00 sec)
    
    mysql> show binlog events;
    +---------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------+
    | Log_name      | Pos  | Event_type     | Server_id | End_log_pos | Info                                                                                                                 |
    +---------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------+
    | binlog.000001 |    4 | Format_desc    |         1 |         123 | Server ver: 5.7.17-log, Binlog ver: 4                                                                                |
    | binlog.000001 |  123 | Previous_gtids |         1 |         150 |                                                                                                                      |
    | binlog.000001 |  150 | Gtid           |         1 |         211 | SET @@SESSION.GTID_NEXT= '3c992270-c282-11e6-93bf-fa163ee40410:1'                                                    |
    | binlog.000001 |  211 | Query          |         1 |         386 | ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*E74858DB86EBA20BC33D0AECAE8A8108C56B17FA' |
    | binlog.000001 |  386 | Gtid           |         1 |         447 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1'                                                    |
    | binlog.000001 |  447 | Query          |         1 |         506 | BEGIN                                                                                                                |
    | binlog.000001 |  506 | View_change    |         1 |         645 | view_id=14817781596395401:1                                                                                          |
    | binlog.000001 |  645 | Query          |         1 |         710 | COMMIT                                                                                                               |
    | binlog.000001 |  710 | Gtid           |         1 |         771 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:2'                                                    |
    | binlog.000001 |  771 | Query          |         1 |         861 | CREATE DATABASE test                                                                                                 |
    | binlog.000001 |  861 | Gtid           |         1 |         922 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:3'                                                    |
    | binlog.000001 |  922 | Query          |         1 |        1046 | use `test`; CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 TEXT NOT NULL)                                                   |
    | binlog.000001 | 1046 | Gtid           |         1 |        1107 | SET @@SESSION.GTID_NEXT= 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:4'                                                    |
    | binlog.000001 | 1107 | Query          |         1 |        1175 | BEGIN                                                                                                                |
    | binlog.000001 | 1175 | Table_map      |         1 |        1218 | table_id: 219 (test.t1)                                                                                              |
    | binlog.000001 | 1218 | Write_rows     |         1 |        1260 | table_id: 219 flags: STMT_END_F                                                                                      |
    | binlog.000001 | 1260 | Xid            |         1 |        1287 | COMMIT /* xid=47 */                                                                                                  |
    +---------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------------------------------------+
    17 rows in set (0.00 sec)
    

    2.3 신규 멤버 s2 추가
    cd data/s2
    touch s2.cnf
    vi s2.cnf

    s1 인 스 턴 스 와 유사 합 니 다. s2. cnnf 를 추가 하고 다음 설정 을 기록 합 니 다.
    [mysqld]
    
    # server configuration
    datadir=/dba/mysql/data/s2
    basedir=/dba/mysql/mysql-5.7/
    
    port=24802
    socket=/dba/mysql/data/s2/s2.sock
    
    #
    # Replication configuration parameters
    #
    server_id=2
    gtid_mode=ON
    enforce_gtid_consistency=ON
    master_info_repository=TABLE
    relay_log_info_repository=TABLE
    binlog_checksum=NONE
    log_slave_updates=ON
    log_bin=binlog
    binlog_format=ROW
    
    #
    # Group Replication configuration
    #
    transaction_write_set_extraction=XXHASH64
    loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
    loose-group_replication_start_on_boot=off
    loose-group_replication_local_address= "127.0.0.1:24902"
    loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
    loose-group_replication_bootstrap_group= off
    loose-group_replication_single_primary_mode=true
    loose-group_replication_enforce_update_everywhere_checks=false

    이후 s2 인 스 턴 스 시작:
    nohup mysql-5.7/bin/mysqld --defaults-file=data/s2/s2.cnf >data/s2/nohup.out 2>data/s2/nohup.out &

    사용자 암호 수정:
    SET SQL_LOG_BIN=0;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
    SET SQL_LOG_BIN=1;

    다음 에 group replication 에 필요 한 사용 자 를 설정 합 니 다:
    SET SQL_LOG_BIN=0;
    CREATE USER rpl_user@'%';
    GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
    FLUSH PRIVILEGES;
    SET SQL_LOG_BIN=1;
    CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';

    다음 에 group replication 플러그 인 을 설치 합 니 다:
    mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';

    그리고 s2 를 현재 group 에 추가 할 수 있 습 니 다.
    mysql> START GROUP_REPLICATION;

    [주의] 앞의 사용자 비밀번호 수정 과 사용자 생 성 작업 은 반드시 binlog 를 기록 하지 않 고 실행 한 후에 열 어야 합 니 다. 그렇지 않 으 면 START GROUP_REPLICATION 실행 오류 가 발생 할 수 있 습 니 다.
    오류 보고 정 보 는 다음 과 같다.
    ERROR 3092 (HY000): The server is not configured properly to be an active member of the group. Please see more details on error log.

    mysql 배경 오류 메시지:
    2016-12-15T07:51:28.317816Z 0 [ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: f16f7f74-c283-11e6-ae37-fa163ee40410:1 > Group transactions: 3c992270-c282-11e6-93bf-fa163ee40410:1,
    aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-5'
    2016-12-15T07:51:28.317878Z 0 [ERROR] Plugin group_replication reported: 'The member contains transactions not present in the group. The member will now exit the group.'
    2016-12-15T07:51:28.317887Z 0 [Note] Plugin group_replication reported: 'To force this member into the group you can use the group_replication_allow_local_disjoint_gtids_join option'
    2016-12-15T07:51:28.317999Z 14 [Note] Plugin group_replication reported: 'Going to wait for view modification'
    2016-12-15T07:51:28.318429Z 0 [Note] Plugin group_replication reported: 'getstart group_id 4317e324'
    2016-12-15T07:51:32.437462Z 0 [Note] Plugin group_replication reported: 'state 4330 action xa_terminate'
    2016-12-15T07:51:32.437897Z 0 [Note] Plugin group_replication reported: 'new state x_start'
    2016-12-15T07:51:32.437913Z 0 [Note] Plugin group_replication reported: 'state 4257 action xa_exit'
    2016-12-15T07:51:32.437981Z 0 [Note] Plugin group_replication reported: 'Exiting xcom thread'
    2016-12-15T07:51:32.437993Z 0 [Note] Plugin group_replication reported: 'new state x_start'
    2016-12-15T07:51:37.472364Z 14 [Note] Plugin group_replication reported: 'auto_increment_increment is reset to 1'
    2016-12-15T07:51:37.472474Z 14 [Note] Plugin group_replication reported: 'auto_increment_offset is reset to 1'
    2016-12-15T07:51:37.472943Z 19 [Note] Error reading relay log event for channel 'group_replication_applier': slave SQL thread was killed
    2016-12-15T07:51:37.485851Z 16 [Note] Plugin group_replication reported: 'The group replication applier thread was killed'

    상기 문제 가 발생 하면 해결 방안 은 알림 에 따라 group_replication_allow_local_disjoint_gtids_join 옵션 을 열 고 my sql 명령 행 을 실행 하 는 것 입 니 다.
    mysql> set global group_replication_allow_local_disjoint_gtids_join=ON;

    그리고 실행:
    mysql> start group_replication;
    Query OK, 0 rows affected (7.89 sec)

    실행 성공, 그룹 구성원 정보 조회:
    mysql> SELECT * FROM performance_schema.replication_group_members;
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | group_replication_applier | 3c992270-c282-11e6-93bf-fa163ee40410 | ${yourhostname}  |       24801 | ONLINE       |
    | group_replication_applier | f16f7f74-c283-11e6-ae37-fa163ee40410 | ${yourhostname}  |       24802 | ONLINE       |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    2 rows in set (0.00 sec)
    

    인 스 턴 스 s2 가 현재 그룹 에 가입 한 것 을 보 았 습 니 다.
    database 를 보 니 test 데이터베이스 와 표 t1 가 동기 화 되 었 습 니 다.
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | test               |
    +--------------------+
    5 rows in set (0.00 sec)
    
    mysql> use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | t1             |
    +----------------+
    1 row in set (0.00 sec)

    표 t1 의 데이터 도 동기 화 되 었 습 니 다.
    mysql> select * from t1;
    +----+------+
    | c1 | c2   |
    +----+------+
    |  1 | Luis |
    +----+------+
    1 row in set (0.00 sec

    2.4 새로운 인 스 턴 스 s3 추가
    s2 인 스 턴 스 를 추가 하 는 것 과 유사 합 니 다. 군말 하지 않 고 설정 을 직접 보십시오.
    cd data/s3
    touch s3.cnf
    vi s3.cnf
    [mysqld]
    
    # server configuration
    datadir=/dba/mysql/data/s3
    basedir=/dba/mysql/mysql-5.7/
    
    port=24803
    socket=/dba/mysql/data/s3/s3.sock
    
    #
    # Replication configuration parameters
    #
    server_id=3
    gtid_mode=ON
    enforce_gtid_consistency=ON
    master_info_repository=TABLE
    relay_log_info_repository=TABLE
    binlog_checksum=NONE
    log_slave_updates=ON
    log_bin=binlog
    binlog_format=ROW
    
    #
    # Group Replication configuration
    #
    transaction_write_set_extraction=XXHASH64
    loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
    loose-group_replication_start_on_boot=off
    loose-group_replication_local_address= "127.0.0.1:24903"
    loose-group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"
    loose-group_replication_bootstrap_group= off
    loose-group_replication_single_primary_mode=true
    loose-group_replication_enforce_update_everywhere_checks=false

    s3 인 스 턴 스 시작:
    nohup mysql-5.7/bin/mysqld --defaults-file=data/s3/s3.cnf >data/s3/nohup.out 2>data/s3/nohup.out &

    로그 인, 비밀번호 변경 후 실행:
    SET SQL_LOG_BIN=0;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
    SET SQL_LOG_BIN=1;
    SET SQL_LOG_BIN=0;
    CREATE USER rpl_user@'%';
    GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%' IDENTIFIED BY 'rpl_pass';
    FLUSH PRIVILEGES;
    SET SQL_LOG_BIN=1;
    CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='rpl_pass' FOR CHANNEL 'group_replication_recovery';

    플러그 인 설치:
    INSTALL PLUGIN group_replication SONAME 'group_replication.so';

    마지막 으로 s3 를 그룹 에 가입:
    START GROUP_REPLICATION;

    동기 화 상태 보기:
    mysql> SELECT * FROM performance_schema.replication_group_members;
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    | group_replication_applier | 3c992270-c282-11e6-93bf-fa163ee40410 | ${yourhost}  |       24801 | ONLINE       |
    | group_replication_applier | f16f7f74-c283-11e6-ae37-fa163ee40410 | ${yourhost}  |       24802 | ONLINE       |
    | group_replication_applier | f9b49bd8-c283-11e6-afb2-fa163ee40410 | ${yourhost}  |       24803 | ONLINE       |
    +---------------------------+--------------------------------------+-------------+-------------+--------------+
    3 rows in set (0.00 sec)
    
    
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    | sys                |
    | test               |
    +--------------------+
    5 rows in set (0.00 sec)
    
    mysql> use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | t1             |
    +----------------+
    1 row in set (0.00 sec)
    
    mysql> select * from t1;
    +----+------+
    | c1 | c2   |
    +----+------+
    |  1 | Luis |
    +----+------+
    1 row in set (0.00 sec)

    이때 group replication multi primary mode 의 배 치 를 완 료 했 습 니 다.
    그룹 내 어느 노드 가 primary 노드 인지 어떻게 보 는 지 공식 적 으로 방법 을 제공 합 니 다.
    SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member';

    primary 노드 의 MEMBER 를 얻 었 습 니 다.ID, 이 id 는 server_uuid 와 같 습 니 다.
    3. 간단 한 테스트
  • s3 에서 집행:
  • mysql> insert into t1(c1, c2) values(null, 's3');
    ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

    실행 오류, single - primary mode 에 primary 만 쓸 수 있 습 니 다 (s1).
  • s2 에서 집행:
  • mysql> insert into t1(c1, c2) values(null, 's2');
    ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

    똑 같이 잘못 을 보고 하 다.
  • s1 에서 실행:
  • mysql> insert into t1(c1, c2) values(null, 's1');
    Query OK, 1 row affected (0.03 sec)

    실행 성공.
    s2 와 s3 에서 데이터 동기 화 상황 조회:
    mysql> select * from t1;
    +----+------+
    | c1 | c2   |
    +----+------+
    |  1 | Luis |
    |  8 | s1   |
    +----+------+
    2 rows in set (0.00 sec)

    group replication 에서 열 을 늘 리 는 보폭 은 기본적으로 7 입 니 다.
    4. 참고
    http://dev.mysql.com/doc/refman/5.7/en/group-replication-getting-started.html

    좋은 웹페이지 즐겨찾기