Percona Cluster Kurulumu / Ubuntu 20.04

Onur BOLATOĞLU
5 min readApr 16, 2023

--

sudo apt-get update -y  && sudo apt-get upgrade -y && apt-get dist-upgrade -y && sudo apt-get install wget -y && wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb && sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb && sudo percona-release setup pxc57 && sudo apt-get update -y && sudo apt install percona-xtradb-cluster-full-57 -y

Yukarıdaki komut seti ile pxc için gerekli hazırlıkları yapıp, pxc servisini sunucumuza kuruyoruz ( Bu hazırlık ve kurulum işlemi her node da yapılmalı!) . Özetle komutlar şu işe yarar;

  • sudo apt-get update -y: Paket deposunu günceller.
  • sudo apt-get upgrade -y: Mevcut paketleri günceller.
  • apt-get dist-upgrade -y: Sistemi, mevcut sürümleri ile uyumlu hale getirir.
  • sudo apt-get install wget -y: wget aracını yükler.
  • wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb: Percona paket deposunun son sürümünü indirir.
  • sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb: İndirilen paketi kurar.
  • sudo percona-release setup pxc57: Percona XtraDB Cluster 5.7'yi yüklemek için gerekli yapılandırmayı yapar.
  • sudo apt-get update -y: Paket deposunu yeniden günceller.
  • sudo apt install percona-xtradb-cluster-full-57 -y: Percona XtraDB Cluster 5.7'nin tam sürümünü yükler.

Bu komut seti, bir PXC kümesinin oluşturulması için gereken tüm bileşenleri yükler ve yapılandırır.

Yukarıdaki komut seti ile pxc kurulumu yapıldığında, mysql servisi çalışır vaziyette olacaktır. Ayrıca start etmemize gerek yoktur.

  • Tüm nodeların “hosts” dosyasını aşağıdaki şekilde düzenliyoruz.
10.145.0.171 p1
10.145.0.172 p2
10.145.0.173 p3
10.145.0.174 p4
  • Ardından, node 1 ‘de /etc/mysql/my.cnf dosyasına girip aşağıdaki yapılandırma parametrelerini ekliyoruz.
[mysqld]

# Path to Galera library
wsrep_provider=/usr/lib/galera3/libgalera_smm.so

# 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://10.145.0.171,10.145.0.172,10.145.0.173,10.145.0.174

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=10.145.0.171

# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=p1

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=DISABLED

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:sstpassword123"
  • Ardından node 1 ‘de (10.145.0.171), Percona XtraDB Cluster’ın ilk önyükleme aşamasını gerçekleştirmek için . bootstrap-pxc komutunu kullanıyoruz.
/etc/init.d/mysql bootstrap-pxc
  • mysql shell’e bağlanıp, aşağıdaki sorgu ile clusterın durumunu görüntüleyebiliriz.
show status like 'wsrep%';
  • Percona XtraDB Cluster’da State Snapshot Transfer (SST) işlemi sırasında kullanılan bir kullanıcı oluşturmak ve bu kullanıcıya gerekli izinleri vermemiz gerekiyor ( Bu işlem her node’da yapılmalı!)
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpassword123';
mysql> GRANT PROCESS, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;

İlk komut (CREATE USER) sstuser adında bir kullanıcı oluşturur. Bu kullanıcı, yalnızca yerel makineden (‘localhost’) erişebilir ve ‘sstpassword123’ şifresi ile kimlik doğrulaması yapar.

İkinci komut (GRANT) kullanıcının sahip olması gereken izinleri belirtir. Bu izinler, SST işlemi sırasında Percona XtraDB Cluster tarafından kullanılır ve veritabanına yönelik işlemlerin tamamını kapsar. PROCESS, RELOAD, PROCESS, LOCK TABLES ve REPLICATION CLIENT izinleri, sstuser kullanıcısının SST işlemini gerçekleştirmek için gerekli tüm ayrıcalıklara sahip olmasını sağlar.

Üçüncü komut (FLUSH PRIVILEGES) veritabanı yetkililerinin güncellenmiş ayrıcalık ayarlarını yüklemesini sağlar ve bu sayede yeni kullanıcı ve izinleri yürürlüğe girer.

Node 1 ‘de işlemler tamamlandı, diğer nodelara bağlanıp, my.cnf dosyasını değiştiriyoruz.

Node 2:

  • Mysql shelle bağlanıp sst kullanıcısını oluşturuyoruz.
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpassword123';
mysql> GRANT PROCESS, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;
  • Ardından mysql servisimizi stop ediyoruz.
/etc/init.d/mysql stop
  • my.cnf dosyamızı düzenliyoruz.
[mysqld]

# Path to Galera library
wsrep_provider=/usr/lib/galera3/libgalera_smm.so

# 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://10.145.0.171,10.145.0.172,10.145.0.173,10.145.0.174

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=10.145.0.172

# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=p2

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=DISABLED

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:sstpassword123"

Servisi start ediyoruz.

/etc/init.d/mysql start

Node 3:

  • Mysql shelle bağlanıp sst kullanıcısını oluşturuyoruz.
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpassword123';
mysql> GRANT PROCESS, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;
  • Ardından mysql servisimizi stop ediyoruz.
/etc/init.d/mysql stop
  • my.cnf dosyamızı düzenliyoruz.
[mysqld]

# Path to Galera library
wsrep_provider=/usr/lib/galera3/libgalera_smm.so

# 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://10.145.0.171,10.145.0.172,10.145.0.173,10.145.0.174

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=10.145.0.173

# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=p3

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=DISABLED

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:sstpassword123"

Servisi start ediyoruz.

/etc/init.d/mysql start

Node 4:

  • Mysql shelle bağlanıp sst kullanıcısını oluşturuyoruz.
mysql> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 'sstpassword123';
mysql> GRANT PROCESS, RELOAD, PROCESS, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost';
mysql> FLUSH PRIVILEGES;
  • Ardından mysql servisimizi stop ediyoruz.
/etc/init.d/mysql stop
  • my.cnf dosyamızı düzenliyoruz.
[mysqld]

# Path to Galera library
wsrep_provider=/usr/lib/galera3/libgalera_smm.so

# 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://10.145.0.171,10.145.0.172,10.145.0.173,10.145.0.174

# In order for Galera to work correctly binlog format should be ROW
binlog_format=ROW

# MyISAM storage engine has only experimental support
default_storage_engine=InnoDB

# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode=2

# Node IP address
wsrep_node_address=10.145.0.174

# Cluster name
wsrep_cluster_name=pxc-cluster

#If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=p4

#pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=DISABLED

# SST method
wsrep_sst_method=xtrabackup-v2

#Authentication for SST method
wsrep_sst_auth="sstuser:sstpassword123"

Servisi start ediyoruz.

/etc/init.d/mysql start

İşlem bu kadar. Cluster kuruldu. Herhangi bir node da mysql shell de aşağıdaki komutu çalıştırıp, clusterın durumunu sorgulayabilirsiniz.

show status like 'wsrep%';

--

--