1. 程式人生 > >利用nginx搭建tomcat叢集

利用nginx搭建tomcat叢集

一、安裝tomcat

tomcat安裝不做介紹,在每臺伺服器上都安裝tomcat即可!

二、安裝nginx

yum安裝nginx

三、修改nginx的配置檔案

yum安裝後,nginx的配置檔案在/etc/nginx下面

可以執行指令:

vim /etc/nginx/nginx.conf

修改為:

 
 user  nginx;
 worker_processes  1;
   
 error_log  /var/log/nginx/error.log warn;
 pid        /var/run/nginx.pid;

 events {
     worker_connections  1024;
 }
 
 
 http {
     include       /etc/nginx/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  /var/log/nginx/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
     keepalive_timeout  65;
 
    #gzip  on;

     include /etc/nginx/conf.d/*.conf;
         upstream 名字{
                 server  192.168.30.101:8080 weight=1;
                 server  192.168.30.102:8080 weight=3;
                 server  192.168.30.103:8080 weight=3;
         }
 
         server {
                 listen  監聽埠號;
                 server_name     域名;
 
 
                 location / {
                         proxy_pass http://名字;
                         proxy_redirect default;
                 }
         }
 }

注意:upstream後面的名字要與proxy_pass的的名字對應起來。

之後在每臺伺服器上都啟動tomcat,訪問你的域名加埠號就實現nginx部署tomcat叢集了!

nginx較為詳細的配置請點選 ↓

nginx的詳細配置

-------------------------------------------------------------------------------------------------------------------

外加一個啟動tomcat時實時檢視日誌的指令

./startup.sh | tail -f ../logs/catalina.out