@
目錄- 前言
- 一、流程及圖
- 1.簡易流程圖如下
- 一、nginx服務器配置:
- 1.下載并安裝nginx
- 1.1 將下載好的nginx包傳到服務器/usr/local/目錄下
- 2.nginx配置
- 1.下載并安裝nginx
- 二、服務器1、2、3配置(以一臺講解)
- 1.jdk安裝與配置
- 2.tomcat
- 1.tomcat安裝
- 2.tomcat配置
- 1.1 server.xml
- 1.2 web.xml
- 一、流程及圖
前言
使用ngnix轉發所有服務的網址到各個服務器,然后在各個服務器同時部署多個服務,一、流程及圖
1.簡易流程圖如下

一、nginx服務器配置:
1.下載并安裝nginx
1.1 將下載好的nginx包傳到服務器/usr/local/目錄下
# cd /usr/local
// -y表示遇到判斷全部yes,autoconf表示自動配置,automake表示自動編譯,
# yum -y install gcc gcc-c++ autoconf automake //gcc、gcc-c++的庫檔案
# yum install -y pcre pcre-devel //安裝Nginx依賴包
# yum install -y zlib zlib-devel
# tar -zxvf nginx-1.10.2.tar.gz //解壓縮
# cd nginx-1.10.2 //切換到該目錄下
# ./configure //配置
# make
# make install //安裝
// 檢驗是否完成安裝
# cd /usr/local
# ls //如果存在nginx檔案夾,則安裝成功
// 注意:最后結束前不要去改解壓后的nginx檔案,否則安裝不成功
2.nginx配置
#設定低權限用戶,為了安全而設定的
#user nobody;
#作業衍生行程數
worker_processes 10;
#設定錯誤檔案存放路徑
# error_log logs/error.log;
# error_log logs/error.log notice;
# error_log logs/error.log info;
#設定pid存放路徑(pid是控制系統中重要檔案)
pid logs/nginx.pid;
#設定最大連接數
events {
worker_connections 102400;
}
http {
#檔案擴展名與檔案型別映射表
include mime.types;
map $time_iso8601 $logdate {
'~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
default 'date-not-found';
}
#默認檔案型別
default_type application/octet-stream;
limit_req_zone $binary_remote_addr zone=qps1:1m rate=800r/s;
#用來設定日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$upstream_addr" "$request_time" "$upstream_response_time"';
access_log off;
#用來指定日志檔案的存放路徑
# access_log logs/access-$logdate.log;
# error_log logs/error-$logdate.log;
#開啟高效檔案傳輸模式
sendfile on;
#防止網路阻塞
tcp_nopush on;
underscores_in_headers on;
#長連接超時時間,單位是秒
keepalive_timeout 120;
#(配置請求體快取區大小)
client_max_body_size 50M;
#(設定客戶端請求體最大值)
#client_body_buffer_size 128k;
#fastcgi_intercept_errors on;
#開啟gzip壓縮,開啟后,訪問網頁會自動壓縮
#gzip on;
#主要是用于設定一組可以在proxy_pass和fastcgi_pass指令中使用額代理服務器,默認負載均衡方式為輪詢
upstream mysvr {
#設定同一個cookie的兩次/多次請求,請求的是同一臺服務器
#ip_hash;
#1.down 表示單前的server暫時不參與負載
#server 192.168.1.116 down;
#3.backup: 其它所有的非backup機器down或者忙的時候,請求backup機器,所以這臺機器壓力會最輕,
#server 192.168.2.21 backup;
#weigth引數表示權值,權值越高被分配到的幾率越大,weight 默認為1.weight越大,負載的權重就越大,
#max_fails 配置的是熔斷機制失敗次數,即當訪問一個服務器的時候,出現三次失敗,就發生熔斷
#fail_timeout 熔斷時間,當服務器熔斷超過10s后,nginx會重新嘗試連接熔斷的服務器
server 192.168.2.21:7798 weight=3 max_fails=6 fail_timeout=60; # 服務1
server 192.168.2.21:7798 weight=2 max_fails=6 fail_timeout=60; # 服務2
server 192.168.2.22:7798 weight=2 max_fails=6 fail_timeout=60; # 服務3
}
#指定服務器的名稱和引數
server {
listen 80;
server_name www.aaa.com;
#proxy_connect_timeout 600;
#proxy_read_timeout 600;
#proxy_send_timeout 600;
#設定字符
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
location /ams.cloud/report/getError.do {
return 200 '{code: "-1", message: "系統錯誤",success : false}';
}
#location / 指用根目錄做負載均衡
location / {
#設定代理
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8898;
#proxy_buffering off;
}
location /ams.api {
#set $version $http_version;
# 強制版本升級
#if ( $version != "2.0" ) {
# return 200 '{code: "-1", message: "版本過低請升級",success : false}';
#}
limit_req zone=qps1 burst=6000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://mysvr;
}
location /CLodopfuncs.js {
proxy_pass http://localhost:8000/CLodopfuncs.js;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
二、服務器1、2、3配置(以一臺講解)
1.jdk安裝與配置
2.tomcat
1.tomcat安裝
2.tomcat配置
1.1 server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector
port="8898" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="5000"
minSpareThreads="20"
maxThreads="2048"
maxSpareThreads="2048"
acceptCount="2048"
minProcessors="20"
maxProcessors="2048"
enableLookups="false"
maxHttpHeaderSize ="102400"
maxPostSize="83886080"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
1.2 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<!-- The mapping for the default servlet -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- The mappings for the JSP servlet -->
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
隨心所往,看見未來,Follow your heart,see night!
歡迎點贊、關注、留言,一起學習、交流!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/500109.html
標籤:其他
