新浦京81707con > 功能介绍 > 如何搭建Percona

原标题:如何搭建Percona

浏览次数:198 时间:2019-11-02

怎么样搭建Percona XtraDB Cluster集群

豆蔻梢头、情状计划

     主机IP                     主机名               操作系统版本     PXC

     192.168.244.146     node1              CentOS7.1      Percona-XtraDB-Cluster-56-5.6.30

     192.168.244.147     node2              CentOS7.1      Percona-XtraDB-Cluster-56-5.6.30

     192.168.244.148     node3              CentOS7.1      Percona-XtraDB-Cluster-56-5.6.30

     关闭防火墙大概允许3306, 4444, 4567和4568七个端口的总是

     关闭SElinux

二、下载PXC

     安装PXC yum源

     # yum install

     这样会在/etc/yum.repos.d下生成percona-release.repo文件

     安装PXC

     # yum install Percona-XtraDB-Cluster-56

     最后下载下来的本子是Percona-XtraDB-Cluster-56-5.6.30

     注意:四个节点上均要安装。

三、配置节点

     配置节点豆蔻年华

     修改node1的/etc/my.cnf

[mysqld]

datadir=/var/lib/mysql
user=mysql

# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.244.146,192.168.244.147,192.168.244.148

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node #1 address
wsrep_node_address=192.168.244.146

# SST method
wsrep_sst_method=xtrabackup-v2

# Cluster name
wsrep_cluster_name=my_centos_cluster

# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"

     启动node1

     # systemctl start mysql@bootstrap.service

    注意:那些是CentOS 7下的起步形式,假设是CentOS 6,则运行情势为 # /etc/init.d/mysql bootstrap-pxc

    之所以接受bootstrap运维,其实是告诉数据库,那是第一个节点,不用进行数量的合作。

    利用这种措施运行,也正是wsrep_cluster_address方式设置为gcomm://。

    当时,可登入客商端查看数据库的情景

    mysql> show status like 'wsrep%';

    主要关心以下参数的动静

 ------------------------------ -------------------------------------- 
| Variable_name                | Value                                |
 ------------------------------ -------------------------------------- 
| wsrep_local_state_uuid       | 1fbb69e3-32a3-11e6-a571-aeaa962bae0c |
 ...
| wsrep_local_state            | 4   
| wsrep_local_state_comment    | Synced                               |
 ...
| wsrep_cluster_size           | 1
 ...
| wsrep_cluster_status         | Primary                              |
| wsrep_connected              | ON                                   |
 ...
| wsrep_ready                  | ON                                   |

    在地点的安插文件中,有个wsrep_sst_auth参数。该参数是用于其余节点参与到该集群中,利用XtraBackup实行State Snapshot Transfer(肖似于全量同步)的。

    所以,接下去是授权 

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cret';
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;

    配置节点二

    修改node2的/etc/my.cnf

[mysqld]

datadir=/var/lib/mysql
user=mysql

# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.244.146,192.168.244.147,192.168.244.148

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node #2 address
wsrep_node_address=192.168.244.147

# SST method
wsrep_sst_method=xtrabackup-v2

# Cluster name
wsrep_cluster_name=my_centos_cluster

# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"     

     启动node2

     # systemctl start mysql

     要是是CentOS 6,则运维格局为 # /etc/init.d/mysql start

     如果在开发银行的长河中现身难点,可查阅mysql的不当日志,假如是RPM安装,暗中认可是/var/lib/mysql/主机名.err 

     运营完结后,也可由此mysql> show status like 'wsrep%';命令查看集群的音信。

     配置节点三

     修改node3的/etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
user=mysql

# Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

# Cluster connection URL contains the IPs of node#1, node#2 and node#3
wsrep_cluster_address=gcomm://192.168.244.146,192.168.244.147,192.168.244.148

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node #3 address
wsrep_node_address=192.168.244.148

# SST method
wsrep_sst_method=xtrabackup-v2

# Cluster name
wsrep_cluster_name=my_centos_cluster

# Authentication for SST method
wsrep_sst_auth="sstuser:s3cret"

图片 1;)

   

     启动node3

     # systemctl start mysql

     登入数据库,查看集群的图景

 ------------------------------ -------------------------------------- 
| Variable_name                | Value                                |
 ------------------------------ -------------------------------------- 
