进入下载页面http://galeracluster.com/downloads/
Galera3必下载,其他根据所安装的MySQL版本与系统类型进行下载。
这里我直接提供一个CentOS 7、MySQL 5.7版本的下载:http://releases.galeracluster.com//mysql-wsrep-5.7/centos/7/x86_64/
除了红色框住的那两个非必要下载,其他6个一定要下载。
下载成功后上传到服务器目录。
这里准备三台主机:
10.211.55.17 node1
10.211.55.25 node2
10.211.55.26 node3
先安装依赖包socat、boost、rsync、lsof:
# yum install socat boost rsync lsof
依次执行命令安装:
# rpm -ivh mysql-wsrep-common-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh mysql-wsrep-libs-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh mysql-wsrep-libs-compat-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh mysql-wsrep-client-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh mysql-wsrep-server-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh mysql-wsrep-5.7-5.7.24-25.16.el7.x86_64.rpm
# rpm -ivh galera-3-25.3.25-2.el7.x86_64.rpm
然后第2,3主机同样安装
然后配置my.cnf文件
# vi /my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables #初次需要修改root密码
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
server-id=101 #每个节点一个唯一的ID
# 当前版本galera cluster只支持innodb
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0 #开启远程访问
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options='gmcast.listen_addr=tcp://10.211.55.17:4567' #修改为本节点地址
wsrep_cluster_name="my_wsrep_cluster" #集群名称,所有节点配置为同一个
wsrep_cluster_address=gcomm://10.211.55.17,10.211.55.25,10.211.55.26 #节点中所有节点地址
wsrep_node_name=node1 #node名称,每个节点名称唯一
wsrep_node_address='10.211.55.17' #本节点地址
wsrep_node_incoming_address='10.211.55.17' #本节点地址
wsrep_slave_threads=1
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=rsync
wsrep_sst_auth=root:123456 #数据量库用户名密码
wsrep_sst_donor='node1,node2' #节点中所有节点的node名称
将配置好的my.cnf复制到另外两个主机的/etc目录下,分别进入另外两个主机修改my.cnf中的IP与server_id、wsrep_node_name
启动第一个节点(随意用一个主机):
# mysqld_bootstrap
剩下节点的启动:
# systemctl start mysqld
启动成功后进入mysql:
# mysql -u root -p
Enter password:
因为初次使用还设置了skip-grant-tables所以无密码直进入:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.24 MySQL Community Server - (GPL), wsrep_25.16
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
这里先修改root密码:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string = password('123456') where user = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
注意:这里的密码一定要与my.cnf中wsrep_sst_auth值一致,因为当中配置的是root密码,如果是其他用户密码也需改成一样。
然后先停止当前节点的mysql服务
# systemctl stop mysqld
然后修改my.cnf文件,将skip-grant-tables注释可删除,保存my.cnf退出编辑。
再次启动mysql服务:
# systemctl start mysqld
其他节点的mysql一样的配置初始root密码。
都初始好后进入mysql。
然后查看galera cluster运行情况:
mysql> show status like 'wsrep%';
可以看到输出结果:
+------------------------------+--------------------------------------+
| Variable_name | Value |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid | addca9f7-1d30-11e9-a5ea-17d3a014ca91 |
| wsrep_protocol_version | 9 |
| wsrep_last_committed | 0 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_received | 5 |
| wsrep_received_bytes | 672 |
| wsrep_local_commits | 0 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_max | 3 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.600000 |
| wsrep_local_cached_downto | 18446744073709551615 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 0.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 0 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_open_transactions | 0 |
| wsrep_open_connections | 0 |
| wsrep_incoming_addresses | 172.16.4.15:3306,172.16.4.13:3306 |
| wsrep_cluster_weight | 2 |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | b104a366-1ec8-11e9-a036-d6f80c5f04b8 |
| wsrep_cluster_conf_id | 4 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | addca9f7-1d30-11e9-a5ea-17d3a014ca91 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 1 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy |
| wsrep_provider_version | 3.25(rddf9876) |
| wsrep_ready | ON |
+------------------------------+--------------------------------------+
60 rows in set (0.00 sec)
当中wsrep_connected的值为ON就表示galera cluster启动成功