首页 > 其他分享 >tomcat安装

tomcat安装

时间:2023-06-14 17:56:43浏览次数:45  
标签:安装 tomcat root sh usr local centos8

二进制文件安装
#官网或镜像网站下载: [root@centos8 ~]#wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz [root@centos8 ~]#tar xf apache-tomcat-8.5.50.tar.gz -C /usr/local/ [root@centos8 ~]#cd /usr/local/ [root@centos8 local]#ln -s apache-tomcat-8.5.50/tomcat #指定PATH变量 [root@centos8 ~]#echo 'PATH=/usr/local/tomcat/bin:$PATH' > /etc/profile.d/tomcat.sh [root@centos8 ~]#. /etc/profile.d/tomcat.sh [root@centos8 ~]#echo $PATH /usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/jdk/bin:/root/bin #查看当前变量设置和命令用法 [root@centos8 ~]#catalina.sh #查看环境变量和版本信息 [root@centos8 ~]#catalina.sh version #启动tomcat [root@centos8 ~]#startup.sh 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 Tomcat started. #查看端口 [root@centos8 ~]#ss -ntl State       Recv-Q Send-Q       Local Address:Port     Peer Address:Port     LISTEN      0      128                 0.0.0.0:22            0.0.0.0:*         LISTEN      0      100                       *:8080               *:*         LISTEN      0      128                   [::]:22               [::]:*         LISTEN      0      1       [::ffff:127.0.0.1]:8005               *:*   #关闭tomcat [root@centos8 ~]#shutdown.sh #或者以下也可以,指定10s后停止,默认5s [root@centos8 ~]#catalina.sh stop 10 #再次用不同方式启动tomcat [root@centos8 ~]#catalina.sh start #再次用不同方式关闭tomcat [root@centos8 ~]#catalina.sh stop
 
配置tomcat自启动的service文件
#创建tomcat专用帐户
[root@centos8 ~]#useradd -r -s /sbin/nologin tomcat

#准备service文件中相关环境文件
[root@centos8 ~]#vim /usr/local/tomcat/conf/tomcat.conf
#两个变量至少设置一项才能启动 tomcat
JAVA_HOME=/usr/local/jdk
#JRE_HOME=/usr/local/jdk/jre 

#如果不指定上面变量,/var/log/messages文件中会出现下面无法启动错误提示
Mar 15 14:30:09 centos8 startup.sh[1530]: Neither the JAVA_HOME nor the JRE_HOME 
environment variable is defined
Mar 15 14:30:09 centos8 startup.sh[1530]: At least one of these environment 
variable is needed to run this program

[root@centos8 ~]#chown -R tomcat.tomcat /usr/local/tomcat/

#创建tomcat.service文件
[root@centos8 ~]#vim /lib/systemd/system/tomcat.service
[Unit]
Description=Tomcat
#After=syslog.target network.target remote-fs.target nss-lookup.target
After=syslog.target network.target 
[Service]
Type=forking
#以下二选一
EnvironmentFile=/usr/local/tomcat/conf/tomcat.conf
#或者,如果没有创建上面的/usr/local/tomcat/conf/tomcat.conf文件,可以加下面一行也可
Environment=JAVA_HOME=/usr/local/jdk
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
PrivateTmp=true
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target

[root@centos8 ~]#systemctl daemon-reload
[root@centos8 ~]#systemctl enable --now tomcat
Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → 
/usr/lib/systemd/system/tomcat.service.

[root@centos8 ~]#systemctl status tomcat
● tomcat.service - Tomcat
   Loaded: loaded (/usr/lib/systemd/system/tomcat.service; enabled; vendor 
preset: disabled)
   Active: active (running) since Sat 2020-02-08 23:37:02 CST; 5s ago
 Process: 14312 ExecStart=/usr/local/tomcat/bin/startup.sh (code=exited, 
status=0/SUCCESS)
 Main PID: 14320 (java)
   Tasks: 43 (limit: 4895)
   Memory: 64.2M
   CGroup: /system.slice/tomcat.service
           └─14320 /usr/local/jdk/jre/bin/java -
Djava.util.logging.config.file=/usr/local/tomcat/conf/logging>
Feb 08 23:37:02 centos8.localdomain systemd[1]: Starting Tomcat...
Feb 08 23:37:02 centos8.localdomain systemd[1]: Started Tomcat.

#查看日志
[root@centos8 ~]#tail /var/log/messages 
Mar 15 14:32:13 centos8 systemd[1]: Reloading.
Mar 15 14:32:23 centos8 systemd[1]: Starting Tomcat...
Mar 15 14:32:23 centos8 startup.sh[1575]: Tomcat started.
Mar 15 14:32:23 centos8 systemd[1]: Started Tomcat.

 

一键安装脚本(带jdk)
JDK_FILE="jdk-11.0.15.1_linux-x64_bin.tar.gz"
#JDK_FILE="jdk-11.0.14_linux-x64_bin.tar.gz"
#JDK_FILE="jdk-8u281-linux-x64.tar.gz"
TOMCAT_FILE="apache-tomcat-9.0.64.tar.gz"
#TOMCAT_FILE="apache-tomcat-9.0.59.tar.gz"
#TOMCAT_FILE="apache-tomcat-8.5.64.tar.gz"
JDK_DIR="/usr/local"
TOMCAT_DIR="/usr/local"
DIR=`pwd`

