您好,登录后才能下订单哦!
PXC的安装非常简单!!!!!!
--软件下载
https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/LATEST/
--基础环境准备
[root@node2 ~]# vim /etc/hosts ---在3个节点hosts文件加入如下信息
192.168.2.100 node1
192.168.2.200 node2
192.168.2.210 node3
[root@localhost ~]# rpm -e --nodeps mariadb mariadb-server mariadb-libs marisa --卸载
1、3个节点安装依赖包
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 perl-time-hires perl-io-socket-ssl.noarch perl-dbd-mysql.x86_64
--解压软件包,并安装:
下载软件包要注意:切记选择ssl101版本,官方使用手册上有如下说明
[root@localhost ~]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm [root@localhost ~]# rpm -ivh percona-xtrabackup-24-2.4.11-1.el7.x86_64.rpm [root@node1 ~]# tar zxvf Percona-XtraDB-Cluster-5.7.21-rel20-29.26.1.Linux.x86_64.ssl101.tar.gz -C /usr/local/^C [root@node1 ~]# cd /usr/local/ [root@node1 local]# ln -s Percona-XtraDB-Cluster-5.7.21-rel20-29.26.1.Linux.x86_64.ssl101.tar.gz pxc_mysql
2、创建用户,新建文件夹请授权【三个节点都要操作】 :
[root@localhost ~]# userdel mysql [root@localhost ~]# useradd -g mysql mysql [root@localhost ~]# passwd mysql [root@localhost ~]# mkdir -p /usr/local/pxc_mysql/{data,logs,tmp} [root@localhost ~]# mkdir -p /usr/local/pxc_mysql/logs/binlog [root@localhost ~]# chown -R mysql:mysql /usr/local/pxc_mysql/ [root@localhost ~]# chmod -R +x /usr/local/pxc_mysql/
3、切换mysql用户创建my.cnf (该配置文件只简单的几个参数,如果生产环境需要更多的数据库参数)
[root@node1 ~]# su - mysql [mysql@node1 ~]$ cd /usr/local/pxc_mysql/ [mysql@node1 pxc_mysql]$ vi my.cnf [client] socket=/usr/local/pxc_mysql/data [mysqld] server-id=142 port = 3306 basedir=/usr/local/pxc_mysql datadir=/usr/local/pxc_mysql/data socket=/usr/local/pxc_mysql/data/mysql.sock log-error=/usr/local/pxc_mysql/data/mysqld.log pid-file=/usr/local/pxc_mysql/data/mysqld.pid log-bin=/usr/local/pxc_mysql/logs slow_query_log_file = /usr/local/pxc_mysql/data/slow.log log_slave_updates expire_logs_days=7 binlog_format=ROW innodb_buffer_pool_size = 1524M #pxc wsrep_provider=/usr/local/pxc_mysql/lib/libgalera_smm.so wsrep_cluster_name=pxc-nie wsrep_cluster_address=gcomm://192.168.2.100,192.168.2.200,192.168.2.210 wsrep_node_name=node1 wsrep_node_address=192.168.2.100 wsrep_sst_method=xtrabackup-v2 wsrep_sst_auth=pxc:123456 pxc_strict_mode=ENFORCING binlog_format=ROW default_storage_engine=InnoDB innodb_autoinc_lock_mode=2
注意:
其他两个个节点,只需要修改:
server-id=142 --id不能一样
wsrep_node_name=node1 --改成自己节点的主机名
wsrep_node_address=192.168.2.100 --改成自己节点的主机IP
4、初始化3个节点的数据库
/usr/local/pxc_mysql/bin/mysqld --defaults-file=/usr/local/pxc_mysql/my.cnf --datadir=/usr/local/pxc_mysql/data --basedir=/usr/local/pxc_mysql --initialize
(在/usr/local/pxc_mysql/data/mysqld.log这个日志里有root的密码)
5、首先启动第一个节点:
[root@node1 pxc_mysql]# /usr/local/pxc_mysql/bin/mysqld_safe --defaults-file=/usr/local/pxc_mysql/my.cnf --wsrep-new-cluster --user=mysql & ---用root起
然后进入MySQL,执行如下操作(如果进不去,报错密码过期,那么在my.cnf文件加入:skip-grant-tables,然后无密码进入数据库: update mysql.user set password_expired="N" where user="root"; 最后把参数从配置文件去掉,重启数据库,用刚才的root密码进入即可。)
MySQL [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) MySQL [(none)]> show status like 'wsrep_local_state%'; +---------------------------+--------------------------------------+ | Variable_name | Value | +---------------------------+--------------------------------------+ | wsrep_local_state_uuid | c2ab52e7-67cf-11e8-9d02-e76acee85210 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | +---------------------------+--------------------------------------+ 3 rows in set (0.00 sec) MySQL [(none)]> show status like 'wsrep_cluster_%'; +--------------------------+--------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------+ | wsrep_cluster_conf_id | 1 | | wsrep_cluster_size | 1 | | wsrep_cluster_state_uuid | c2ab52e7-67cf-11e8-9d02-e76acee85210 | | wsrep_cluster_status | Primary | +--------------------------+--------------------------------------+ 4 rows in set (0.00 sec) MySQL [(none)]> GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'pxc'@'%' IDENTIFIED BY '123456'; ---创建一个SST用户 MySQL [(none)]> flush privileges;
(从上面的信息集群大小为1个节点,状态为primary,节点处于Synced状态,它已完全连接,可以进行write-set replication。 )
6、依次启动第二、第三个节点:
[root@node2 pxc_mysql]# /usr/local/pxc_mysql/bin/mysqld_safe --defaults-file=/usr/local/pxc_mysql/my.cnf --user=mysql &
7、验证集群部署成功:
在各个节点查看:
MySQL [(none)]> show status like 'wsrep_cluster_%'; +--------------------------+--------------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------------+ | wsrep_cluster_conf_id | 5 | | wsrep_cluster_size | 3 | ---现在是3个节点都加入了集群 | wsrep_cluster_state_uuid | c2ab52e7-67cf-11e8-9d02-e76acee85210 | | wsrep_cluster_status | Primary | +--------------------------+--------------------------------------+
在其中一个节点创建表或数据库 看看是否3个节点都同步完成。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。