1. 程式人生 > >tomcat+nginx負載均衡群集

tomcat+nginx負載均衡群集

負載均衡群集


線上環境Nginx+Tomcat網站拓撲架構


技術分享













服務器軟件要求:

主機

IP地址

主要軟件

Nginx服務器

192.168.1.102

nginx-1.6.0.tar.gz

Tomcat1

192.168.1.100

1.jdk-7u65-linux-x64.gz

2.apache-tomcat-7.0.54.tar.gz

Tomcat2

192.168.1.101

1.jdk-7u65-linux-x64.gz

2.apache-tomcat-7.0.54.tar.gz


安裝並配置java環境:

技術分享


技術分享


技術分享//

java腳本導入環境變量並使其生效

技術分享


//檢查安裝版本

4.安裝配置tomcat

技術分享


//減壓文件後並生成apache-tomcat-7.0.54,移動到常用的/usr/local下並改名為tomcat7,

//啟動服務,檢查監聽端口

技術分享


5.設置javaweb站點:

1)首先在創建web目錄 2)在webapp1下建立一個index.jsp測試頁面

技術分享


進入tomcat配置文件中,/usr/local/tomcat7/conf/server.vml

技術分享

3)修改tomcatserver.xml文件:

<host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"

定義一個主機,域名為localhostappBase定義應用程序基準目錄,unpackWARs定義是否自動解壓,autoDeploy定義是否自動部署

<ContextdocBase="/web/webapp1" path=""reloadable="false">

</Context>

說明:context定義虛擬主機,path指定訪問目錄,docBase定義網頁目錄,當應用程序發生變化時候,自動裝載,不用重啟tomcat

技術分享

技術分享


4)重新啟動服務 Tomcat2 server同上

技術分享

6.nginx服務器配置:

nginx的配置,實現反向代理和負載均衡

(一)安裝nginx

1.安裝相關包

技術分享


2.創建程序用戶和組

技術分享


3.安裝nginx

技術分享

//--with-user,--with-group 指定用戶和組

//--with-file-aio 啟用文件修改支持

//--with-http_stub_status_module 啟用狀態統計

//-with-http_gzip_static_module 啟用gzip靜態壓縮

//ith-http_flv_module 啟用flv模塊,提供尋求內存使用基於時間的偏移量文件

//--with-http_ssl_module 啟用ssl模塊


(二)、配置nginx

技術分享

http {

........

upstream tomcat_server {

server 192.168.1.2:8080 weight=1;

server 192.168.1.3:8080 weight=1;

} //設定負載均衡的服務器列表,weight參數表示權限,權值越高被分到的概率越大

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html;

index index.html index.htm;

proxy_pass http://tomcat_server; //實現反向代理

}

技術分享

(三)、啟動nginx進程


/usr/local/nginx/sbin/nginx-c /usr/local/nginx/conf/nginx.conf


.內部測試反向代理與負載均衡測試

技術分享



技術分享

tomcat+nginx負載均衡群集