pxc高可用集群安装部署

参考文档:

https://www.percona.com/doc/percona-xtradb-cluster/LATEST/install/yum.html#yum

http://www.cnblogs.com/lyhabc/p/6812284.html

https://www.percona.com/doc/percona-xtradb-cluster/LATEST/bootstrap.html    ##官方文档

https://www.cnblogs.com/zejin2008/p/5475285.html

Yum 源安装包

percona-release-0.1-6.noarch.rpm 文件

 

一些名词介绍:

 

    WSwrite set 写数据集

 

    IST: Incremental State Transfer 增量同步

 

    SSTState Snapshot Transfer 全量同步

 

         一,准备环境

 

1.1 centos 7 系统,三台主机

 

IP分别为:192.168.80.163192.168.80.167192.168.80.168

 

建议关闭iptables4个端口 3306,4444,4567,4568

 

pxc环境所涉及的端口:

 

#mysql实例端口:3306

 

1.2 清空mysql数据库mariDB,及其他数据库

 

[root@localhost ~]# yum list|grep mari

 

[root@localhost ~]# yum remove “”

 

1.3 关闭防火墙、selinux

 

[root@bogon ~]# systemctl stop firewalld

 

[root@bogon ~]# systemctl disable firewalld

 

[root@bogon ~]# systemctl status firewalld

 

[root@linux01 ~]#vi /etc/selinux/config  

 

#This file controls the state of SELinux on the system.

 

# SELINUX= can take one of these three values:

 

#     enforcing - SELinux security policy is enforced.

 

#     permissive - SELinux prints warnings instead of enforcing.

 

#     disabled - No SELinux policy is loaded.

 

SELINUX=disabled

 

# SELINUXTYPE= can take one of these two values:

 

#     targeted - Targeted processes are protected,

 

#     mls - Multi Level Security protection.

 

  

 

          二,下载安装

 

2.1下载yum源安装包,Yum安装

 

[root@localhost /]# yum install percona-release-0.1-6.noarch\ .rpm -y

 

[root@localhost /]# yum install Percona-XtraDB-Cluster-57

 

[root@localhost /]# yum install -y git scons gcc gcc-c++ openssl check cmake bison \

 

boost-devel asio-devel libaio-devel ncurses-devel readline-devel pam-devel \

 

Socat

[root@localhost ~]# mv my.cnf /etc/my.cnf

 

[root@localhost ~]# vi /etc/my.cnf

 

          三,创建第一个节点

 

3.1主机192.168.80.163上编辑my.cnf文件

 

/etc下编辑my.cnf文件

 

内容:

 

[mysqld]

 

datadir = /mysqldb/db_pxc

 

pid_file= /mysqldb/db_pxc/mysql.pid

 

character-set-server=utf8

 

log-bin=/mysqldb/db_pxc/log_bin

 

server-id = 9816000

 

innodb_buffer_pool_size = 300M

 

innodb_data_file_path = ibdata1:10M:autoextend

 

innodb_data_home_dir = /mysqldb/db_pxc

 

innodb_file_per_table=1

 

skip-name-resolve

 

port            = 3306

 

socket          = /mysqldb/db_pxc/mysql.sock

 

user=mysql

 

log_error=/mysqldb/db_pxc/mysql_error.log

 

#pxc

 

user=mysql

 

binlog_format=ROW

 

log-slave-updates

 

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so

 

wsrep_cluster_name=pxc

 

wsrep_cluster_address='gcomm://192.168.80.163,192.168.80.167,192.168.80.168'     ##加入三台主机地址##

 

wsrep_node_name=pxc3 

 

wsrep_node_address=192.168.80.166           ##当前主机地址##

 

wsrep_sst_method=xtrabackup-v2

 

wsrep_sst_auth=sstuser:passw0rd            ##数据库所用用户及密码##

 

pxc_strict_mode=ENFORCING

 

binlog_format=ROW

 

default_storage_engine=InnoDB

 

innodb_autoinc_lock_mode=2

pxc高可用集群安装部署_第1张图片

 

 

        四,创建文件目录

 

[root@localhost ~]# mkdir -p /mysqldb/db_pxc

       五,实例1启动

 

 5.1 启动、关闭第一个实例需要加“@bootstrap.service

 

