部署tomcat&部署LNAMT

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

部署tomcat

java环境安装

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

安装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
访问测试

在这里插入图片描述

设置开机自启
[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.
添加自定义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.134Centos8/rocky9
LNMT 8081 (web2)192.168.227.141rocky9
nginx(负载均衡)80192.168.227.153rocky9
更改tomcat端口号
[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            [::]:*  
在负载均衡服务器上配置
定义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 


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值