2014年6月15日星期日

安裝Percona的XtraDB集群

Original post: http://anothermysqldba.blogspot.com/2014/06/installing-percona-xtradb-cluster.html

所以當然Percona的都有解釋的過程文檔。 這個博客的目的是進入了更多的細節,希望能幫助別人。 

超鏈接的點評: 
先決條件 
  • 防火牆已經被設置為允許連接到端口3306,4444,4567和4568
  • 停止iptables的內部局域網絡或調整iptable的規則。
/etc/init.d/iptables stop 

  • 的SELinux被禁用
echo 0 >/selinux/enforce 
vi /etc/selinux/config 

  • 設置SSH密鑰,並放入authorized_keys文件,這樣所有的id_rsa.pub文件值在所有服務器上的authorized_keys。
# ssh-keygen -t rsa 
# cd /root/.ssh/ 
# cp id_rsa.pub authorized_keys 
# chmod 600 /root/.ssh/authorized_keys 
# chmod 700 /root/.ssh/ 


於是我開始了一個基本的服務器安裝CentOS 6.5。 
# yum -y install http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm 
# yum -y install http://mirror.pnl.gov/epel/6/x86_64/epel-release-6-8.noarch.rpm 
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# wget http://www.percona.com/downloads/RPM-GPG-KEY-percona /etc/pki/rpm-gpg/RPM-GPG-KEY-percona 
# yum -y install socat 


為了避免我刪除了mysql-庫和相關的依賴任何衝突 
# rpm -e mysql-libs postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat


然後我安裝了Percona的集群包。 
# yum -y install Percona-XtraDB-Cluster-full-56 
[root@node1 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 
mysql -e "CREATE FUNCTION fnv1a_64 RETURNS INTEGER SONAME 'libfnv1a_udf.so'" 
mysql -e "CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'libfnv_udf.so'" 
mysql -e "CREATE FUNCTION murmur_hash RETURNS INTEGER SONAME 'libmurmur_udf.so'" 


所以我們可以更換,我們每個節點中刪除的項目.. 
yum -y install postfix cronie redhat-lsb-core redhat-lsb-printing redhat-lsb-graphics libcgroup numad redhat-lsb sysstat crontabs cronie-anacron redhat-lsb-compat 


因此,重複上面的步驟將安裝包,以便我們可以配置下一個集群。 

[root@node2 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)......... SUCCESS! 
[root@node3 ~]# /etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........ SUCCESS! 

雖然我們的MySQL運行著三個實例這還不是一個集群。 

配置節點

節點1的/ etc / my.cnf中 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

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

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# 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 auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.33 

# SST method 
#wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 

# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:<password_here>" 

# server_id 
server_id=3232235553 #SELECT INET_ATON('192.168.0.33') 

#[client] 
socket=/var/lib/mysql/mysql.sock 


啟動第一個群集節點 
/etc/init.d/mysql start --wsrep-cluster-address="gcomm://" 
Starting MySQL (Percona XtraDB Cluster)...................................... SUCCESS! 

[root@node1 mysql]# cat grastate.dat 
# GALERA saved state 
version: 2.1 
uuid: 97c457f8-f3d2-11e3-9b4e-374ebb7427e6 
seqno: -1 
cert_index: 


集群是目前唯一的一個節點。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 1 


現在好了現在一個是啟動並運行,我們就可以開始節點2 
節點2的/ etc / my.cnf中 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

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

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# 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 auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.34 

# SST method 
#wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 


# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:" 

# to enable debug level logging, set this to 1 
wsrep_debug=1 

# server_id 
server_id=3232235554 # SELECT INET_ATON('192.168.0.34') 

#[client] 
socket=/var/lib/mysql/mysql.sock 

[root@node2 mysql]#/etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS! 


現在,在每個節點上比較我們的價值觀。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 2 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node2.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 2 
1 row in set (0.18 sec) 


現在我們添加節點3到組合。 

節點3的/ etc / my.cnf中 
[mysqld] 

datadir=/var/lib/mysql 
user=mysql 

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

# Cluster connection URL contains the IPs of node#1, node#2 and node#3 
# node 1 192.168.0.33 
# nod3 2 192.168.0.34 
# nod3 3 192.168.0.35 
wsrep_cluster_address=gcomm://192.168.0.33,192.168.0.34,192.168.0.35 

# 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 auto increment locks are managed and is a requirement for Galera 
innodb_autoinc_lock_mode=2 

# Node #1 address 
wsrep_node_address=192.168.0.35 

# SST method 
# wsrep_sst_method=xtrabackup 
wsrep_sst_method=rsync # 
# wsrep_sst_method=rsync_wan # 
# wsrep_sst_method=mysqldump # SLOW 


# Cluster name 
wsrep_cluster_name=percona_cluster 

# Authentication for SST method 
wsrep_sst_auth="root:" 

# to enable debug level logging, set this to 1 
wsrep_debug=1 

# server_id 
server_id=3232235555 # SELECT INET_ATON('192.168.0.35') 

#[client] 
socket=/var/lib/mysql/mysql.sock 

[root@node3 mysql]#/etc/init.d/mysql start 
Starting MySQL (Percona XtraDB Cluster)........................... SUCCESS! 

[root@node3 mysql]# cat grastate.dat 
# GALERA saved state 
version: 2.1 
uuid: 97c457f8-f3d2-11e3-9b4e-374ebb7427e6 
seqno: -1 
cert_index: 


那麼,如何我們的所有節點的樣子了。 
mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node1.localdomain 
1 row in set (0.01 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node2.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

mysql> select @@hostname\G show global status like 'wsrep_cluster_size' \G 
*************************** 1. row *************************** 
@@hostname: node3.localdomain 
1 row in set (0.00 sec) 

*************************** 1. row *************************** 
Variable_name: wsrep_cluster_size 
Value: 3 

測試節點 
所以,現在我們可以加載一些數據,並對其進行測試.. 
[root@node2 ~]# wget http://downloads.mysql.com/docs/world_innodb.sql.gz 
[root@node2 ~]# gzip -d world_innodb.sql.gz 
[root@node2 ~]# mysql -e "create database world" 
[root@node2 ~]# mysql world < world_innodb.sql 


所以,現在一切都被加載...它是所有在集群? 
@@hostname: node1.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

@@hostname: node2.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

@@hostname: node3.localdomain 
DATABASE_SCHEMA: world 
ENGINE: InnoDB 
count_tables: 3 
TOTAL_DB_GB: 0.001 

看起來這是工作。