日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql动静分离_haproxy的web服务负载均衡、动静分离、 MySQL服务负载均衡、状态监控...

發(fā)布時間:2023/12/10 数据库 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql动静分离_haproxy的web服务负载均衡、动静分离、 MySQL服务负载均衡、状态监控... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

實(shí)驗(yàn)環(huán)境:基于centos6.6

haproxy-Server:172.16.249.98 ?hostname:node1

upsteram server1:172.16.249.100 hostname:node2

upstream server2:172.16.249.99 ?hostname:node3

web服務(wù)的負(fù)載均衡以及狀態(tài)監(jiān)控:

設(shè)置記錄haproxy日志的文件位置:

node1:#vim?/etc/rsyslog.conf

(1)啟用UDP:

#?Provides?UDP?syslog?reception

$ModLoad?imudp

$UDPServerRun?514

(2)添加記錄日志的文件位置

#?Save?boot?messages?also?to?boot.log

local7.*????????????????????????????????????????????????/var/log/boot.log

local2.*???????????????????????????????????????????????/var/log/haproxy.log

#service?rsyslog?restart

node1:#yum?install?haproxy?-y

#cd?/etc/haproxy/

#cp?haproxy.cfg{,.bak}

#vim?haproxy.cfg#---------------------------------------------------------------------

#?Global?settings

#---------------------------------------------------------------------

global

#?to?have?these?messages?end?up?in?/var/log/haproxy.log?you?will

#?need?to:

#

#?1)?configure?syslog?to?accept?network?log?events.??This?is?done

#????by?adding?the?‘-r‘?option?to?the?SYSLOGD_OPTIONS?in

#????/etc/sysconfig/syslog

#

#?2)?configure?local2?events?to?go?to?the?/var/log/haproxy.log

#???file.?A?line?like?the?following?can?be?added?to

#???/etc/sysconfig/syslog

#

#????local2.*???????????????????????/var/log/haproxy.log

#

log?????????127.0.0.1?local2

chroot??????/var/lib/haproxy

pidfile?????/var/run/haproxy.pid

maxconn?????4000

user????????haproxy

group???????haproxy

daemon

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?????????????????30000

listen?stats???????????????#此段為設(shè)置狀態(tài)監(jiān)控

mode?http

bind?:8888?????????????????#生產(chǎn)環(huán)境中為保證安全性,為設(shè)置特殊端口,例如:8888

stats?enable

stats?hide-version

stats?uri?????/haproxyadmin?stats

stats?realm???Haproxy\?Statistics

stats?auth????admin:admin??????#設(shè)置用戶名以及密碼

stats?admin?if?TRUE

frontend?http-in

bind?*:80

mode?http

log?global

option?httpclose

option?logasap

option?dontlognull

capture?request??header?Host?len?20

capture?request??header?Referer?len?60

default_backend?servers

frontend?healthcheck

bind?:1099

mode?http

option?httpclose

option?forwardfor

default_backend?servers

backend?servers

balance?roundrobin

server?node2?172.16.249.100:80?check?maxconn?2000

server?node3?172.16.249.99:80?check?maxconn?2000#serivce?haproxy?start

node2,node3節(jié)點(diǎn)分別建立測試頁面,并啟動httpd服務(wù);node2:#vim?/var/www/html/index.html

?httpd?on?node2?

#service?httpd?start

node3:#vim?/var/www/html/index.html

?httpd?on?node3?

#service?httpd?start

打開瀏覽器:172.16.249.98:

打開瀏覽器:172.16.249.98:8888/haproxy?stats

動靜分離配置:

#vim /etc/haproxy/haproxy.cfg#---------------------------------------------------------------------

global

#?to?have?these?messages?end?up?in?/var/log/haproxy.log?you?will

#?need?to:

#

#?1)?configure?syslog?to?accept?network?log?events.??This?is?done

#????by?adding?the?‘-r‘?option?to?the?SYSLOGD_OPTIONS?in

#????/etc/sysconfig/syslog

#

#?2)?configure?local2?events?to?go?to?the?/var/log/haproxy.log

#???file.?A?line?like?the?following?can?be?added?to

#???/etc/sysconfig/syslog

#

#????local2.*???????????????????????/var/log/haproxy.log

#

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

frontend??main?*:80

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

acl?url_static???????path_end???????-i?.jpg?.gif?.png?.css?.js?.html?.txt?.htm

use_backend?static??????????if?url_static

default_backend?????????????app

backend?static

balance?????roundrobin

server??????node2?172.16.249.100:80?check

backend?app

balance?????roundrobin

server?node3?172.16.249.99:80?check#serivce?haproxy?start????#啟動haproxy服務(wù)

所有靜態(tài)頁面請求代理至node2節(jié)點(diǎn);所有動態(tài)頁面請求代理至node3節(jié)點(diǎn)。node2:#vim?/var/www/html/index.html

?httpd?on?node2?

#service?httpd?start

node3:#vim?/var/www/html/index.php

phpinfo();

?>

#service?httpd?start

打開瀏覽器:172.16.249.98/index.html

打開瀏覽器:172.16.249.98/index.php

負(fù)載均衡mysql服務(wù):

node1:#yum?install?mysql?-y

#vim?/etc/haproxy/haproxy.cfg#---------------------------------------------------------------------

global

#?to?have?these?messages?end?up?in?/var/log/haproxy.log?you?will

#?need?to:

#

#?1)?configure?syslog?to?accept?network?log?events.??This?is?done

#????by?adding?the?‘-r‘?option?to?the?SYSLOGD_OPTIONS?in

#????/etc/sysconfig/syslog

#

#?2)?configure?local2?events?to?go?to?the?/var/log/haproxy.log

#???file.?A?line?like?the?following?can?be?added?to

#???/etc/sysconfig/syslog

#

#????local2.*???????????????????????/var/log/haproxy.log

#

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????????????????????tcp

log?????????????????????global

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

frontend?bd

bind?:3306

default_backend?dbsrvs

backend?dbsrvs

balance?leastconn

server?node2?172.16.249.100:3306?check

server?node3?172.16.249.99:3306?check

listen?stats

bind?:80

mode?http

stats?enable

stats?uri?/haproxy?stats

stats?realm?haproxy\?stats

stats?auth?admin:admin

stats?admin?if?TRUE

分別在node2、node3節(jié)點(diǎn)建立數(shù)據(jù)庫,并授權(quán)可遠(yuǎn)程連接:

node2:#yum?install?mysql-server?-y

#serivce?mysqld?start

#mysql

node3:#yum?install?mysql-server?-y

#serivce?mysqld?start

#mysql

node1:#service?haproxy?restart??#重啟服務(wù),配置文件才能生效

#mysql?-uroot?-h172.16.249.98?-pmageedu

檢測:

node2:#mysql?-uroot?-pmageedu

node3:#mysql?-uroot?-pmageedu;

說明:由于我們在node1節(jié)點(diǎn)調(diào)用了數(shù)據(jù)庫并創(chuàng)建了表,node2節(jié)點(diǎn)查看有此表,node3節(jié)點(diǎn)無此表,因此我們剛才的測試中調(diào)用了node2節(jié)點(diǎn)的mysql數(shù)據(jù)庫而非node3節(jié)點(diǎn)。

原文:http://9612520.blog.51cto.com/9602520/1601566

總結(jié)

以上是生活随笔為你收集整理的mysql动静分离_haproxy的web服务负载均衡、动静分离、 MySQL服务负载均衡、状态监控...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。