Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Building highly available load balancer mongodb with HAProxy+mongos

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In the production environment, the built mongodb slicing provides three mongos interfaces. However, there is no failover mechanism in mongodb. It is officially recommended that mongos and application servers be deployed together, and multiple mongos instances should be deployed by multiple application servers, which is very inconvenient. Check that there are several ways to make use of all three mongos interfaces to reduce the pressure on a single interface. The commonly used ones are LVS and HAProxy. So try to use HAProxy for load balancing.

HAProxy is a proxy software that provides high availability, load balancing and based on TCP and HTTP applications. HAProxy is completely free. With the help of HAProxy, you can quickly and reliably provide proxy solutions based on TCP and HTTP applications. HAProxy is suitable for heavily loaded web sites, which usually require session persistence or seven-tier processing. HAProxy can support tens of thousands of concurrent connections, and the operation mode of HAProxy makes it easy and secure to integrate into the architecture, while protecting web servers from being exposed to the network.

Start now, using the Ubuntu64 bit operating system

1. Install HAproxy on Ubuntu:

Sudo apt-get install haproxy

two。 After installation, configure to boot:

Sudo vim / etc/default/haproxy

Change ENABLE=0 to ENABLE=1 save exit

3. Configure haproxy:

Sudo vim / etc/haproxy/haproxy.cfg, modify the contents as follows:

Global

Chroot / data/app_platform/haproxy/share/

User root

Group root

Pidfile / var/run/haproxy.pid

Nbproc 1

Stats socket / tmp/haproxy level admin

Stats maxconn 20

Node master_loadbalance1

Description lb1

Maxconn 65536

Nosplice

Spread-checks 3

Defaults

Log global

Mode tcp

Option abortonclose

Option allbackups

Option tcpka

Option redispatch

Retries 3

Timeout check 60s

Timeout connect 600s

Timeout queue 600s

Timeout server 600s

Timeout tarpit 60s

Timeout client 600s

Frontend mongos_pool 0.0.0.0:28018

Mode tcp

Maxconn 32768

No option dontlognull

Option tcplog

Log global

Option log-separate-errors

Default_backend mongos_pool

Backend mongos_pool

Mode tcp

Balance source

Default-server inter 2s fastinter 1s downinter 5s slowstart 60s rise 2 fall 5 weight 30

Server gintama-xxx-mongos1 172.16.2.230:27017 check maxconn 30000

Server gintama-xxx-mongos2 172.16.2.231:27017 check maxconn 30000

Server gintama-xxx-mongos3 172.16.2.232:27017 check maxconn 30000

Change the corresponding parameters inside to your parameters.

4. Start haproxy:

Based on the startup of mongos, run haproxy, using the following command:

Haproxy-f / etc/haproxy/haproxy.cfg

Open your database client and link to haproxy to view the results

As shown in the figure above, the first is an interface of mongos, and the following is haproxy

At this point, you have set up the mongodb framework of haproxy+mongos and used all three mongos.

Attached:

Start haproxy:sudo / etc/init.d/haproxy start

Restart haproxy:sudo / etc/init.d/haproxy restart

Close haproxy:sudo / etc/init.d/haproxy stop

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report