haproxy配置文件詳解參考:haproxy
成都創(chuàng)新互聯(lián)服務(wù)項目包括蘭考網(wǎng)站建設(shè)、蘭考網(wǎng)站制作、蘭考網(wǎng)頁制作以及蘭考網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,蘭考網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到蘭考省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!環(huán)境如下:
一、準(zhǔn)備:
1、下載haproxy 軟件包,haproxy???提取碼: 9it6?
2、web 網(wǎng)站可以使用Apache、Nginx、搭建都可以,這里為了方便我就直接使用系統(tǒng)盤帶的httpd服務(wù)了。
web網(wǎng)站的搭建可參考:基于 Linux 安裝 web 服務(wù)及基本配置;基于 Centos 7 搭建Nginx;
3、配置防火墻放行流量
4、我這里使用的全部是centos 7系統(tǒng),注意,該環(huán)境不是生產(chǎn)環(huán)境,若是在生產(chǎn)環(huán)境中,肯定還有后端存儲來存放網(wǎng)頁文件,web服務(wù)器讀取存儲服務(wù)器上的網(wǎng)頁返回給客戶端。這樣才可保證網(wǎng)頁內(nèi)容的一致性。
二、開始搭建:
1、配置主服務(wù)器:
[root@haproxy1?/]#?yum?-y?install?pcre-devel?bzip2-devel?keepalived??????????#?安裝相關(guān)的依賴包和軟件包 [root@haproxy1?media]#?tar?zxf?haproxy-1.5.19.tar.gz?-C?/usr/src/ [root@haproxy1?media]#?cd?/usr/src/haproxy-1.5.19/ [root@haproxy1?haproxy-1.5.19]#?make?TARHET=linux26??&&??make??install?????????#?編譯安裝,TARGET表示64位操作系統(tǒng) [root@haproxy1?haproxy-1.5.19]#?mkdir?/etc/haproxy????????????????????#?創(chuàng)建用來存放主配文件的目錄 [root@haproxy1?haproxy-1.5.19]#?cp?examples/haproxy.cfg?/etc/haproxy/?????????????#?將編譯包中的主配文件復(fù)制到配置文件目錄,注意?。哼@個配置文件是在編譯包中,注意看路徑 [root@haproxy1?/]#?vim?/etc/haproxy/haproxy.cfg? #?this?config?needs?haproxy-1.1.28?or?haproxy-1.2.1 global ????????log?/dev/log????local0?info ????????log?/dev/log????local0?notice ????????#log?loghost????local0?info ????????maxconn?4096 ????????#chroot?/usr/share/haproxy????????????????#?將此行注釋掉 ????????uid?99 ????????gid?99 ????????daemon ????????#debug ????????#quiet defaults ????????log?????global ????????mode????http ????????option??httplog ????????option??dontlognull ????????retries?3 ????????redispatch ????????maxconn?2000 ????????contimeout??????5000 ????????clitimeout??????50000 ????????srvtimeout??????50000 listen??webcluster??0.0.0.0:80?????????????????????????????#?將端口號修改為80,webcluster為群集名稱,可修改 ????????option??httpchk?GET??/index.html ????????balance?roundrobin????????????????????????????#?表示采用輪詢算法 ????????server??web1?192.168.1.20:80?check?inter?2000?fall?3??????????????????#?兩個web節(jié)點 ????????server??web2?192.168.1.30:80?check?inter?2000?fall?3 [root@haproxy1?/]#?cp?/usr/src/haproxy-1.5.19/examples/haproxy.init?/etc/init.d/haproxy?????????????#?復(fù)制服務(wù)控制腳本 [root@haproxy1?/]#?ln?-s?/usr/local/sbin/haproxy?/usr/sbin/haproxy??????????????????#?創(chuàng)建鏈接使命令使用更方便 [root@haproxy1?/]#?chmod?+x?/etc/init.d/haproxy??????????????????????#?添加執(zhí)行權(quán)限 [root@haproxy1?/]#?chkconfig?--add?/etc/init.d/haproxy????????????????#?添加為系統(tǒng)服務(wù) [root@haproxy1?/]#?/etc/init.d/haproxy?start?????????????????#?啟動 Starting?haproxy?(via?systemctl):??????????????????????????[??OK??] [root@haproxy1?/]#?vim?/etc/rsyslog.d/haproxy.conf??????????????#?配置日志文件,寫入如下內(nèi)容 if?($programname?==?'haproxy'?and?$syslogseverity-text?==?'info')?then?-/var/log/haproxy/haproxy-info.log &?~? if?($programname?==?'haproxy'?and?$syslogseverity-text?==?'notice')?then?-/var/log/haproxy/haproxy-notice.log &?~? [root@haproxy1?/]#?systemctl?restart?rsyslog.service?????????????????#?重啟日志服務(wù)配置 keepalived :
[root@haproxy1?/]#?vim?/etc/keepalived/keepalived.conf? !?Configuration?File?for?keepalived 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?LVS1??????????#?主從調(diào)度器名稱區(qū)分開 } vrrp_instance?VI_1?{ ????state?MASTER ????interface?ens33??????????????#?修改網(wǎng)卡名稱 ????virtual_router_id?51 ????priority?100 ????advert_int?1 ????authentication?{ ????????auth_type?PASS ????????auth_pass?1111 ????} ????virtual_ipaddress?{? ????????192.168.1.100??????????#?填寫漂移地址 ????} } [root@haproxy1?/]#?systemctl?restart?keepalived?????????????#?重啟服務(wù)使配置生效2、配置從服務(wù)器:
[root@haproxy2?/]#??yum?-y?install?pcre-devel?bzip2-devel??keepalived [root@haproxy2?media]#?tar?zxf?haproxy-1.5.19.tar.gz?-C?/usr/src/ [root@haproxy2?media]#?cd?/usr/src/haproxy-1.5.19/ [root@haproxy2?haproxy-1.5.19]#?make?TARGET=linux26?&&?make?install [root@haproxy2?haproxy-1.5.19]#?mkdir?/etc/haproxy [root@haproxy2?haproxy-1.5.19]#?scp?root@192.168.1.10:/etc/haproxy/haproxy.cfg?/etc/haproxy/??????????#?圖個方便直接復(fù)制 root@192.168.1.10's?password:? haproxy.cfg??????????????????????????????????????????100%??570?????0.6KB/s???00:00???? [root@haproxy2?/]#?cp?/usr/src/haproxy-1.5.19/examples/haproxy.init?/etc/init.d/haproxy???????????#?復(fù)制服務(wù)控制腳本 [root@haproxy2?/]#?ln?-s?/usr/local/sbin/haproxy?/usr/sbin/haproxy [root@haproxy2?/]#?chmod?+x?/etc/init.d/haproxy? [root@haproxy2?/]#?chkconfig?--add?/etc/init.d/haproxy? [root@haproxy2?/]#?/etc/init.d/haproxy?start? Starting?haproxy?(via?systemctl):??????????????????????????[??OK??] [root@haproxy2?/]#?scp?root@192.168.1.10:/etc/rsyslog.d/haproxy.conf?/etc/rsyslog.d/ root@192.168.1.10's?password:? haproxy.conf?????????????????????????????????????????100%??226?????0.2KB/s???00:00??? [root@haproxy2?/]#?systemctl?restart?rsyslog.service?????????????????#?重啟服務(wù)使配置生效 [root@haproxy2?haproxy-1.5.19]#?scp?root@192.168.1.10:/etc/keepalived/keepalived.conf?/etc/keepalived/ root@192.168.1.10's?password:? keepalived.conf??????????????????????????????????????100%?3511?????3.4KB/s???00:00???? [root@haproxy2?/]#?vim?/etc/keepalived/keepalived.conf????????????#?修改主配置文件,修改如下幾個部分 .......................?省略部分 ???router_id?LVS2???????????????#?主從調(diào)度器區(qū)分ID } vrrp_instance?VI_1?{ ????state?BACKUP???????????????????????#?狀態(tài)修改為?BACKUP ????interface?ens33????????????????? ????virtual_router_id?51 ????priority?90???????????????????????????#?優(yōu)先級調(diào)低 ????advert_int?1 ????authentication?{ ????????auth_type?PASS ????????auth_pass?1111 ????} ????virtual_ipaddress?{ ????????192.168.1.100????????????????#?漂移地址 ????} } [root@haproxy2?/]#?systemctl?restart?keepalived兩個web節(jié)點配置(兩個配置相同):
[root@web2 /]# yum -y install httpd
[root@web2 /]# echo server2.com > /var/www/html/index.html? ? ? ? ? # 創(chuàng)建測試網(wǎng)頁
[root@web2 /]# systemctl start httpd?
[root@web2 /]# systemctl enable httpd
當(dāng)然,在實際生產(chǎn)環(huán)境中網(wǎng)頁是一樣的,這里我為了驗證出效果,所以做了兩個不同的測試文件。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享標(biāo)題:keepalived+haproxy搭建web群集-創(chuàng)新互聯(lián)
鏈接URL:http://muchs.cn/article32/ceespc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、建站公司、外貿(mào)網(wǎng)站建設(shè)、虛擬主機(jī)、靜態(tài)網(wǎng)站、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容