赞
踩
目录名 | 作用 |
---|---|
bin | 存放启动和关闭Tomcat脚本 |
conf | 存放Tomcat不同的配置文件 |
doc | 存放Tomcat文档 |
lib | 存放Tomcat运行需要的库文件 |
logs | 存放Tomcat执行时的LOG文件 |
src | 存放Tomcat的源代码 |
webapps | Tomcat的主要Web发布目录 |
work | 存放jsp编译后产生的class文件 |
Nginx实现负载均衡是通过反向代理实现
反向代理原理:
动静分离原理
[root@localhost ~]# tar xf jdk-8u144-linux-x64.tar.gz -C /opt
[root@localhost ~]# cd /opt
[root@localhost opt]# cp -rv jdk1.8.0_144/ /usr/local/java
[root@localhost opt]# vi /etc/profile
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export PATH=$PATH:/usr/local/java/bin
export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib
[root@localhost opt]# source /etc/profile
[root@localhost opt]# java -version
java version "1.8.0_144"
……省略部分
[root@localhost ~]# tar vxf apache-tomcat-8.5.23.tar.gz -C /opt
[root@localhost ~]# cd /opt
[root@localhost opt]# mv apache-tomcat-8.5.23/ /usr/local/tomcat8
[root@localhost opt]# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
[root@localhost opt]# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
[root@localhost opt]# tomcatup
……省略部分
Tomcat started.
[root@localhost opt]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 ::: * LISTEN 77010/java
[root@localhost tomcat8]# vim /usr/local/tomcat8/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp1" path="" reloadable="false" > //插入这两行配置 </Context> [root@localhost tomcat8]# mkdir -pv /web/webapp1 //创建网页目录 [root@localhost tomcat8]# vim /web/webapp1/index.jsp <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>JSP test1 page</title> </head> <body> <h1> <% out.println("动态页面 1,http://www.TOM1.com");%> </h1> </body> <body> <div>静态页面的图片 1</div><br><img src="123.jpg"> <br><h1> 床前看月光,<br> 疑是地上霜。<br> 抬头望山月,<br> 低头思故乡。<br> </h1> </body> </html> [root@localhost tomcat8]# tomcatdown [root@localhost tomcat8]# tomcatup
[root@localhost ~]# tar xf jdk-8u144-linux-x64.tar.gz -C /opt
[root@localhost ~]# cd /opt
[root@localhost opt]# cp -rv jdk1.8.0_144/ /usr/local/java
[root@localhost opt]# vi /etc/profile
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export PATH=$PATH:/usr/local/java/bin
export CLASSPATH=./:/usr/local/java/lib:/usr/local/java/jre/lib
[root@localhost opt]# source /etc/profile
[root@localhost opt]# java -version
java version "1.8.0_144"
……省略部分
[root@localhost ~]# tar vxf apache-tomcat-8.5.23.tar.gz -C /opt
[root@localhost ~]# cd /opt
[root@localhost opt]# mv apache-tomcat-8.5.23/ /usr/local/tomcat8
[root@localhost opt]# ln -s /usr/local/tomcat8/bin/startup.sh /usr/bin/tomcatup
[root@localhost opt]# ln -s /usr/local/tomcat8/bin/shutdown.sh /usr/bin/tomcatdown
[root@localhost opt]# tomcatup
……省略部分
Tomcat started.
[root@localhost opt]# netstat -anpt | grep 8080
tcp6 0 0 :::8080 ::: * LISTEN 77010/java
[root@localhost tomcat8]# vim /usr/local/tomcat8/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp1" path="" reloadable="false" > </Context> [root@localhost tomcat8]# mkdir -pv /web/webapp1 [root@localhost tomcat8]# vim /web/webapp1/index.jsp <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>JSP test2 page</title> </head> <body> <h1> <% out.println("动态页面2,http://www.TOM1.com");%> </h1> </body> <body> <div>静态页面的图片 2</div><br><img src="123.jpg"> <br><h1> 床前看月光,<br> 疑是地上霜。<br> 抬头望山月,<br> 低头思故乡。<br> </h1> </body> </html> [root@localhost tomcat8]# tomcatdown [root@localhost tomcat8]# tomcatup
### 1.安装环境
[root@localhost opt]# yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
zlib-devel
[root@localhost ~]# groupadd www
[root@localhost ~]# useradd -g www www -s /bin/false
补充:/bin/false是最严格的禁止login选项,一切服务都不能用。
/sbin/nologin只是不允许login系统
[root@localhost ~]# tar xzvf nginx-1.15.9.tar.gz -C /opt
[root@localhost ~]# cd /opt/nginx-1.15.9/
[root@localhost nginx-1.15.9]# ./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-file-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module
[root@localhost nginx-1.15.9]# make -j3 && make install
[root@localhost nginx-1.15.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[root@localhost nginx-1.15.9]# 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@localhost nginx-1.15.9]# nginx
[root@localhost nginx-1.15.9]# netstat -anpt | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 14763/nginx: master
[root@localhost nginx-1.15.9]# yum -y install psmisc [root@localhost nginx-1.15.9]# killall -9 nginx [root@localhost nginx-1.15.9]# vim /lib/systemd/system/nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/bin/kill -s HUP $MAINPID ExecStop=/usr/bin/ki11 -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target [root@localhost nginx-1.15.9]# systemctl enable nginx.service [root@localhost nginx-1.15.9]# systemctl start nginx.service [root@localhost nginx-1.15.9]# systemctl status nginx.service ● nginx.service - nginx Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-09-25 20:08:41 CST; 6s ago Process: 14822 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, sta
[root@localhost img]# vim /usr/local/nginx/conf/nginx.conf http { ……省略部分 upstream tomcat_server { //在http{}区域内插入这4行配置 server 192.168.100.22:8080 weight=1; server 192.168.100.23:8080 weight=1; } ###docBase:web 应用的文档基准目录 ###reloadable 设置监视"类"是否变化 ###path="" 设置默认"类" server { location ~ .*.jsp$ { //在server{}区域内插入以下配置 proxy_set_header HOST $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Client-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_server; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|css)$ { root /usr/local/nginx/html/img; expires 30d; } [root@localhost nginx-1.15.9]# vim /usr/local/nginx/html/index.html <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>静态页面</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>静态页面</h1> <p>这是个静态页面</p> </body> </html>
[root@localhost nginx-1.15.9]# mkdir /usr/local/nginx/html/img
[root@localhost nginx-1.15.9]# cd /usr/local/nginx/html/img
[root@localhost img]# ls
123.jpg
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。