首页 > 代码库 > Percona-Server-Cluster安装
Percona-Server-Cluster安装
Percona-XtraDB-Cluster的安装
1. 准备工作
1.1. PXC介绍
Percona-XtraDB-Cluster时MySQL的高可用性和可扩展性的解决方案。其特性包含:同步复制,多主复制,并行复制,数据一致性。主要组件为Percona-XtraDB-Cluster-server,Percona-XtraDB-Cluster-client,Percona-XtraDB-Cluster-galera。
1.2. 环境准备
192.168.10.146----CentOS-6.*
192.168.10.147----CentOS-6.5 (ftp yum)
192.168.10.148----CentOS-6.*
此处使用了一台CentOS-6.5系统的机器作为ftp yum源。其他两台机器为CentOS-6.*环境,使用CentOS-6.5的源。配置均为1G内存,2G swap,32G动态磁盘空间。
需要在每台机器上确认以下服务:
1.SElinux为关闭状态。
2.iptables关闭,如开启,放通端口3306,4444,,4567以及4568.
3.需要配置文件/etc/resolv.conf,添加nameserver,能够解析域名。
2. 安装Percona-Server
2.1. 安装
在所有服务器上安装Percona-Server:
yum installhttp://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
yum installhttp://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install Percona-Server-shared-compat
yum install Percona-Server-server-55Percona-Server-client-55
-----使用centos-6.1-4 yum源,会有如下错误,文件均存在于本机:
Error: Package:Percona-Server-shared-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libssl.so.10(libssl.so.10)(64bit)
Error: Package:Percona-Server-shared-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libcrypto.so.10(libcrypto.so.10)(64bit)
Error: Package:Percona-Server-client-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libssl.so.10(libssl.so.10)(64bit)
Error: Package:Percona-Server-server-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libcrypto.so.10(libcrypto.so.10)(64bit)
Error: Package:Percona-Server-server-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libssl.so.10 (libssl.so.10)(64bit)
Error: Package:Percona-Server-client-55-5.5.39-rel36.0.el6.x86_64 (percona)
Requires: libcrypto.so.10(libcrypto.so.10)(64bit)
Youcould try using --skip-broken to work around the problem
Youcould try running: rpm -Va --nofiles –nodigest
由于openssl及其他依赖包版本的原因,即使本地有libssl.so.10,libssl.so.10文件,Percona仍然无法识别。因此选择CentOS-6.5来作为yum源,对本地依赖包进行升级。
-----使用centos-6.5 yum源,能成功进行依赖性解析,如下:
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================
Package Arch Version Repository Size
===============================================================================
Installing:
Percona-Server-client-55 x86_64 5.5.39-rel36.0.el6 percona 5.9 M
Percona-Server-server-55 x86_64 5.5.39-rel36.0.el6 percona 15 M
Installing for dependencies:
Percona-Server-shared-55 x86_64 5.5.39-rel36.0.el6 percona 647 k
libaio x86_64 0.3.107-10.el6 Packages 21 k
make x86_64 1:3.81-20.el6 Packages 389 k
Updating for dependencies:
openssl x86_64 1.0.1e-15.el6 Packages 1.5 M
Transaction Summary
===============================================================================
Install 5 Package(s)
Upgrade 1 Package(s)
2.2. 初始化
在所有服务器上配置/etc/my.cnf:
[mysqld]
# basic settings
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid
skip-external-locking
max_allowed_packet = 16M
# innodb settings
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index =/opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path =ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb
# server id
server-id=1
# other settings
[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192
[mysqlhotcopy]
interactive-timeout
[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8
创建相对应目录以供使用,并修改用户:
mkdir -p/opt/mysql/{data,tmp,run,binlogs,log}
chown mysql:mysql /opt/mysql/{data,tmp,run,binlogs,log}
对数据库进行初始化:
su – mysql
mysql_install_db --user=mysql--datadir=/opt/mysql/data/
或者使用:
/usr/bin/mysql_install_db --user=mysql--datadir=/opt/mysql/data/
/etc/init.d/mysql start
登录查看数据库,验证数据库成功后退出。
3. 删除包
原有软件包会与PXC软件包冲突,所以要删除。
Error: Percona-XtraDB-Cluster-clientconflicts with Percona-Server-client-55-5.5.34-rel32.0.591.rhel6.x86_64
Error: Percona-XtraDB-Cluster-serverconflicts with Percona-Server-server-55-5.5.34-rel32.0.591.rhel6.x86_64
Error: Percona-XtraDB-Cluster-shared conflictswith Percona-Server-shared-55-5.5.34-rel32.0.591.rhel6.x86_64
停掉数据库,删除包:
/etc/init.d/mysql stop
rpm -qa | grep Percona-Server | grep -vcompat | xargs sudo rpm -e --nodeps
4. 配置PXC
4.1. 添加PXC支持
对每台服务器添加XtraDB Cluster支持,配置my.cnf:
第一个节点:
[mysqld]
# basic settings
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid
skip-external-locking
max_allowed_packet = 16M
# innodb settings
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index =/opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path =ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb
# xtradb cluster settings
binlog_format = ROW
wsrep_cluster_name = mycluster
wsrep_cluster_address =gcomm://192.168.10.146,192.168.10.147,192.168.10.148
wsrep_node_address = 192.168.10.146
wsrep_provider =/usr/lib64/libgalera_smm.so
wsrep_sst_method = rsync
#wsrep_sst_method = xtrabackup
#wsrep_sst_auth = sst:secret
#wsrep_slave_threads=4
#log_slave_updates
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
# server id
server-id=1
# other settings
[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192
[mysqlhotcopy]
interactive-timeout
[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8
注:wsrep_node_address后写本机IP地址或者hostname,应确保不一样。server_id应区分开。
说明:wsrep_sst_method = xtrabackup-v2为官方推荐的配置,同时支持rsync等其他方式。但是此处测试选择xtrabackup方式会在新增节点时报错handshake failed。所以更改为rsync方式。
4.2. 安装PXC套件
yum install Percona-Server-shared-compat
yum install Percona-XtraDB-Cluster-serverPercona-XtraDB-Cluster-client
4.3. 启动
4.3.1. 启动第一个节点
/etc/init.d/mysql bootstrap-pxc
Bootstrapping PXC (Percona XtraDBCluster)Starting MySQL (Percona XtraDB Cluster).. SUCCESS!
mysql –uroot –p
mysql> show global status like ‘wsrep%‘;
+----------------------------------+----------------------------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------------------------+
| wsrep_local_state_uuid |4682078f-3f0b-11e4-a6bf-66e0202d8999 |
| wsrep_protocol_version | 6 |
| wsrep_last_committed | 3 |
| 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 | 2 |
| wsrep_received_bytes | 143 |
| 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 | 18446744073709551615 |
| 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_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_incoming_addresses | 192.168.10.147:3306 |
| wsrep_evs_repl_latency |2.28e-06/5.2768e-06/8.433e-06/2.149e-06/5 |
| wsrep_cluster_conf_id | 1 |
| wsrep_cluster_size | 1 |
| wsrep_cluster_state_uuid |4682078f-3f0b-11e4-a6bf-66e0202d8999 |
| 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.7(r7f44a18) |
| wsrep_ready | ON |
| wsrep_thread_count | 5 |
+----------------------------------+----------------------------------------------+
53 rows in set (0.01 sec)
create database testdb;
use testdb;
CREATE TABLE `hostgroup` (
-> `hostgroup_id` tinyint(4)NOT NULL AUTO_INCREMENT,
-> `hostgroup_name` char(20)DEFAULT NULL,
-> `hostgroup_next`tinyint(4) NOT NULL,
-> `colo_name` char(4) NOTNULL,
-> PRIMARY KEY(`hostgroup_id`)
-> )ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
GRANT RELOAD, LOCK TABLES, REPLICATIONCLIENT ON *.* TO ‘sst‘@‘localhost‘ IDENTIFIED BY ‘secret‘;
flush privileges;
4.3.2. 增加节点
第二个新增节点,配置my.cnf文件:
[mysqld]
# basic settings
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid
skip-external-locking
max_allowed_packet = 16M
# innodb settings
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index =/opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path =ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb
# xtradb cluster settings
binlog_format = ROW
wsrep_cluster_name = mycluster
wsrep_cluster_address =gcomm://192.168.10.146,192.168.10.147,192.168.10.148
wsrep_node_address = 192.168.10.148
wsrep_provider =/usr/lib64/libgalera_smm.so
wsrep_sst_method = rsync
#wsrep_sst_method = xtrabackup
#wsrep_sst_auth = sst:secret
#wsrep_slave_threads=4
#log_slave_updates
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
# server id
server-id=2
# other settings
[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192
[mysqlhotcopy]
interactive-timeout
[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8
启动mysql,区分于第一个节点:
/etc/init.d/mysql start
在主节点查看:
mysql> show global status like ‘wsrep%‘;
+----------------------------------+----------------------------------------------+
| Variable_name | Value |
+----------------------------------+----------------------------------------------+
| wsrep_local_state_uuid |4682078f-3f0b-11e4-a6bf-66e0202d8999 |
| wsrep_protocol_version | 6 |
| wsrep_last_committed | 3 |
| 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 | 6 |
| wsrep_received_bytes | 412 |
| 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 | 18446744073709551615 |
| 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_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_incoming_addresses | 192.168.10.146:3306,192.168.10.147:3306 |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 4682078f-3f0b-11e4-a6bf-66e0202d8999 |
| 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.7(r7f44a18) |
| wsrep_ready | ON |
| wsrep_thread_count | 5 |
+----------------------------------+---------- -----------------------------------+
53 rows in set (0.00 sec)
在新增节点上登入mysql,可以通过show databases查看testdb已经同步。
第三个节点,配置my.cnf:
[mysqld]
# basic settings
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid
skip-external-locking
max_allowed_packet = 16M
# innodb settings
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index = /opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path =ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb
# xtradb cluster settings
binlog_format = ROW
wsrep_cluster_name = mycluster
wsrep_cluster_address =gcomm://192.168.10.146,192.168.10.147,192.168.10.148
wsrep_node_address = 192.168.10.148
wsrep_provider =/usr/lib64/libgalera_smm.so
wsrep_sst_method = rsync
#wsrep_sst_method = xtrabackup
#wsrep_sst_auth = sst:secret
#wsrep_slave_threads=4
#log_slave_updates
innodb_locks_unsafe_for_binlog = 1
innodb_autoinc_lock_mode = 2
# server id
server-id=3
# other settings
[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192
[mysqlhotcopy]
interactive-timeout
[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8
启动:
/etc/init.d/mysql start
可依照此方法依次添加多个节点。
Percona-Server-Cluster安装