2019-06-13 13:50:21 1148瀏覽
今天千鋒扣丁學(xué)堂Linux培訓(xùn)老師給大家分享一篇關(guān)于如何輕松配置Nginx+Tomcat的集群和負(fù)載均衡的詳細(xì)介紹,首先Tomcat集群是當(dāng)單臺服務(wù)器達(dá)到性能瓶頸,通過橫向擴(kuò)展的方式提高整體系統(tǒng)性能的有效手段。Nginx是一個高性能的HTTP和反向代理web服務(wù)器,可以通過簡單的配置實現(xiàn)Tomcat集群的負(fù)載均衡。本文使用的Tomcat是8.5.35版本,Nginx是1.14.2版本。
http { ... #gzip on; #設(shè)置負(fù)載均衡的服務(wù)器列表和權(quán)重 upstream tomcat-ha { #ip_hash; server 172.31.1.41:8080 weight=1; server 172.31.1.42:8080 weight=1; } server { listen 8000; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; #轉(zhuǎn)發(fā)請求 proxy_pass http://tomcat-ha$request_uri; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } ... } }
<!-- channelSendOptions=6 同步復(fù)制 --> <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <!-- 集群 Session 管理器 --> <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/> <!-- <Manager className="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true"/> --> <!-- 集群內(nèi)部通信配置 --> <Channel className="org.apache.catalina.tribes.group.GroupChannel"> <Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime="3000"/> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.10.2" port="5000" selectorTimeout="100" maxThreads="6"/> <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter"> <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/> </Sender> <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> </Channel> <!-- 此 vavle 攔截請求,并將 Session 信息發(fā)給內(nèi)部節(jié)點(diǎn) --> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/> <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/> </Cluster>
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進(jìn)入Python全棧開發(fā)免費(fèi)公開課】
查看更多關(guān)于“Linux培訓(xùn)資訊”的相關(guān)文章>>