[root@localhost ~]# systemctl start [email protected]

 

@bootstrap.service中的参数

 

[root@localhost ~]# more /etc/sysconfig/mysql.bootstrap

 

# Arguments to pass to mysqld_safe in systemctl

 

# For Bootstrapping

 

# You can append any extra options in to the same variable.

 

EXTRA_ARGS=" --wsrep-new-cluster "

 

# Other environment variables if any

 

# ABC=123 for example

 

查看日志[root@localhost ~]# tail -f /mysqldb/db_pxc/mysql_error.log

 

 5.2 日志中查看临时密码

 

[root@localhost ~]# vi /mysqldb/db_pxc/mysql_error.log

pxc高可用集群安装部署_第2张图片

 5.3 进入数据库,创建用户、授权

[root@localhost ~]# mysql -uroot -p -S /mysqldb/db_pxc/mysql.sock

mysql> alter user root@'localhost' identified by 'oracle';

mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'passw0rd';

mysql> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';

所创建用户及密码需要与文件my.cnf中的配置相同

 5.4 查看集群状态

mysql> show status like 'wsrep%';

 

##{文件资料:#安装实例

/usr/local/pxc_56/scripts/mysql_install_db --defaults-file=/home/mysql/my6000.cnf --basedir=/usr/local/pxc_56

#启动第一个实例

/usr/local/pxc_56/bin/mysqld_safe --defaults-file=/home/mysql/my6000.cnf --ledir=/usr/local/pxc_56/bin/ --wsrep-new-cluster  &

#修改密码

/usr/local/pxc_56/bin/mysqladmin -u root -P6000 password '000000' -S /home/mysql/I6000/mysql.sock

#登陆并增加用户

/usr/local/pxc_56/bin/mysql -uroot -p -P6000 -S /home/mysql/I6000/mysql.sock

grant all on *.* to 'sstuser'@'localhost' identified by '123';

flush privielges;}##

        六,创建第二个节点

6.1在主机192.168.80.167上编辑文件my.cnf

vi /etc/my.cnf

pxc高可用集群安装部署_第3张图片

 

         七,创建文件目录

 [root@localhost ~]# mkdir -p /mysqldb/db_pxc

        八,启动实例2,第二个节点不用加参数@bootstrap.service  ##参数:--wsrep -new-cluster

[root@localhost ~]# systemctl start mysql

pxc高可用集群安装部署_第4张图片

 

           九,查看集群状态

mysql> show status like 'wsrep%';

          十,创建第三个节点

 10.1 编辑主机IP192.168.80.168my.cnf 文件

pxc高可用集群安装部署_第5张图片

          十一,创建文件目录

 

[root@localhost ~]# mkdir -p /mysqldb/db_pxc

         十二,启动实例节点3

 

[root@localhost ~]#  systemctl start mysql

 

        十三,查看集群状态

 

mysql> show status like 'wsrep%';

pxc高可用集群安装部署_第6张图片pxc高可用集群安装部署_第7张图片pxc高可用集群安装部署_第8张图片

            十四,关闭自动启动

[root@localhost ~]# systemctl list-unit-files|grep mysql

mysql.service                                 enabled

[email protected]                                disabled

mysqld.service                                enabled

[root@localhost ~]# systemctl disable mysql.service

Removed symlink /etc/systemd/system/multi-user.target.wants/mysql.service.

Removed symlink /etc/systemd/system/mysqld.service.

          十五,安装所遇问题解决

15.1 关闭后再启动第一个节点失败时,按照日志提醒设置以下参数safe_to_bootstrap: 0

改为:1 可以启动:

[root@localhost db_pxc]# pwd

/mysqldb/db_pxc

[root@localhost db_pxc]# vi  grastate.dat

# GALERA saved state

version: 2.1

uuid:    26b3d51f-a867-11e8-8b78-e7ac0d1df513

seqno:   -1

safe_to_bootstrap: 0

  15.2 启动第一个节点时需用命令systemctl start [email protected]

       其他两个节点用systemctl start mysql 

 

转载于:https://www.cnblogs.com/lswei/p/9560368.html

你可能感兴趣的:(pxc高可用集群安装部署)