Tomcat实战案例(JPress 的安装部署)

【Tomcat实战案例(JPress 的安装部署)】著论准过秦,作赋拟子虚。这篇文章主要讲述Tomcat实战案例:JPress 的安装部署相关的知识,希望能为你提供帮助。
1.概述
        JPress,一个专业的建站神器。已有超过10万+网站使用 JPress 搭建,其中包括多个政府机构,200+上市公司,中科院、红十字会等。  官网上的WAR包只能在相对低版本JDK和Tomcat成功,在最新的apache-tomcat-10.0.20.tar.gz   和   jdk-11.0.14_linux-x64_bin.tar.gz 下部署War包一直显示出错,改到低版本下去部署正常。
开源协议: LGPL-3.0
官方网站: http://www.jpress.io/
2.Tomcat环境准备基本步骤:先安装好Oracle JDK,在此基础上再配置好Tomcat,下一步才能部署 Jpress的war包。下面是我们提供的一个一键安装 Tomcat的脚本,它会自动完成JDK和Tomcat的安装。

#### 在最新的apache-tomcat-10.0.20.tar.gz和jdk-11.0.14_linux-x64_bin.tar.gz 下部署Jpress 4.0.2 War包一直显示出错,改低版本下去部署工作正常

# 准备好下面几个软件包
[root@CentOS84-IP58 ]#ll
-rw-r--r--1 root root10520844 Mar 152021 apache-tomcat-8.5.64.tar.gz
-rw-r--r--1 root root3108 Sep12021 install_tomcat.sh
-rw-r--r--1 root root 143722924 Mar 152021 jdk-8u281-linux-x64.tar.gz

# install_tomcat.sh 是准备好的一键安装 Tomcat的脚本文件
[root@CentOS84-IP58 ]#cat install_tomcat.sh
DIR=`pwd`
JDK_FILE="jdk-8u281-linux-x64.tar.gz"
TOMCAT_FILE="apache-tomcat-8.5.64.tar.gz"
JDK_DIR="/usr/local"
TOMCAT_DIR="/usr/local"

color ()
RES_COL=60
MOVE_TO_COL="echo -en \\\\033[$RES_COLG"
SETCOLOR_SUCCESS="echo -en \\\\033[1; 32m"
SETCOLOR_FAILURE="echo -en \\\\033[1; 31m"
SETCOLOR_WARNING="echo -en \\\\033[1; 33m"
SETCOLOR_NORMAL="echo -en \\E[0m"
echo -n "$2" & & $MOVE_TO_COL
echo -n "["
if [ $1 = "success" -o $1 = "0" ] ; then
$SETCOLOR_SUCCESS
echo -n $"OK"
elif [ $1 = "failure" -o $1 = "1"] ; then
$SETCOLOR_FAILURE
echo -n $"FAILED"
else
$SETCOLOR_WARNING
echo -n $"WARNING"
fi
$SETCOLOR_NORMAL
echo -n "]"
echo




install_jdk()
if ![-f "$DIR/$JDK_FILE" ]; then
color 1 "$JDK_FILE 文件不存在"
exit;
elif [ -d $JDK_DIR/jdk ]; then
color 1"JDK 已经安装"
exit
else
[ -d "$JDK_DIR" ] || mkdir -pv $JDK_DIR
fi
tar xvf $DIR/$JDK_FILE-C $JDK_DIR
cd$JDK_DIR & & ln -s jdk1.8.* jdk

cat > /etc/profile.d/jdk.sh < < EOF
export java_HOME=$JDK_DIR/jdk
export JRE_HOME=\\$JAVA_HOME/jre
export CLASSPATH=\\$JAVA_HOME/lib/:\\$JRE_HOME/lib/
export PATH=\\$PATH:\\$JAVA_HOME/bin
EOF
./etc/profile.d/jdk.sh
java -version & & color 0 "JDK 安装完成" ||color 1"JDK 安装失败" ; exit;



