mysql --- Percona XtraDB Cluster(PXC) 安装的简单介绍

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

注:

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 200,783评论 5 472
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,396评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 147,834评论 0 333
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,036评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,035评论 5 362
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,242评论 1 278
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,727评论 3 393
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,376评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,508评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,415评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,463评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,140评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,734评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,809评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,028评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,521评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,119评论 2 341

推荐阅读更多精彩内容