环境:
阿里云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配置:
[root@a0a2568d002d centos_data]# mkdir /usr/java
[root@a0a2568d002d centos_data]# tar -zxvf jdk-8u201-linux-x64.tar.gz -C /usr/java[root@a0a2568d002d 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[root@a0a2568d002d centos_data]# source /root/.bashrc[root@a0a2568d002d 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配置:
[root@a0a2568d002d centos_data]# mkdir /usr/local/tomcat [root@a0a2568d002d centos_data]# tar -xf apache-tomcat-8.5.39.tar.gz -C /usr/local/tomcat设置tomcat随容器自动而自启动:
[root@ecaea7d3388c /]# 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[root@ecaea7d3388c /]# systemctl daemon-reload
[root@ecaea7d3388c /]# systemctl enable tomcat.service
[root@ecaea7d3388c /]# systemctl start tomcat.service[root@ecaea7d3388c /]# 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