首先,安裝兩個tomcat,可以是同一個複製成兩個,也可以下載兩個不同版本的tomcat,我就是下載了兩個不同的版本。
(這是8.0版本的,隨便找兩個不是特別老的版本的就行)。
然後啟動兩個tomcat,在啟動前,先更改其中一個的端口號,使得兩個tomcat啟動時不會端口衝突,一個是本身的8080端口,一個是改成了9080端口。配好以後,打開cmd命令窗口,我的tomcat一個放在d:\software\apache-tomcat-8.5.24目錄下,按照如下命令即可啟動,啟動成功會彈出另一個窗口,顯示如下:
開啟瀏覽器,輸入http://localhost:9080/,出現下列介面即tomcat啟動成功。另一個採用同樣的步驟即可。
圖1:tomcat8 圖2:tomcat7
再之後,安裝一個nginx,我裝的是穩定版的nginx,下載位址:http://nginx.org/download/nginx-1.12.2.zip,解壓縮即可使用
##在啟動前,必須要對nginx進行一下設定才可實現負載平衡的功能,打開conf資料夾,下面有一個nginx.conf文件,配置如下:#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on;
upstream netitcast.com{ server 127.0.0.1:8080 weight=1; server 127.0.0.1:9080 weight=2; } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
location / { proxy_pass http://netitcast.com; proxy_redirect default; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the php scripts to apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_filename /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of ip-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # https server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:ssl:1m; # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!md5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
以上是nginx+tomcat怎麼實現Windows系統下的負載平衡的詳細內容。更多資訊請關注PHP中文網其他相關文章!