Tomcat轻量级web服务器

时间:2024-05-23 11:34:50

1.三种web服务器

apache: 动态网站

nginx: 静态网站

tomcat:java开发的程序

2.tomcat安装

官网下载安装包(tomcat 9)

解压并放在/usr/local下

chmod  -R +x /usr/local/tomcat

./startup.sh  #启动(需在bin目录下)

yum install java -y 解决java环境

./shutdown.sh  #关闭

3.tomcat主配置文件

[root@li tomcat]# vim conf/server.xml

<Server port=”8005″ shutdown=”SHUTDOWN”>

<Connector port=”8080″ protocol=”HTTP/1.1″

<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />

<Host name=”localhost” appBase=”webapps”

8005端口接收shutdown指令

[root@li tomcat]# telnet 127.0.0.1 8005

Trying 127.0.0.1…

Connected to 127.0.0.1.

Escape character is ‘^]’.

SHUTDOWN

Connection closed by foreign host.

[root@li tomcat]#

[root@li tomcat]#

[root@li tomcat]# ss -tnl

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 *:22 *:*

LISTEN 0 100 127.0.0.1:25 *:*

LISTEN 0 128 :::80 :::*

LISTEN 0 128 :::22 :::*

LISTEN 0 100 ::1:25 :::*

4. tomcat的三个端口

8005: 接收shutdown指令

8080: 监听的端口

8009: AJP协议

5. tomcat多实例部署

1)复制两份tomcat文件

  

  cp /usr/local/tomcat /usr/local/tomcat1 -a

  cp /usr/local/tomcat /usr/local/tomcat2 -a

2)修改两个端口:

vim /usr/local/tomcat1/conf/server.xml

将8005端口改为8006

将8080端口改为8081

vim /usr/local/tomcat1/conf/server.xml

将8005端口改为8007

将8080端口改为8082

3)分别进入两个文件中的bin下进行启动

6. tomcat集群编辑nginx配置文件

前端nginx做调度器

后端节点是tomcat

upstream li {

server 192.168.64.4:8080 weight=2 max_fails=2 fail_timeout=2;

server 192.168.64.4:8081 weight=2 max_fails=2 fail_timeout=2;

server 192.168.64.4:8082 weight=2 max_fails=2 fail_timeout=2;

}

location / {

proxy_pass http://li;

}

7.tomcat上线java开发的软件包

1)下载jpress

https://gitee.com/fuhai/jpress/blob/alpha/wars/jpress-web-newest.war

2)上传软件包并解压

  cd /usr/local/tomcat/webapps/ROOT

  [root@li ROOT]# ls

  fuhai-jpress-alpha.zip

  [root@li ROOT]# unzip fuhai-jpress-alpha.zip

3)复制

  [root@li ROOT]# cp jpress/wars/jpress-web-newest.war .

  [root@li ROOT]# ls

  fuhai-jpress-alpha.zip jpress jpress-web-newest.war

4)解压jpress-web-newest.war

  [root@li ROOT]# unzip jpress-web-newest.war

5)浏览器访问

输入ip:8080/jpress

6)下载数据库并启动

  [root@li ROOT]# yum install mariadb-server -y

  [root@li ROOT]# systemctl restart mariadb

7)创建数据库和用户

[root@li ROOT]# mysql -uroot

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 2

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> create database li;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to li@’localhost’ identified by ‘123’;

Query OK, 0 rows affected (0.00 sec)

8)浏览器输入数据库相关的库和用户

9)重启tomcat

[root@li bin]# ./shutdown.sh

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

[root@li bin]# ./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

Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Tomcat started.

10)再次访问浏览器