Use HAproxy to separate dynamic and static data

Source: Internet
Author: User
Tags haproxy

HAProxy provides high availability, Server Load balancer, and TCP and HTTP application-based proxy. It supports Virtual Hosts and is a free, fast, and reliable solution. HAProxy is especially suitable for websites with extremely high loads, which usually require session persistence or layer-7 processing. HAProxy runs on current hardware and supports tens of thousands of concurrent connections. In addition, its running mode enables it to be easily and securely integrated into your current architecture, while protecting your web servers from being exposed to the network.


Lab environment: centos-6.4

HAproxy: 172.16.8.10 & 192.168.100.254

Node1: 192.168.100.1 static Server

Node2: 192.168.100.2 Dynamic Server

Through the front-end HAproxy reverse proxy upstream web Site Server, the effect of static and dynamic separation is achieved to improve the speed and security of the website!

Bytes -----------------------------------------------------------------------------------------

1. Now HAproxy installs and configures the front-end server

[root@haproxy ~]# yum install haproxy

2. After the installation is complete, check that all files are generated.

[root@haproxy ~]# rpm -ql   haproxy/etc/haproxy/etc/haproxy/haproxy.cfg/etc/logrotate.d/haproxy/etc/rc.d/init.d/haproxy/usr/bin/halog/usr/sbin/haproxy

3. Edit the HAproxy main configuration file and add the rules to the backend by proxy.

[Root @ haproxy] # vim haproxy. using Global log 127.0.0.1 local2 chroot/var/lib/haproxy pidfile/var/run/haproxy. pid maxconn 5000 maximum number of connections user haproxy service enables the daemon # turn on stats unix socket stats socket/var/lib/haproxy/stats, generally, no modifications are required. ---------------------------------------------------------------------- Defaults mode http use protocol log global log record option httplog detailed record http log option dontlognull do not record null log option http-server-close option forwardfor Login T 127.0.0.0/8 option redispatch retries 3 timeout http-request 10 s timeout queue 1 m timeout connect 10 s timeout client 1 m timeout server 1 m timeout http-keep-alive 10 s timeout check 10 s max Conn 30000 listen stats listener management background mode http service mode bind 172.16.8.10: 888 specify the IP address and port number stats enable status page stats hide-version does not display the header information stats uri/haproxyadmin? Stats access path stats realm Haproxy \ Statistics encryption mode stats auth admin: admin authenticated user and password stats admin if TRUEfrontend http-in listening front-end service bind *: port 80 mode http log global option httpclose option logasap option dontlognull capture request header Host len 20 capture request header Referer len 60 acl url_static path_beg-I/static/images/javascript/stylesheets/css CAL dynamic page acl url_static path_end-I. jpg. jpeg. gif. png. js matches Static Page use_backend static_servers if url_static matches default_backend dynamic_servers, which is assigned to the backend static_servers server by default. defines the static group balance roundrobin algorithm server web1 192.168.100.1 of the backend server: 80 check maxconn 8000 # server web2 192.168.100.2: 80 check maxconn 8000 backend dynamic_servers defines the dynamic group balance source Algorithm for backend servers # server web1 192.168.100.1: 80 check maxconn 2000 server web2 192.168.100.2: 80 check maxconn 2000

View the HAproxy server status graphic Management Interface

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/040F04T1-0.png "title =" o.png "alt =" 153031045.png"/>

Configure the static server to use apache on node1. for installation and configuration, refer to the previous blog

1. decompress the Forum package and put it in the access file directory to start the service.


[root@node1 ~]# unzip  JspRun\!_6.0.0_GBK.zip ^C[root@node1 ~]# cd  upload/*    /var/www/html/  -r^C[root@node1 ~]# service  httpd  start

2. Set up the tomcat service on node2. For details, refer to the previous blog

[Root @ node2 conf] # vim server. 

3. decompress the Forum program to the corresponding directory and start tomcat

[root@node1 ~]# unzip  JspRun\!_6.0.0_GBK.zip[root@node1 ~]# cd  upload/*    /web/app  -r[root@node2 ~]# catalina.sh  start

4. Start the HAproxy Service

[root@haproxy haproxy]# service haproxy start

5. Test stopping the static server and check whether static files are not displayed.

[root@node1 ~]# service  httpd  stopStopping httpd:                                            [  OK  ]


650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/040F03352-1.png "title =" v.png "alt =" 153709107.png"/>

7. Check whether the static server is normal when it is started

[root@node1 ~]# service  httpd  startStopping httpd:                                            [  OK  ]

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/040F04c2-2.png "title =" t.png "alt =" 153849367.png"/>

8. It seems that there is no problem. The separation is successful. 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/040F02A8-3.gif "alt =" j_0028.gif "/>

This article is from the "linux" blog, please be sure to keep this source http://gyulong.blog.51cto.com/6844383/1305108

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.