In the production environment, the MongoDB shards are built, providing three mongos interfaces. However, there is no failover mechanism in MongoDB, the official recommendation is to deploy MONGOs and application servers together, multiple application servers will deploy multiple MONGOs instances, which is inconvenient. Check it out, there are several ways to make these three mongos interfaces available, reducing the pressure on a single interface. Commonly used are LVS and haproxy. So try to do load balancing with Haproxy.
Haproxy is a high availability, load balancing, and proxy software based on TCP and HTTP applications, Haproxy is completely free, with Haproxy to provide fast and reliable proxy solutions based on TCP and HTTP applications. Haproxy is suitable for those Web sites that are heavily loaded, and these sites typically require session hold or seven-tier processing. Haproxy can support tens of thousands of concurrent connections, and Haproxy's operating mode makes it easy and secure to integrate into the architecture while protecting the Web server from being exposed to the network.
Start now, using the Ubuntu64-bit operating system
1. Install Haproxy on Ubuntu:
sudo apt-get install Haproxy
2. After installation, it is configured to boot from:
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 of the inside as:
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
The corresponding parameters inside are changed to your parameters.
4. Start Haproxy:
On the basis of MONGOs start up, run Haproxy, using the following command:
Haproxy-f/etc/haproxy/haproxy.cfg
Open your database client, link haproxy View results
650) this.width=650; "title=" Haproxy+mongos build a high-availability load balancer Mongodb-an_world-Wind Rain "alt=" Haproxy+mongos build high-availability load balancing Mongodb-an_ World-wind drizzle "src=" http://img0.ph.126.net/hnfwbCcO2EyDhi7cclX6yQ==/6631233791956632321.png "style=" border:0px; margin:0px 10px 0px 0px; "/>
For example, the first one is an interface to MONGOs, and the following is Haproxy
Here, you build up the Haproxy+mongos MongoDB frame, and use up to three mongos.
Report:
Start Haproxy:sudo/etc/init.d/haproxy Start
Restart Haproxy:sudo/etc/init.d/haproxy restart
Close Haproxy:sudo/etc/init.d/haproxy Stop
This article is from the "Black Time" blog, so be sure to keep this source http://blacktime.blog.51cto.com/11722918/1795306
Haproxy+mongos Building high-availability load-balanced MongoDB