首頁  >  文章  >  後端開發  >  nginx+tomcat負載平衡

nginx+tomcat負載平衡

WBOY
WBOY原創
2016-07-29 09:16:18994瀏覽

一、環境介紹

1.這次實驗共3台虛擬機(rhel6.2-64)

    168.232.154(tomcat)

     192.168.232.155(tomcat)

2.安裝並設定JDK

3.設定相關環境變數(proweb,K

3.設定相關環境變數(prowebfile,均衡,本次實驗用一以前寫的權限管理的模組

二、安裝配置tomcat

1.在192.168.232.154,192515253. 2.下載一個linux版本的apache-tomcat-7.0.64.tar.gz解壓縮即可用

3.在標籤裡添加

<Context  path="" docBase="/root/webapps/permission" reloadable="false"/>
4.創建/root/webapps目錄,然後把這個目錄web專案放到目錄下,啟動tomcat,訪問

http://192.168.232.154:8080/ ,

http://192.168.232.154:8080/

http://192.168.232.154:8080/http://192.168.232.154:8080/ 三、安裝配置Nginx

1.下載nginx-1.2.6.tar.gz 並解壓放到指定的目錄下

2.確保nginx編譯所具備的運行環境

2.確保nginx編譯所具備的運行環境

3. pcre-devel openssl openssl-devel

(1)設定本機yum,讓yum安裝時能找到安裝包

(2)安裝:yumopeny install pcre-de

4.建立www使用者:useradd www

5.準備編譯安裝環境

./configure --user=www --group=www --prefix=/usr/local/nginx with-http_stub_status_module --with-http_ssl_module

6.編譯安裝,進到nginx解壓的根目錄:cd /root/app/nginx-1.2.6 7.檢查nginx安裝是否成功

[root@storm1 nginx-1.2.6]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file/usr/local/nginx/ngx .conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful


8.訪問nginx預設首頁:http://192.18.

8.訪問nginx預設首頁:http://192.18.3838到nginx歡迎主頁

到此Nginx安裝完畢

四、配置nginx+tomcat集成,其實只需配置nginx,tomcat1./




/local/nginx,把nginx.conf簡單的改成如下

user  www www;
worker_processes  1;
pid     /usr/local/nginx/logs/nginx.pid;
events {
    use epoll;
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    include     /usr/local/nginx/conf/proxy.conf;
    sendfile        on;
    tcp_nopush      on;
    keepalive_timeout  65;
    log_format  $upstream_addr  $status $request_time   $time_local     $remote_user    $http_user_agent;
    upstream panguoyuan.com {
      server  192.168.232.154:8080;
      server  192.168.232.155:8080;
                }

        server{
            listen 80;
            server_name panguoyuan.com;
            location / {
                proxy_pass         http://panguoyuan.com;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
        }
}
2.在192.168.232.147機器上的hostsd

.232.147 storm1192.168.232.154 storm2

192.168.232.155 storm3

192.168.232.147 panguoyuan.com

版權聲明:本文為博主原創文章,未經博主允許不得轉載。

以上就介紹了nginx+tomcat負載平衡,包括了方面的內容,希望對PHP教程有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn