部署tomcat&部署LNAMT

这里写目录标题

tomcat就是中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中。而tomcat本身的运行也依赖于jdk环境。

部署tomcat

java环境安装

tomcat 官网https://archive.apache.org/

powershell 复制代码
安装jdk环境
[root@web1 ~]#: yum clean all
...
[root@web1 ~]#: yum makecache
...
[root@web1 ~]#: yum -y install java-11-openjdk*
...
[root@web1 ~]#: wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz
....
[root@web1 ~]#: rpm -qa | grep jdk
java-11-openjdk-devel-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-javadoc-11.0.18.0.9-0.3.ea.el8.x86_64
copy-jdk-configs-4.0-2.el8.noarch
java-11-openjdk-headless-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-jmods-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-demo-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-javadoc-zip-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-static-libs-11.0.18.0.9-0.3.ea.el8.x86_64
java-11-openjdk-src-11.0.18.0.9-0.3.ea.el8.x86_64

[root@web1 ~]#: java -version
openjdk version "11.0.18-ea" 2023-01-17 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.18.0.9-0.3.ea.el8) (build 11.0.18-ea+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.18.0.9-0.3.ea.el8) (build 11.0.18-ea+9-LTS, mixed mode, sharing)
[root@web1 ~]#: tar xf apache-tomcat-10.1.19.tar.gz -C  /usr/local/
[root@web1 ~]#: cd /usr/local/
[root@web1 local]#: ls
apache                 apr-util  games    lib64    php8   src
apache-tomcat-10.1.19  bin       include  libexec  sbin
apr                    etc       lib      mysql    share
[root@web1 local]#: ln -s /usr/local/apache-tomcat-10.1.19/ tomcat
[root@web1 local]#: ll
total 0
drwxr-xr-x. 14 root  root  164 Jan  5 10:32 apache
drwxr-xr-x   9 root  root  220 Feb 26 15:11 apache-tomcat-10.1.19
drwxr-xr-x.  6 root  root   58 Jan  5 10:31 apr
drwxr-xr-x.  5 root  root   43 Jan  5 10:31 apr-util
drwxr-xr-x.  2 root  root    6 Jun 22  2021 bin
drwxr-xr-x.  2 root  root    6 Jun 22  2021 etc
drwxr-xr-x.  2 root  root    6 Jun 22  2021 games
drwxr-xr-x.  2 root  root   19 Jan  5 10:33 include
drwxr-xr-x.  2 root  root    6 Jun 22  2021 lib
drwxr-xr-x.  3 root  root   17 Jul 28  2023 lib64
drwxr-xr-x.  2 root  root    6 Jun 22  2021 libexec
drwxr-xr-x.  9 mysql mysql 147 Jan  5 10:33 mysql
drwxr-xr-x.  9 root  root   88 Jan  5 10:43 php8
drwxr-xr-x.  2 root  root    6 Jun 22  2021 sbin
drwxr-xr-x.  5 root  root   49 Jul 28  2023 share
drwxr-xr-x.  2 root  root    6 Jun 22  2021 src
lrwxrwxrwx   1 root  root   33 Feb 26 15:12 tomcat -> /usr/local/apache-tomcat-10.1.19/
[root@web1 local]#: cd tomcat/
[root@web1 tomcat]#: ls
bin           CONTRIBUTING.md  logs       RELEASE-NOTES  webapps
BUILDING.txt  lib              NOTICE     RUNNING.txt    work
conf          LICENSE          README.md  temp
[root@web1 tomcat]#: cd bin/
[root@web1 bin]#: ls
bootstrap.jar                 daemon.sh         shutdown.sh
catalina.bat                  digest.bat        startup.bat
catalina.sh                   digest.sh         startup.sh
catalina-tasks.xml            makebase.bat      tomcat-juli.jar
ciphers.bat                   makebase.sh       tomcat-native.tar.gz
ciphers.sh                    migrate.bat       tool-wrapper.bat
commons-daemon.jar            migrate.sh        tool-wrapper.sh
commons-daemon-native.tar.gz  setclasspath.bat  version.bat
configtest.bat                setclasspath.sh   version.sh
configtest.sh                 shutdown.bat

启动tomcat
[root@web1 bin]#: /usr/local/tomcat/bin/catalina.sh start
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:   
Tomcat started.
[root@web1 bin]#: ss -antl
State  Recv-Q Send-Q      Local Address:Port  Peer Address:Port Process 
LISTEN 0      128               0.0.0.0:9000       0.0.0.0:*            
LISTEN 0      128               0.0.0.0:22         0.0.0.0:*            
LISTEN 0      70                      *:33060            *:*            
LISTEN 0      1      [::ffff:127.0.0.1]:8005             *:*            
LISTEN 0      128                     *:3306             *:*            
LISTEN 0      100                     *:8080             *:*            
LISTEN 0      128                     *:80               *:*            
LISTEN 0      128                  [::]:22            [::]:* 

