Link Search Menu Expand Document

HAProxy Installation

Document guides through the installation and configuration of the HAProxy service which is required to route ClickHouse request to MongoDB’s current master instance.

Installation

VM Requirements

  • Separate VM
  • RAM: 1 GB
  • Storage: 10 GB

Steps

  1. Install version 1.8.8,
  2. Make it accessible by IP address from the networks where ClickHouse instances located. Also configure firewall to allow access to a proxy port 27017 of this VM

Configuration

Change /etc/haproxy/haproxy.cfg contents to contain:

listen mongodb_cluster
 bind [vm_ip]:[vm_port]
 log 127.0.0.1 local0
 option tcp-check
 # MongoDB Wire Protocol
 tcp-check send-binary 3a000000 # Message Length (58)
 tcp-check send-binary EEEEEEEE # Request ID (random value)
 tcp-check send-binary 00000000 # Response To (nothing)
 tcp-check send-binary d4070000 # OpCode (Query)
 tcp-check send-binary 00000000 # Query Flags
 tcp-check send-binary 61646d696e2e # fullCollectionName (admin.$cmd)
 tcp-check send-binary 24636d6400 # continued
 tcp-check send-binary 00000000 # NumToSkip
 tcp-check send-binary FFFFFFFF # NumToReturn
 # Start of Document
 tcp-check send-binary 13000000 # Document Length (19)
 tcp-check send-binary 10 # Type (Int32)
 tcp-check send-binary 69736d617374657200 # ismaster:
 tcp-check send-binary 01000000 # Value : 1
 tcp-check send-binary 00 # Term

tcp-check expect binary 69736d61737465720001 #ismaster True

option tcpka
 option tcplog
 log global
 server mongo-node-01 [mongodb_ip_1]:[mongodb_port_1] check inter 2000
 server mongo-node-02 [mongodb_ip_2]:[mongodb_port_1] check inter 2000
 server mongo-node-03 [mongodb_ip_3]:[mongodb_port_1] check inter 2000

Here are suggestions for the dummy values:

  • [vm_ip] (e.g. 10.111.0.1) - HAProxy VM IP address to listen on
  • [vm_port] (e.g. 27017) - HAProxy VM port to listen ClickHouse requests on [mongodb_ip_1]/[mongodb_ip_2]/[mongodb_ip_3] (e.g. 10.112.0.1, 10.112.0.2, 10.112.0.3) - IP addresses of MongoDB instances.
  • [mongodb_port_1]/[mongodb_port_2]/[mongodb_port_3] (e.g.27017`) - Ports of MongoDB instances respectively If you have more than 3 MongoDB replicas, add them too.