Servlet和 JSP 容器
安装
组件下载
JDK下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Tomcat下载:http://tomcat.apache.org/
jdk安装
[root@sanqi ~]# tar -xvf jdk-8u191-linux-x64.tar.gz -C /application
[root@sanqi ~]# cd /application
[root@sanqi application]# ln -s jdk1.8.0_191/ jdk
[root@sanqi application]# sed -i.ori '$a export JAVA_HOME=/application/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@sanqi application]# source /etc/profile
[root@sanqi application]# java -version
[root@sanqi application]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
tomcat安装
[root@sanqi ~]# tar xf apache-tomcat-8.5.35.tar.gz -C /application
[root@sanqi ~]# cd /application
[root@sanqi application]# ln -s apache-tomcat-8.5.35 tomcat
[root@sanqi application]# echo 'export TOMCAT_HOME=/application/tomcat'>>/etc/profile
[root@sanqi application]# source /etc/profile
[root@sanqi application]# chown -R root.root /application/jdk/ /application/tomcat/
tomcat目录
[root@sanqi tomcat]# tree -L 1
.
|-- bin #启动、关闭Tomcat或者其它功能的脚本(.bat文件和.sh文件)
|-- BUILDING.txt
|-- conf #用以配置Tomcat的XML及DTD文件
|-- CONTRIBUTING.md
|-- lib
|-- LICENSE
|-- logs #Catalina和其它Web应用程序的日志文件
|-- NOTICE
|-- README.md
|-- RELEASE-NOTES
|-- RUNNING.txt
|-- temp#→临时文件
|-- webapps #Web应用程序根目录
`-- work #用以产生有JSP编译出的Servlet的.java和.class文件
→启动程序/application/tomcat/bin/startup.sh
→关闭程序/application/tomcat/bin/shutdown.sh
[root@sanqi ~]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE: /application/tomcat
Using CATALINA_HOME: /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME: /application/jdk
Using CLASSPATH: /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@sanqi ~]# ps -ef|grep java
root 3305 1 14 11:09 pts/0 00:00:03 /application/jdk/bin/java -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 3374 2090 0 11:10 pts/0 00:00:00 grep --color=auto java
[root@sanqi ~]# ss -nutlp|grep java
tcp LISTEN 0 1 127.0.0.1:8005 *:* users:(("java",pid=3305,fd=70))
tcp LISTEN 0 100 *:8009 *:* users:(("java",pid=3305,fd=54))
tcp LISTEN 0 100 *:8080 *:* users:(("java",pid=3305,fd=49))
$<2>$ pwd
/application/tomcat/conf
$<2># root @ VM_0_14_centos in $<2>/application/tomcat/conf [16:54:06]
$<2>$ ll
total 228K
drwxr-x--- 3 root root 4.0K Nov 15 16:49 Catalina
-rw------- 1 root root 14K Nov 4 01:42 catalina.policy
-rw------- 1 root root 7.6K Nov 4 01:42 catalina.properties
-rw------- 1 root root 1.4K Nov 4 01:42 context.xml
-rw------- 1 root root 1.2K Nov 4 01:42 jaspic-providers.xml
-rw------- 1 root root 2.3K Nov 4 01:42 jaspic-providers.xsd
-rw------- 1 root root 3.6K Nov 4 01:42 logging.properties
-rw------- 1 root root 7.4K Nov 4 01:42 server.xml #主配置文件
-rw------- 1 root root 2.2K Nov 4 01:42 tomcat-users.xml #Tomcat管理用户配置文件
-rw------- 1 root root 2.6K Nov 4 01:42 tomcat-users.xsd
-rw------- 1 root root 166K Nov 4 01:42 web.xml
配置文件
/application/tomcat/conf
Tomcat manager
生产勿用
vim /application/tomcat/conf/tomcat-users.xml
##在行上添加三行
如果想要进入/manager/html页面,则新建或编辑conf/Catalina/localhost/manager.xml
如果想要进入/host-manager/html页面,则新建或编辑conf/Catalina/localhost/host-manager.xml
配置文件如下
多实例,
[root@sanqi webapps]# mv docs/ examples/ host-manager/ manager/ /tmp
[root@sanqi webapps]# rm -rf ROOT/*
配置文件
server.xml
关闭
访问端口
redirectPort="8443" />
主目录设置自动解压自动发布
更改主目录
多实例
[root@sanqi application]# cp -a apache-tomcat-8.5.35/ tomcat-1
[root@sanqi application]# cp -a apache-tomcat-8.5.35/ tomcat-2
修改各个实例的端口号
8005 8080
反向代理
[root@sanqi ~]# vim /application/nginx/conf/nginx.conf
upstream web-pools {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.jsp index.html index.htm;
proxy_pass http://web-pools;
}
}
这里有点小坑,配完后,访问一直报400
找了好久
后来发现竟然是因为upstream名称不能用'_'
我去啊,那我重启你倒是报错啊