端口号8005/8080和进程要同时启动成功
[root@web1 bin]#: ps -ef | grep tomcat
root        6169       1  1 15:14 pts/0    00:00:02 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root        6211    1846  0 15:16 pts/0    00:00:00 grep --color=auto tomcat
访问测试
powershell 复制代码
设置开机自启
[root@web1 ~]#: cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/tomcat10.service
[root@web1 ~]#: vim /usr/lib/systemd/system/tomcat10.service
[root@web1 ~]#: cat /usr/lib/systemd/system/tomcat10.service
[Unit]
Description=tomcat server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/tomcat/bin/catalina.sh start
ExecStop=/usr/local/tomcat/bin/catalina.sh stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@web1 ~]#: systemctl daemon-reload 
[root@web1 ~]#: systemctl status tomcat10.service 
● tomcat10.service - tomcat server daemon
   Loaded: loaded (/usr/lib/systemd/system/tomcat10.service; disabled; >
   Active: inactive (dead)
lines 1-3/3 (END)
[root@web1 ~]# systemctl enable --now tomcat10.service 
Created symlink /etc/systemd/system/multi-user.target.wants/tomcat10.service → /usr/lib/systemd/system/tomcat10.service.
powershell 复制代码
添加自定义Java测试页面
[root@web1 ~]#: mkdir /usr/local/tomcat/webapps/test
[root@web1 ~]#: cd /usr/local/tomcat/webapps/test
[root@web1 test]#: vim index.jsp 
[root@web1 test]#: cat index.jsp 
<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
            out.println("Hellow World");
        %>
</body>
</html>

部署LNAMT

环境准备 IP 服务器版本
LAMT 8080(web1) 192.168.227.134 Centos8/rocky9
LNMT 8081 (web2) 192.168.227.141 rocky9
nginx(负载均衡)80 192.168.227.153 rocky9
更改tomcat端口号
powershell 复制代码
[root@web2 ~]# cd /usr/local/tomcat/conf/
[root@web2 conf]# vim server.xml 
......
    <Connector port="8081" protocol="HTTP/1.1"    更改端口号为8081
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               />
......
[root@web2 conf]# systemctl restart tomcat10.service 
[root@web2 conf]# ss -antl
State  Recv-Q Send-Q      Local Address:Port  Peer Address:Port Process 
LISTEN 0      4096            127.0.0.1:9000       0.0.0.0:*            
LISTEN 0      511               0.0.0.0:80         0.0.0.0:*            
LISTEN 0      128               0.0.0.0:22         0.0.0.0:*            
LISTEN 0      70                      *:33060            *:*            
LISTEN 0      1      [::ffff:127.0.0.1]:8005             *:*            
LISTEN 0      151                     *:3306             *:*            
LISTEN 0      100                     *:8081             *:*            
LISTEN 0      128                  [::]:22            [::]:*  
powershell 复制代码
在负载均衡服务器上配置
定义upstream
[root@nginx ~]#: cd /usr/local/nginx/conf/
[root@nginx conf]#: ls
fastcgi.conf            koi-utf             nginx.conf           uwsgi_params
fastcgi.conf.default    koi-win             nginx.conf.default   uwsgi_params.default
fastcgi_params          mime.types          scgi_params          win-utf
fastcgi_params.default  mime.types.default  scgi_params.default
[root@nginx conf]#: vim nginx.conf
    ......
    ......
    upstream webs {                定义upstream
        server 192.168.227.134:8080;
        server 192.168.227.141:8081;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://webs;  修改此行
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
......
......

重启nginx
[root@nginx conf]#: systemctl restart nginx.service 
相关推荐
色空大师11 分钟前
23种设计模式
java·开发语言·设计模式
闲人一枚(学习中)12 分钟前
设计模式-创建型-建造者模式
java·设计模式·建造者模式
丁总学Java18 分钟前
ARM 架构(Advanced RISC Machine)精简指令集计算机(Reduced Instruction Set Computer)
arm开发·架构
2202_7544215429 分钟前
生成MPSOC以及ZYNQ的启动文件BOOT.BIN的小软件
java·linux·开发语言
蓝染-惣右介32 分钟前
【MyBatisPlus·最新教程】包含多个改造案例,常用注解、条件构造器、代码生成、静态工具、类型处理器、分页插件、自动填充字段
java·数据库·tomcat·mybatis
小林想被监督学习33 分钟前
idea怎么打开两个窗口,运行两个项目
java·ide·intellij-idea
HoneyMoose35 分钟前
IDEA 2024.3 版本更新主要功能介绍
java·ide·intellij-idea
我只会发热36 分钟前
Java SE 与 Java EE:基础与进阶的探索之旅
java·开发语言·java-ee
是老余38 分钟前
本地可运行,jar包运行错误【解决实例】:通过IDEA的maven package打包多模块项目
java·maven·intellij-idea·jar
crazy_wsp38 分钟前
IDEA怎么定位java类所用maven依赖版本及引用位置
java·maven·intellij-idea