MySQL_Perocna_Xtradb_Cluster_Setup_Guide_1721558780
MySQL_Perocna_Xtradb_Cluster_Setup_Guide_1721558780
We will first show the server list where we will install Percona XtraDB Cluster
below are details for DB server
prod-proxysql 10.10.10.133
setup prerequisites
before we start installing its advisable to turn off the SELINUIX and disable firewall to avoid in issue
during adding nodes to the cluster
disable SELINUIX
for this task you require to have root user or user with sudo privilege
open config file using any favorite note tool for this purpose I will be using vim
vi /etc/selinux/config
the variable SELINUX should be equal to enforcing change it to disabled and save and exit using
:wq!
do the same to all all nodes and proxysql server and reboot server once done to apply the SELINUIX
changes
Disable firewall
To disable the firewall, first, stop the firewall service and then disable it to prevent it from auto-starting.
In Rocky Linux, the firewall daemon is handled by firewalld.service , which is different in Debian-
based systems such as Ubuntu.
sudo vi /etc/my.cnf
wsrep_cluster_name=pxc-cluster: you can keep this name for the cluster or change it, but ensure
this value is the same on all three nodes
[mysqld]
wsrep_provider_options=”socket.ssl_key=server-
key.pem;socket.ssl_cert=server-cert.pem;socket.ssl_ca=ca.pem”
[sst]
encrypt=4
ssl-key=server-key.pem
ssl-ca=ca.pem
ssl-cert=server-cert.pem
Set up node 2 and node 3 in the same way: Stop the server and update the configuration file applicable
to your system. All settings are the same except for wsrep_node_name and wsrep_node_address.
below is image on how my.cnf file confige should look for three node
prod-db01
prod-db02
prod-db03
perocna xtradb cluster uses encryption method between nodes in the cluster
the certificate we need are one mentioned in my.cnf file under [sst] section
we will move the certificate of prod-db01 to db2 and db3 using scp
this step involve starting up the first node mysqld services with Bootstrap
use the following command on first node which is in our case its prod-db01
to add the node to the cluster simple steps of starting MySQL service normally on prod-db02 & prod-
db03
systemctl start mysqld
login to mysql and issue the below query it should say cluster size is 2
Once completed, the system should indicate that the cluster size is 3, meaning all three nodes are now
connected to the cluster.
You can test replication by creating a database and checking if it replicates across all three nodes.
Since the Percona XtraDB Cluster is set up to be active-active, it is best to set up load balancing to
distribute the load across the three nodes. This can be achieved by setting up a separate server for load
balancing, which will also handle the connections between the application and the database.
To achieve this, we will install ProxySQL and configure it for load balancing.
installing ProxySQL
Next, we need to install the Percona-XtraDB-Cluster-client. I will download the RPM package directly
from Percona using wget . Please visit the Percona website and obtain the correct package for your
OS.
wget https://downloads.percona.com/downloads/Percona-XtraDB-Cluster-
80/Percona-XtraDB-Cluster-8.0.36/binary/redhat/8/x86_64/percona-xtradb-
cluster-client-8.0.36-28.1.el8.x86_64.rpm?
_gl=1*b5c6np*_gcl_au*MTMxMzQzNzU4OC4xNzE3NDMzOTYx
Configure ProxySQL
we will add three node ip address to database using the below format
INSERT INTO mysql_servers (hostname, port, hostgroup_id) VALUES
('node1_host', 3306, 10);
INSERT INTO mysql_servers (hostname, port, hostgroup_id) VALUES
('node2_host', 3306, 10);
INSERT INTO mysql_servers (hostname, port, hostgroup_id) VALUES
('node3_host', 3306, 10);
We will create a user called monitor on one of the nodes in the cluster. You don't need to create the
user on each node individually; just create it on one node, and it should replicate to the other nodes in
the cluster.
fLUSH PRIVILEGES
Set the monitoring user in ProxySQL: by adding the user information inside Proxysql database
Load the user into runtime space and save these changes to disk :
We will create a user inside the cluster node that will be allowed to access the cluster through
ProxySQL. This user will have full privileges and will be allowed to connect from anywhere.
To test the connection, use the following connection string for the appuser we created. Keep in mind
that ProxySQL uses port 6032 instead of the MySQL default port, so make sure to configure this
correctly in your application setup
For your setup, since you are connecting directly from the ProxySQL server, you will use the localhost or
APIPA (Automatic Private IP Addressing) IP