环境:
阿里云ecs服务器
步骤:
1、安装docker
2、获取centos镜像
3、下载tomcat 和 jdk 安装包
4、配置
1、安装docker
https://www.cnblogs.com/shijunjie/p/10436293.html
2、获取centos 镜像
1、在docker官方镜像源搜索centos镜像,选择合适的版本下载镜像
https://hub.docker.com/search?q=&type=image&operating_system=
2、举例:
docker pull centos:7.6.1810
3、下载tomcat 和 jdk 安装包
tomcat下载地址:
https://tomcat.apache.org/download-80.cgi tomcat官方下载地址
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/ 清华大学开源软件镜像站下载地址
jdk:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html java官方下载地址
4、配置
java配置:
[[email protected] centos_data]# mkdir /usr/java[[email protected] centos_data]# tar -zxvf jdk-8u201-linux-x64.tar.gz -C /usr/java[[email protected] centos_data]# vi /root/.bashrc export JAVA_HOME=/usr/java/jdk1.8.0_201 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH[[email protected] centos_data]# source /root/.bashrc[[email protected] centos_data]# java -version java version "1.8.0_201" Java(TM) SE Runtime Environment (build 1.8.0_201-b09) Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)## 容器内java环境如果配置到 /etc/profile 那么,重启容器后很大可能不会生效,需要再次执行一遍 source /etc/profile 命令才会生效 。 ## 而java环境如果配置到/root/.bashrc 那么,容器重启后java环境还会生效tomcat配置:
[[email protected] centos_data]# mkdir /usr/local/tomcat [[email protected] centos_data]# tar -xf apache-tomcat-8.5.39.tar.gz -C /usr/local/tomcat设置tomcat随容器自动而自启动:
[[email protected] /]# vi /lib/systemd/system/tomcat.service [Unit] Description=tomcat After=network.target [Service] Type=oneshot ExecStart=/usr/local/tomcat/apache-tomcat-8.5.39/bin/startup.sh ExecStop=/usr/local/tomcat/apache-tomcat-8.5.39/bin/shutdown.sh ExecReload=/bin/kill -s HUP $MAINPID RemainAfterExit=yes [Install] WantedBy=multi-user.target[[email protected] /]# systemctl daemon-reload[[email protected] /]# systemctl enable tomcat.service [[email protected] /]# systemctl start tomcat.service[[email protected] /]# systemctl status tomcat.service## 问题1:systemctl start tomcat.service 启动tomcat时可能无法启动,可能会出现以下报错: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined解决办法: 用 vi 打开 tomcat 的bin目录下的setclasspath.sh,添加JAVA_HOME和JRE_HOME两个环境变量,两个环境变量路径为您安装的java JDK的路径。举例:export JAVA_HOME=/usr/java/jdk1.8.0_201
export JRE_HOME=${JAVA_HOME}/jre
原文地址:https://www.cnblogs.com/shijunjie/p/10712381.html
时间: 2024-10-07 06:30:16