haproxy实验笔记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了haproxy实验笔记相关的知识,希望对你有一定的参考价值。

实验规划:

主机名IP地址角色
node01192.168.112.128web01
node02192.168.112.129web02
node03192.168.112.130haproxy

操作系统信息:

[[email protected] ~]# cat /etc/redhat-release 

CentOS release 6.6 (Final)

[[email protected] ~]# uname -a

Linux node03 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

[[email protected] ~]# 

安装haproxy:

[[email protected] ~]# yum -y install haproxy nginx php

安装nginx php:

[[email protected] ~]# yum -y install nginx

[[email protected] ~]# yum -y install nginx

node01和node02上nginx配置文件:

user  nginx;

worker_processes  4;


#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       mime.types;

    default_type  application/octet-stream;


server {

        listen       80;

        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {

            root   html;

            index  index.html index.htm;

        }

}


node03上haproxy和nginx配置文件

haproxy:

global

    log         127.0.0.1 local2


    chroot      /var/lib/haproxy

    pidfile     /var/run/haproxy.pid

    maxconn     4000

    user        haproxy

    group       haproxy

    daemon


    # turn on stats unix socket

    stats socket /var/lib/haproxy/stats


defaults

    mode                    http

    log                     global

    option                  httplog

    option                  dontlognull

    option http-server-close

    option forwardfor       except 127.0.0.0/8

    option                  redispatch

    retries                 3

    timeout http-request    10s

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 3000

listen s-monitor *:90

   mode http

   stats enable

   stats refresh 5s

   stats realm New0ldName

   stats uri /

   stats auth user:123456

frontend  main *:80

    acl url_static       path_beg       -i /static /images /javascript /stylesheets

    acl url_static       path_end       -i .jpg .gif .png .css .js


    use_backend static          if url_static

    default_backend             app


backend static

    balance     roundrobin

    server      static 127.0.0.1:8080 check


backend app

    balance     roundrobin

    server  app1 192.168.112.128:80 check

    server  app2 192.168.112.129:80 check

nginx配置文件:

user  nginx;

worker_processes  4;


#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

user  nginx;

worker_processes  4;


#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


#pid        logs/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       mime.types;

    default_type  application/octet-stream;


    #log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

    #                  ‘$status $body_bytes_sent "$http_referer" ‘

    #                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;


    #access_log  logs/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    #keepalive_timeout  0;

    keepalive_timeout  65;


    #gzip  on;


    server {

        listen       8080;

        server_name  localhost;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;

        root    /data/website/app;

        location / {

            #root   html;

            index  index.php index.html index.htm;

        }


        #error_page  404              /404.html;


        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }


本文出自 “平平淡淡才是真” 博客,请务必保留此出处http://ucode.blog.51cto.com/10837891/1880704

以上是关于haproxy实验笔记的主要内容,如果未能解决你的问题,请参考以下文章

Haproxy配合Nginx搭建Web集群部署实验

HAproxy+keepalived+nginx实验部署

小实验3:实现haproxy的增删查

HAProxy学习笔记

haproxy笔记之二:HAProxy简介

利用keepalived和haproxy配置mysql的高可用负载均衡