1. 程式人生 > >如何在CentOS 7上安裝Percona XtraDB叢集

如何在CentOS 7上安裝Percona XtraDB叢集

原作者:Muhammad Arul  轉載&翻譯來源:https://www.howtoforge.com/tutorial/how-to-install-percona-xtradb-cluster-on-centos-7/

 

如何在CentOS 7上安裝Percona XtraDB叢集

 

在本教程中,我將向您展示如何在CentOS 7伺服器上安裝和配置Percona XtraDB Cluster。我們將使用與MySQL和Percona Server完全相容的Percona XtraDB Cluster 5.6。

Percona是一家由MySQL和MongoDB資料庫專家組成的公司,成立於2006年.Percona為MySQL和MongoDB構建和維護開源軟體:Percona伺服器(用於MySQL的資料庫伺服器,具有高可用性效能增強),Percona XtraDB叢集(用於MySQL的高可用性解決方案)叢集),用於MongoDB的Percona Server和用於管理資料庫的其他工具,如Percona工具包,Percona監控工具和Percona XtraBackup。

 

先決條件

  • 3個CentOS 7伺服器節點。
  • Root許可權。
  • 基本的CentOS 7知識。

 

第1步 - 設定hosts檔案

首先要做的是配置所有伺服器的主機名。我有3臺CentOS 7伺服器,如下所示:

Node           Server IP       Hostname
 
Node1   -   192.168.43.36     percona1
Node2   -   192.168.43.166    percona2
Node3   -   192.168.43.148    percona3

使用終端連線到所有伺服器:

# 測試則三臺伺服器節點是否可以ssh連線成功
ssh -p 22 [email protected] 

如果您已登入所有伺服器,請 使用vim 編輯每個伺服器上的“/ etc / hosts”檔案:

vim /etc/hosts

貼上下面的主機配置:

# 在三臺伺服器上,配置您的hosts檔案,這樣可以通過hostname來連線目標主機
192.168.43.36   percona1
192.168.43.166  percona2
192.168.43.148  percona3

將IP地址替換為與本地網路配置匹配的IP地址。儲存並退出。

 

第2步 - 配置Firewalld

Firewalld是CentOS 7上新的預設防火牆介面 firewall-cmd命令用於配置防火牆。我們可以定義和配置特定的組或區域,或者我們可以為ssh,MySQL資料庫,nginx / apache web伺服器等服務配置防火牆。

在此步驟中,我們將使用firewalld進行防火牆配置。我們將使用'firewall-cmd'命令開啟percona伺服器埠以及群集所需的其他埠。

使用此systemctl命令啟動firewalld:

systemctl start firewalld

然後執行以下命令開啟MySQL / percona伺服器使用的埠:

firewall-cmd --zone=public --add-service=mysql --permanent

接下來,使用以下命令為叢集新增其他埠:

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=4567/tcp --permanent
firewall-cmd --zone=public --add-port=4568/tcp --permanent
firewall-cmd --zone=public --add-port=4444/tcp --permanent
firewall-cmd --zone=public --add-port=4567/udp --permanent

重新載入防火牆規則:

firewall-cmd --reload

要檢視所有防火牆規則的列表,請使用選項'--list-all'


firewall-cm --list-all

 

第3步 - 安裝Epel儲存庫和Socat

要在伺服器上執行Percona XtraDB叢集,我們需要安裝socat,它可以在epel-repository中使用。所以我們需要先安裝Epel儲存庫,然後再安裝socat。此外,我們必須從伺服器中刪除mariadb-libs,因為它們與Percona XtraDB叢集衝突。

安裝epel-repository和socat:

yum -y install epel-release
yum -y install socat

刪除mariadb-libs以避免mariadb-libs和Percona XtraDB Cluster之間的包衝突:

yum -y remove mariadb-libs

安裝了Epel儲存庫和socat。

 

第4步 - 安裝Percona XtraDB叢集

在此步驟中,我們將安裝具有所有程式包依賴性的Percona xtradb群集。我們需要為安裝新增Percona儲存庫,然後啟動Percona伺服器並配置資料庫伺服器的root使用者和密碼。

使用yum安裝Percona儲存庫:

yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm

現在安裝Percona XtraDB叢集以及本教程所需的其他軟體包:

yum install Percona-XtraDB-Cluster-server-56 Percona-XtraDB-Cluster-client-56 Percona-XtraDB-Cluster-shared-56 percona-toolkit percona-xtrabackup Percona-XtraDB-Cluster-galera-3 rsync nc

安裝Percona XtraDB Cluster,使用zhis systemctl命令啟動Percona伺服器:

