Ubuntu部署tomcat及基本配置

Ubuntu部署tomcat及基本配置

本文详细介绍了在Ubuntu系统中安装Java环境及Tomcat8的过程,包括下载、解压、设置路径以及开启服务。同时,讲解了如何修改Tomcat的默认端口号和网站根目录,以实现自定义配置。最后,提到了关闭防火墙以允许外部访问,并提供了重启服务的命令。

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包
使用wget下载:

qinziteng@tomcat:~$ sudo wget https://archive.apache.org/dist/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 //关闭

开启后浏览器地址里:公网ip+端口号8080,就能看到tomcat的默认页面,如果没有页面,可以查看下是否是云服务器的安全组端口没有打开。

2、tomcat基本配置

//更改端口号

qinziteng@tomcat:~$ vim /usr/local/tomcat/conf/server.xml 
	.......

  <Connector port="8081" protocol="HTTP/1.1"   #将之前8080端口改成8081端口
               connectionTimeout="20000"
               redirectPort="8443" />

//更改网站目录

qinziteng@tomcat:~$ vim /usr/local/tomcat/conf/server.xml 
	.......
	
      <Host name="localhost"  appBase="/var/www"  #将网站根目录改到/opt/www
            unpackWARs="true" autoDeploy="true">

//重启tomcat服务

qinziteng@tomcat:/usr/local/tomcat/bin$ shutdown.sh 
qinziteng@tomcat:/usr/local/tomcat/bin$ startup.sh 

服务器上的目录这样安排:

//创建默认的网页,即公网ip+端口号8080就可以访问网页,而无需再在后面加项目名。注意ROOT一定要是大写!!

qinziteng@tomcat:~$ sudo mkdir /opt/www/ROOT -p

重启tomcat服务

其他项目的话,通过在公网ip+端口号8080后面加项目名访问:

posted @ 2024-09-13 14:24  梁君牧  阅读(241)  评论(0编辑  收藏  举报