Centos7+nginx+tomcat 叢集部署實戰
1:安裝centos7(連結:http://pan.baidu.com/s/1o80x36a 密碼:xuwb),安裝步驟自己百度,並克隆4個虛擬機器
我的ip為(192.168.72.129 192.168.72.130 192.168.72.131 192.168.72.132)
2:下載xshell,連線上這四臺linux
3:在192.168.72.129安裝nginx(連結:http://pan.baidu.com/s/1skAQ3X7 密碼:lwrz)
安裝步驟:先在192.168.72.129建立資料夾
------------------------nginx開始安裝---------------------------
cd /usr/local
mkdir software/nginx
cd /usr/local/software/nginx
rz 這裡把下載好的nginx複製到/usr/local/software/nginx目錄下,
tar -xzvf nginx-1.8.1.tar.gz
cd /usr/local/software/nginx/nginx-1.8.1
./configure
這裡會報錯,一些包找不到
安裝缺失的包
yum -y install pcre-devel
yum -y install openssl-devel
安裝完成後執行
./configure
make
make install
測試nginx
cd /usr/local/nginx/sbin
./nginx -t
啟動nginx
./nginx
訪問nginx 192.168.72.129:80
--------------------nginx安裝完成-----------------------
4:4個機器上安裝tomcat,並分別部署測試專案(連結:http://pan.baidu.com/s/1i4VzLtF 密碼:qnxv)
安裝步驟略
5:修改nginx配置檔案
#user nobody;
#啟動程序,通常設定成和cpu的數量相等
worker_processes 1;
#全域性錯誤日誌及PID檔案
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
#epoll是多路複用IO(I/O Multiplexing)中的一種方式,但是僅用於linux2.6以上核心,可以大大提高nginx的效能
use epoll;
#單個後臺worker process程序的最大併發連結數
worker_connections 1024;
}
#設定http伺服器,利用它的反向代理功能提供負載均衡支援
http {
#設定mime型別,型別由mime.type檔案定義
include mime.types;
default_type application/octet-stream;
#設定日誌格式
#設定負載均衡的伺服器列表
upstream tomcat {
#weigth引數表示權值,權值越高被分配到的機率越大
server 192.168.72.129:8080 weight=1 max_fails=1 fail_timeout=30s;
server 192.168.72.130:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.72.131:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.72.132:8080 weight=1 max_fails=2 fail_timeout=30s;
}
#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;
server {
#偵聽8888埠
listen 8888;
# server_name 192.168.72.129;
# 定義使用 www.GeekPlusA.com 訪問
server_name www.GeekPlusA.com;
#設定本虛擬主機的訪問日誌
# access_log logs/www.GeekPlusA.com.access.log main;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#定義伺服器的預設網站根目錄位置
root html;
#定義首頁索引檔案的名稱
index index.jsp index.html index.htm;
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
#請求轉向 tomcat 定義的伺服器列表
proxy_pass http://tomcat;
#以下是一些反向代理的配置可刪除.
}
#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;
# }
#}
}
6:啟動tomcat,啟動tomcat,觀看效果
瀏覽器輸入(http://192.168.72.129:8888/nginx/),重新整理看效果
每重新整理一次,就切換一下
7:停止某個tomcat,觀看效果.再啟動觀看效果
如有疑問,隨時加Q交流:1428424253