ubuntu16.0.4 配置MariaDB Galera Cluster
1.安装基本套件:
$ sudo apt-get update
$ sudo apt-get -y install software-properties-common python-software-properties
2. 更新 APT repository for MariaDB Galera Cluster
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu trusty main'
$ sudo apt-get update
3. 安裝 MariaDB Galera Cluster相关组件
$ sudo apt-get -y install python-mysqldb galera mariadb-galera-server
4.设置cluster配置文件
cd /etc/mysql/conf.d/ #进入这个目录
新建cluster配置文件
vim galera.cnf
输入如下内容
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
# Galera Provider Configuration
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
# Galera Cluster Configuration
wsrep_cluster_name="Openstack_DB_cluster"
wsrep_cluster_address="gcomm://192.168.2.151,192.168.2.81,192.168.2.80" #集群所有结点的ip地址
# Galera Synchronization Configuration
wsrep_sst_method=rsync
# Galera Node Configuration
wsrep_node_address="192.168.2.151" #集群当前节点的ip地址
wsrep_node_name="db1" #集群当前节点的主机名
5. 修改集群认证文件,并复制到所有结点
cd /etc/mysql/
vim debian.cnf
内容如下所示
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = cdT9xj9lbrAne1tU
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = cdT9xj9lbrAne1tU
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
将该文件复制到所有结点,或者将所有节点的文件内容修改一致。
6.编辑hosts文件将所有结点添加到hosts文件中,或者有dns服务器支持
...................................................略
7.修改集群所有节点的时区,同步时间
....................................................略
8.禁用防火墙,或者添加防火墙规则
...................................................略
9.重启所有结点服务器。(本人在做这个实验的时候,不重启是不能成功的。)
10.关闭所有结点的mysql服务
service mysql stop
11.在第一节点上输入如下命令启动群集(只需要执行一次)
service mysql bootstrap
12.启动成功后输入mysql -u root -p进入数据库输入如下命令查看:
show status like 'wsrep%';
13.启动其他节点
service mysql start
14.重复步骤12
+------------------------------+--------------------------------------+
| Variable_name | Value |
+------------------------------+--------------------------------------+
| wsrep_local_state_uuid | fc919daa-dcbb-11e6-9c42-1b3cac4cc581 |
| wsrep_protocol_version | 7 |
| wsrep_last_committed | 1 |
| 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 | 7 |
| wsrep_received_bytes | 865 |
| 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 | 1 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_cached_downto | 1 |
| 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 | 1.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | 1 |
| wsrep_causal_reads | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_incoming_addresses | 192.168.2.80:3306,192.168.2.81:3306 |#成员ip
| 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 | 482fd4eb-dcbc-11e6-9dc0-ba26a2e61405 |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | fc919daa-dcbb-11e6-9c42-1b3cac4cc581 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_index | 0 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.19(r3667) |
| wsrep_ready | ON |
| wsrep_thread_count | 2 |
+------------------------------+--------------------------------------+
15.基本完成了。