PXC 5.7.14 安装部署
3,846 total views, 2 views today
PXC是Percona XtraDB Cluster的缩写,是一种具有高可用性和高扩展性的MySQL开源集群。它集成了Percona Server和Percona XtraBackup,同时采用了Codership Galera库。
常见的PXC架构如下,
下面,开始安装PXC 5.7.14
一、环境说明
主机
1 2 3 4 |
# PXC # 10.9.15.111 pxc1 10.9.15.112 pxc2 10.9.15.113 pxc3 |
OS : CentOS release 6.5 (Final)
二、安装 Percona-XtraDB-Cluster
1、卸载CentOS 自带的mysql-libs包
1 |
rpm -qa | grep -i mysql | xargs sudo rpm -e --nodeps |
2、所有节点安装依赖包
1 2 3 4 5 6 7 |
libev-4.03-3.el6.x86_64.rpm socat-1.7.2.3-1.el6.x86_64.rpm Percona-XtraDB-Cluster-shared-57-5.7.14-26.17.1.el6.x86_64.rpm Percona-XtraDB-Cluster-server-57-5.7.14-26.17.1.el6.x86_64.rpm Percona-XtraDB-Cluster-client-57-5.7.14-26.17.1.el6.x86_64.rpm Percona-XtraDB-Cluster-57-5.7.14-26.17.1.el6.x86_64.rpm percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm |
所有节点安装软件包的步骤
1 2 3 4 5 6 7 8 9 |
yum -y install perl-Time-HiRes yum install –y perl-DBD-MySQL.x86_64 perl-IO-Socket-SSL.noarch nc yum localinstall libev-4.03-3.el6.x86_64.rpm yum localinstall socat-1.7.2.3-1.el6.x86_64.rpm yum localinstall Percona-XtraDB-Cluster-client-57-5.7.14-26.17.1.el6.x86_64.rpm yum localinstall Percona-XtraDB-Cluster-shared-57-5.7.14-26.17.1.el6.x86_64.rpm yum localinstall percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm yum localinstall Percona-XtraDB-Cluster-server-57-5.7.14-26.17.1.el6.x86_64.rpm yum localinstall Percona-XtraDB-Cluster-57-5.7.14-26.17.1.el6.x86_64.rpm |
3、所有节点创建mysql组和用户
1 2 |
# groupadd mysql # useradd -r -g mysql -s /bin/false mysql |
4、创建相关目录
1 2 |
# mkdir /data/mysql/{data,logs,tmp} -p # chown mysql.mysql /data/ -R |
5、配置my.cnf文件
1 2 3 |
find / -name 'my-default.cnf' /usr/share/doc/Percona-XtraDB-Cluster-server-57-5.7.14/my-default.cnf /usr/share/percona-xtradb-cluster/my-default.cnf |
拷贝到/etc/my.cnf
1 |
cp /usr/share/percona-xtradb-cluster/my-default.cnf /etc/my.cnf |
编辑my.cnf
@第一节点 pxc1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[mysqld] user = mysql innodb_buffer_pool_size = 1024M datadir = /data/mysql/data port = 3306 server_id = 3306111 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ## pxc variables ## # Path to Galera library wsrep_provider=/usr/lib64/libgalera_smm.so # Cluster connection URL contains the IPs of node#1, node#2 and node#3 wsrep_cluster_address=gcomm://10.9.15.111,10.9.15.112,10.9.15.113 # 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 InnoDB autoincrement locking mode is a requirement for Galera innodb_autoinc_lock_mode=2 # Node name wsrep_node_name = pxc1 # Node 1 address wsrep_node_address=10.9.15.111 # SST method wsrep_sst_method=xtrabackup-v2 # Cluster name wsrep_cluster_name=my-pxc-test # Authentication for SST method wsrep_sst_auth="sstuser:sstuser" |
@第二节点 pxc2
注意修改 server_id 、wsrep_node_name 、 wsrep_node_address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[mysqld] user = mysql innodb_buffer_pool_size = 1024M datadir = /data/mysql/data port = 3306 server_id = 3306112 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ## pxc variables ## # Path to Galera library wsrep_provider=/usr/lib64/libgalera_smm.so # Cluster connection URL contains the IPs of node#1, node#2 and node#3 wsrep_cluster_address=gcomm://10.9.15.111,10.9.15.112,10.9.15.113 # 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 InnoDB autoincrement locking mode is a requirement for Galera innodb_autoinc_lock_mode=2 # Node name wsrep_node_name = pxc2 # Node 1 address wsrep_node_address=10.9.15.112 # SST method wsrep_sst_method=xtrabackup-v2 # Cluster name wsrep_cluster_name=my-pxc-test # Authentication for SST method wsrep_sst_auth="sstuser:sstuser" |
@第三节点 pxc3
注意修改 server_id 、wsrep_node_name 、 wsrep_node_address
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
[mysqld] user = mysql innodb_buffer_pool_size = 1024M datadir = /data/mysql/data port = 3306 server_id = 3306113 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ## pxc variables ## # Path to Galera library wsrep_provider=/usr/lib64/libgalera_smm.so # Cluster connection URL contains the IPs of node#1, node#2 and node#3 wsrep_cluster_address=gcomm://10.9.15.111,10.9.15.112,10.9.15.113 # 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 InnoDB autoincrement locking mode is a requirement for Galera innodb_autoinc_lock_mode=2 # Node name wsrep_node_name = pxc3 # Node 1 address wsrep_node_address=10.9.15.113 # SST method wsrep_sst_method=xtrabackup-v2 # Cluster name wsrep_cluster_name=my-pxc-test # Authentication for SST method wsrep_sst_auth="sstuser:sstuser" |
三、启动PXC
1、启动第一节点
1 2 3 |
# /etc/init.d/mysql bootstrap-pxc Bootstrapping PXC (Percona XtraDB Cluster)Initializing MySQ[ OK ]se: Starting MySQL (Percona XtraDB Cluster).. [ OK ] |
查看进程是否启动
1 2 3 |
# ps -ef|grep mysql root 9410 1 0 14:06 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/logs/mysql.pid --wsrep-new-cluster mysql 9788 9410 2 14:06 pts/0 00:00:02 /usr/sbin/mysqld --basedir=/usr --datadir=/data/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --wsrep-provider=/usr/lib64/libgalera_smm.so --wsrep-new-cluster --log-error=/data/mysql/logs/error.log --pid-file=/data/mysql/logs/mysql.pid --socket=/data/mysql/mysql.sock --port=3306 --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1 |
查看错误日志信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
".err" 372L, 35184C 195,1 52% last_appl. = -1, protocols = 0/7/3 (gcs/repl/appl), group UUID = f4a3595a-9b40-11e6-ad57-c622a8ebb29a 2016-10-26T05:56:36.594604Z 0 [Note] WSREP: Flow-control interval: [16, 16] 2016-10-26T05:56:36.594609Z 0 [Note] WSREP: Restored state OPEN -> JOINED (0) 2016-10-26T05:56:36.594630Z 0 [Note] WSREP: Member 0.0 (pxc1) synced with group. 2016-10-26T05:56:36.594636Z 0 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 0) 2016-10-26T05:56:36.594660Z 2 [Note] WSREP: New cluster view: global state: f4a3595a-9b40-11e6-ad57-c622a8ebb29a:0, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 3 2016-10-26T05:56:36.594698Z 0 [Note] WSREP: SST complete, seqno: 0 2016-10-26T05:56:36.595680Z 0 [Note] InnoDB: PUNCH HOLE support available 2016-10-26T05:56:36.595692Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-10-26T05:56:36.595698Z 0 [Note] InnoDB: Uses event mutexes 2016-10-26T05:56:36.595702Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier 2016-10-26T05:56:36.595707Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-10-26T05:56:36.595711Z 0 [Note] InnoDB: Using Linux native AIO 2016-10-26T05:56:36.595967Z 0 [Note] InnoDB: Number of pools: 1 2016-10-26T05:56:36.596092Z 0 [Note] InnoDB: Using CPU crc32 instructions 2016-10-26T05:56:36.597310Z 0 [Note] InnoDB: Initializing buffer pool, total size = 1G, instances = 8, chunk size = 128M 2016-10-26T05:56:36.620596Z 0 [Note] InnoDB: Completed initialization of buffer pool 2016-10-26T05:56:36.627552Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2016-10-26T05:56:36.628969Z 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /data/mysql/data/xb_doublewrite 2016-10-26T05:56:36.629545Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2016-10-26T05:56:37.375510Z 0 [Note] InnoDB: Created parallel doublewrite buffer at /data/mysql/data/xb_doublewrite, size 31457280 bytes 2016-10-26T05:56:37.385112Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2016-10-26T05:56:37.385168Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2016-10-26T05:56:37.575501Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2016-10-26T05:56:37.576818Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2016-10-26T05:56:37.576867Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2016-10-26T05:56:37.578343Z 0 [Note] InnoDB: Waiting for purge to start 2016-10-26T05:56:37.628499Z 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.14-8 started; log sequence number 2491156 2016-10-26T05:56:37.628805Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/data/ib_buffer_pool 2016-10-26T05:56:37.629037Z 0 [Note] Plugin 'FEDERATED' is disabled. 2016-10-26T05:56:37.630587Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161026 13:56:37 2016-10-26T05:56:37.632355Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2016-10-26T05:56:37.632379Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2016-10-26T05:56:37.642032Z 0 [Warning] CA certificate ca.pem is self signed. 2016-10-26T05:56:37.642143Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2016-10-26T05:56:37.642230Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2016-10-26T05:56:37.642285Z 0 [Note] IPv6 is available. 2016-10-26T05:56:37.642295Z 0 [Note] - '::' resolves to '::'; 2016-10-26T05:56:37.642309Z 0 [Note] Server socket created on IP: '::'. 2016-10-26T05:56:37.649657Z 0 [Note] Event Scheduler: Loaded 0 events 2016-10-26T05:56:37.650070Z 0 [Note] /usr/sbin/mysqld: ready for connections. Version: '5.7.14-8-57' socket: '/data/mysql/mysql.sock' port: 3306 Percona XtraDB Cluster (GPL), Release rel8, Revision a3f9d06, WSREP version 26.17, wsrep_26.17 2016-10-26T05:56:37.651418Z 2 [Note] WSREP: Initialized wsrep sidno 2 2016-10-26T05:56:37.651445Z 2 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification. 2016-10-26T05:56:37.651468Z 2 [Note] WSREP: REPL Protocols: 7 (3, 2) 2016-10-26T05:56:37.651492Z 0 [Note] WSREP: Service thread queue flushed. 2016-10-26T05:56:37.651515Z 2 [Note] WSREP: Assign initial position for certification: 0, protocol version: 3 2016-10-26T05:56:37.651534Z 0 [Note] WSREP: Service thread queue flushed. 2016-10-26T05:56:37.651599Z 2 [Note] WSREP: Synchronized with group, ready for connections 2016-10-26T05:56:37.651609Z 2 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification. |
去error.log日志搜索关键字password找到默认root密码,登录后修改
1 |
alter user 'root'@'localhost' idnetified by '123456'; |
第一节点启动后,检查cluster的状态。
当前第一节点是Primary。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
mysql> show status like '%wsrep%'; +------------------------------+--------------------------------------+ | Variable_name | Value | +------------------------------+--------------------------------------+ | wsrep_local_state_uuid | 57a3ecf4-9b42-11e6-bc43-03970944486f | | wsrep_protocol_version | 7 | | wsrep_last_committed | 0 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | ... | wsrep_repl_other_bytes | 0 | | wsrep_received | 21 | | wsrep_received_bytes | 2021 | | wsrep_local_commits | 0 | | wsrep_local_state_comment | Synced | ... | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 0 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 3.17(r447d194) | | wsrep_ready | ON | +------------------------------+--------------------------------------+ 59 rows in set (0.00 sec) |
第一节点创建后,其他节点初始化,需要使用xtrabackup工具来备份,然后恢复。
所以,需要创建一个用户用于备份。
1 2 3 |
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstuser'; mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT, PROCESS ON *.* TO 'sstuser'@'localhost'; # 注意,官方文档中少了 PROCESS 权限 mysql> FLUSH PRIVILEGES; |
验证sstuser登录
1 |
# mysql -usstuser -psstuser -S /data/mysql/mysql.sock -e 'show databases' |
启动第二节点
1 |
# /etc/init.d/mysql start |
确认第二节点的状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
mysql> show status like 'wsrep%'; +------------------------------+--------------------------------------+ | Variable_name | Value | +------------------------------+--------------------------------------+ | wsrep_local_state_uuid | 57a3ecf4-9b42-11e6-bc43-03970944486f | | wsrep_protocol_version | 7 | | wsrep_last_committed | 5 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_received | 3 | | wsrep_received_bytes | 214 | | wsrep_local_commits | 0 | | wsrep_local_cert_failures | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_max | 1 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_recv_queue_avg | 0.000000 | | wsrep_local_cached_downto | 0 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_sent | 0 | | wsrep_flow_control_recv | 0 | | wsrep_cert_deps_distance | 0.000000 | | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 0.000000 | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 0.000000 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_cert_index_size | 0 | | wsrep_cert_bucket_count | 22 | | wsrep_gcache_pool_size | 1450 | | wsrep_causal_reads | 0 | | wsrep_cert_interval | 0.000000 | | wsrep_incoming_addresses | 10.9.15.111:3306,10.9.15.112:3306 | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_gcomm_uuid | 622855c9-9b55-11e6-87b1-3bdafc7edcfd | | wsrep_cluster_conf_id | 10 | | wsrep_cluster_size | 2 | | wsrep_cluster_state_uuid | 57a3ecf4-9b42-11e6-bc43-03970944486f | | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 1 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 3.17(r447d194) | | wsrep_ready | ON | +------------------------------+--------------------------------------+ 59 rows in set (0.00 sec) |
启动第三节点
1 |
# /etc/init.d/mysql start |
确定状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
mysql> show status like '%wsrep%'; +------------------------------+----------------------------------------------------+ | Variable_name | Value | +------------------------------+----------------------------------------------------+ | wsrep_local_state_uuid | 57a3ecf4-9b42-11e6-bc43-03970944486f | | wsrep_protocol_version | 7 | | wsrep_last_committed | 5 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_received | 3 | | wsrep_received_bytes | 281 | | wsrep_local_commits | 0 | | wsrep_local_cert_failures | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_max | 1 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_recv_queue_avg | 0.000000 | | wsrep_local_cached_downto | 0 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_sent | 0 | | wsrep_flow_control_recv | 0 | | wsrep_cert_deps_distance | 0.000000 | | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 0.000000 | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 0.000000 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_cert_index_size | 0 | | wsrep_cert_bucket_count | 22 | | wsrep_gcache_pool_size | 1450 | | wsrep_causal_reads | 0 | | wsrep_cert_interval | 0.000000 | | wsrep_incoming_addresses | 10.9.15.111:3306,10.9.15.113:3306,10.9.15.112:3306 | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_gcomm_uuid | 55ebc909-9b56-11e6-9867-1361f4f94504 | | wsrep_cluster_conf_id | 11 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | 57a3ecf4-9b42-11e6-bc43-03970944486f | | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 1 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 3.17(r447d194) | | wsrep_ready | ON | +------------------------------+----------------------------------------------------+ 59 rows in set (0.00 sec) |
至此,PXC安装启动完毕。