tomcat

tomcat简介

 

Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。

Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。

Tomcat和Nginx、Apache(httpd)、lighttpd等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,

Tomcat处理静态HTML的能力不如Nginx/Apache服务器。

目前Tomcat最新版本为9.0。Java容器还有resin、weblogic等。

tomcat安装

 

第一步:官网下载安装包

https://tomcat.apache.org/

 

第二步:上传安装包

[root@root ~]# rz

[root@root ~]# ls
apache-tomcat-9.0.17.zip 
[root@root ~]#

 

第三步:解压安装包

[root@root ~]# unzip apache-tomcat-9.0.17.zip

 

第四步:移动文件到/usr/local

[root@root ~]# mv apache-tomcat-9.0.17 /usr/local/tomcat

 

第五步:加执行权限

[root@root local]# chmod -R +x tomcat/

 

第六步:下载java环境(jdk)

[root@root bin]# yum install java -y   #java-1.8.0-openjdk

 

第七步:启动tomcat

[root@root 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.

 

第八步:检测端口

[root@root bin]# 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 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*

 

第九步:浏览器访问

 

 

第十步:关闭tomcat

[root@root 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

 

 

tomcat网站根目录

 

webapps

 

tomcat日志

 

logs/catalina.out

 

tomcat主配置文件

 

[root@root 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@root 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@root tomcat]#
[root@root tomcat]#
[root@root 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 :::*

 

 

tomcat多实例部署-三台

 

第一步:复制两份tomcat文件

[root@root local]# ls
bin etc games include lib lib64 libexec sbin share src tomcat
[root@root local]# cp tomcat tomcat1 -a
[root@root local]# cp tomcat tomcat2 -a
[root@root local]# ls
bin etc games include lib lib64 libexec sbin share src tomcat tomcat1 tomcat2

 

第二步:修改tomcat1端口

只需要修改两处:

8005–》8006

8080–》8081

 

第三步:修改tomcat2端口

只需要修改两处:

8005–》8007

8080–》8082

 

第四步:启动各个tomcat实例

[root@root local]# tomcat/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.
[root@root local]# tomcat1/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat1
Using CATALINA_HOME: /usr/local/tomcat1
Using CATALINA_TMPDIR: /usr/local/tomcat1/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.
[root@root local]# tomcat2/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat2
Using CATALINA_HOME: /usr/local/tomcat2
Using CATALINA_TMPDIR: /usr/local/tomcat2/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat2/bin/bootstrap.jar:/usr/local/tomcat2/bin/tomcat-juli.jar
Tomcat started.

 

第五步:查看端口

[root@root local]# 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 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 100 :::8081 :::*
LISTEN 0 100 :::8082 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*

 

第六步:访问网站

 

tomcat集群部署

 

nginx服务器:192.168.64.5

tomcat集群: 192.168.64.4

 

第一步:部署tomcat后端节点

 

第二步:编辑nginx配置文件

upstream song {
server 192.168.64.4:8080 weight=2 max_fails=2 fail_timeout=2;
server 192.168.64.4:8081 weight=4 max_fails=2 fail_timeout=2;
server 192.168.64.4:8082 weight=1 max_fails=2 fail_timeout=2;

}

 

location / {
proxy_pass http://song;
}

 

第三步:检测nginx配置并启动

[root@root yum.repos.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@root yum.repos.d]# systemctl restart nginx

 

第四步:浏览器访问

访问的是nginx服务器

 

 

tomcat上线jpress博客系统

 

第一步:下载jpress

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

 

第二步:上传软件包并解压

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

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

 

第三步:复制

[root@root ROOT]# cp jpress/wars/jpress-web-newest.war .
[root@root ROOT]# ls
fuhai-jpress-alpha.zip jpress jpress-web-newest.war

 

第四步:解压jpress-web-newest.war

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

 

第五步:浏览器访问

输入ip:8080/jpress

 

第六步:下载数据库并启动

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

[root@root ROOT]# systemctl restart mariadb

 

 

第七步:创建数据库和用户

[root@root 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 ken;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to ken@’localhost’ identified by ‘123’;
Query OK, 0 rows affected (0.00 sec)

 

第八步:浏览器输入数据库相关的库和用户

 

第九步:重启tomcat

[root@root 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@root 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.

 

第十步:再次访问浏览器

就可以访问了

posted on 2019-05-30 19:50  师兄你好  阅读(115)  评论(0编辑  收藏  举报

导航