programing

MariaDB 및 HAProxy(클러스터)와의 접속 문제

itsource 2022. 10. 25. 21:56
반응형

MariaDB 및 HAProxy(클러스터)와의 접속 문제

haproxy가 실행 중인 VM과 클러스터의 연결에 문제가 있습니다.제가 그 문제를 설명하겠습니다.MariaDB(IP 192.168.0.1 및 192.168.0.2)와 haproxy 호스트(IP 192.168.0.3)를 사용하여 2개의 galera 클러스터 시스템을 설정했습니다.인터넷에서 찾은 거의 모든 튜토리얼을 따라 했지만 항상 같은 문제가 발생합니다.happroxy에서 접속하여 쿼리를 실행할 수 없습니다.

실제 상태:

  • 갤러라 정상 작동

    root@db1:# mysql -u root -pPASSWORD -e 'SELECT VARIABLE_VALUE as "cluster size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME="wsrep_cluster_size"'
    +--------------+
    | cluster size |
    +--------------+
    | 2            |
    +--------------+
    
  • haproxy가 올바르게 설치되어 있고 모든 권한을 가진 사용자가 데이터베이스에 있습니다.haproxy 설정 파일은 다음과 같습니다.

    global
       log 127.0.0.1   local0                                                                  
       log 127.0.0.1   local1 notice                                                           
       maxconn 1024                                                                            
       user haproxy                                                                            
       group haproxy                                                                           
       daemon                                                                                  
    
       stats socket /var/lib/haproxy/stats.sock mode 600 level admin                           
       stats timeout 2m                                                                        
    
    defaults                                                                                        
       log     global                                                                          
       mode    http                                                                            
       option  tcplog                                                                          
       option  dontlognull                                                                     
       retries 3                                                                               
       option redispatch                                                                       
       maxconn 1024                                                                            
       timeout connect 5000ms                                                                  
       timeout client  50000ms                                                                 
       timeout server  50000ms                                                                 
    
    listen haproxy-monitoring                                                                       
       bind *:80                                                                               
       mode http                                                                               
       stats enable                                                                            
       stats show-legends                                                                      
       stats refresh   5s                                                                      
       stats uri       /                                                                       
       stats realm     Statistics                                                              
       stats auth      User:Password                                                         
       stats admin     if TRUE                                                                 
    
    frontend lb1db                                                                                  
       bind *:3306                                                                             
       default_backend         galera-cluster                                                  
    
    backend galera-cluster                                                                          
       balance roundrobin                                                                      
       server db1      192.168.0.1:3306 check weight 1                                        
       server db2      192.168.0.2:3306 check weight 1   
    
  • 통계 화면에는 VM이 가동되어 실행되고 있는 것이 표시됩니다.

  • my.cnf는 다음과 같습니다.

    [galera]                                                                                        
    wsrep_on=ON                                                                                     
    wsrep_provider=/usr/lib/galera/libgalera_smm.so                                                 
    wsrep_cluster_address=gcomm://192.168.0.94,192.168.0.93                                         
    wsrep_node_addres=192.168.0.1. #vm1 IP; in the other config is present the vm2 IP                                                                  
    wsrep_node_name=db1                                                                             
    binlog_format=row                                                                               
    default_storage_engine=InnoDB                                                                   
    innodb_autoinc_lock_mode=2                                                                      
    
    wsrep_cluster_name="Cluster_name"                                                                    
    wsrep_sst_method=rsync                                                                          
    bind-address=192.168.0.1  #vm1 IP; in the other config is present the vm2 IP                                                                     
    

haproxy에서 쿼리를 실행하려고 하면 다음과 같은 결과가 나타납니다.

mysql -u root -pPASSWORD --host=192.168.0.3 --port=3306
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.0.3' (111 "Connection refused")

글을 쓰면서 몇 가지 튜토리얼을 따라 해봤는데 문제는 항상 똑같아요.누가 나를 도와줄 수 있나요?

사용하고 있는 명령어가 HAProxy 서버의 데이터베이스 서비스에 접속하려고 합니다.당신의 설명에서 알 수 있듯이, 이 서버(192.168.0.3)에서 실행되고 있는 데이터베이스 서비스는 없습니다.

데이터베이스 서비스에 접속하려면 Galera 클러스터 내의 서버 중 하나(192.168.0.1 또는 192.168.0.2 등)의 IP 주소 또는 호스트 이름을 사용해야 합니다.

이러한 종류의 액세스를 허가하려면 데이터베이스 서비스에 사용자를 작성해야 합니다(투고를 읽어본 결과 그렇게 하지 않은 것 같습니다).둘째, 'root'이 활성화되어 있으므로 원격 액세스를 사용하지 않는 것이 좋습니다.데이터베이스 클러스터에 원격 사용자를 생성하고 일부 사용 권한을 부여할 수 있습니다.클러스터 내의 서버 중 하나에 로그인하여 루트로 데이터베이스에 로그인합니다.

# mysql -u root -p

그런 다음 원격 액세스 권한을 가진 사용자를 생성하고 몇 가지 권한을 부여합니다.

MariaDB [(none)]> create user 'haproxy'@'192.168.0.3'identified by 'aPassword';
MariaDB [(none)]> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'haproxy'@'192.168.0.3';
MariaDB [(none)]> FLUSH PRIVILEGES;

그런 다음 HAProxy 서버의 'haproxy' 계정을 사용해 보십시오.

# mysql -u haproxy --host 192.168.0.1 -p

이제 작동해야 합니다.또한 클러스터의 my.cnf에서 클러스터 서버와의 회선에는 실제 서버 이외의 주소가 포함되어 있습니다.

wsrep_cluster_address=gcomm://192.168.0.94,192.168.0.93

실제로 복사 및 붙여넣기의 아티팩트가 아닌 경우 구성과 일치하는지 확인하십시오.

행운을 빕니다.

언급URL : https://stackoverflow.com/questions/50667374/connection-issue-with-mariadb-and-haproxy-cluster

반응형