MySQL PXC集群安装配置

1、关闭防火墙
[root@node04 ~]#systemctl disable firewalld
[root@node04 ~]#systemctl stop firewalld
[root@node05 ~]#systemctl disable firewalld
[root@node05 ~]#systemctl stop firewalld
[root@node06 ~]#systemctl disable firewalld
[root@node06 ~]#systemctl stop firewalld

2、关闭selinux
[root@node04 ~]# vi /etc/selinux/config
SELINUX=disabled
[root@node05 ~]# vi /etc/selinux/config
SELINUX=disabled
[root@node06 ~]# vi /etc/selinux/config
SELINUX=disabled

3、重启服务器
[root@node04 ~]# reboot
[root@node05 ~]# reboot
[root@node06 ~]# reboot

4、卸载mariadb
[root@node04 ~]# rpm -qa | grep mariadb | xargs yum remove -y {}
[root@node05 ~]# rpm -qa | grep mariadb | xargs yum remove -y {}
[root@node06 ~]# rpm -qa | grep mariadb | xargs yum remove -y {}

5、所有节点上传PXC集群依赖包,并安装PXC集群
安装PXC集群
[root@node04 ~]# yum localinstall -y *.rpm
[root@node05 ~]# yum localinstall -y *.rpm
[root@node06 ~]# yum localinstall -y *.rpm

6、修改参数文件
删除三个节点的MySQL参数文件/etc/my.cnf,添加如下内容
[client]
socket=/tmp/mysql.sock

[mysqld]
server-id=4
datadir=/data/mysql/data
socket=/tmp/mysql.sock
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/data/mysqld.pid
log-bin=/data/mysql/log/mysql-bin
log_slave_updates
expire_logs_days=7
character_set_server=utf8
bind-address=0.0.0.0
skip-name-resolve

6、取消MySQL数据库自动启动
[root@node04 ~]# chkconfig mysqld off
[root@node05 ~]# chkconfig mysqld off
[root@node06 ~]# chkconfig mysqld off

7、启动各个节点数据库
[root@node04 ~]# systemctl start mysql
[root@node05 ~]# systemctl start mysql
[root@node06 ~]# systemctl start mysql

8、初始化MySQL数据库
所有查看临时密码:
cat /var/log/mysqld.log | grep "A temporary password"

所有节点按如下方法修改MySQL密码
[root@node04 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: n
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

9、所有节点添加管理用户admin,并设置权限
mysql> create user 'admin'@'%' identified by 'mysql@A123';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'admin'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

10、所有节点关闭数据库,修改MySQL参数文件
节点一:
[client]
socket=/tmp/mysql.sock

[mysqld]
server-id=4
datadir=/data/mysql/data
socket=/tmp/mysql.sock
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/data/mysqld.pid
log-bin=/data/mysql/log/mysql-bin
log_slave_updates
expire_logs_days=7
character_set_server=utf8
bind-address=0.0.0.0
skip-name-resolve

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name=pxc-cluster2
wsrep_cluster_address=gcomm://192.168.12.14,192.168.12.15,192.168.12.16
wsrep_node_name=pxc-node04
wsrep_node_address=192.168.12.14
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth= admin:mysql@A123
pxc_strict_mode=ENFORCING
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

节点二:
[client]
socket=/tmp/mysql.sock

[mysqld]
server-id=4
datadir=/data/mysql/data
socket=/tmp/mysql.sock
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/data/mysqld.pid
log-bin=/data/mysql/log/mysql-bin
log_slave_updates
expire_logs_days=7
character_set_server=utf8
bind-address=0.0.0.0
skip-name-resolve

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name=pxc-cluster2
wsrep_cluster_address=gcomm://192.168.12.14,192.168.12.15,192.168.12.16
wsrep_node_name=pxc-node05
wsrep_node_address=192.168.12.15
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth= admin:mysql@A123
pxc_strict_mode=ENFORCING
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

节点三:
[client]
socket=/tmp/mysql.sock

[mysqld]
server-id=4
datadir=/data/mysql/data
socket=/tmp/mysql.sock
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/data/mysqld.pid
log-bin=/data/mysql/log/mysql-bin
log_slave_updates
expire_logs_days=7
character_set_server=utf8
bind-address=0.0.0.0
skip-name-resolve

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name=pxc-cluster2
wsrep_cluster_address=gcomm://192.168.12.14,192.168.12.15,192.168.12.16
wsrep_node_name=pxc-node06
wsrep_node_address=192.168.12.16
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth= admin:mysql@A123
pxc_strict_mode=ENFORCING
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

11、启动主节点
[root@node04 ~]# systemctl start mysql@bootstrap.service

12、其他节点加入集群
[root@node05 ~]# systemctl start mysql
[root@node06 ~]# systemctl start mysql

13、查看集群状态信息
mysql> show status like 'wsrep_cluster%';
+--------------------------+--------------------------------------+
| Variable_name            | Value                                |
+--------------------------+--------------------------------------+
| wsrep_cluster_weight     | 3                                    |
| wsrep_cluster_conf_id    | 3                                    |
| wsrep_cluster_size       | 3                                    |
| wsrep_cluster_state_uuid | 2d2b5f7c-d4e5-11ea-b628-123f3f8ed2aa |
| wsrep_cluster_status     | Primary                              |
+--------------------------+--------------------------------------+
5 rows in set (0.01 sec)

自此,MySQL PXC集群搭建完成!
  
  

  

posted @ 2020-08-02 18:42  orcl  阅读(471)  评论(0编辑  收藏  举报