haproxy实验

实验1

部署discuz

1、  不做会话绑定 基于roundrobin

haproxy实验

—————————10.1.72.40|30——————————

安装环境,启动服务

[root@localhost ~]# yum -y install php php-fpm mariadb-server httpd

[root@localhost ~]# systemctl start httpd

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# cp -a upload/ /var/www/html/

[root@localhost ~]# cd /var/www/html/

测试服务器是否启动成功

haproxy实验

[root@localhost html]# setfacl  -Rm u:apache:rwx upload/           //给安装权限

更改php.ini的时区

创建数据库并授权

MariaDB [(none)]> create database discuz;

MariaDB [(none)]> grant all on discuz.* to 'user'@'localhost' identified by '123';

MariaDB [(none)]> grant all on discuz.* to 'user'@'127.0.0.1' identified by '123';

MariaDB [(none)]> grant all on discuz.* to 'user'@'%' identified by '123';

MariaDB [(none)]> flush privileges;

 

haproxy实验

haproxy实验

 

—————————–10.1.72.60—————————

63       frontend discuz

64         bind :80

 65         defa ult_backend app

 66

 67        backend app

 68         balance roundrobin

 69         maxconn 350

 70         server ser1 10.1.72.30:80 check maxconn 100 maxqueue 20

 71         server ser2 10.1.72.40:80 check maxconn 200 maxqueue 30

 72

 73      listen stats  *:9001

 74         stats enable

 75         stats uri /admin?stats

 76         stats realm "haproxy status"

 77         stats refresh 3s

 78         stats hide-version

 79         stats auth admin:123

 80         stats admin if LOCALHOST

haproxy实验

haproxy实验

 

2、  基于cookie的会话粘性,测试上传图片是否可以访问

frontend discuz

    bind :80

    default_backend app

 

backend app

    balance roundrobin

    maxconn 350

    cookie web insert indirect nocache

    server ser1 10.1.72.30:80 check cookie ser1 maxconn 100 maxqueue 20

        server ser2 10.1.72.40:80 check cookie ser2 maxconn 200 maxqueue 30

haproxy实验

haproxy实验

 

 

 

 

 

 

 

 

 

 

 

实验2

haproxy实验

—————————–10.1.72.40———————————

[root@localhost html]# systemctl start rpcbind

[root@localhost /]# mkdir /var/www/html/upload/data/attachment/forum

[root@localhost ~]# systemctl start nfs

[root@localhost ~]#setfacl –m u:apache:rwx /pic

[root@localhost ~]# vim /etc/exports

/var/www/html/upload/data/attachment/forum 10.1.0.0/16(rw,anonuid=48)

   Vim /etc/nginx/nginx.conf   

 location / {

    root /var/www/html;

        }

———————-10.1.72.30————————–

共享的nfs挂载到discuz上传的目录

[root@centos7 ~]# mount -t nfs 10.1.72.40:/var/www/html/upload/data/attachment/forum/ /var/www/html/upload/data/attachment/forum/

 

 

 

——————10.1.72.60————————–

frontend discuz

        bind :80

        acl static path_reg .*/data/attachment/forum.*

        use_backend upload if static

        default_backend app

backend app

        balance roundrobin

        maxconn 350

        cookie web insert indirect nocache

        server ser1 10.1.72.30:80 check cookie ser1 maxconn 100 maxqueue 20

 

backend upload

        balance roundrobin

        maxconn 350

        server ser1 10.1.72.40:80 check  maxconn 100 maxqueue 20

 

测试:

取消挂载,并刷新页面

———————-10.1.72.30———————

[root@centos7 upload]# umount /var/www/html/upload/data/attachment/forum/

haproxy实验

 

 

 

 

 

 

 

 

 

 

 

 

 

实验3

haproxy实验

 

——————————-10.1.72.50———————————–

[root@localhost varnish]# vim default.vcl

# This is an example VCL file for Varnish.

