nginx處理靜態(tài)
tomcat處理動態(tài)
合并為動靜分離(前后端分離)
bin:存放啟動和關(guān)閉Tomcat腳本
conf:存放Tomcat不同的配置文件
doc:存放Tomcat文檔
lib/japser/common:存放Tomcat運行需要的庫文件
logs:存放Tomcat執(zhí)行時的LOG文件
src:存放Tomcat的源代碼
webapps:Tomcat的主要Web發(fā)布目錄
Nginx靜態(tài)處理優(yōu)勢
在成都網(wǎng)站設(shè)計、成都做網(wǎng)站中從網(wǎng)站色彩、結(jié)構(gòu)布局、欄目設(shè)置、關(guān)鍵詞群組等細微處著手,突出企業(yè)的產(chǎn)品/服務/品牌,幫助企業(yè)鎖定精準用戶,提高在線咨詢和轉(zhuǎn)化,使成都網(wǎng)站營銷成為有效果、有回報的無錫營銷推廣。創(chuàng)新互聯(lián)建站專業(yè)成都網(wǎng)站建設(shè)十余年了,客戶滿意度97.8%,歡迎成都創(chuàng)新互聯(lián)客戶聯(lián)系。
1.Nginx處理靜態(tài)頁面的效率遠高于Tomcat的處理能力
2.如果Tomcat的請求量為1000次,則Nginx的請求量為6000次
3.Tomcat每秒的吞吐量為0 6M,Nginx的每秒吞吐量為3.6M
4.Nginx處理靜態(tài)資源的能力是Tomcat處理的6倍,優(yōu)勢可見一斑
動靜分離原理:服務端接收來自客戶端的請求中,既有靜態(tài)資源也有動態(tài)資源
nginx:192.168.18.147----CentOS 7-1
Tomcat 1:192.168.18.128----CentOS 7-2
Tomcat 2:129.168.18.148----CentOS 7-3
客戶端:192.168.18.129----Win 7
[root@localhost ~]# hostnamectl set-hostname tomcat1
[root@localhost ~]# su
[root@tomcat1 ~]# systemctl stop firewalld.service
[root@tomcat1 ~]# setenforce 0
[root@tomcat1 ~]# mkdir /aaa
[root@tomcat1 ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@tomcat1 ~]# cd /aaa/tomcat/
[root@tomcat1 tomcat]# ls
apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz
apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz
jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz
[root@tomcat1 tomcat]# tar zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/
#設(shè)置環(huán)境變量:
[root@tomcat1 tomcat]# vim /etc/profile
#按大寫字母G到末行,按小寫字母o在下行插入以下內(nèi)容:
export JAVA_HOME=/usr/local/jdk1.8.0_91
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#修改完成后,按Esc退出插入模式,輸入:wq保存退出
[root@tomcat1 tomcat]# source /etc/profile
[root@tomcat1 tomcat]# ls
apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz
apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz
jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz
[root@tomcat1 tomcat]# tar zxvf apache-tomcat-8.5.16.tar.gz -C /usr/local/
[root@tomcat1 tomcat]# cd /usr/local/
[root@tomcat1 local]# ls
apache-tomcat-8.5.16 etc include lib libexec share
bin games jdk1.8.0_91 lib64 sbin src
[root@tomcat1 local]# mv apache-tomcat-8.5.16/ tomcat
[root@tomcat1 local]# ls
bin games jdk1.8.0_91 lib64 sbin src
etc include lib libexec share tomcat
[root@tomcat1 local]# ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/
[root@tomcat1 local]# ln -s /usr/local/tomcat/bin/shutdown..sh /usr/local/bin/
[root@tomcat1 local]# mkdir -pv /web/webapp1
mkdir: 已創(chuàng)建目錄 "/web"
mkdir: 已創(chuàng)建目錄 "/web/webapp1"
[root@tomcat1 local]# cd /web/webapp1/
[root@tomcat1 webapp1]# vim index.jsp
<%@ page language="java" import="java.until.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("Welcome ACCP Web");%>
</body>
</html>
#添加完成后輸入:wq保存退出
[root@tomcat1 webapp1]# vim /usr/local/tomcat/conf/server.xml
#輸入/Host查找到以下內(nèi)容
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
#在此行下插入,添加站點目錄
<Context docBase="/web/webapp1" path="" reloadable="false">
</Context>
#添加完成后輸入:wq保存退出
[root@tomcat1 webapp1]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8.0_91/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.ja
Tomcat started.
到宿主機中的瀏覽器輸入:192.168.18.128:8080 可以看到:Welcome KGC Web
[root@localhost ~]# hostnamectl set-hostname tomcat2
[root@localhost ~]# su
[root@tomcat1 ~]# systemctl stop firewalld.service
[root@tomcat1 ~]# setenforce 0
[root@tomcat1 ~]# mkdir /aaa
[root@tomcat1 ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@tomcat1 ~]# cd /aaa/tomcat/
[root@tomcat1 tomcat]# ls
apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz
apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz
jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz
[root@tomcat1 tomcat]# tar zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/
#設(shè)置環(huán)境變量:
[root@tomcat1 tomcat]# vim /etc/profile
#按大寫字母G到末行,按小寫字母o在下行插入以下內(nèi)容:
export JAVA_HOME=/usr/local/jdk1.8.0_91
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
#修改完成后,按Esc退出插入模式,輸入:wq保存退出
[root@tomcat1 tomcat]# source /etc/profile
[root@tomcat1 tomcat]# ls
apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz
apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz
jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz
[root@tomcat1 tomcat]# tar zxvf apache-tomcat-8.5.16.tar.gz -C /usr/local/
[root@tomcat1 tomcat]# cd /usr/local/
[root@tomcat1 local]# ls
apache-tomcat-8.5.16 etc include lib libexec share
bin games jdk1.8.0_91 lib64 sbin src
[root@tomcat1 local]# mv apache-tomcat-8.5.16/ tomcat
[root@tomcat1 local]# ls
bin games jdk1.8.0_91 lib64 sbin src
etc include lib libexec share tomcat
[root@tomcat1 local]# ln -s /usr/local/tomcat/bin/startup.sh /usr/local/bin/
[root@tomcat1 local]# ln -s /usr/local/tomcat/bin/shutdown..sh /usr/local/bin/
[root@tomcat1 local]# mkdir -pv /web/webapp1
mkdir: 已創(chuàng)建目錄 "/web"
mkdir: 已創(chuàng)建目錄 "/web/webapp1"
[root@tomcat1 local]# cd /web/webapp1/
[root@tomcat1 webapp1]# vim index.jsp
<%@ page language="java" import="java.until.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("Welcome KGC Web");%>
</body>
</html>
#添加完成后輸入:wq保存退出
[root@tomcat1 webapp1]# vim /usr/local/tomcat/conf/server.xml
#輸入/Host查找到以下內(nèi)容
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
#在此行下插入,添加站點目錄
<Context docBase="/web/webapp1" path="" reloadable="false">
</Context>
#添加完成后輸入:wq保存退出
[root@tomcat1 webapp1]# startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/jdk1.8.0_91/jre
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.ja
Tomcat started.
到宿主機中的瀏覽器輸入:192.168.18.148:8080 可以看到:Welcome ACCP Web
[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# su
[root@nginx ~]# yum install pcre-devel zlib-devel gcc gcc-c++ make -y
[root@nginx ~]# mkdir /aaa
[root@nginx ~]# mount.cifs //192.168.10.189/rpm /aaa
Password for root@//192.168.10.189/rpm:
[root@nginx ~]# cd /aaa/tomcat/
[root@nginx tomcat]# ls
apache-tomcat-7.0.54.tar.gz jdk-8u91-linux-x64.tar.gz
apache-tomcat-8.5.16.tar.gz nginx-1.12.0.tar.gz
jdk-7u65-linux-x64.gz nginx-1.6.0.tar.gz
[root@nginx tomcat]# tar zxvf nginx-1.12.0.tar.gz -C /usr/local/
[root@nginx tomcat]# cd /usr/local/nginx-1.12.0/
[root@nginx nginx-1.12.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@nginx nginx-1.12.0]# useradd -M -s /sbin/nologin nginx
[root@nginx nginx-1.12.0]# ./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module
[root@nginx nginx-1.12.0]# make && make install
[root@nginx nginx-1.12.0]# vim /usr/local/nginx/conf/nginx.conf
#gzip on; #在下行插入以下內(nèi)容
upstream tomcat_server {
server 192.168.18.128:8080 weight=1;
server 192.168.18.148:8080 weight=1;
}
location / {
root html;
index index.html index.htm; #在下行插入
proxy_pass http://tomcat_server;
}
#修改完成后按Esc退出插入模式,輸入:wq保存退出
[root@nginx nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@nginx nginx-1.12.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx nginx-1.12.0]# nginx
[root@nginx nginx-1.12.0]# netstat -ntap | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8917/nginx: master
1.在宿主機中的瀏覽器輸入:192.168.18.147 可以看到:Welcome KGC Web
2.再次刷新可以可到:Welcome ACCP Web
當前名稱:Nginx+Tomcat負載均衡群集
轉(zhuǎn)載來于:http://www.rwnh.cn/article0/jipdoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、網(wǎng)站設(shè)計公司、微信公眾號、網(wǎng)站策劃、自適應網(wǎng)站、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)