systemctl start mysql

接下來,為所有percona / mysql伺服器配置root密碼:

mysql_secure_installation

設定percona / mysql密碼:

Enter current password for root (enter for none): PRESS ENTER
Set root password? [Y/n] Y
New password: TYPE YOUR PASSWORD
Re-enter new password: REPEAT PASSWORD
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Reload privilege tables now? [Y/n] Y

注意:

在所有3臺CentOS伺服器上執行步驟1 - 4。

 

步驟5 - 配置Percona XtraDB群集

在第4步中,我們已經安裝了Percona XtraDB Cluster併為所有Percona / Mysql伺服器節點配置了root密碼。在此步驟中,我們將為SST身份驗證建立一個新使用者,並在每個伺服器上編輯MySQL配置my.cnf。

SST(狀態快照傳輸)是從作為捐贈者的一個伺服器到作為加入者的另一個伺服器的完整資料副本。對於SST身份驗證,我們需要建立一個名為'sstuser'的新使用者,密碼為' sstuser @ '。對於SST方法,我們將使用xtrabackup-v2而不是rsync。請為您的群集使用不同且安全的密碼!

登入每臺伺服器上的percona / mysql shell:

mysql -u root -p
TYPE YOUR PASSWORD

並使用密碼sstuser @ '建立新的'sstuser '

create user [email protected]'%' identified by '[email protected]';
grant all on *.* to [email protected]'%';
flush privileges;

然後在編輯配置檔案之前停止每臺伺服器上的MySQL服務:

systemctl stop mysql

接下來,使用vim編輯器在每臺伺服器上編輯mysql配置檔案my.cnf。

Percona1伺服器上:

vim /etc/my.cnf

使用以下配置更改所有'wsrep'行:


wsrep_cluster_address          = gcomm://
wsrep_provider                 = /usr/lib64/galera3/libgalera_smm.so
 
wsrep_slave_threads            = 8
wsrep_cluster_name             = Cluster Percona XtraDB
wsrep_node_name                = percona1
 
wsrep_node_address             = percona1
wsrep_sst_method               = xtrabackup-v2
wsrep_sst_auth                 = sstuser:[email protected]

儲存並退出。

Percona2伺服器上:

vim /etc/my.cnf

使用以下配置更改所有'wsrep'行:

wsrep_cluster_address          = gcomm://percona1,percona3
wsrep_provider                 = /usr/lib64/galera3/libgalera_smm.so
 
wsrep_slave_threads            = 8
wsrep_cluster_name             = Cluster Percona XtraDB
wsrep_node_name                = percona2
 
wsrep_node_address             = percona2
wsrep_sst_method               = xtrabackup-v2
wsrep_sst_auth                 = sstuser:[email protected]

儲存並退出。

Percona3伺服器上:

vim /etc/my.cnf

使用以下配置更改所有'wsrep'行:

wsrep_cluster_address          = gcomm://percona1,percona2
wsrep_provider                 = /usr/lib64/galera3/libgalera_smm.so
 
wsrep_slave_threads            = 8
wsrep_cluster_name             = Cluster Percona XtraDB
wsrep_node_name                = percona3
 
wsrep_node_address             = percona3
wsrep_sst_method               = xtrabackup-v2
wsrep_sst_auth                 = sstuser:[email protected]

儲存並退出。

percona2伺服器的螢幕截圖。

 

步驟6 - 啟動Percona XtraDB Cluster Server

我們在所有伺服器上配置了Percona XtraDB叢集,現在我們可以啟動伺服器了。

在Percona1伺服器上,啟動或啟動並執行叢集:

systemctl start [email protected]

接下來,使用以下命令在percona2和percona3伺服器上啟動Percona / MySQL伺服器:

systemctl start mysql

確保沒有錯誤訊息。如果在鍵入以啟動MySQL後出現錯誤,請檢查日誌檔案  '/ var / log / messages'

 

第7步 - 測試

我們必須登入每臺伺服器上的percona / mysql shell來測試Percona XtraDB叢集。

登入所有伺服器/節點上的Percona / MySQL shell:

mysql -u root -p
TYPE YOUR PASSWORD

使用mysql命令測試高可用性:

SHOW STATUS LIKE 'wsrep_local_state_comment';

在每個節點上嘗試該命令,如果您看到“同步”   作為結果,則該節點已準備好處理流量。

測試叢集的可用節點:

show global status like 'wsrep_cluster_size';

您將獲得Percona群集中的當前節點數。

要獲得完整結果,您可以使用以下命令:

 show global status like 'wsrep%';

 

參考