1. 程式人生 > 實用技巧 >MySQL PXC叢集安裝配置

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新增如下內容
[mysqld]
character_set_server = utf8
bind-address = 0.0.0.0
#跳過DNS解析
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:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:
Sorry, passwords do not match.

New password:

Re-enter new password:
Sorry, passwords do not match.

New password:

Re-enter new password:
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=/var/lib/mysql/mysql.sock

[mysqld]
server-id=4
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-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=/var/lib/mysql/mysql.sock

[mysqld]
server-id=4
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-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=/var/lib/mysql/mysql.sock

[mysqld]
server-id=4
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-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 [email protected]

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