昨日 の時点で、CentOS 6.6でMySQL Routerを試すには自前ビルドしないといけないことが判明しました。
$ sudo docker run -it centos:centos7 bash # yum install -y http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm # yum install -y mysql-router .. Installed: mysql-router.x86_64 0:2.0.2-1.el7 Complete!
お手軽! …って、mysql-routerの依存関係で引きずられてmysql-community-libsとか入るかと思ったけど入ってない。いいのかな。。
# rpm -ql mysql-router /etc/mysqlrouter /etc/mysqlrouter/mysqlrouter.ini /usr/lib/systemd/system/mysqlrouter.service /usr/lib/tmpfiles.d/mysqlrouter.conf /usr/lib64/libmysqlharness.so /usr/lib64/libmysqlharness.so.0 /usr/lib64/libmysqlrouter.so /usr/lib64/libmysqlrouter.so.1 /usr/lib64/mysqlrouter /usr/lib64/mysqlrouter/fabric_cache.so /usr/lib64/mysqlrouter/keepalive.so /usr/lib64/mysqlrouter/logger.so /usr/lib64/mysqlrouter/routing.so /usr/sbin/mysqlrouter /usr/share/doc/mysql-router-2.0.2 /usr/share/doc/mysql-router-2.0.2/License.txt /usr/share/doc/mysql-router-2.0.2/README.txt /var/log/mysqlrouter /var/run/mysqlrouter # cat /usr/lib/systemd/system/mysqlrouter.service [Unit] Description=MySQL Router After=syslog.target After=network.target [Service] Type=simple User=mysql Group=mysql PIDFile=/var/run/mysqlrouter/mysqlrouter.pid ExecStart=/usr/sbin/mysqlrouter PrivateTmp=true [Install] WantedBy=multi-user.target
rpmファイルの構成としては至極フツーな感じ。systemdもただ/usr/sbin/mysqlrouterしてるだけみたいだから取り敢えずやってみようかしら。
# mysqlrouter & Logging to /var/log/mysqlrouter/mysqlrouter.log # less /var/log/mysqlrouter/mysqlrouter.log 2015-12-02 05:13:52 INFO [7f9173b46700] keepalive started with interval 60 2015-12-02 05:13:52 INFO [7f9173b46700] keepalive 2015-12-02 05:14:52 INFO [7f9173b46700] keepalive 2015-12-02 05:15:52 INFO [7f9173b46700] keepalive # ss -ltpn State Recv-Q Send-Q Local Address:Port Peer Address:Port
あれ、どこのポートもLISTENしてない。
ドキュメント をナナメ読みしてみた感じ、どうも[routing:xxx]セクションに設定をしたぶんだけポートをLISTENするシロモノであるっぽい。
# vim /etc/mysqlrouter/mysqlrouter.ini .. [routing:sakila_blue] bind_port= 7001 mode= read-write destinations= 127.0.0.1:3306 # mysqlrouter & Logging to /var/log/mysqlrouter/mysqlrouter.log # ss -ltpn State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 0 127.0.0.1:7001 *:* users:(("mysqlrouter",40,4)) # less /var/log/mysqlrouter/mysqlrouter.log 2015-12-02 15:23:48 INFO [7fae2cb46700] routing:sakila_blue started: listening on 127.0.0.1:7001; read-write 2015-12-02 15:23:48 INFO [7fae2d547700] keepalive started with interval 60 2015-12-02 15:23:48 INFO [7fae2d547700] keepalive # vim /etc/mysqlrouter/mysqlrouter.ini .. [routing:master] bind_port= 7001 mode= read-write destinations= 127.0.0.1:13454 [routing:slave] bind_port= 7002 mode= read-only destinations= 127.0.0.1:13455,127.0.0.1:13456 # pkill mysqlrouter # mysqlrouter & Logging to /var/log/mysqlrouter/mysqlrouter.log # ss -ltpn State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 0 127.0.0.1:7001 *:* users:(("mysqlrouter",49,6)) LISTEN 0 0 127.0.0.1:7002 *:* users:(("mysqlrouter",49,4)) # less /var/log/mysqlrouter/mysqlrouter.log 2015-12-02 15:25:28 INFO [7f0b81e2b700] keepalive started with interval 60 2015-12-02 15:25:28 INFO [7f0b81e2b700] keepalive 2015-12-02 15:25:28 INFO [7f0b8142a700] routing:slave started: listening on 127.0.0.1:7002; read-only 2015-12-02 15:25:28 INFO [7f0b80a29700] routing:master started: listening on 127.0.0.1:7001; read-write
ふむふむ。
MySQL Proxyは1対多のプロキシしか構成できなかったけど、MySQL Routerだと多対多のプロキシが構成できるのね。
このコンフィグは組み込みでサポートしてる「Connection Routing」に当たるもので、MySQL Fabricは取り敢えず今日は関係なさげ。。見た目、Connector/Jのfailover記法みたいな感じで転けたら次のホストに行くって動作をさせられる様子。
MySQL :: MySQL Router :: 1.1.1 Connection Routing
* read-writeのポート
$ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13454 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13454 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13454 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13454 | +--------+
* read-onlyのポート
$ mysql -umsandbox -pmsandbox --protocol=tcp -P 7002 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13455 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7002 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13456 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7002 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13455 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7002 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13456 | +--------+ $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7002 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13455 | +--------+
「read-writeは先頭のホストが失敗したら次のホストへ」
「read-onlyはラウンドロビン」
って書いてあった。ちゃんとドキュメントに書いてあるなんてつらくない!
MySQL :: MySQL Router :: 3.2.2 Connection Routing (Standalone)
マスターを落とすとこの通りフローティングしてくれて
$ ./master/stop $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13455 | +--------+ $ ./master/start $ mysql -umsandbox -pmsandbox --protocol=tcp -P 7001 -e "SELECT @@port" mysql: [Warning] Using a password on the command line interface can be insecure. +--------+ | @@port | +--------+ | 13455 | +--------+
あれ、上げても勝手に戻るわけではないのか。
取り敢えず動いたので楽しい。つらくない!
0 件のコメント :
コメントを投稿