zoukankan      html  css  js  c++  java
  • MGR安装

    二、环境准备

    主机名 IP地址 角色
    node2.com 172.16.8.101 primary
    node3.com 172.16.8.53 seconde
    node3.com 172.16.8.68 seconde

    操作系统:CentOS Linux release 7.2.1511
    MySQL版本:mysql-5.7.26-linux-glibc2.12-x86_64
    MySQL Router版本:mysql-router-8.0.17-linux-glibc2.12-x86_64
    MySQL Shell版本:mysql-shell-8.0.17-linux-glibc2.12-x86-64bit

    三、MySQL安装

    注意: 以下需要在三台机器上分别安装
    本次安装为一主两从模式

    1. 关闭防火墙

    # systemctl stop firewalld
    # systemctl disable firewalld
    # setenforce 0
    # cat /etc/sysconfig/selinux
    ## 如果上一步查的SELINUX=disabled则下一步用sed替换不用执行
    # sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    # getenforce
    

    2. 软件包上传、解压

    # cd /software/
    # tar -xvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    # cd /usr/local/
    # ln -s mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz mysql
    

    3. 创建mysql数据目录,增加系统用户mysql

    # mkdir -p /data/mysql/data/3306
    # useradd mysql
    # chown -R mysql:mysql /data/mysql/data/3306
    # chown -R mysql:mysql /usr/local/mysql*
    

    4. 增加mysql的配置文件

        vim /etc/my.cnf
    

    4.1 node2的配置文件内容如下

    [mysqld]
    basedir=/usr/local/mysql/
    datadir=/data/mysql/data/3306
    port=3306
    socket=/tmp/mysql.sock
    
    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
    
    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= "172.16.8.101:33060"
    loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
    loose-group_replication_bootstrap_group=off
    

    4.2 node3的配置文件内容如下

    [mysqld]
    basedir=/usr/local/mysql/
    datadir=/data/mysql/data/3306
    port=3306
    socket=/tmp/mysql.sock
    
    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
    
    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= "172.16.8.53:33060"
    loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
    loose-group_replication_bootstrap_group=off
    

    4.3 node4的配置文件内容如下

    [mysqld]
    basedir=/usr/local/mysql/
    datadir=/data/mysql/data/3306
    port=3306
    socket=/tmp/mysql.sock
    
    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
    
    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= "172.16.8.68:33060"
    loose-group_replication_group_seeds= "172.16.8.101:33060,172.16.8.53:33060,172.16.8.68:33060"
    loose-group_replication_bootstrap_group=off
    

    说明: 上面的三个配置文件省略了所有不必要的配置项,但是看起来还是有点多,这些都是mgr环境要求的。

    • server_id:每个实例都要不要样
    • loose-group_replication_group_name:为mgr高可用组起一个名字,这个名字一定要是uuid格式的。
    • loose-group_replication_local_address:mgr各实例之前都是要进行通信的、这个配置项设置的就是本实例所监听的ip:端口
    • loose-group_replication_group_seeds:各mgr实例所监听的ip:端口信息
    • Group Replication是要根据GTID(Global Transaction Identifiers)来进行同步的,所以需要开启GTID

    5. 初始化mysql数据库

    # cd /usr/local/mysql/
    # ./bin/mysqld --defaults-file=/etc/my.cnf --datadir=/data/mysql/data/3306/ --user=mysql --initialize-insecure
    

    --initialize-insecure:无密码初始化MySQL

    6. 配置mysql与systemd结合

    说明: CentOS7.x下与服务启动相关的脚本不在是7以下的/etc/init.d/目录的下脚本,而是/usr/lib/systemd/system/目录
    配置systemd相关的配置文件/usr/lib/systemd/system/mysql.service

    vim /usr/lib/systemd/system/mysql.service
    

    输入如下内容

    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target
    
    [Install]
    WantedBy=multi-user.target
    
    [Service]
    User=mysql
    Group=mysql
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    #LimitNOFILE = 5000
    #Restart=on-failure
    #RestartPreventExitStatus=1
    

    7. 启动MySQL,并把MySQL加入开机启动

    # systemctl enable mysql
    # systemctl start mysql
    

    8. 配置环境变量

    # echo 'PATH=/usr/local/mysql/bin/:$PATH' >>/etc/profile
    # source /etc/profile
    

    9. 添加三台机器的DNS解析

    # echo "172.16.8.101  node2.com" >> /etc/hosts
    # echo "172.16.8.53  node3.com" >> /etc/hosts
    # echo "172.16.8.68  node4.com" >> /etc/hosts
    

    10. 测试登录

        # mysql -uroot -p
    

    四、MGR配置

    4.1配置mgr的第一个节点:

    mgr中所有的结点都属于一个逻辑上的组、这个组就像是QQ群一样,是由群主建起来的,有了这个上组之后,其它的结点就可以加入到这个组中来了。onode2.com来建群,以下步骤在node2.com主机上的mysql中执行

    4.1.1 创建用于复制的用户

    mysql> set sql_log_bin=0;
    mysql> create user mgruser@'%' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'%';
    mysql> create user mgruser@'127.0.0.1' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1';
    mysql> create user mgruser@'localhost' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'localhost';
    mysql> set sql_log_bin=1;
    

    4.1.2 配置复制所使用的用户

    mysql> change master to 
        -> master_user='mgruser',
        -> master_password='123456'
        -> for channel 'group_replication_recovery';
    

    4.1.3 安装mysql group replication插件

    mysql> install plugin group_replication soname 'group_replication.so';
    

    4.1.4 建个群(官方点的说法就是初始化一个复制组)

    mysql> set global group_replication_bootstrap_group=on;
    mysql> start group_replication;
    mysql> set global group_replication_bootstrap_group=off;
    

    说明:

    • global group_replication_bootstrap_group=on:代表这个节点是主节点

    4.2配置mgr的第二个节点:

    第二个结点和第一个结点唯一的不同在于它不在要自己去建一个群了,它只要加入第一个结点建的群就可以了,以下步骤在node3.com主机上的mysql中执行

    4.2.1 创建用于复制的用户

    mysql> set sql_log_bin=0;
    mysql> create user mgruser@'%' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'%';
    mysql> create user mgruser@'127.0.0.1' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'127.0.0.1';
    mysql> create user mgruser@'localhost' identified by '123456';
    mysql> grant replication slave,replication client on *.* to mgruser@'localhost';
    mysql> set sql_log_bin=1;
    

    4.2.2 配置复制所要的用户

    mysql> change master to
    -> master_user='mgruser',
    -> master_password='123456'
    -> for channel 'group_replication_recovery';
    

    4.2.3 安装组复制插件

    mysql> install plugin group_replication soname 'group_replication.so';
    

    4.2.4 加入前面创建好的复制组

    mysql> start group_replication;
    

    4.3配置mgr的其它结点:

    逻辑上第二个结点与第三、第四、第五...等等结点有着一样的逻辑角色,就也是说它们都不是群主,所以它们的配置方式和第二个结点是一样的,所以不在详细列举每一步的配置

    WilliamZheng©版权所有 转载请注明出处! 运维架构师群:833329925
  • 相关阅读:
    ‘Host’ is not allowed to connect to this mysql server
    centos7安装mysql
    further configuration avilable 不见了
    Dynamic Web Module 3.0 requires Java 1.6 or newer
    hadoop启动 datanode的live node为0
    ssh远程访问失败 Centos7
    Linux 下的各种环境安装
    Centos7 安装 python2.7
    安装scala
    Centos7 安装 jdk 1.8
  • 原文地址:https://www.cnblogs.com/williamzheng/p/11365235.html
Copyright © 2011-2022 走看看