mysql pxc 安装_MYSQL PXC 集群安装

名词介绍:

WS:write set写数据集

IST: Incremental State Transfer增量同步

SST:State Snapshot Transfer全量同步

1.准备环境

1.1 centos 7系统,三台主机

IP分别为:192.168.80.163;192.168.80.167;192.168.80.168

建议关闭iptables,4个端口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.下载安装

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

3.创建第一个节点

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

9538117.html

9538117.html

4.创建文件目录

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

5.实例1启动

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

[root@localhost ~]# systemctl startmysql@bootstrap.service

@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

9538117.html

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.创建第二个节点

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

9538117.html

7.创建文件目录

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

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

[root@localhost ~]# systemctl start mysql

9538117.html

9.查看集群状态

mysql> show status like 'wsrep%';

10.创建第三个节点

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

9538117.html

11.创建文件目录

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

12.启动实例节点3

[root@localhost ~]#  systemctl start mysql

13.查看集群状态

mysql> show status like 'wsrep%';

9538117.html

9538117.html

9538117.html

14.关闭自动启动

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

mysql.service                                 enabled

mysql@.service                                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.安装所遇问题解决

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 startmysql@bootstrap.service

其他两个节点用systemctl start mysql 不需要加参数。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值