国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

爛泥:haproxy與nginx、zabbix集成

2024-06-28 14:32:47
字體:
來源:轉載
供稿:網友

本文由ilanniweb提供友情贊助,首發于爛泥行天下

想要獲得更多的文章,可以關注我的微信ilanniweb。

昨天介紹了haPRoxy的手機匹配規則,今天再來介紹下haproxy與nginx、zabbix的集成。接下來我會詳細介紹haproxy與nginx目錄瀏覽功能的集成,與zabbix集成我會把haproxy配置貼出來。

一、業務需求

由于業務需求,現在要把服務器上的部分目錄暴露出去,讓其它系統來調用暴露出去的文件,但是現在要求對外提供的還是80端口的http服務。

分析:

要達到上述的要求,首先我們要提供目錄瀏覽的功能,這個我們可以使用apache或者nginx的目錄瀏覽功能。在此,我們使用的是nginx的目錄瀏覽功能(即nginx的目錄索引功能)。

然后讓haproxy反向代理到nginx,就可以實現業務的需求。

二、nginx配置

nginx的安裝在此就不列出了,下面我們直接看nginx的配置文件。如下:

user nginx;

worker_processes 1;

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

events {

worker_connections 1024;

}

http {

include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;

keepalive_timeout 65;

gzip on;

server {

listen 8088;

server_name 127.0.0.1;

charset utf-8;

access_log /var/log/nginx/log/host.access.log main;

location /testnginx/ {

root /data/;

autoindex on;

}

}

}

clip_image001

nginx現在我們定義的是監聽8088這個端口,而且對外開放的是/data下的是testnginx這個目錄。

注意:這個對外的目錄名稱一定要記住,這個名稱我們在haproxy匹配規則中會使用到。

nginx配置完畢后,我們選擇來查看下起目錄瀏覽功能。如下:

http://http.ilanni.com:8088/testnginx/

clip_image002

通過上圖,我們可以很明顯的看出nginx的目錄瀏覽已經完全沒有問題。

三、haproxy配置

nginx配置完畢后,我們現在來配置haproxy。haproxy的配置就很簡單了。

只需要根據客戶端請求的url中匹配目錄的名稱即可。具體配置文件如下:

global

log 127.0.0.1 local0

log 127.0.0.1 local1 notice

maxconn 4096

uid 188

gid 188

daemon

tune.ssl.default-dh-param 2048

defaults

log global

mode http

option httplog

option dontlognull

option http-server-close

option forwardfor except 127.0.0.1

option redispatch

retries 3

option redispatch

maxconn 2000

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 admin_stats

bind 0.0.0.0:1080

mode http

option httplog

maxconn 10

stats refresh 30s

stats uri /stats

stats auth admin:admin

stats hide-version

frontend weblb

bind *:80

acl is_nginx url_beg /testnginx

acl is_http hdr_beg(host) http.ilanni.com

use_backend nginxserver if is_nginx is_http

use_backend httpserver if is_http

backend httpserver

balance source

server web1 127.0.0.1:8080 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3

backend nginxserver

balance source

server web1 127.0.0.1:8088 maxconn 1024 weight 3 check inter 2000 rise 2 fall 3

clip_image003

在haproxy配置文件中,我們定義了一個is_nginx規則,該規則匹配的是以testnginx目錄開始的url,然后把該規則轉發到后端的nginxserver服務器組,而nginxserver服務器組就是nginx服務器。

這樣就完成了nginx與haproxy集成。

注意:在這有一點一定要注意啦,haproxy匹配目錄的時候,后端的服務器組一定要存在該目錄,否則會報404錯誤的。這個是我踩過很多坑后才知道的。

四、測試集成功能

nginx與haproxy集成配置完畢后,我們選擇來訪問http://http.ilanni.com/testnginx/測試其功能,如下:

clip_image004

通過上圖,我們可以很明顯的看出haproxy已經完美的和nginx目錄瀏覽功能集成了。

五、haproxy與zabbix集成

前幾章節我們講解了haproxy與nginx進行集成的功能,在這一章節,我們再來介紹下haproxy與zabbix集成的功能。

zabbix在此我們是使用的yum方式進行安裝的,安裝完畢后apache監聽的是8099端口。訪問形式如下:

http://zabbix.ilanni.com:8099/zabbix/

clip_image005

現在要求直接使用80端口訪問zabbix,haproxy具體配置如下:

global

log 127.0.0.1 local0

log 127.0.0.1 local1 notice

maxconn 4096

uid 188

gid 188

daemon

defaults

log global

mode http

option httplog

option dontlognull

option http-server-close

option forwardfor except 127.0.0.1

option redispatch

retries 3

option redispatch

maxconn 2000

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 admin_stats

bind 0.0.0.0:1080

mode http

option httplog

maxconn 10

stats refresh 30s

stats uri /stats

stats auth admin:admin

stats hide-version

frontend weblb

bind *:80

acl is_lianzhou hdr_beg(host) zabbix.ilanni.com

acl is_zabbix url_beg /zabbix

use_backend zabbix if is_zabbix

backend zabbix

balance source

server web1 192.168.1.22:8099 maxconn 1024 weight 1 check inter 2000 rise 2 fall 3

haproxy配置很簡單,只需要定義一個is_zabbix的url匹配規則,然后分發到后端的服務器組即可。

還是需要注意的,匹配的目錄在后端服務器是存在的。

配置完畢后,訪問如下:

http://zabbix.ilanni.com/zabbix/

clip_image006

通過上圖,我們可以很明顯的看出haproxy與zabbix已經完美集成。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上栗县| 固原市| 宣化县| 石河子市| 天台县| 米林县| 军事| 栾川县| 昌邑市| 正定县| 平顶山市| 拉萨市| 临城县| 延寿县| 长葛市| 城固县| 松原市| 聂荣县| 温泉县| 威远县| 乐山市| 洪湖市| 招远市| 灯塔市| 金门县| 双流县| 巢湖市| 肃宁县| 宜丰县| 富民县| 新乐市| 铁岭县| 香河县| 凉山| 安新县| 莱西市| 清苑县| 鹤岗市| 宜黄县| 阿合奇县| 伊宁市|