美文网首页
mysql --- Percona XtraDB Cluster

mysql --- Percona XtraDB Cluster

作者: 月白白222 | 来源:发表于2017-03-25 16:48 被阅读0次

    1、构建安装环境

    1.1、获取 Percona XtraDB Cluster

    浏览器访问:

    https://www.percona.com/downloads/

    在 【Percona XtraDB Cluster】选中【Download 5.6 Now】

    在新页面选择:

    • 【Version】:Percona XtraDB Cluster 5.6.35-26.20
    • 【Software】:Linux-Generic
    • 【Hardware】:x86_64
    • Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101.tar.gz
    1.2、获取 Percona XtraBackup

    浏览器访问:

    https://www.percona.com/downloads/

    在 【Percona XtraBackup】选中【Download Latest】

    在新页面选择:

    • 【Version】:Percona-XtraBackup-2.4.6
    • 【Software】:Linux-Generic
    • 【Hardware】:x86_64
    • percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
    1.3、实验机的准备

    实验用虚拟机的安装请参见:

    《VMware --- CentOS6.x 实验机安装配置的简单说明》

    链接如下:

    http://www.jianshu.com/p/624441bf5e48

    本次实验使用的系统版本为:

    CentOS release 6.8 (Final)

    实验用网络规划:

    IP 用途
    192.168.135.11 node1
    192.168.135.12 node2
    192.168.135.13 node3
    1.4、软件环境的准备

    安装依赖软件

    ]# yum install git scons gcc gcc-c++ openssl check cmake bison boost-devel asio-devel libaio-devel ncurses-devel readline-devel pam-devel -y
    ]# yum install socat -y
    

    删除冲突软件

    ]# rpm -qa |grep -i mysql |xargs rpm -e --nodeps
    

    注:

    需安装 EPEL 源

    2、Percona XtraDB Cluster 的安装、配置

    将下载的安装文件,上传到 /apps01/src 中

    ]# mkdir /apps01/src
    ]# cd /apps01/src/
    ]# tar -xzf Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101.tar.gz
    ]# mv Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101 mysql
    
    ]# tar -xzf percona-xtrabackup-2.4.6-Linux-x86_64.tar.gz
    ]# mv percona-xtrabackup-2.4.6-Linux-x86_64/bin/* mysql/bin/
    ]# mv percona-xtrabackup-2.4.6-Linux-x86_64/man/man1/* mysql/man/man1/
    ]# mv percona-xtrabackup-2.4.6-Linux-x86_64/percona-xtrabackup-2.4-test/ mysql/
    

    安装

    ]# mkdir -p /apps01/local/
    ]# mv mysql/ /apps01/local/
    ]# cd /apps01/local/mysql/
    ]# mkdir -p {log/{binlog,relaylog,slowlog},tmp}
    

    新建 mysql 用户,并更改权限

    ]# useradd -r mysql
    ]# chown -R mysql:mysql /apps01/local/mysql/
    

    初始化 MySQL

    ]# ./scripts/mysql_install_db --user=mysql --basedir=/apps01/local/mysql --datadir=/apps01/local/mysql/data --explicit_defaults_for_timestamp
    

    新建并编辑配置文件

    ]# sudo -u mysql touch my.cnf
    ]# vim my.cnf
    [mysqld]
    
    ###### basic settings ######
    port = 3306
    bind-address = 0.0.0.0
    basedir = /apps01/local/mysql
    datadir = /apps01/local/mysql/data
    tmpdir = /apps01/local/mysql/tmp
    socket = /tmp/mysql.sock
    pid-file = /apps01/local/mysql/mysql.pid
    server-id = 11
    user = mysql
    
    ###### Percona XtraDB Cluster ######
    # Specify the path to the Galera library.
    wsrep_provider = /apps01/local/mysql/lib/libgalera_smm.so
    
    # Specify the logical name for your cluster. It must be the same for all nodes in your cluster.
    wsrep_cluster_name = bind
    
    # Specify the IP addresses of nodes in your cluster. At least one is required for a node to join the cluster, but it is recommended to list addresses of all nodes. This way if the first node in the list is not available, the joining node can use other addresses.
    wsrep_cluster_address = gcomm://192.168.135.11,192.168.135.12,192.168.135.13
    
    # Specify the logical name for each individual node. If this variable is not specified, the host name will be used.
    wsrep_node_name = node1
    
    # Specify the IP address of this particular node.
    wsrep_node_address = 192.168.135.11
    
    # By default, Percona XtraDB Cluster uses Percona XtraBackup for State Snapshot Transfer (SST). Setting wsrep_sst_method=xtrabackup-v2 is highly recommended. This method requires a user for SST to be set up on the initial node. Provide SST user credentials with the wsrep_sst_auth variable.
    wsrep_sst_method = xtrabackup-v2
    
    # Specify authentication credentials for SST as <sst_user>:<sst_pass>. You must create this user when Bootstrapping the First Node and provide necessary privileges for it:
    wsrep_sst_auth = sstuser:sstuserPass
    
    # Galera supports only interleaved (2) lock mode for InnoDB. Setting the traditional (0) or consecutive (1) lock mode can cause replication to fail due to unresolved deadlocks. Set this variable to innodb_autoinc_lock_mode=2.
    innodb_autoinc_lock_mode = 2
    # Galera supports only row-level replication, so set binlog_format=ROW.
    binlog_format = ROW
    # Galera fully supports only the InnoDB storage engine. It will not work correctly with MyISAM or any other non-transactional storage engines. Set this variable to default_storage_engine=InnoDB.
    default_storage_engine = InnoDB
    

    注:

    其它两个节点的配置文件,主要需要修改以下几项,其余可以保持不变:

    server-id =
    wsrep_node_name = 
    wsrep_node_address = 
    

    复制 mysql 启动脚本

    ]# cp support-files/mysql.server /etc/init.d/mysql
    

    修改启动脚本

    ]# vim /etc/init.d/mysql
    basedir=/apps01/local/mysql
    datadir=/apps01/local/mysql/data
    

    修改 mysqld_safe 文件

    ]# sed -i 's#/mnt/workspace/percona-xtradb-cluster-5.6-binary-new/label_exp/centos6-64/Percona-XtraDB-Cluster-5.6.35-80.0/110/usr/local/Percona-XtraDB-Cluster-5.6.35-rel80.0-26.20.2.Linux.x86_64.ssl101/#/apps01/local/mysql/#g' /apps01/local/mysql/bin/mysqld_safe
    

    链接配置文件到 /etc 目录

    ]# ln -s /apps01/local/mysql/my.cnf  /etc/my.cnf
    

    配置环境变量

    ]# vim /etc/profile
    export PATH=$PATH:/apps01/local/mysql/bin
    
    ]# source /etc/profile
    

    重复以步骤,完成剩余两个节点的安装

    3、Percona XtraDB Cluster 的启动

    3.1、启动第一个节点
    ]# /etc/init.d/mysql bootstrap-pxc
    

    添加同步用户

    ]# mysql -u root -p
    Enter password: 
    
    > grant all on *.* to 'sstuser'@'localhost' identified by 'sstuserPass';
    Query OK, 0 rows affected (0.00 sec)
    
    > FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)
    

    检查集群状态:

    > show status like 'wsrep%';
    
    > show status like 'wsrep%';
    +------------------------------+--------------------------------------+
    | Variable_name                | Value                                |
    +------------------------------+--------------------------------------+
    | wsrep_incoming_addresses     | 192.168.135.11:3306                  |
    | wsrep_evs_state              | OPERATIONAL                          |
    | wsrep_gcomm_uuid             | 5480f3f7-112a-11e7-975a-e7e64467f6d3 |
    | wsrep_cluster_conf_id        | 1                                    |
    | wsrep_cluster_size           | 1                                    |
    | wsrep_cluster_state_uuid     | 54819951-112a-11e7-9630-4e25ee000443 |
    | wsrep_cluster_status         | Primary                              |
    | wsrep_connected              | ON                                   |
    | wsrep_ready                  | ON                                   |
    +------------------------------+--------------------------------------+
    59 rows in set (0.00 sec)
    
    

    注:

    为节省篇幅,以上命令输出只保留了需要重点关的几个参数,其它的都删除了

    3.2、启动第二、第三个节点

    第一个节点启动完成,检查状态正常后,就可以通过依次启动第二,第三个节点

    ]# /etc/init.d/mysql start
    

    注:

    节点必须逐个启动,也就是说,一个启动完成后,检查状态正常后,再启动下一个

    相关文章

      网友评论

          本文标题:mysql --- Percona XtraDB Cluster

          本文链接:https://www.haomeiwen.com/subject/ctpcottx.html