color () {
    RES_COL=60
    MOVE_TO_COL="echo -en \\033[${RES_COL}G"
    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 jdk* jdk 

cat >  /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=$JDK_DIR/jdk
export PATH=\$PATH:\$JAVA_HOME/bin
#export JRE_HOME=\$JAVA_HOME/jre
#export CLASSPATH=.:\$JAVA_HOME/lib/:\$JRE_HOME/lib/
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

 

扩展知识:tomcat 和 catalina 关系 Tomcat的servlet容器在4.X版本中被Craig McClanahan(Apache Struts项目的创始人,也是Tomcat 的 Catalina 的架构师)重新设计为Catalina.即Catalina就是servlet容器。 Tomcat的核心分为3个部分: (1)Web容器:处理静态页面; (2)JSP容器:把jsp页面翻译成一般的 servlet (3)catalina: 是一个servlet容器,用于处理servlet Catalina是美国西海岸靠近洛杉矶22英里的一个小岛,因为其风景秀丽而著名,曾被评为全美最漂亮的小 岛。Servlet运行模块的最早开发者Craig McClanahan因为喜欢Catalina岛,故以Catalina命名他所开 这个模块,另外在开发的早期阶段,Tomcat是被搭建在一个叫Avalon的服务器框架上,而Avalon则是 Catalina岛上的一个小镇的名字,于是想一个与小镇名字相关联的单词也是自然而然。设计者估计是想把 tomcat设计成最美的轻量级容器吧。下图为该小岛。   TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
  TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back

标签:安装,tomcat,root,sh,usr,local,centos8
From: https://www.cnblogs.com/qude/p/17480979.html

相关文章

  • 安装JDK
    rpm安装#需要登录下载:https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html[root@centos8~]#ls-lhjdk-8u241-linux-x64.rpm-rw-r--r--1rootroot171MFeb 818:29jdk-8u241-linux-x64.rpm#安装jdk,无相关依赖包[root@centos8~]#dnf-yins......
  • docker启动tomcat时区差了8小时
    docker启动tomcat时区差了8小时进入tomcat容器,一般在/usr/local/tomcat/bin找到目录下的catalina.sh文件,在这里修改时区大概100多行,下面这个JAVA_OPTS就是我们加进去的#OSspecificsupport.$var_must_besettoeithertrueorfalse.cygwin=falseJAVA_OPTS="-se......
  • docker的安装
    1.安装gcc,gcc-c++,yum-utils,由于蜜蜂已经安装过了,这里显示已是最新版[root@bee~]#yuminstall-ygccgcc-c++yum-utils2.指定镜像仓库(其实就是配置几个yum)[root@bee~]#yum-config-manager--add-repohttp://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo3.......
  • yarn 安装进行时,显现错误 node_modules\gifsicle: Command failed.
    1.错误显示[4/5]Buildingfreshpackages...[7/13]⠠jpegtran-bin[6/13]⠠gifsicle[8/13]⠠mozjpeg[4/13]⠠gifsicleerrorE:\IdeaStudyProjects\ucthings-ui-vue\node_modules\gifsicle:Commandfailed.Exitcode:1Command:nodelib/install.jsArguments:D......
  • Scala简介和安装
    简介Scala是一种多范式的编程语言(多范式:多种编程方法的意思。有面向过程、面向对象、泛型、函数式四种程序设计方法),其设计的初衷是要集成面向对象编程和函数式编程的各种特性。Scala运行于Java平台(Java虚拟机),并兼容现有的Java程序官网:https://www.scala-lang.org/Scala以一种......
  • Ubuntu 源代码编译安装 Nginx
    建立nginx用户和用户组sudogroupaddnginxsudouseraddnginx-gnginx-s/sbin/nologin-M在线安装依赖sudoapt-yinstallgccmakeopenssllibssl-devlibpcre3libpcre3-devlibgd-devvimwgetnet-tools下载并解压nginx源代码wgethttp://nginx.org/download/nginx-1.24......
  • 安装elasticsearch集群开启认证
    ##节点:172.30.1.101172.30.1.131172.30.1.102##下载rpmwgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-x86_64.rpm#安装elasticsearch##设置环境rpm-ivhelasticsearch-7.12.0-x86_64.rpm##禁用swapswapoff-ased-ri's/......
  • docker 安装mysql-server
    ################查找mysql-server镜像:dockersearchmysql-server[root@igoodful~]#dockersearchmysql-serverINDEXNAMEDESCRIPTIONSTARSOFFICIALAUTOMATEDdocker.iodock......
  • MySQL基础:安装和启动
    MySQL基础:安装和启动课程安排基础篇介绍数据库相关概念SQL是操作关系型数据库的编程语言主流关系型数据库总结安装MySQL数据库MySQL数据库启动与停止默认mysql开机启动客户端连接方式1方式2需要配置环境变量......
  • 如何在Ubuntu Nginx上安装fcgiwrap
    fcgiwrap是一个简单的服务器,用于在FastCGI上运行CGI应用程序。我们可以用它来为nginxwebserver提供干净的CGI支持。它是一个轻量级的服务器,具有零配置选项,可以使用同一个池来运行不同的站点。本文介绍了如何在Ubuntu20.04上安装fcgiwrap。CGI的意思是CommonGatewayInterface,......