hoctinhoc |
09-04-2015 08:19 AM |
Cài đặt Galera Percona XtraDB Cluster mysql trên CentOS
Cài đặt Galera Percona XtraDB Cluster mysql trên CentOS
http://tuoitreit.vn/tuoitreit/quote/admin_01.gif
http://tuoitreit.vn/tuoitreit/quote/admin_03.gif http://tuoitreit.vn/tuoitreit/quote/admin_05.gif Bài này sẽ hướng dẫn cài đặt Percona XtraDB Cluster trên ba máy chủ CentOS 6.3, sử dụng gói từ kho Percona.
Cluster này sẽ sử dụng 3 máy chủ để tao thành một cụm MYSQL
CODE
Máy # 1 hostname: percona1 IP: 192.168.70.71 Máy # 2 hostname: percona2 IP: 192.168.70.72 Máy # 3 hostname: percona3 IP: 192.168.70.73
Điều kiện cần có :
CODE
-Tất cả ba máy chủ cần cài đặt CentOS 6.3 hoặc 6.4 -Tường lửa đã được thiết lập để cho phép kết nối với cổng 3306, 4444, 4567 và 4568 - SELinux vô hiệu hóa
Cài đặt :
Trên cả 3 máy cần cài Percona repository sau
CODE
rpm -Uhv http://www.percona.com/downloads/per...0-1.x86_64.rpm
Tiếp theo cài gói Percona XtraDB Cluster trên cả 3 máy
CODE
yum install Percona-XtraDB-Cluster-server Percona-XtraDB-Cluster-client
Cấu hình mysql trên máy thứ nhất
Chỉnh sửa file /etc/my.cnf
CODE
[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 wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73 # 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 is a recommended tuning variable for performance innodb_locks_unsafe_for_binlog=1 # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node #1 address wsrep_node_address=192.168.70.71 # SST method wsrep_sst_method=xtrabackup # Cluster name wsrep_cluster_name=my_centos_cluster # Authentication for SST method wsrep_sst_auth="sstuser:s3cret"
Sau đó chạy lệnh
CODE
[root@percona1 ~]# /etc/init.d/mysql start --wsrep-cluster-address="gcomm://"
Kiểm tra tình trạng thấy như thế này là ok
CODE
mysql> show status like 'wsrep%'; +----------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------+--------------------------------------+ | wsrep_local_state_uuid | c2883338-834d-11e2-0800-03c9c68e41ec | ... | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | ... | wsrep_cluster_size | 1 | | wsrep_cluster_status | Primary | | wsrep_connected | ON | ... | wsrep_ready | ON | +----------------------------+--------------------------------------+ 40 rows in set (0.01 sec)
Tiếp theo chạy lệnh sau để tạo mật khẩu cho root
CODE
mysql@percona1> UPDATE mysql.user SET password=PASSWORD("Passw0rd") where user='root'; mysql@percona1> FLUSH PRIVILEGES;
Tạo user mới và set quyền
CODE
mysql@percona1> CREATE USER 'sstuser'@'localhost' IDENTIFIED BY 's3cret'; mysql@percona1> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost'; mysql@percona1> FLUSH PRIVILEGES;
Tiếp tục trên file /etc/my.cnf trên máy thứ 2 (percona2)
CODE
[mysqld] datadir=/var/lib/mysql user=mysql # Path to Galera library wsrep_provider=/usr/lib64/libgalera_smm.so # Cluster connection URL contains IPs of node#1, node#2 and node#3 wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73 # 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 is a recommended tuning variable for performance innodb_locks_unsafe_for_binlog=1 # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node #2 address wsrep_node_address=192.168.70.72 # Cluster name wsrep_cluster_name=my_centos_cluster # SST method wsrep_sst_method=xtrabackup #Authentication for SST method wsrep_sst_auth="sstuser:s3cret"
Khởi động mysql
CODE
/etc/init.d/mysql start
Kiểm tra
CODE
mysql> show status like 'wsrep%'; +----------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------+--------------------------------------+ | wsrep_local_state_uuid | c2883338-834d-11e2-0800-03c9c68e41ec | ... | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | ... | wsrep_cluster_size | 2 | | wsrep_cluster_status | Primary | | wsrep_connected | ON | ... | wsrep_ready | ON | +----------------------------+--------------------------------------+ 40 rows in set (0.01 sec)
Tiếp tục trên file /etc/my.cnf trên máy thứ 3 (percona3)
CODE
[mysqld] datadir=/var/lib/mysql user=mysql # Path to Galera library wsrep_provider=/usr/lib64/libgalera_smm.so # Cluster connection URL contains IPs of node#1, node#2 and node#3 wsrep_cluster_address=gcomm://192.168.70.71,192.168.70.72,192.168.70.73 # 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 is a recommended tuning variable for performance innodb_locks_unsafe_for_binlog=1 # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node #3 address wsrep_node_address=192.168.70.73 # Cluster name wsrep_cluster_name=my_centos_cluster # SST method wsrep_sst_method=xtrabackup #Authentication for SST method wsrep_sst_auth="sstuser:s3cret"
Khởi động lại
CODE
[root@percona3 ~]# /etc/init.d/mysql start
Kiểm tra như thế này là ok
CODE
mysql> show status like 'wsrep%'; +----------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------+--------------------------------------+ | wsrep_local_state_uuid | c2883338-834d-11e2-0800-03c9c68e41ec | ... | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | ... | wsrep_cluster_size | 3 | | wsrep_cluster_status | Primary | | wsrep_connected | ON | ... | wsrep_ready | ON | +----------------------------+--------------------------------------+ 40 rows in set (0.01 sec)
Thử nghiệm :
Trên máy 2 tạo một database là percona
CODE
mysql@percona2> CREATE DATABASE percona; Query OK, 1 row affected (0.01 sec)
Trên máy thứ 3 tạo một bảng example
CODE
mysql@percona3> USE percona; Database changed mysql@percona3> CREATE TABLE example (node_id INT PRIMARY KEY, node_name VARCHAR(30)); Query OK, 0 rows affected (0.05 sec)
Trên máy thứ nhất thử chèn dữ liệu vào bảng
CODE
mysql@percona1> INSERT INTO percona.example VALUES (1, 'percona1'); Query OK, 1 row affected (0.02 sec)
Đọc thử tấc cả các rows từ bảng trên máy thứ 2
CODE
mysql@percona2> SELECT * FROM percona.example; +---------+-----------+ | node_id | node_name | +---------+-----------+ | 1 | percona1 | +---------+-----------+ 1 row in set (0.00 sec)
Ví dụ thử nghiệm cho thấy 3 máy chủ MYSQL sử dụng 1 cụm Percona XtraDB Cluster đã hoàn toàn được đồng bộ với nhau , khi bạn ghi dữ liệu vào 1 trong 3 máy trên thì các máy còn lại sẽ được đồng bộ dữ liệu sang
:battay:
|