文章目录
1、tomcat的安装
//安装java环境
tomcat本身是一个Java程序,所以必须要有Java的的运行状态!
qinziteng@tomcat:~$ java ##执行java可以查看java的一些安装包
Command 'java' not found, but can be installed with:
sudo apt install default-jre
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless
qinziteng@tomcat:~$ sudo apt install openjdk-8-jre-headless
qinziteng@tomcat:~$ java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~18.04-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)
//下载对应版本tomcat包
tomcat官网:
https://tomcat.apache.org/
或者使用wget下载
qinziteng@tomcat:~$ sudo wget https://downloads.apache.org/tomcat/tomcat-8/v8.5.65/bin/apache-tomcat-8.5.65.tar.gz
下载好之后解压缩
qinziteng@tomcat:~$ tar zxf apache-tomcat-8.5.65.tar.gz
qinziteng@tomcat:~$ sudo mv apache-tomcat-8.5.65 /usr/local/tomcat
qinziteng@tomcat:~$ ls /usr/local/tomcat/
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp wor
//优化路径并开启
qinziteng@tomcat:~$ sudo ln -s /usr/local/tomcat/bin/* /usr/local/sbin/
qinziteng@tomcat:~$ startup.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
qinziteng@tomcat:~$ netstat -anput | grep 8080
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::8080 :::* LISTEN 3860/java
启动参数:
startup.sh start //启动
shutdown.sh //关闭
catalina.sh stop //启动
catalina.sh start //关闭
//关闭防火墙
qinziteng@tomcat:~$ sudo ufw disable
浏览器访问
2、tomcat基本配置
//更改端口号
qinziteng@tomcat:~$ vim /usr/local/tomcat/conf/server.xml
.......
<Connector port="8081" protocol="HTTP/1.1" #将之前8080端口改成8081端口
connectionTimeout="20000"
redirectPort="8443" />
重启tomcat服务
qinziteng@tomcat:/usr/local/tomcat/bin$ shutdown.sh
qinziteng@tomcat:/usr/local/tomcat/bin$ startup.sh
//更改网站目录
qinziteng@tomcat:~$ vim /usr/local/tomcat/conf/server.xml
.......
<Host name="localhost" appBase="/opt/www" #将网站根目录改到/opt/www
unpackWARs="true" autoDeploy="true">
创建网站家目录
qinziteng@tomcat:~$ sudo mkdir /opt/www/ROOT -p
注意ROOT一定要是大写!!
重启tomcat服务
qinziteng@tomcat:/usr/local/tomcat/bin$ shutdown.sh
qinziteng@tomcat:/usr/local/tomcat/bin$ startup.sh