{"action":"opened","issue":{"url":"https://api.github.com/repos/sxyx2008/DevArticles/issues/147","repository_url":"https://api.github.com/repos/sxyx2008/DevArticles","labels_url":"https://api.github.com/repos/sxyx2008/DevArticles/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/sxyx2008/DevArticles/issues/147/comments","events_url":"https://api.github.com/repos/sxyx2008/DevArticles/issues/147/events","html_url":"https://github.com/sxyx2008/DevArticles/issues/147","id":141798324,"number":147,"title":"使用Galera Load Balancer实现高可用MariaDB Galera Cluster","user":{"login":"sxyx2008","id":887836,"avatar_url":"https://avatars.githubusercontent.com/u/887836?v=3","gravatar_id":"","url":"https://api.github.com/users/sxyx2008","html_url":"https://github.com/sxyx2008","followers_url":"https://api.github.com/users/sxyx2008/followers","following_url":"https://api.github.com/users/sxyx2008/following{/other_user}","gists_url":"https://api.github.com/users/sxyx2008/gists{/gist_id}","starred_url":"https://api.github.com/users/sxyx2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sxyx2008/subscriptions","organizations_url":"https://api.github.com/users/sxyx2008/orgs","repos_url":"https://api.github.com/users/sxyx2008/repos","events_url":"https://api.github.com/users/sxyx2008/events{/privacy}","received_events_url":"https://api.github.com/users/sxyx2008/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-18T07:57:56Z","updated_at":"2016-03-18T07:57:56Z","closed_at":null,"body":"### 安装Galera Load Balancer\r\n\r\n```bash\r\nyum install gcc* libtool\r\ngit clone https://github.com/codership/glb\r\ncd glb/\r\n./bootstrap.sh\r\n./configure\r\nmake\r\nmake install\r\n```\r\n### 配置Galera Load Balancer\r\n\r\n```bash\r\ncp glb/files/glbd.sh /etc/init.d/glb\r\ncp glb/files/glbd.cfg /etc/sysconfig/glbd\r\n```\r\n\r\n### 修改/etc/sysconfig/glbd\r\n\r\n```\r\nLISTEN_ADDR=\"8010\"\r\nCONTROL_ADDR=\"127.0.0.1:8011\"\r\nCONTROL_FIFO=\"/var/run/glbd.fifo\"\r\nTHREADS=\"4\"\r\nMAX_CONN=256\r\nDEFAULT_TARGETS=\"192.168.64.145:3306:2 192.168.64.146:3306 192.168.64.147:3306\"\r\nOTHER_OPTIONS=\"--round-robin\"\r\n```\r\n### 启动Galera Load Balancer\r\n\r\n```bash\r\n[root@c1 ~]# service glb start\r\n[Fri Mar 18 23:38:04 CST 2016] glbd: starting...\r\nglb v1.0.1 (epoll)\r\nIncoming address: 0.0.0.0:8010, control FIFO: /var/run/glbd.fifo\r\nControl  address:  127.0.0.1:8011\r\nNumber of threads: 4, max conn: 256, nodelay: ON, keepalive: ON, defer accept: OFF, linger: OFF, daemon: YES, lat.count: 0, policy: 'round-robin', top: NO, verbose: NO\r\nDestinations: 3\r\n   0:  192.168.64.145:3306 , w: 2.000\r\n   1:  192.168.64.146:3306 , w: 1.000\r\n   2:  192.168.64.147:3306 , w: 1.000\r\n   INFO: glb_daemon.c:44: Changing effective user to 'daemon'\r\n[Fri Mar 18 23:38:04 CST 2016] glbd: started, pid=5833\r\n```\r\n\r\n查看状态\r\n```\r\n[root@c1 ~]# service glb getinfo\r\nRouter:\r\n------------------------------------------------------\r\n        Address       :   weight   usage    map  conns\r\n 192.168.64.145:3306  :    2.000   0.000    N/A      0\r\n 192.168.64.146:3306  :    1.000   0.000    N/A      0\r\n 192.168.64.147:3306  :    1.000   0.000    N/A      0\r\n------------------------------------------------------\r\nDestinations: 3, total connections: 0 of 256 max\r\n```\r\n\r\n### 实验测试\r\n\r\n客户端使用glb的代理端口`8010`连接`MariaDB Galera Cluster`客户端\r\n\r\n```\r\n[root@c1 glb]# mysql -uroot -proot -h127.0.0.1 -P8010\r\nMariaDB [(none)]> SELECT @@wsrep_node_name;\r\n+-------------------+\r\n| @@wsrep_node_name |\r\n+-------------------+\r\n| c1                |\r\n+-------------------+\r\n1 row in set (0.00 sec)\r\n```\r\nglb状态信息\r\n```\r\n[root@c1 ~]# service glb getinfo\r\nRouter:\r\n------------------------------------------------------\r\n        Address       :   weight   usage    map  conns\r\n 192.168.64.145:3306  :    2.000   0.500    N/A      1\r\n 192.168.64.146:3306  :    1.000   0.000    N/A      0\r\n 192.168.64.147:3306  :    1.000   0.000    N/A      0\r\n------------------------------------------------------\r\nDestinations: 3, total connections: 1 of 256 max\r\n```\r\n\r\n退出，再次连接\r\n\r\n```\r\n[root@c1 glb]# mysql -uroot -proot -h127.0.0.1 -P8010\r\nMariaDB [(none)]> SELECT @@wsrep_node_name;\r\n+-------------------+\r\n| @@wsrep_node_name |\r\n+-------------------+\r\n| c2                |\r\n+-------------------+\r\n1 row in set (0.00 sec)\r\n\r\nMariaDB [(none)]> \r\n```\r\nglb状态信息\r\n```\r\n[root@c1 ~]# service glb getinfo\r\nRouter:\r\n------------------------------------------------------\r\n        Address       :   weight   usage    map  conns\r\n 192.168.64.145:3306  :    2.000   0.000    N/A      0\r\n 192.168.64.146:3306  :    1.000   0.500    N/A      1\r\n 192.168.64.147:3306  :    1.000   0.000    N/A      0\r\n------------------------------------------------------\r\nDestinations: 3, total connections: 1 of 256 max\r\n```\r\n退出，再次连接\r\n```\r\n[root@c1 glb]# mysql -uroot -proot -h127.0.0.1 -P8010\r\nMariaDB [(none)]> SELECT @@wsrep_node_name;\r\n+-------------------+\r\n| @@wsrep_node_name |\r\n+-------------------+\r\n| c3                |\r\n+-------------------+\r\n1 row in set (0.00 sec)\r\n```\r\nglb状态信息\r\n```\r\n[root@c1 ~]# service glb getinfo\r\nRouter:\r\n------------------------------------------------------\r\n        Address       :   weight   usage    map  conns\r\n 192.168.64.145:3306  :    2.000   0.000    N/A      0\r\n 192.168.64.146:3306  :    1.000   0.000    N/A      0\r\n 192.168.64.147:3306  :    1.000   0.500    N/A      1\r\n------------------------------------------------------\r\nDestinations: 3, total connections: 1 of 256 max\r\n```\r\n可见已成功使用`Galera Load Balancer`完成`MariaDB Galera Cluster`负载\r\n\r\n### 参考文章\r\n\r\n[http://galeracluster.com/documentation-webpages/glb.html](http://galeracluster.com/documentation-webpages/glb.html)\r\n\r\n[http://galeracluster.com/documentation-webpages/glbparameters.html#glb-other-options](http://galeracluster.com/documentation-webpages/glbparameters.html#glb-other-options)\r\n\r\n[https://mariadb.com/blog/setup-mariadb-enterprise-cluster-part-3-setup-ha-proxy-load-balancer-read-and-write-pools](https://mariadb.com/blog/setup-mariadb-enterprise-cluster-part-3-setup-ha-proxy-load-balancer-read-and-write-pools)\r\n\r\n[http://www.fromdual.com/making-haproxy-high-available-for-mysql-galera-cluster](http://www.fromdual.com/making-haproxy-high-available-for-mysql-galera-cluster)\r\n\r\n[http://severalnines.com/tutorials/mysql-load-balancing-haproxy-tutorial](http://severalnines.com/tutorials/mysql-load-balancing-haproxy-tutorial)\r\n\r\n[http://blog.secaserver.com/2015/09/configure-haproxy-galera-cluster/](http://blog.secaserver.com/2015/09/configure-haproxy-galera-cluster/)\r\n\r\n[http://severalnines.com/blog/benchmark-load-balancers-mysqlmariadb-galera-cluster](http://severalnines.com/blog/benchmark-load-balancers-mysqlmariadb-galera-cluster)\r\n\r\n[https://extremeshok.com/4845/ubuntu-12-04-lts-3-node-mariadb-cluster-percona-xtradb-cluster-mysql-galera/](https://extremeshok.com/4845/ubuntu-12-04-lts-3-node-mariadb-cluster-percona-xtradb-cluster-mysql-galera/)\r\n\r\n[http://www.sebastien-han.fr/blog/2012/04/08/mysql-galera-cluster-with-haproxy/](http://www.sebastien-han.fr/blog/2012/04/08/mysql-galera-cluster-with-haproxy/)"}}