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安装
系统环境:Centos7
第一步:下载tomcat安装包
tomcat官网:https://tomcat.apache.org/
第二步:安装包上传至linux中
[[email protected] ~]# rz
[[email protected] ~]# ls
apache-tomcat-9.0.17.zip fuhai-jpress-alpha.zip
[[email protected] ~]#
第三步:解压安装包
[[email protected] ~]# unzip apache-tomcat-9.0.17.zip
第四步:移动文件到/usr/local
[[email protected] ~]# mv apache-tomcat-9.0.17 /usr/local/tomcat
第五步:加执行权限
[[email protected] local]# chmod -R +x tomcat/
第六步:下载java环境(jdk)
[[email protected] bin]# yum install java -y #java-1.8.0-openjdk(低版本)
第七步:启动tomcat(如果打不开可以先关闭,再打开)
[[email protected] 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.
第八步:检测端口(查看80端口是否启动)
[[email protected] 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
[[email protected] 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
/usr/local/tomcat/webapps/ROOT(如果在tomcat上上传关于网页的,在这个目录下)如果指定文件可以在webapps下创建一个目录
tomcat日志
logs/catalina.out
tomcat主配置文件
[[email protected] 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指令
如果没有telnet这个命令,需要打开yum仓库下载
cd /etc/yum.repos.d
ls
yum clean all
yum repolist
yum install telnet -y
[[email protected] 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.
[[email protected] 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多实例部署-三台(用xshell打开同一个虚拟机三个)
第一步:复制两份tomcat文件
[[email protected] local]# ls
bin etc games include lib lib64 libexec sbin share src tomcat
[[email protected] local]# cp tomcat tomcat1 -a
[[email protected] local]# cp tomcat tomcat2 -a
[[email protected] local]# ls
bin etc games include lib lib64 libexec sbin share src tomcat tomcat1 tomcat2
第二步:修改tomcat1端口
vim conf/server.xml
只需要修改两处:
8005–》8006
8080–》8081
打开/usr/local/tomcat1/webapps/ROOT
在webapps写
echo "zhangpan" > ROOT/index.html
第三步:修改tomcat2端口
vim conf/server.xml
只需要修改两处:
8005–》8007
8080–》8082
打开/usr/local/tomcat2/webapps/ROOT
在webapps写
echo "pan" > ROOT/index.html
第四步:启动各个tomcat实例
[[email protected] local]# tomcat/bin/startup.sh
[[email protected] local]# tomcat1/bin/startup.sh
[[email protected] local]# tomcat2/bin/startup.sh
第五步:查看端口
[[email protected] 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.221.45
tomcat集群: 192.168.221.123
第一步:部署tomcat后端节点
第二步:编辑nginx配置文件(在nginx服务器上)
首先查看yum源,是否能下载
cd /etc/yum.repos.d
ls
yum clean all
yum repolist
下载nginx yum install nginx -y
vim /etc/nginx/nginx.conf
upstream pan {
server 192.168.221.123:8080 weight=2 max_fails=2 fail_timeout=2;
server 192.168.221.123:8081 weight=4 max_fails=2 fail_timeout=2;
server 192.168.221.123:8082 weight=1 max_fails=2 fail_timeout=2;
}
中间不用改
location / {
proxy_pass http://pan;
}
第三步:检测nginx配置并启动
[[email protected] 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
[[email protected] yum.repos.d]# systemctl restart nginx
第四步:监测tomcat集群: 192.168.221.123端口(打开三个窗口)
监控端口:
tail /usr/local/logs/catalina.out -f
tail /usr/local/tomcat1/logs/catalina.out -f
tail /usr/local/tomcat2/logs/catalina.out -f
第四步:浏览器访问(如果不行,有可能防火墙没关)
访问的时候nginx服务器
tomcat上线jpress博客系统
第一步:下载jpress
https://gitee.com/fuhai/jpress/blob/alpha/wars/jpress-web-newest.war
第二步:上传软件包并解压
[[email protected] ROOT]# ls
fuhai-jpress-alpha.zip
[[email protected] ROOT]# unzip fuhai-jpress-alpha.zip
第三步:复制
[[email protected] ROOT]# cp jpress/wars/jpress-web-newest.war .(复制到当前目录下)
[[email protected] ROOT]# ls
fuhai-jpress-alpha.zip jpress jpress-web-newest.war
第四步:解压jpress-web-newest.war
[[email protected] ROOT]# unzip jpress-web-newest.war
第五步:浏览器访问
输入ip:8080/jpress
第六步:下载数据库并启动
[[email protected] ROOT]# yum install mariadb-server -y
[[email protected] ROOT]# systemctl restart mariadb
第七步:创建数据库和用户
[[email protected] 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 pan;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on *.* to [email protected]’localhost’ identified by ‘123’;
Query OK, 0 rows affected (0.00 sec)
第八步:浏览器输入数据库相关的库和用户
略
第九步:重启tomcat
[[email protected] 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
[[email protected] 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.
第十步:再次访问浏览器
就可以访问了
原文地址:https://www.cnblogs.com/zp-1996/p/10941705.html