欢迎来到天天文库
浏览记录
ID:46595923
大小:141.06 KB
页数:5页
时间:2019-11-26
《负载均衡、高可用的 Web 集群》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第18章负载均衡、高可用的Web集群18.3架构的实现18.3.1Web服务器的安装及配置1.安装Apache2$sudoapt-getinstallapache22.修改apache2.conf$sudonano/etc/apache2/apache2.conf[...]#LogFormat"%h%l%u%t"%r"%>s%b"%{Referer}i""%{User-Agent}i""combinedLogFormat"%{X-Forwarded-For}i%l%u%t"%r"%>s%b"%{Refe
2、rer}i""%{User-Agent}i""combined[...]3.创建文件check.txt$sudotouch/var/www/check.txt4.修改虚拟主机配置$sudonano/etc/apache2/sites-available/default[...]SetEnvIfRequest_URI"^/check.txt$"dontlogCustomLog/var/log/apache2/access.logcombinedenv=!dontlog[...]$sudo/etc/init.d/ap
3、ache2restart18.3.2HAProxy的安装及配置1.安装HAProxy$sudoapt-getinstallhaproxy第18章负载均衡、高可用的Web集群2.配置haproxy.cfg$sudomv/etc/haproxy.cfg/etc/haproxy.cfg-back$sudonano/etc/haproxy.cfggloballog127.0.0.1local0log127.0.0.1local1noticemaxconn4096userhaproxygrouphaproxydefaultslog
4、globalmodehttpoptionhttplogoptiondontlognullretries3redispatchmaxconn2000contimeout5000clitimeout50000srvtimeout50000listenwebfarm192.168.1.14:80modehttpstatsenablestatsauthadmin:passwordbalanceroundrobincookieJSESSIONIDprefixoptionhttpcloseoptionforwardforoption
5、httpchkHEAD/check.txtHTTP/1.0serverwebA192.168.1.12:80cookieAcheckserverwebB192.168.1.13:80cookieBcheck3.修改/etc/sysctl.conf$sudonano/etc/sysctl.confnet.ipv4.ip_nonlocal_bind=1$sudosysctl-p4.让HAProxy自动启动$sudonano/etc/default/haproxy#SetENABLEDto1ifyouwanttheinitsc
6、ripttostarthaproxy.ENABLED=1#Addextraflagshere.#EXTRAOPTS="-de-m16"283最佳方案18.3.3Keepalived的安装及配置1.安装Keepalived$sudoapt-getinstallkeepalived2.配置Keepalived$sudonano/etc/keepalived/keepalived.confvrrp_scriptchk_haproxy{script"killall-0haproxy"interval2#每2秒钟检查一次weigh
7、t2}vrrp_instanceVI_1{interfaceeth0stateMASTERvirtual_router_id51priority101#101为“主”,100为“从”virtual_ipaddress{192.168.1.14}track_script{chk_haproxy}}$sudo/etc/init.d/keepalivedstart$sudonano/etc/keepalived/keepalived.confvrrp_scriptchk_haproxy{script"killall-0hapr
8、oxy"interval2#每2秒钟检查一次weight2}vrrp_instanceVI_1{interfaceeth0stateMASTERvirtual_router_id51priority100#101为“主”,100为“从”virtual_ipaddress{192.168.1.14}track_scri
此文档下载收益归作者所有