先到Java官网下载Java的sdk
http://www.oracle.com/technetwork/java/javase/downloads/index.html
下载后将Java包解压到 /usr/local/java/ 目录下
tar -zxvf jdk-10.0.1_linux-x63.tar.gz -C /usr/local/java/
把Java路劲写到环境变量中
vim ~/etc/profile.d/java10.sh
export JAVA_HOME=/usr/local/java/jdk-10.0.1/
export PATH=$JAVA_HOME/bin:$PATH
source ~/etc/profile.d/java10.sh
使用 java -version 查看版本信息
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
这步有的jdk没有内置jre,还需要单独下载jre放到jdk的目录下
先下载Tomcat安装包
curl -O http://mirrors.shu.edu.cn/apache/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
解压到 /usr/local 目录
tar xvf apache-tomcat-9.0.8.tar.gz -C /usr/local/
创建软链接
ln -sv /usr/local/apache-tomcat-9.0.8 /usr/local/tomcat9
配置环境变量
vim /etc/profile.d/tomcat9.sh
export TOMCAT_HOME=/usr/local/tomcat9
export PATH=$TOMCAT_HOME/bin:$PATH
官方建议在tomcat安装目录的bin目录下建一个setenv.sh,将JAVA_HOME,JRE_HOME等环境变量信息指定。示例如下:
cat bin/setenv.sh
CATALINA_HOME=/usr/local/tomcat9
CATALINA_BASE=/usr/local/tomcat9
JAVA_HOME=/usr/local/java/jdk-10.0.1
JRE_HOME=/usr/local/java/jdk-10.0.1/jre/
CATALINA_PID=/usr/local/tomcat9/tomcat9.pid
配置Tomcat使用systemctl控制
vim /usr/lib/systemd/system/tomcat9.service
[Unit]
Description=Apache Tomcat 9
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat9/tomcat9.pid
ExecStart=/usr/local/tomcat9/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
systemctl start tomcat9
参考链接https://www.cnblogs.com/mfyang/p/8688800.html