#

# It does not do anything by default, delegating control to the

# builtin VCL. The builtin VCL is called when there is no explicit

# return statement.

#

# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/

# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.

 

# Marker to tell the VCL compiler that this VCL has been adapted to the

# new 4.0 format.

vcl 4.0;

 

# Default backend definition. Set this to point to your content server.

backend default {

    .host = "10.1.72.40";

    .port = "80";

}

#probe health_check {

#       .url = "/";

#       .window = 5;

#       .threshold = 4;

#       .interval = 2s;

#       .timeout = 1s;

#}

#backend ser1 {

#    .host = "10.1.72.40";

#    .port = "80";

#    .probe = health_check;

#}

#import directors;

#sub vcl_init {

#    new sers = directors.random();

#    sers.add_backend(ser1);

#}

#acl client_purge {

#       "127.0.0.0"/8;

#       "10.1.72.60";

#}

sub vcl_purge {

        return(synth(200,"clean suss"));

}

sub vcl_recv {

 

# if (req.http.Authorization || req.http.Cookie) {

#        /* Not cacheable by default */

#        return (hash);

#    }

 

#       set req.backend_hint = sers.backend();

    # Happens before we check if we have this in cache already.

    #

    # Typically you clean up the request here, removing cookies you don't need,

    # rewriting the request, etc.

#    if (req.url ~ "^/") {

#       return(pass);

#       }

 #   if (req.method == "PURGE") {

#       if (client.ip ~ client_purge) {

#       return(purge);

#       } else {

#       return(synth(405,"not allow for "+client.ip));

#       }

#       }

#    if (req.url ~ "(?i)\.php$") {

#       } else {

#       set req.backend_hint = default;

#       }

}

sub vcl_deliver {

    if (obj.hits>0) {

        set resp.http.x-ache = "hit via "+server.ip;

        } else {

        set resp.http.x-cache = "miss via "+server.ip;

        }

}

 

sub vcl_backend_response {

    # Happens after we have read the response headers from the backend.

    #

    # Here you clean the response headers, removing silly Set-Cookie headers

    # and other mistakes your backend does.

                if (bereq.url ~ "(?i)\.(jpg|png|jpeg)$") {

                        unset beresp.http.Set-Cookie;

                        set beresp.ttl=10s;

                }

}

 

haproxy实验

—————————10.1.72.60———————————-

vim /etc/haproxy/haproxy.cfg

 

frontend discuz

        bind :80

        acl static path_reg .*/data/attachment/forum.*

        use_backend upload if static

        default_backend app

 

backend app

        balance roundrobin

        maxconn 350

        server ser1 10.1.72.30:80 check  maxconn 100 maxqueue 20

 

backend upload

        balance roundrobin

        maxconn 350

        server ser1 10.1.72.50:6081 check  maxconn 100 maxqueue 20

 

listen stats  *:9001

        stats enable

        stats uri /admin?stats

        stats realm "haproxy status"

        stats refresh 3s

        stats hide-version

        stats auth admin:123

        stats admin if LOCALHOST

 

—————————–10.1.72.40———————————

[root@localhost html]# systemctl start rpcbind

[root@localhost /]# mkdir /var/www/html/upload/data/attachment/forum

[root@localhost ~]# systemctl start nfs

[root@localhost ~]#setfacl –m u:apache:rwx /pic

[root@localhost ~]# vim /etc/exports

/var/www/html/upload/data/attachment/forum 10.1.0.0/16(rw,anonuid=48)

   Vim /etc/nginx/nginx.conf   

 location / {

    root /var/www/html;

        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

实验4

haproxy实验

————————————————–10.1.72.60———————————-

[root@centos7clean haproxy]# vim /etc/keepalived/keepalived.conf

global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

 

vrrp_instance VI_1 {

    state MASTER

    interface eno16777736

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        10.1.72.111

    }

}

 

Haproxy

