1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Expand nginx server using Haproxy

Discussion in 'Cluster Computing' started by ASTRAPI, Jun 30, 2012.

  1. #1
    Hello

    I am using a server with nginx and php-fpm and Mariadb using xcache and memcache :)

    Now i am thinking to get a second server and use it as web server using again the same setup nginx and php-fpm and Mariadb using xcache and memcache...

    Now i want to ask where i must install Haproxy and how it will work with existing data or the new data that users will upload how they will go on both servers so when Haproxy share requests on both servers to be able to respond?

    Is there any tutorial for this?

    On Google i found a few but i can't get how i will configure it so both servers will have same data ....

    Thank you
     
    ASTRAPI, Jun 30, 2012 IP
  2. st1905

    st1905 Well-Known Member

    Messages:
    573
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Ok, first of all you need, rsync+inotify to clone files to both servers, bi-directional or you may use lsyncd, it just does what you need, watch a directory and clone it when something is uploaded or deleted.

    http://code.google.com/p/lsyncd/

    Now for the haproxy part, its fairly easy to setup a loadbalancer,

    global
    #stats socket /var/run/haproxy.stat mode 666
            maxconn     8000
                    daemon
    nbproc 8
                    defaults
                            mode        http
                            option    httplog
                            option    dontlognull
                                    cookie      SERVERID insert nocache indirect
                                            clitimeout  60000
                                                    srvtimeout  30000
                                                            contimeout  8000
                                                                    option      httpclose
                                                                    option      forwardfor
                                                                    option redispatch
    
                                                                            maxconn     8000
    
                                                                            listen  http_proxy  loadbalancer_ip:82
                                                                                    stats enable
    stats scope    .
    mode http
    balance     roundrobin
    cookie whoopi_server1 insert indirect
                                                                                                    option      httpchk HEAD /index.php HTTP/1.1\r\nHost:\ domain.com
                                                                                                    option      httpclose
                                                                                                            option      forwardfor
                                                                                                                    server      server1 first_server_nginx:81 weight 1 maxconn 1500 cookie SERVER1 check
    
                                    server      server2 second_server_nginx:81 weight 1 maxconn 2500 cookie SERVER2 check
    Code (markup):
    An example haproxy.cfg for you to load balance your webservers. Notice the timeout values if you lower them you may get lots of 503 errors from haproxy, depending on your backend`s response.

    And, you asked where to install haproxy, of course you need to install it on the most reliable (Uptime performance) server you have. You could install haproxy on the same server within one of your webservers, for example, you may install haproxy on ip:82 and ip:81 would have nginx on same server(Both ips are same), you can do this by pre-routing port 80 responses to 82 with iptables where haproxy will listen for incoming connections.

    Ok there is one question though, will you use some kind of replication between your database servers or one database server will serve the requests ?
     
    Last edited: Jul 7, 2012
    st1905, Jul 7, 2012 IP