Galera Cluster for MySQL Comments (five) - Load Balancing

        Galera load balancer (Galera Load Balancer, GLB) client requests to provide a simple TCP connection balance function, which is similar to the relationship between the Cluster Galera MySQL Router copy of the group. It draws from another Lightweight Load Balancer Pen inspiration, consider the development of performance and scalability, but only to balance the TCP connection. GLB provides the following functions:

  • It supports the back-end server configuration at run time.
  • Support server to exclude (draining).
  • Support for improving the routing performance of epoll API.
  • Support multithreading.
  • Alternatively watchdog module for monitoring and adjusting the routing table a destination address.

First, install

        With different Galera Cluster, GLB not provide binary packages, require the following command as root constructed from the source file.

# 安装依赖包
yum install gcc* libtool

# 下载GLB源文件
git clone https://github.com/codership/glb

# 在git创建的glb目录中,运行bootstrap脚本
cd glb/
./bootstrap.sh

# 配置
./configure

# 编译
make

# 安装
make install

        After the successful execution of all these operations, you can use the command to start glbd GLB command line. In addition to the system daemons, also installed libglb shared library, any Linux application using the C standard library connect () call is connected to the balance.

Second, the service is installed

        The above process only GLB installed software to run manually from the command line, but sometimes the application as a system service to run more conducive to safeguarding. The GLB installed as a service simply copy the two files in the directory files to the appropriate location.

# GLB脚本文件
cp files/glbd.sh /etc/init.d/glb

# GLB配置文件
cp files/glbd.cfg /etc/sysconfig/glbd

        After this is done through the service order management GLB.

Third, the configuration

        Edit / etc / sysconfig / glbd file, as follows:

LISTEN_ADDR="8010"
CONTROL_ADDR="127.0.0.1:8011"
CONTROL_FIFO="/var/run/glbd.fifo"
THREADS="4"
MAX_CONN=256
DEFAULT_TARGETS="172.16.1.125:3306 172.16.1.126:3306 172.16.1.127:3306"
OTHER_OPTIONS="--round-robin"

        Item Description:

  • LISTEN_ADDR: Address to listen for client connections. Just to give the port, which means the machine address of all network adapters binding.
  • CONTROL_ADDR: Control address, for displaying information GLB.
  • CONTROL_FIFO: FIFO control file, it is always open.
  • THREADS: pool thread connections, usually some threads per CPU core allocation.
  • MAX_CONN: maximum number of connections, you may need to modify the system to open the file limit (ulimit the open file).
  • DEFAULT_TARGETS: space-separated target server address in the format IP [: PORT [: WEIGHT]], and the weight WEIGHT PORT port is optional. WEIGHT default value is 1, PORT default LISTEN_ADDR specified port.
  • OTHER_OPTIONS: glbd Other command-line options, here designated target selection policy for polling.

        If you do not specify a target selection policy in glbd the command line, you must add parameters to the configuration file glbd OTHER_OPTIONS options. GLB supports the following five target selection strategy:

  • Least Connected: least connections, which is the default strategy. The new connections to the server currently connected minimal. It will be adjusted according to the server heavy weights.
  • Round Robin: polling, using -round option is enabled. The new connection cycle directed to the next target address DEFAULT_TARGETS list.
  • Single: a new connection points to a maximum weight of a single server, using -single option is enabled. Continue the route directed to the server until it fails, or until a higher weight to the server has available.
  • Random: randomly connect to an available server, use -random option is enabled.
  • Source Tracking: the connection from the same address directed to the same server, using the -source option is enabled.

Fourth, start

[root@manager~/glb]#service glb start
[Sat Feb 29 14:16:15 CST 2020] glbd: starting...
glb v1.0.1 (epoll)
Incoming address: 0.0.0.0:8010, control FIFO: /var/run/glbd.fifo
Control  address:  127.0.0.1:8011
Number 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
Destinations: 3
   0:    172.16.1.125:3306 , w: 1.000
   1:    172.16.1.126:3306 , w: 1.000
   2:    172.16.1.127:3306 , w: 1.000
   INFO: glb_daemon.c:44: Changing effective user to 'daemon'
[Sat Feb 29 14:16:15 CST 2020] glbd: started, pid=542577
[root@manager~/glb]#

        View status:

[root@manager~/glb]#service glb getinfo
Router:
------------------------------------------------------
        Address       :   weight   usage    map  conns
   172.16.1.125:3306  :    1.000   0.000    N/A      0
   172.16.1.126:3306  :    1.000   0.000    N/A      0
   172.16.1.127:3306  :    1.000   0.000    N/A      0
------------------------------------------------------
Destinations: 3, total connections: 0 of 256 max
[root@manager~/glb]#

        The results are shown in the list of available servers, and utilization of their weights, and the number of connections established with them.

        The following script is glb service support operations:

  • start start GLB.
  • stop stop GLB.
  • restart restart GLB
  • getinfo retrieve the current routing information.
  • getstats provide cluster-related performance statistics.
  • add <IP Address> add an IP address from the routing table.
  • remove <IP Address> delete the specified IP address from the routing table.
  • drain <IP Address> specified server to drain. When you do this, GLB does not send a new connection to a given server, but it will not terminate an existing connection, but will wait until the end of the specified server connected properly.

        Add IP addresses, you must follow the following format runtime: IP Address: Port: weight. You can use a host name instead of IP address.

Five test

[root@manager~/glb]#mysql -uwxy -pP@sswo2d -h127.0.0.1 -P8010 -N -s -e "select @@wsrep_node_name;"
Warning: Using a password on the command line interface can be insecure.
node1
[root@manager~/glb]#mysql -uwxy -pP@sswo2d -h127.0.0.1 -P8010 -N -s -e "select @@wsrep_node_name;"
Warning: Using a password on the command line interface can be insecure.
node2
[root@manager~/glb]#mysql -uwxy -pP@sswo2d -h127.0.0.1 -P8010 -N -s -e "select @@wsrep_node_name;"
Warning: Using a password on the command line interface can be insecure.
node3
[root@manager~/glb]#mysql -uwxy -pP@sswo2d -h127.0.0.1 -P8010 -N -s -e "select @@wsrep_node_name;"
Warning: Using a password on the command line interface can be insecure.
node1
[root@manager~/glb]#

        Each client by the end of 8010 under a new connection port loop points to an available server, visible GLB has been used successfully completed Galera Cluster load balancing.

reference:

Published 363 original articles · won praise 584 · Views 2.15 million +

Guess you like

Origin blog.csdn.net/wzy0623/article/details/104574057