vim haproxy.cfg

frontend discuz

        bind :80

        acl static path_reg .*/data/attachment/forum.*

        use_backend upload if static

        default_backend app

 

backend app

        balance roundrobin

        maxconn 350

        server ser1 10.1.72.30:80 check  maxconn 100 maxqueue 20

 

backend upload

        balance roundrobin

        maxconn 350

        server ser1 10.1.72.50:6081 check  maxconn 100 maxqueue 20

 

listen stats  *:9001

        stats enable

        stats uri /admin?stats

        stats realm "haproxy status"

        stats refresh 3s

        stats hide-version

        stats auth admin:123

        stats admin if TRUE

 

haproxy实验

 

日志:

修改/etc/rsyslog

开启udp 514号端口

haproxy实验

 

错误页:

frontend discuz

        bind :80

        acl static path_reg .*/data/attachment/forum.*

        use_backend upload if static

        default_backend app

        errorfile 503 /var/www/html/index.html

haproxy实验

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

原创文章,作者:landanhero,如若转载,请注明出处:http://www.178linux.com/59250

(0)
上一篇 2016-12-05 17:05
下一篇 2016-12-05 17:05

相关推荐

  • 子网掩码快速划分-心算

    问题状况: 不管作为一名网络工程师还是一名运维工程师,快速心算划分出网络掩码是必备得技能,      为什么要进行子网掩码划分? 纯二层环境不能隔离广播 有安全 管理方面的问题 解决办法:在二层环境下增加三层设备 将原本的一个主类网络号划分成多个子网     掩码基础知识:     注意:此步没记住不要往下进行     死记硬背1:     2^0=1   …

    Linux干货 2017-03-26
  • Bash Shell编程初学基础篇之一

     Bash Shell编程初学基础篇之一 说明: 本文仅供初学Linux  Bash  shell学员参考学习,大神们如有兴趣请批评指正!!!    相信对于很多Linux初学者或者仅仅是听说Linux还没有接触过的同学会有一种神秘感或者不敢碰触的感觉,今天就帮大家揭开它的神秘面纱,其实并没有那么深不可测,只…

    Linux干货 2015-03-29
  • 优云软件数据专家最佳实践:数据挖掘与运维分析

    这份研究报告,作者是优云软件数据专家陈是维,在耗时1年时间制作的一份最佳实践,今天和大家分享下,关于《数据采矿和运维分析》,共同探讨~ 数据挖掘(Data Mining)是从大量数据中提取或“挖掘”知识。 广义数据挖掘:数据挖掘是从存放在数据库、数据仓库或其它信息库中的大量数据挖掘有趣知识的过程。 数据挖掘技术侧重:1)概率与数理统计 2)数据库技术 3)人…

    大数据运维 2016-07-16
  • 数据结构应用详解-

    概述 最小生成树——无向连通图的所有生成树中有一棵边的权值总和最小的生成树 拓扑排序 ——由偏序定义得到拓扑有序的操作便是拓扑排序。建立模型是AOV网 关键路径——在AOE-网中有些活动可以并行地进行,所以完成工程的最短时间是从开始点到完成点的最长路径的长度,路径长度最长的路径叫做关键路径(Critical Path)。 最短路径——最短路径问题是…

    Linux干货 2015-04-07
  • 进程管理

    linux进程管理     内核的功能:进程管理、文件系统、网络管理、驱动程序、安全功能等     Pcrocess:运行中的程序的一个副本,是被载入内存中的一个指令集和         PID:进程…

    Linux干货 2016-09-12
  • Linux计划任务

    Linux任务计划 Linux任务计划、周期性执行任务 未来某一时间点执行一次任务:at,batch 周期性计划任务:crontab     默认执行结果会通过邮件形式发送给用户 本地电子邮件服务 smtp:Simple Mail Transfer Protocol,既简单邮件传输协议,主…

    Linux干货 2016-09-14