Це стара версія документу!
Percona XtraDB Cluster
Встановлення Percona XtraDB Cluster на Debian 11
Підготовка Осі
apt update apt install -y wget gnupg2 curl lsb-release
https://docs.percona.com/percona-xtradb-cluster/8.0/apt.html#install-from-repository
https://www.howtoforge.com/how-to-install-percona-xtradb-cluster-on-debian-11/
https://habr.com/ru/articles/422347/
port | protocol | description |
---|---|---|
3306 | tcp | MySQL client connection and SST (State Snapshot Transfer) |
4444 | tcp | SST via Percona XtraBackup |
4567 | tcp / udp | write-set replication traffic (over TCP) and multicast replication (over TCP and UDP) |
4568 | tcp | IST (Incremental State Transfer) |
Встановлення кластера
Отримуємо репозиторій і встановлюємо його
wget https://repo.percona.com/apt/percona-release_latest.generic_all.deb dpkg -i percona-release_latest.generic_all.deb
Встановлюємо кластер
Для версії percona cluster 8.0
percona-release disable all
percona-release setup pxc80
apt install percona-xtradb-cluster
В процесі встановлення буде запропоновано встановити пароль для користувача root, я на цьому етапі встановлюю пароль також root, після чого його зміню сам.
При необхідності встановлюємо утиліти percona-toolkit
percona-release enable tools release apt update apt install percona-toolkit
Після встановлення зупиняємо mysql
# Після встановлення зупиняємо mysql
service mysql stop
Конфігуруємо кластер
Є два сервери, які потрібно зібрати в кластер
Node | Host | IP |
---|---|---|
Node 1 | db6 | 172.16.0.56 |
Node 2 | db7 | 172.16.0.57 |
Створюємо конфіг першої ноди
nano /etc/mysql/mysql.conf.d/wsrep.cnf
У файл додаємо наступний вміст:
[mysqld] # Path to Galera library wsrep_provider=/usr/lib/galera4/libgalera_smm.so # Cluster name wsrep_cluster_name=pxc-cluster # Cluster connection URL contains IPs of nodes #If no IP is found, this implies that a new cluster needs to be created, #in order to do that you need to bootstrap this node wsrep_cluster_address=gcomm://172.16.0.56,172.16.0.57,172.16.0.58 # Node IP address wsrep_node_address=172.16.0.56 # In order for Galera to work correctly binlog format should be ROW binlog_format=ROW # Applier thread to use wsrep_applier_threads=8 wsrep_log_conflicts #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=pxc-cluster-node-1 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING # SST method wsrep_sst_method=xtrabackup-v2 # IST method #wsrep_provider_options='gcache.size=20G;'
#Конфігуруємо користувача для синка даних між БД mysql -u root -p
Додаємо користувача MySQL
Зупиняємо MySQL
service mysql stop
Bootstrat їм ноду
# У цей момент поточна нода визначає змінну wsrep_cluster_conf_id в 1 systemctl start mysql@bootstrap.service # Підключаємося в mysql і додаємо користувача з паролем mysql -p
CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'verySt0ngPa$$wd'; GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost'; FLUSH PRIVILEGES;
Генерація сертифікатів
# Генерація сертифікатів mkdir /etc/mysql/certs; cd /etc/mysql/certs # Generate CA key and certificate # Generate the CA key file: openssl genrsa 2048 > ca-key.pem # Generate the CA certificate file: openssl req -new -x509 -nodes -days 9999 -key ca-key.pem -out ca.pem # Generate server key and certificate # Generate the server key file: openssl req -newkey rsa:2048 -days 9999 -nodes -keyout server-key.pem -out server-req.pem # Remove the passphrase: openssl rsa -in server-key.pem -out server-key.pem # Generate the server certificate file: openssl x509 -req -in server-req.pem -days 9999 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem # Generate client key and certificate # Generate the client key file: openssl req -newkey rsa:2048 -days 9999 -nodes -keyout client-key.pem -out client-req.pem # Remove the passphrase: openssl rsa -in client-key.pem -out client-key.pem # Generate the client certificate file: openssl x509 -req -in client-req.pem -days 9999 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
root@db4 ~ # /etc/init.d/mysql bootstrap-pxc Bootstrapping Percona XtraDB Cluster database server: mysqld ..
Особливості конфігурації в Debian
Тут є важливе зауваження, на яке слід звернути пильну увагу. Проблема в тому, що в скрипті systemd debian немає опцій для зупинки bootstrap
root@db4:~# service mysql Usage: /etc/init.d/mysql start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc
Сам файл /etc/systemd/system/mysql.bootstrap.service:
[Unit] Description=Percona XtraDB Cluster daemon After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=forking TimeoutSec=0 PermissionsStartOnly=true ExecStart=/etc/init.d/mysql bootstrap-pxc ExecStop=/usr/bin/mysqladmin shutdown ExecReload=/etc/init.d/mysql reload EnvironmentFile=-/etc/default/mysql LimitNOFILE = 5000 Restart=on-failure RestartSec=3 RestartPreventExitStatus=1 PrivateTmp=false
Тому для зупинки bootstrap слід через ps aux визначити id працюючого процесу та вбити його.
Після цього потрібно запустити працювати mysql у звичайному режимі командою service mysql start
Додаємо другу ноду
Необхідно додати користувача на ноду, аналогічно першій ноді. У конфізі виправляємо два параметри - IP та ім'я ноди:
wsrep_node_name=db5 wsrep_node_address=172.16.0.57
Стартуємо сервер MySQL
root@db5 ~ # service mysql stop root@db5 ~ # service mysql start
Перевіряємо роботу, заходимо в MySQL mysql -p
mysql> SHOW STATUS LIKE 'wsrep%'; mysql> SHOW STATUS LIKE 'wsrep_local_state_comment'; +---------------------------+--------+ | Variable_name | VALUE | +---------------------------+--------+ | wsrep_local_state_comment | Synced | +---------------------------+--------+ 1 ROW IN SET (0.00 sec) mysql> SHOW STATUS LIKE 'wsrep_cluster_status'; +----------------------+---------+ | Variable_name | VALUE | +----------------------+---------+ | wsrep_cluster_status | PRIMARY | +----------------------+---------+ 1 ROW IN SET (0.00 sec) mysql> SHOW STATUS LIKE 'wsrep_connected'; +-----------------+-------+ | Variable_name | VALUE | +-----------------+-------+ | wsrep_connected | ON | +-----------------+-------+ 1 ROW IN SET (0.00 sec) mysql> SHOW STATUS LIKE 'wsrep_local_state'; +-------------------+-------+ | Variable_name | VALUE | +-------------------+-------+ | wsrep_local_state | 4 | +-------------------+-------+ 1 ROW IN SET (0.00 sec)
Аналогічно можна додати ще одну або кілька нод percona за потреби.