haproxy實驗筆記
實驗規劃:
主機名 | IP地址 | 角色 |
node01 | 192.168.112.128 | web01 |
node02 | 192.168.112.129 | web02 |
node03 | 192.168.112.130 | haproxy |
作業系統資訊:
1
2
3
4
5
|
[root@node03 ~] # cat /etc/redhat-release
CentOS release 6.6 (Final) [root@node03 ~] # 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
[root@node03 ~] #
|
安裝haproxy:
1
|
[root@node03 ~] # yum -y install haproxy nginx php
|
安裝nginx php:
1
2
|
[root@node01 ~] # yum -y install nginx
[root@node02 ~] # yum -y install nginx
|
node01和node02上nginx配置檔案:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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配置檔案:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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;
}
|
haproxy平滑重啟操作:
(1)如果是編譯安裝
1
|
[root@node03 ~] #/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.conf -sf `cat /usr/local/haproxy/var/run/haproxy.pid`
|
或者
1
|
[root@node03 ~] #/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.conf -st `cat /usr/local/haproxy/var/run/haproxy.pid`
|
(2)如果是yum安裝
1
|
[root@node03 ~] # /etc/init.d/haproxy reload
|
開啟日誌記錄:
編輯/etc/rsyslog.conf和/etc/sysconfig/syslog檔案
1
2
3
4
5
6
7
8
9
10
|
[root@~] # vim /etc/rsyslog.conf:
13 $ModLoad imudp #將註釋去除
14 $UDPServerRun 514 #將註釋去除
local3.* /var/log/haproxy .log #最下方新增
local0.* /var/log/haproxy .log #最下方新增
[root@~] #vi /etc/sysconfig/syslog
####################################### 把SYSLOGD_OPTIONS= "-m 0"
改成 SYSLOGD_OPTIONS= "-r -m 0"
####################################### |
相關解釋說明:
1
2
3
4
5
|
-r:開啟接受外來日誌訊息的功能,其監控514 UDP埠; -x:關閉自動解析對方日誌伺服器的FQDN資訊,這能避免DNS不完整所帶來的麻煩; -m:修改syslog的內部mark訊息寫入間隔時間(0為關閉),例如240為每隔240分鐘寫入一次"--MARK--"資訊; -h:預設情況下,syslog不會傳送從遠端接受過來的訊息到其他主機,而使用該選項,則把該開關開啟,所有 接受到的資訊都可根據syslog.conf中定義的@主機轉發過去 |
重啟rsyslog服務
1
|
[root@~] # systemctl restart rsyslog.service
|
本文轉自027ryan 51CTO部落格,原文連結:http://blog.51cto.com/ucode/1880704,如需轉載請自行聯絡原作者
相關文章
- lfs 6.3實驗筆記筆記
- KgCaptcha驗證碼實現筆記GCAPT筆記
- Mysql學習筆記-臨鍵鎖實驗MySql筆記
- 學習筆記:openstack實驗環境安裝筆記
- Redis學習筆記六:持久化實驗(AOF,RDB)Redis筆記持久化
- 《搭建個人Leanote雲筆記本》阿里雲體驗實驗室 教程筆記阿里
- HaProxy 實現 MySQL 負載均衡MySql負載
- haproxy
- C#滑動拼圖驗證碼實現筆記C#筆記
- CDH5大資料實驗平臺搭建筆記H5大資料筆記
- 讀書筆記:組合語言(王爽)實驗七筆記組合語言
- Vue筆記之props驗證Vue筆記
- Vue.js 滑動拼圖驗證碼實現筆記Vue.js筆記
- Docker筆記之Docker初體驗Docker筆記
- 套路雲ASK的體驗筆記筆記
- Haproxy搭建 Web 群集實現負載均衡Web負載
- [筆記]最佳實踐筆記
- ADB 實用筆記筆記
- 實用技巧筆記筆記
- Haproxy+Heartbeat 高可用叢集方案操作記錄
- 【日常筆記】生成驗證碼圖片筆記
- swoft 學習筆記之驗證器筆記
- haproxy和lvs
- HAProxy 配置教程
- RHEL 7配置HAProxy實現Web負載均衡Web負載
- Kubernetes基於haproxy實現ingress服務暴露
- Android 隨筆—— ConstraintLayout 實戰經驗AndroidAI
- 工作學習筆記(八)去重校驗筆記
- substrate學習筆記1:Substrate初體驗筆記
- 《Spring實戰》讀書筆記 #每日筆記 100-004Spring筆記
- SpringBoot + Spring Security 學習筆記(三)實現圖片驗證碼認證Spring Boot筆記
- 大資料實驗記錄大資料
- keepalived+haproxy實現mysql負載均衡高可用MySql負載
- haproxy-詳解
- 《演算法筆記上機實驗指南》第4章 入門篇(2)8.1演算法筆記
- SpringBoot + Spring Security 學習筆記(五)實現簡訊驗證碼+登入功能Spring Boot筆記
- 資料庫課程作業筆記 - 驗收資料庫筆記
- webpack4實操筆記Web筆記
- ThreadLoop實踐學習筆記threadOOP筆記