Haproxy static and dynamic Separation

Source: Internet
Author: User
Tags haproxy rsyslog

Haproxy: Server Load balancer scheduler that works on the ISO 7 layer to provide Web Services Based on HTTP protocol (or work on the ISO 4 layer based on TCP protocol)

Configuration file/etc/haproxy. cfg

Configuration File

Global settings: Set the attributes of the haproxy process ---------- global settings Section

Proxies: proxy settings ----------------- proxy settings

defaults

frontend

backend

listen

Among them, ults provides default attributes for proxies. frontend accepts client requests and backend connects to the backend upstream server (similar to nginx upstream). Listen is a combination of specific frontend and backend.

Define a complete proxy method:

  frontend

  backend

  listen

  Defaults segment Analysis

  Option httpclose: Use a short connection

  Option redispath: use cookie to maintain the session. If the backend server is down, use redispath to redirect another path to continue the session;

  Option http-server-close: When keep-alive times out, use this option to close the session on the server.

  Timeout CONNECT: The waiting duration when haproxy forwards data to the backend upstream server.

  Timeout client: timeout duration of the client's inactive status

  Timeout server: haproxy maintains a session with the backend server segment. When the backend server is down, haproxy waits for timeout.

  Timeout-keep-alive: defines the timeout duration of the connection persistence mode.

 Timeout-check: the timeout time for establishing status detection.

  Maxconn: Maximum number of concurrent connections per server

Lab environment:

3 virtual machines

Haproxy dual NIC: Public Network: 172.16.17.3

Intranet: 192.168.17.1

Upstream Server 1: 192.168.17.11

Upstream Server 2: 192.168.17.12

Configure the game servers on two platforms to provide the configuration page and test:

Install and configure haproxy for 172.16.17.3

Enable global Logging

Edit rsyslog. conf

#vim  /etc/rsyslog.conf  
  # Provides UDP syslog reception
  $ModLoad imudp
  $UDPServerRun 514
  # Provides TCP syslog reception
  $ModLoad imtcp
  $InputTCPServerRun 514


In another row

  local2.*           /var/log/haproxy.log

#service rsyslog restart 


# vim  /etc/haproxy/haproxy.cfg 

log         127.0.0.1 local2

# Service haproxy restart the service

Implementation of haproxy dynamic/static Separation

Install PHP on node2 Server

yum -y install php php-mysql

Provide PHP dynamic pages



Configure the haproxy configuration file
# Vim/etc/haproxy. cfg
Frontend websrvs
Bind *: 80
ACL url_static path_beg-I/static/images/JavaScript/stylesheets
ACL url_static path_end-I. jpg. gif. PNG. CSS. js. html
ACL host_static hdr_beg (host)-I IMG. Video. Download. FTP. imags. Videos.
ACL url_php path_end-I. php
Use_backend static if url_static or host_static
Use_backend dynamic if url_php
Default_backend dynamic
Backend static
Balance roundrobin
Server node1 192.168.17.11: 80 check maxconn 30000

Backend dynamic
Balance roundrobin
Server node2 192.168.17.12: 80 check maxconn 1000
# Service haproxy restart
Static/dynamic separation test on the client

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/F7/wKiom1QgQBjC50pJAACtJ9FycAI591.jpg "Title =" image 003.png" alt = "wkiom1qgqbjc50pjaactj9fycai591.jpg"/> static resource requests sent to node node1

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/49/F9/wKioL1QgQGKj3o4RAAB782VSJa0540.jpg "Title =" image 004.png" alt = "wkiol1qgqgkj3o4raab782vsja0540.jpg"/> static resource requests sent to node node2


Haproxy static and dynamic Separation

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.