mysql卸载安装pxc_MySQL PXC集群安装配置

本文档详细介绍了如何在三台服务器上卸载Mariasdb并安装配置MySQL PXC集群,包括关闭防火墙和Selinux,卸载旧数据库,安装依赖包,修改配置文件,初始化数据库,创建管理用户,启动集群,以及检查集群状态等步骤。
摘要由CSDN通过智能技术生成

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集群搭建完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值