From f7859319ec9c15f67ac582445507a0b3a55bd701 Mon Sep 17 00:00:00 2001 From: kev Date: Mon, 9 May 2016 23:28:47 +0800 Subject: [PATCH] update mysql-proxy --- README.md | 1 + mysql-proxy/Dockerfile | 4 ++-- mysql-proxy/README.md | 12 ++++++++++++ mysql-proxy/code.lua | 2 ++ mysql-proxy/code.py | 20 ++++++++++++++++++++ mysql-proxy/docker-compose.yml | 9 ++++++++- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100755 mysql-proxy/code.py diff --git a/README.md b/README.md index 04aa2e3..f1e5953 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ A collection of delicious docker recipes. - [x] moodle :beetle: - [x] mosquitto - [x] motion-arm :+1: +- [x] mysql-proxy - [x] nginad - [x] nginx - [x] ngrok :+1: diff --git a/mysql-proxy/Dockerfile b/mysql-proxy/Dockerfile index fd8c223..545554f 100644 --- a/mysql-proxy/Dockerfile +++ b/mysql-proxy/Dockerfile @@ -10,7 +10,7 @@ RUN set -xe \ && apt-get install -y mysql-proxy \ && rm -rf /var/lib/apt/lists/* -EXPOSE 4040 +EXPOSE 4040 4041 ENTRYPOINT ["mysql-proxy"] -CMD ["--help"] +CMD ["--help-all"] diff --git a/mysql-proxy/README.md b/mysql-proxy/README.md index fefca3f..f697903 100644 --- a/mysql-proxy/README.md +++ b/mysql-proxy/README.md @@ -5,4 +5,16 @@ mysql-proxy MySQL client/server protocol and provides communication between one or more MySQL servers and one or more MySQL clients. +``` +# run docker container +$ docker-compose up -d + +# view log in shell +$ journalctl -f CONTAINER_NAME=mysql-proxy + +# view log in python +$ apt install python3-systemd +$ python3 code.py +``` + [1]: https://github.com/mysql/mysql-proxy diff --git a/mysql-proxy/code.lua b/mysql-proxy/code.lua index 00bb907..11ec802 100644 --- a/mysql-proxy/code.lua +++ b/mysql-proxy/code.lua @@ -1,3 +1,5 @@ +io.stdout:setvbuf 'no' + function read_query(packet) if packet:byte() == proxy.COM_QUERY then print("we got a normal query: " .. packet:sub(2)) diff --git a/mysql-proxy/code.py b/mysql-proxy/code.py new file mode 100755 index 0000000..ab165f9 --- /dev/null +++ b/mysql-proxy/code.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import select from systemd +import journal + +j = journal.Reader() +j.log_level(journal.LOG_INFO) +j.add_match(CONTAINER_NAME="mysql-proxy") +j.seek_tail() +j.get_previous() + +p = select.poll() +p.register(j, j.get_events()) + +while p.poll(): + if j.process() != journal.APPEND: + continue + for entry in j: + if entry['MESSAGE']: + print(str(entry['__REALTIME_TIMESTAMP']), entry['MESSAGE']) diff --git a/mysql-proxy/docker-compose.yml b/mysql-proxy/docker-compose.yml index e8a12d1..e0d9198 100644 --- a/mysql-proxy/docker-compose.yml +++ b/mysql-proxy/docker-compose.yml @@ -1,11 +1,18 @@ mysql-proxy: image: vimagick/mysql-proxy + container_name: mysql-proxy command: > --proxy-address=:4040 --proxy-backend-addresses=mysql-server:3306 --proxy-lua-script=/code.lua + --admin-address=:4041 + --admin-username=root + --admin-password=root + --admin-lua-script=/usr/lib/mysql-proxy/lua/admin.lua ports: - - "3306:4040" + - "4040:4040" + - "4041:4041" volumes: - ./code.lua:/code.lua + log_driver: journald restart: always