Load Balancing Cluster Summary (Haproxy)

Environment: Centos 6.9, Mysql 8.0


 First, configure the mysql master-slave replication set, you can refer to my previous article >> Mysql master-slave replication summary (detailed)

       My master node is at (master): 192.168.110.76

       Two slave nodes are in (slave): 192.168.110.77, 192.168.110.78

    Load balancing node (proxy): 192.168.110.69

HaProxy

 


 

HaProxy、Lvs、Nginx

   Nginx is based on http. In the web field, the path parsing function is very powerful. I have carried it manually, it is not complicated. lowest performance

     Lvs (Linux Virtual Service) has the highest performance

     HaProxy can proxy mysql based on Tcp

    Download address: www.haproxy.org (FQ to download, then upload to master) I downloaded 1.7.10

step


  First, create a user on the master node to grant permissions and ensure that it can synchronize to the slave nodes.

  create user 'test'@'192.168.110.%' identified by 'Test_123456';

  grant all on *.* to 'test'@'192.168.110.%';

  Unzip the haproxy file ready to compile and install it tar -zxvf haproxy-1.7.10.tar.gz 

  

      Then use make TARGET=linux26 (linux kernel)

       

  Prompt that gcc is not installed. Installation: yum install gcc-c++

  Recompile after installation is complete. (soon)

  The compilation is successful. Next, install make install PREFIX=/usr/local/haproxy

       Next, go to /usr/local/haproxy and create a conf folder to place our configuration files. mkdir conf ; cd conf ; touch haproxy.cnf; vim haproxy.cnf

 

global
        daemon #Running in background mode
        nbproc 1
        pidfile  /usr/local/haproxy/conf/haproxy.pid

defaults
	 mode tcp #Default mode mode{tcp|http|health}, tcp is layer 4, http is layer 7, health will only return ok
	 retries 2 #If the connection fails twice, the server is considered to be unavailable, and it can also be set later.
	 option redispatch #When the server corresponding to serverId hangs, force the assignment to other healthy servers
	 option abortonclose #When the server load is very high, automatically end the link that has been processed for a long time in the current queue
	 maxconn 4096 #The default maximum number of connections
	 timeout connect 5000ms #Connection timeout
	 timeout client 30000ms #Client timeout
	 timeout server 30000ms #Server timeout
	 #timeout check 2000 #=Heartbeat check timeout
	 log 127.0.0.1 local0 err #[err warning info debug]
##################test1 configuration######################
listen test1 #Here is to configure load balancing, test1 is the name, it can be arbitrary
	bind 0.0.0.0:3306 #Here is the listening IP address and port, the local machine is 0.0.0.0 The port number can be between 0~6553, to avoid port conflicts
	mode tcp #Linked protocol tcp
	#maxconn 4086
	#log 127.0.0.1 local0 debug
	server s1 192.168.110.77:3306 #Load machine
	server s2 192.168.119.78:3306 #Load machine, multiple rows down

  

   echo 1 > haproxy.pid

   ./sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cnf Start haproxy The configuration is complete!

  The database access connection accesses the ip of the proxy node, and the username and password are the newly created test.

question


 

  It may be because my mysql is using 8.0, which appears when connecting remotely

  authentication plugin 'caching_sha2_password' cannot be loaded的错误。

      There are two solutions:

   1、ALTER USER 'username'@'IP' IDENTIFIED WITH mysql_native_password BY 'password';

   2. Modify /etc/my.cnf

   default_authentication_plugin=mysql_native_password and restart the mysql service.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324804021&siteId=291194637