open stack--galera cluster

1、環境準備
一、各主機配置靜態域名解析:
cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.210.131 node1 node1.test.com
192.168.210.130 node2 node2.test.com
192.168.210.132 node3 node3.test.com
 
二、並配置各節點ssh無密鑰登錄
 
三、安裝docker環境
wget http://download2.yunwei.edu/shell/docker.tar.gz
tar zxf  docker.tar.gz
cd docker
sh docker
 
四、下載配置文件而且導入鏡像
wget http://download2.yunwei.edu/shell/galera.tar.gz
tar zxf  galera.tar.gz
docker load -i mariadb-galera.tar
mkdir mkdir /opt/mariadb
#######將config.tar.gz 解壓後,mv到mkdir /opt/mariadb,
tar zxf config.tar.gz && mv config /opt/mariadb/
 
2、配置集羣
#######node1
docker run -d --net host --name galera1 \
-e WSREP_NODE_ADDRESS=192.168.210.131 \
-p 3306:3306 \
-p 4567:4567/udp \
-p 4567-4568:4567-4568 \
-p 4444:4444 \
-v /opt/mariadb/config/mysql:/etc/mysql \
-v /opt/mariadb/config/data:/var/lib/mysql:Z \
--restart=always \
panubo/mariadb-galera mysqld
 
#######node2
docker run -d --net host --name galera2 \
-e WSREP_NODE_ADDRESS=192.168.210.130 \
-p 3306:3306 \
-p 4567:4567/udp \
-p 4567-4568:4567-4568 \
-p 4444:4444 \
-v /opt/mariadb/config/mysql:/etc/mysql \
-v /opt/mariadb/config/data:/var/lib/mysql:Z \
--restart=always \
panubo/mariadb-galera mysqld
 
#########node3
docker run -d --net host --name galera3 \
-e WSREP_NODE_ADDRESS=192.168.210.132 \
-e MYSQL_ROOT_PASSWORD=123 \
-p 3306:3306 \
-p 4567:4567/udp \
-p 4567-4568:4567-4568 \
-p 4444:4444 \
-v /opt/mariadb/config/mysql:/etc/mysql \
-v /opt/mariadb/config/data:/var/lib/mysql:Z \
--restart=always \
panubo/mariadb-galera mysqld --wsrep-new-cluster
 
 
3、登錄數據庫時,安裝mariadb客戶端
yum install mariadb -y
mysql -h 192.168.210.131 -P 3306 -u root -p123
 
檢查集羣狀態:
SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+
 
 
4、故障恢復:
(1)集羣中某slave節點down機,重啓該節點後,重啓docke容器便可;
(2)集羣中master節點down機,重啓該master節點後,master-docker容器不能正常啓動,由於這是master節點已經切換,
         須要將原先master-docker容器刪除,再以非wrsep方式啓動一個普通容器;
(3)集羣所有意外down機,強制找一臺節點做爲master節點;到以下路徑,將 safe_to_bootstrap: 0修改成1(平時集羣正常時,每一個節點都爲0)
[root@con3 data]# pwd
/opt/mariadb/data
[root@con3 data]# cat grastate.dat
# GALERA saved state
version: 2.1
uuid:    6a26abec-e7b5-11e8-b15b-b74046986de4
seqno:   -1
safe_to_bootstrap: 0
 
以後在該節點啓動wsrep進程的docker
相關文章
相關標籤/搜索