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.www58058.com/59250

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

相關推薦

  • 第五周作業

    1、顯示當前系統上root、fedora、或user1用戶的默認shell;          [root@yangjifeng~]# grep -E “^(root|fedora|user1)\>” /etc/passwd | cut -d: -f…

    Linux干貨 2017-09-04
  • Linux小工具之cheat

    隨著linux學習的深入,接觸到的命令越來越多,此時,考驗腦力的時候就到了,除非你是”腦王”,否則面對多如牛毛的linux命令,真的會崩潰!linux前輩們貌似也被同樣的問題所困擾,所以,他們發明了cheat。cheat是在GNU通用公共許可證下,為Linux命令行用戶發行的交互式備忘單應用程序。它提供顯示Linux命令使用案例,包括該命令所有的選項和簡短但…

    2017-08-10
  • N25 the second week

    1.文件管理命令 1.1.cat concatenate files and print on the standard output # 正序打印文件 cat [OPTION]… [FILE]… # 常用參數 -n 編號顯示每行 -E 顯示每行的結束符 1.2.tac concatenat…

    Linux干貨 2016-12-19
  • 文件歸檔,shell循環和函數運用

    文件歸檔 tar (1)  創建歸檔 tar -c -f / PATH/TO/SOMEFILE .tar FILE… tar cf / PATH/TO/SOMEFILE .tar FILE… (2)  查看歸檔文件中的文件列表 tar -t -f  /PATH/TO/SOMEFILE .tar (3) &…

    Linux干貨 2016-08-21
  • Linux的哲學思想

    Linux的哲學思想 一切皆文件  幾乎把所有的資源系統抽象為文件形式:包括硬件設備,甚至通信接口等 由眾多功能單一的程序組成:一個程序只做一件事,并且做好;組合小程序完成復雜任務  力求使程序精簡凝練,出現地完成最核心的需求;盡量避免使其膨脹成為一個臃腫的程序,致使大部分代碼很少被需要和執行。 小程序易于理解,維護,消耗系統資源較少,易…

    Linux干貨 2017-07-03
  • 從Linux小白到大牛——與狼共舞的日子11

    馬哥教育網絡班21期+第10周課程練習 1、詳細描述一次加密通訊的過程,結合圖示最佳。 加密過程 1.使用單向加密算法,提取A的文件的特征碼。 2.使用A的私鑰對提取出來的特征碼進行加密,把加密后的特征碼附加在A的文件的后面。 3.使用對稱加密對剛剛的A的文件和加密后的特征碼進行加密,生成對稱加密密鑰 4.使用B的公鑰對第3步驟的對稱加密的密鑰進行加密,加密…

    Linux干貨 2016-12-05
欧美性久久久久