生活随笔
收集整理的這篇文章主要介紹了
HAProxy实现动静分离
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
環境背景:CentOS 7.2
實驗拓撲圖:
實驗配置:
#安裝nginx,因為我本地有nginx的rpm包,所以直接安裝的是本地的包
[root@localhost?~]#?ls
anaconda-ks.cfg??Documents??f1??ha????issue.out??Music????nginx-1.10.0-1.el7.ngx.x86_64.rpm??out?????phone?????Public??s1???????Templates??Videos
Desktop??????????Downloads??g1??haha??mail???????mysh.sh??num????????????????????????????????passwd??Pictures??qq??????shenfen??test
[root@localhost?~]#?yum?install?./nginx-1.10.0-1.el7.ngx.x86_64.rpm?
Loaded?plugins:?fastestmirror,?langpacks
Examining?./nginx-1.10.0-1.el7.ngx.x86_64.rpm:?1:nginx-1.10.0-1.el7.ngx.x86_64
./nginx-1.10.0-1.el7.ngx.x86_64.rpm:?does?not?update?installed?package.
Error:?Nothing?to?do
#配置主頁信息
[root@localhost?~]#?rm?/usr/share/nginx/html/index.html
rm:?remove?regular?file?‘/usr/share/nginx/html/index.html’??y
[root@localhost?~]#?vim?/usr/share/nginx/html/index.html<h1>Node2?Static?Page</h1>
#啟動nginx服務
[root@localhost?~]#?nginx
[root@localhost?~]#?ss?-tnl
State??????Recv-Q?Send-Q?????????????????????????????Local?Address:Port????????????????????????????????????????????Peer?Address:Port??????????????
LISTEN?????0??????64?????????????????????????????????????????????*:56300??????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:111????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:80?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:20048??????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:22?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????127.0.0.1:631????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:42681??????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????100????????????????????????????????????127.0.0.1:25?????????????????????????????????????????????????????????*:*??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
[root@localhost?~]#
#yum安裝httpd和php
[root@localhost?~]#?yum?install?httpd?php
Loaded?plugins:?fastestmirror,?langpacks
Repodata?is?over?2?weeks?old.?Install?yum-cron??Or?run:?yum?makecache?fast
base?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????|?3.6?kB??00:00:00?????
Determining?fastest?mirrors
Package?httpd-2.4.6-40.el7.centos.x86_64?already?installed?and?latest?version
Package?php-5.4.16-36.el7_1.x86_64?already?installed?and?latest?version
Nothing?to?do
#提供php測試頁
[root@localhost?~]#?vim?/var/www/html/index.php?<h1>Node1?Dynamic?Server<h1>
<?phpphpinfo();
?>
#啟動服務
[root@localhost?~]#?systemctl?start?httpd
[root@localhost?~]#?ss?-tnl
State??????Recv-Q?Send-Q?????????????????????????????Local?Address:Port????????????????????????????????????????????Peer?Address:Port??????????????
LISTEN?????0??????50?????????????????????????????????????????????*:3306???????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:22?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????127.0.0.1:631????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????100????????????????????????????????????127.0.0.1:25?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????127.0.0.1:6010???????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????64?????????????????????????????????????????????*:44421??????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????64????????????????????????????????????????????:::40360?????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128???????????????????????????????????????????:::80????????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128???????????????????????????????????????????:::22????????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128??????????????????????????????????????????::1:631???????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????100??????????????????????????????????????????::1:25????????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128??????????????????????????????????????????::1:6010??????????????????????????????????????????????????????:::*??????????????????
[root@localhost?~]#
#yum安裝haproxy
[root@localhost?haproxy]#?yum?install?haproxy
Loaded?plugins:?fastestmirror,?langpacks
Loading?mirror?speeds?from?cached?hostfile
Package?haproxy-1.5.14-3.el7.x86_64?already?installed?and?latest?version
Nothing?to?do
#修改配置文件62?#---------------------------------------------------------------------
#在frontend配置段做以下修改?63?frontend??main?*:80????????#將端口更改為8064?????acl?url_static???????path_beg???????-i?/static?/p_w_picpaths?/javascript?/stylesheets65?????acl?url_static???????path_end???????-i?.jpg?.gif?.png?.css?.js66?????acl?dynamic??????????path_end???????-i?.php????#以.php結尾的定義為dynamic67?????acl?static???????????path_end???????-i?.html???#以.html結尾定義為static68?????use_backend?dyna????????????if?dynamic????????#如果url匹配到dynamic則調度至dyna69?#????use_backend?static??????????if?url_static????#如果url匹配到static則調度至static70?????use_backend?static??????????if?static71?????default_backend?????????????static72?73?#---------------------------------------------------------------------74?#?static?backend?for?serving?up?p_w_picpaths,?stylesheets?and?such75?#---------------------------------------------------------------------76?backend?static???#定義后端主機10.1.53.11為static?????????????78?????server??????web2??10.1.53.11:8079?backend?dyna?????#定義后端主機10.1.0.53為dyna80?????server??????web1??10.1.0.53:8081?82?#---------------------------------------------------------------------
#啟動服務
[root@localhost?haproxy]#?systemctl?start?haproxy
[root@localhost?haproxy]#?ss?-tnl
State??????Recv-Q?Send-Q?????????????????????????????Local?Address:Port????????????????????????????????????????????Peer?Address:Port??????????????
LISTEN?????0??????128????????????????????????????????????????????*:80?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????????????*:22?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????127.0.0.1:631????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????100????????????????????????????????????127.0.0.1:25?????????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128????????????????????????????????????127.0.0.1:6010???????????????????????????????????????????????????????*:*??????????????????
LISTEN?????0??????128???????????????????????????????????????????:::22????????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128??????????????????????????????????????????::1:631???????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????100??????????????????????????????????????????::1:25????????????????????????????????????????????????????????:::*??????????????????
LISTEN?????0??????128??????????????????????????????????????????::1:6010??????????????????????????????????????????????????????:::*??????????????????
[root@localhost?haproxy]#
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????謝謝瀏覽...
轉載于:https://blog.51cto.com/dashui/1874045
總結
以上是生活随笔為你收集整理的HAProxy实现动静分离的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。