| wsrep_local_state_uuid       | 1fbb69e3-32a3-11e6-a571-aeaa962bae0c |
 ...
| wsrep_local_state            | 4   
| wsrep_local_state_comment    | Synced                               |
 ...
| wsrep_cluster_size           | 3
 ...
| wsrep_cluster_status         | Primary                              |
| wsrep_connected              | ON                                   |
 ...
| wsrep_ready                  | ON        

    通过wsrep_cluster_size能够看到集群有3个节点。

四、 测试

     上边来测量试验大器晚成把,在node3中创设一张表,并插入记录,看node1和node第22中学能或无法查询得到。

      node3中创设测量检验表并插入记录

root@node3 > create table test.test(id int,description varchar(10));
Query OK, 0 rows affected (0.18 sec)

root@node3 > insert into test.test values(1,'hello,pxc');
Query OK, 1 row affected (0.01 sec)

      node1和node2中查询

root@node1 > select * from test.test;
 ------ ------------- 
| id   | description |
 ------ ------------- 
|    1 | hello,pxc   |
 ------ ------------- 
1 row in set (0.00 sec)

 

 

root@node2 > select * from test.test;
 ------ ------------- 
| id   | description |
 ------ ------------- 
|    1 | hello,pxc   |
 ------ ------------- 
1 row in set (0.05 sec) 

时至前不久,Percona XtraDB Cluster搭建落成~

总结:

  1. 刚开始起步node2的时候,运营战败,错误日志中报如下音信:

    2016-06-15 20:06:09 4937 [ERROR] WSREP: failed to open gcomm backend connection: 110: failed to reach primary view: 110 (Connection timed out)

          at gcomm/src/pc.cpp:connect():162
    

    2016-06-15 20:06:09 4937 [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():208: Failed to open backend connection: -110 (Connection timed out) 2016-06-15 20:06:09 4937 [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():1387: Failed to open channel 'my_centos_cluster' at 'gcomm://192.168.244.146,192.168.244.147,192.168.244.148': -110 (Connection timed out) 2016-06-15 20:06:09 4937 [ERROR] WSREP: gcs connect failed: Connection timed out 2016-06-15 20:06:09 4937 [ERROR] WSREP: wsrep::connect(gcomm://192.168.244.146,192.168.244.147,192.168.244.148) failed: 7 2016-06-15 20:06:09 4937 [ERROR] Aborting

 

 

2016-06-15 20:27:03 5870 [ERROR] WSREP: Failed to read 'ready <addr>' from: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.244.147' --datadir '/var/lib/mysql/' --defaults-file '/etc/my.cnf' --defaults-group-suffix '' --parent '5870'  ''
        Read: '(null)'
2016-06-15 20:27:03 5870 [ERROR] WSREP: Process completed with error: wsrep_sst_xtrabackup-v2 --role 'joiner' --address '192.168.244.147' --datadir '/var/lib/mysql/' --defaults-file '/etc/my.cnf' --defaults-group-suffix '' --parent '5870'  '' : 2 (No such file or directory)
2016-06-15 20:27:03 5870 [ERROR] WSREP: Failed to prepare for 'xtrabackup-v2' SST. Unrecoverable.
2016-06-15 20:27:03 5870 [ERROR] Aborting

特意是上面的报错音信,根据的杀绝思路,还以为是socat的本子太低。

新生才发现,是S埃利nux没有关闭。。。

此外,在节点参加集群的进度中,若是报关于xtrabackup-v2的错误,无妨先将wsrep_sst_method的点子设置为rsync大概mysqldump,看能或不能够成功。

  1. 以systemctl start mysql@bootstrap.service运营的节点,必得以systemctl stop mysql@bootstrap.service关闭,如若以systemctl stop mysql关闭,则没效果。

参照文书档案:

1. http://www.linuxidc.com/Linux/2016-06/132701.htm

2. PXC官方文书档案

3. 

Percona XtraDB Cluster 的详细介绍:请点这里
Percona XtraDB Cluster 的下载地址:请点这里

正文长久更新链接地址:http://www.linuxidc.com/Linux/2016-06/132700.htm

图片 2

本文由新浦京81707con发布于功能介绍,转载请注明出处:如何搭建Percona

关键词: 新浦京81707con

上一篇:数据处理流程

下一篇:没有了