-
Notifications
You must be signed in to change notification settings - Fork 551
Quick Start with Docker
With docker, you can quick test PhxSQL with a simulate cluster, as test-with-docker.sh do.
First install docker on your system (documents). Then download PhxSQL image with:
docker pull phxsql/phxsql:latestCreate 3 containers as a PhxSQL cluster:
docker run -d --name node1 phxsql/phxsql:latest
docker run -d --name node2 phxsql/phxsql:latest
docker run -d --name node3 phxsql/phxsql:latestThis will create a new docker volume inside container at
/data, usedocker rm -vwhen you want to remove the container so that the volume will be clean up.
Inspect their IP addresses:
ip1=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" node1)
ip2=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" node2)
ip3=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" node3)Then you should wait for processes booting in each containers. Display processes of a container with:
docker top node1 # and node2, node3Wait for phxbinlogsvr, phxsqlproxy and mysqld. Once PhxSQL finish booting, docker top should display like:
UID PID PPID C STIME TTY TIME CMD
root 5888 5871 0 02:49 ? 00:00:00 tail -f /dev/null
root 6065 5888 0 02:49 ? 00:00:00 sh /phxsql/bin/mysqld_safe --defaults-file=/phxsql/etc/my.cnf --super_read_only
root 6067 5888 1 02:49 ? 00:00:00 /phxsql/sbin/phxbinlogsvr_phxrpc
root 6077 5888 4 02:49 ? 00:00:03 /phxsql/sbin/phxsqlproxy_phxrpc /phxsql/etc/phxsqlproxy.conf daemon
root 6079 5888 4 02:49 ? 00:00:03 /phxsql/sbin/phxsqlproxy_phxrpc /phxsql/etc/phxsqlproxy.conf daemon
999 7454 6065 0 02:49 ? 00:00:00 /phxsql/sbin/mysqld --defaults-file=/phxsql/etc/my.cnf --basedir=/phxsql/percona.src --datadir=/data/percona.workspace/data --plugin-dir=/phxsql/lib --user=mysql --super-read-only --log-error=/data/percona.workspace/log.err --pid-file=/data/percona.workspace/data/percona.pid --socket=/data/percona.workspace/tmp/percona.sock --port=11111
Then run InitBinlogSvrMaster command on any one of containers:
docker exec -it node1 phxbinlogsvr_tools_phxrpc \
-f InitBinlogSvrMaster -h "$ip1,$ip2,$ip3" -p 17000The cluster is active after the command finished and showed add ip IP1 to master done, add ip IP2 to master done, add ip IP3 to master done.
Now you can play with the PhxSQL cluster through:
docker exec -it node1 mysql -u root -h $ip1 -P 54321Try replacing
node1tonode2ornode3,$ip1to$ip2or$ip3,54321to54322, and run SQL commandselect @@hostname, user();to understand how PhxSQL fowarding the connections.
Try writing some data into cluster through the read/write port 54321:
docker exec -it node1 mysql -u root -h $ip1 -P 54321
mysql> create table ...
mysql> insert into ...And then read from slaves through read only port 54322:
docker exec -it node1 mysql -u root -h $ip2 -P 54322 # and $ip3
mysql> select ...Consistent data on each nodes should be observed.
You can use docker to quick deploy PhxSQL cluster of multiple machines.
It is recommended to read Quick Start a Simulate Cluster on One Machine before your deployment, since lots of steps are similar.
Assume that your cluster consist of 3 machines which addresses are IP1, IP2 and IP3.
Run PhxSQL containers on each machines:
docker run -d --name phxnode --net host phxsql/phxsql:latest -i "your_inner_ip"This will create a new docker volume inside container at
/data, usedocker rm -vwhen you want to remove the container so that the volume will be clean up. In practice, it's better to use a data volume container or a named volume.
Wait for phxbinlogsvr, phxsqlproxy and mysqld started on each nodes. Display processes of a container with:
docker top phxnodeOnce PhxSQL finish booting, docker top should display like:
UID PID PPID C STIME TTY TIME CMD
root 5888 5871 0 02:49 ? 00:00:00 tail -f /dev/null
root 6065 5888 0 02:49 ? 00:00:00 sh /phxsql/bin/mysqld_safe --defaults-file=/phxsql/etc/my.cnf --super_read_only
root 6067 5888 1 02:49 ? 00:00:00 /phxsql/sbin/phxbinlogsvr_phxrpc
root 6077 5888 4 02:49 ? 00:00:03 /phxsql/sbin/phxsqlproxy_phxrpc /phxsql/etc/phxsqlproxy.conf daemon
root 6079 5888 4 02:49 ? 00:00:03 /phxsql/sbin/phxsqlproxy_phxrpc /phxsql/etc/phxsqlproxy.conf daemon
999 7454 6065 0 02:49 ? 00:00:00 /phxsql/sbin/mysqld --defaults-file=/phxsql/etc/my.cnf --basedir=/phxsql/percona.src --datadir=/data/percona.workspace/data --plugin-dir=/phxsql/lib --user=mysql --super-read-only --log-error=/data/percona.workspace/log.err --pid-file=/data/percona.workspace/data/percona.pid --socket=/data/percona.workspace/tmp/percona.sock --port=11111
After all processes started, run InitBinlogSvrMaster command on one machine:
docker exec -it phxnode phxbinlogsvr_tools_phxrpc \
-f InitBinlogSvrMaster -h "IP1,IP2,IP3" -p 17000The cluster is active after the command finished and showed add ip IP1 to master done, add ip IP2 to master done, add ip IP3 to master done.
Then you can test the cluster similarly as above