Percona XtraDB Cluster docker.md
- 拉取Percona XtraDB Cluster鏡像
docker pull percona/percona-xtradb-cluster:5.7
- 官方鏡像下有使用說明
- One of MYSQLROOTPASSWORD, MYSQLALLOWEMPTYPASSWORD or MYSQLRANDOMROOTPASSWORDmust be defined.三個設置密碼的環境變數必須定義其中一個。
- The image will create the user xtrabackup@localhost for the XtraBackup SST method. If you want to use a password for the xtrabackup user, set XTRABACKUPPASSWORD.自動定義用戶xtrabackup,可選設置xtrabackup user的密碼,集群啟動後可以查看資料庫mysql表user,確實有該用戶。
- If you want to use the discovery service (right now only etcd is supported), set the address to DISCOVERYSERVICE. The image will automatically find a running cluser by CLUSTERNAME and join to the existing cluster (or start a new one).可以使用etcd註冊服務,自動生成集群
- If you want to start without the discovery service, use the CLUSTERJOIN variable. Empty variables will start a new cluster, To join an existing cluster, set CLUSTERJOIN to the list of IP addresses running cluster nodes.不使用etcd,可以手動添加環境變數CLUSTERJOIN 添加集群。
- 最重要的提示For an example, see thestart_node.sh script.啟動容器的腳本在github上
- start_node.sh源碼
CLUSTER_NAME=${CLUSTER_NAME:-Theistareykjarbunga}ETCD_HOST=${ETCD_HOST:-10.20.2.4:2379}NETWORK_NAME=${CLUSTER_NAME}_netdocker network create -d overlay $NETWORK_NAME echo "Starting new node..."docker run -d -p 3306 --net=$NETWORK_NAME -e MYSQL_ROOT_PASSWORD=Theistareyk -e DISCOVERY_SERVICE=$ETCD_HOST -e CLUSTER_NAME=${CLUSTER_NAME} -e XTRABACKUP_PASSWORD=Theistare percona/percona-xtradb-cluster#--general-log=1 --general_log_file=/var/lib/mysql/general.logecho "Started $(docker ps -l -q)"# --wsrep_cluster_address="gcomm://$QCOMM"
- 修改啟動腳本> 啟動腳本可以根據實際使用進行修改,比如我使用的網路是calico,因此直接指定net和ip,使用etcd服務發現,並且不定義XTRABACKUP_PASSWORD
CLUSTER_NAME=pxc_clusterETCD_HOST=xxxx:yyyy echo "Starting new node..."docker run -d -p 3306 --net=xxxx -ip xxxx -e MYSQL_ROOT_PASSWORD=123456 -e CLUSTER_NAME=${CLUSTER_NAME} -e DISCOVERY_SERVICE=${ETCD_HOST} percona/percona-xtradb-cluster:5.7echo "Started $(docker ps -l -q)"
- 分別3台宿主機上執行啟動腳本後,查詢容器狀態
[root@172 ~]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES99735a328750 percona/**percona**-xtradb-cluster:5.7 "/entrypoint.sh " 6 hours ago Up 6 hours pensive_kare
- 查詢etcd服務信息,瀏覽器直接查看
http://${ETCD_HOST}/v2/keys/pxc-cluster/pxc_cluster1/?recursive=true
- 登錄集群中任意一個node,執行DDL或者DML,會發現其他節點進行了同步。pxc要求表必須有主鍵。前面說過會自動註冊一個用戶xtrabackup,查看用戶表確實存在
mysql> select host,user from user ; +-----------+---------------+| host | user |+-----------+---------------+| % | monitor || % | proxy || % | root || localhost | monitor || localhost | mysql.session || localhost | mysql.sys || localhost | root || localhost | xtrabackup |+-----------+---------------+8 rows in set (0.00 sec)
推薦閱讀:
※你眼中的#Kubernetes 2017年度十大新聞事件#
※Docker Swarm Mode
※如何通俗解釋Docker是什麼?
※學習docker要有什麼基礎?
※Docker Compose + GPU + TensorFlow 所產生的奇妙火花
TAG:Docker | MySQLCluster |