亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

keepalived+haproxy搭建web群集

發布時間:2020-07-31 21:57:56 來源:網絡 閱讀:386 作者:張九冫 欄目:系統運維

haproxy配置文件詳解參考:haproxy

環境如下:

keepalived+haproxy搭建web群集

一、準備:

1、下載haproxy 軟件包,haproxy???提取碼: 9it6?

2、web 網站可以使用Apache、Nginx、搭建都可以,這里為了方便我就直接使用系統盤帶的httpd服務了。

web網站的搭建可參考:基于 Linux 安裝 web 服務及基本配置基于 Centos 7 搭建Nginx

3、配置防火墻放行流量

4、我這里使用的全部是centos 7系統,注意,該環境不是生產環境,若是在生產環境中,肯定還有后端存儲來存放網頁文件,web服務器讀取存儲服務器上的網頁返回給客戶端。這樣才可保證網頁內容的一致性。

二、開始搭建:

1、配置主服務器:

[root@haproxy1?/]#?yum?-y?install?pcre-devel?bzip2-devel?keepalived??????????#?安裝相關的依賴包和軟件包
[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位操作系統
[root@haproxy1?haproxy-1.5.19]#?mkdir?/etc/haproxy????????????????????#?創建用來存放主配文件的目錄
[root@haproxy1?haproxy-1.5.19]#?cp?examples/haproxy.cfg?/etc/haproxy/?????????????#?將編譯包中的主配文件復制到配置文件目錄,注意啊:這個配置文件是在編譯包中,注意看路徑
[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節點
????????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?????????????#?復制服務控制腳本
[root@haproxy1?/]#?ln?-s?/usr/local/sbin/haproxy?/usr/sbin/haproxy??????????????????#?創建鏈接使命令使用更方便
[root@haproxy1?/]#?chmod?+x?/etc/init.d/haproxy??????????????????????#?添加執行權限
[root@haproxy1?/]#?chkconfig?--add?/etc/init.d/haproxy????????????????#?添加為系統服務
[root@haproxy1?/]#?/etc/init.d/haproxy?start?????????????????#?啟動
Starting?haproxy?(via?systemctl):??????????????????????????[??OK??]
[root@haproxy1?/]#?vim?/etc/rsyslog.d/haproxy.conf??????????????#?配置日志文件,寫入如下內容
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?????????????????#?重啟日志服務

配置 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??????????#?主從調度器名稱區分開
}
vrrp_instance?VI_1?{
????state?MASTER
????interface?ens33??????????????#?修改網卡名稱
????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?????????????#?重啟服務使配置生效

2、配置從服務器:

[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/??????????#?圖個方便直接復制
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???????????#?復制服務控制腳本
[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?????????????????#?重啟服務使配置生效
[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???????????????#?主從調度器區分ID
}
vrrp_instance?VI_1?{
????state?BACKUP???????????????????????#?狀態修改為?BACKUP
????interface?ens33?????????????????
????virtual_router_id?51
????priority?90???????????????????????????#?優先級調低
????advert_int?1
????authentication?{
????????auth_type?PASS
????????auth_pass?1111
????}
????virtual_ipaddress?{
????????192.168.1.100????????????????#?漂移地址
????}
}
[root@haproxy2?/]#?systemctl?restart?keepalived

兩個web節點配置(兩個配置相同):

[root@web2 /]# yum -y install httpd


[root@web2 /]# echo server2.com > /var/www/html/index.html? ? ? ? ? # 創建測試網頁

[root@web2 /]# systemctl start httpd?

[root@web2 /]# systemctl enable httpd

keepalived+haproxy搭建web群集

keepalived+haproxy搭建web群集

當然,在實際生產環境中網頁是一樣的,這里我為了驗證出效果,所以做了兩個不同的測試文件。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

乾安县| 平舆县| 永仁县| 巨鹿县| 安康市| 内黄县| 巴林左旗| 昭觉县| 渑池县| 延吉市| 大邑县| 西乌珠穆沁旗| 宁国市| 康定县| 辉南县| 奉新县| 广元市| 陇南市| 台中市| 南康市| 石棉县| 前郭尔| 康马县| 道真| 建宁县| 永定县| 宁河县| 贵阳市| 白沙| 临夏县| 五华县| 郎溪县| 开阳县| 惠来县| 五家渠市| 宝鸡市| 牙克石市| 达日县| 三明市| 疏勒县| 林西县|