install_tomcat()
if ! [ -f "$DIR/$TOMCAT_FILE" ]; then
color 1 "$TOMCAT_FILE 文件不存在"
exit;
elif [ -d $TOMCAT_DIR/tomcat ]; then
color 1 "TOMCAT 已经安装"
exit
else
[ -d "$TOMCAT_DIR" ] || mkdir -pv $TOMCAT_DIR
fi
tar xf $DIR/$TOMCAT_FILE -C $TOMCAT_DIR
cd$TOMCAT_DIR & & ln -s apache-tomcat-*/tomcat
echo "PATH=$TOMCAT_DIR/tomcat/bin:"$PATH > /etc/profile.d/tomcat.sh
id tomcat & > /dev/null || useradd -r -s /sbin/nologin tomcat

cat > $TOMCAT_DIR/tomcat/conf/tomcat.conf < < EOF
JAVA_HOME=$JDK_DIR/jdk
EOF

chown -R tomcat.tomcat $TOMCAT_DIR/tomcat/

cat > /lib/systemd/system/tomcat.service< < EOF
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=$TOMCAT_DIR/tomcat/conf/tomcat.conf
ExecStart=$TOMCAT_DIR/tomcat/bin/startup.sh
ExecStop=$TOMCAT_DIR/tomcat/bin/shutdown.sh
RestartSec=3
PrivateTmp=true
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now tomcat.service & > /dev/null
systemctl is-active tomcat.service & > /dev/null & & color 0 "TOMCAT 安装完成" ||color 1 "TOMCAT 安装失败" ; exit;



install_jdk

install_tomcat
[root@CentOS84-IP58 ]#

# 运行脚本,一键安装好Tomcat
[root@CentOS84-IP58 ]#bash install_tomcat.sh
...........................
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
JDK 安装完成[OK]
TOMCAT 安装完成[OK]


[root@CentOS84-IP58 ]#java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)

[root@CentOS84-IP58 ]#catalina.sh version
Using CATALINA_BASE:/usr/local/tomcat
Using CATALINA_HOME:/usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:/usr/local/jdk/jre
Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Server version: Apache Tomcat/8.5.64
Server built:Mar 4 2021 23:14:16 UTC
Server number:8.5.64.0
OS Name:Linux
OS Version:4.18.0-305.3.1.el8.x86_64
Architecture:amd64
JVM Version:1.8.0_281-b09
JVM Vendor:Oracle Corporation
[root@CentOS84-IP58 ]#

[root@CentOS84-IP58 ]#reboot

3.部署Jpress war包需要在jpress的官网上下载好WAR包,就可以在Tomcat上开始部署。
# 查看Tomcat的默认网站目录
[root@CentOS84-IP58 ]#ll /usr/local/tomcat/webapps/
total 4
drwxr-x--- 15 tomcat tomcat 4096 Apr9 14:18 docs
drwxr-x---7 tomcat tomcat99 Apr9 14:18 examples
drwxr-x---6 tomcat tomcat79 Apr9 14:18 host-manager
drwxr-x---6 tomcat tomcat114 Apr9 14:18 manager
drwxr-x---3 tomcat tomcat223 Apr9 14:18 ROOT

# 上传 jpress-v4.2.0.war 包到/usr/local/tomcat/webapps/ 目录
[root@CentOS84-IP58 ]#cd /usr/local/tomcat/webapps/
[root@CentOS84-IP58 ]#rz
rz waiting to receive.
Starting zmodem transfer.Press Ctrl+C to cancel.
Transferring jpress-v4.2.0.war...
100%69354 KB788 KB/sec00:01:280 Errors

[root@CentOS84-IP58 ]#ll /usr/local/tomcat/webapps/
total 69360
drwxr-x--- 15 tomcat tomcat4096 Apr9 14:18 docs
drwxr-x---7 tomcat tomcat99 Apr9 14:18 examples
drwxr-x---6 tomcat tomcat79 Apr9 14:18 host-manager
-rw-r--r--1 rootroot71018586 Apr9 11:42 jpress-v4.2.0.war
drwxr-x---6 tomcat tomcat114 Apr9 14:18 manager
drwxr-x---3 tomcat tomcat223 Apr9 14:18 ROOT

# 上传完成后等待一会会就会看到一个 jpress-v4.2.0 目录自动生成
[root@CentOS84-IP58 ]#ll /usr/local/tomcat/webapps/
total 69360
drwxr-x--- 15 tomcat tomcat4096 Apr9 14:18 docs
drwxr-x---

    推荐阅读