java的简介
Java是Sun公司发起的一个项目,最早出现的原因为解决机顶盒程序不兼容的问题,却无心插柳柳成荫成就了互联网的一个项目
Tomcat的安装需要安装jdk组件
[root@centos7 ~]# yum list all *openjdk* 查系统带的
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
java-1.8.0-openjdk.x86_64 1:1.8.0.102-4.b14.el7 @anaconda
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.102-4.b14.el7 @anaconda
Available Packages
java-1.6.0-openjdk.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-demo.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-devel.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-javadoc.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.6.0-openjdk-src.x86_64 1:1.6.0.41-1.13.13.1.el7_3 updates
java-1.7.0-openjdk.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-accessibility.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-demo.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-devel.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-headless.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-javadoc.noarch 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.7.0-openjdk-src.x86_64 1:1.7.0.141-2.6.10.1.el7_3 updates
java-1.8.0-openjdk.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-debug.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-debuginfo.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-debuginfo.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-devel-debug.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-headless-debug.i686 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.141-1.b16.el7_3 updates
java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.141-1.b16.el7_3 updates
[root@centos7 ~]# yum -y install java-1.8.0-openjdk-devel.x86_64 安装openjdk-devel包自动解决相关的依赖程序就可以了
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.141-1.b16.el7_3 will be installed
--> Processing Dependency: java-1.8.0-openjdk = 1:1.8.0.141-1.b16.el7_3 for package: 1:java-1.8.0-openjdk-devel-1.8.0.141-1.b16.el7_3.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.102-4.b14.el7 will be updated
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.141-1.b16.el7_3 will be an update
--> Processing Dependency: java-1.8.0-openjdk-headless = 1:1.8.0.141-1.b16.el7_3 for package: 1:java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64
--> Running transaction check
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.102-4.b14.el7 will be updated
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.141-1.b16.el7_3 will be an update
--> Processing Dependency: nss(x86-64) >= 3.28.4 for package: 1:java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64
--> Running transaction check
---> Package nss.x86_64 0:3.21.0-17.el7 will be updated
--> Processing Dependency: nss = 3.21.0-17.el7 for package: nss-sysinit-3.21.0-17.el7.x86_64
--> Processing Dependency: nss(x86-64) = 3.21.0-17.el7 for package: nss-tools-3.21.0-17.el7.x86_64
---> Package nss.x86_64 0:3.28.4-1.2.el7_3 will be an update
--> Processing Dependency: nss-util >= 3.28.2-1.1 for package: nss-3.28.4-1.2.el7_3.x86_64
--> Processing Dependency: nspr >= 4.13.1 for package: nss-3.28.4-1.2.el7_3.x86_64
--> Processing Dependency: libnssutil3.so(NSSUTIL_3.24)(64bit) for package: nss-3.28.4-1.2.el7_3.x86_64
--> Running transaction check
---> Package nspr.x86_64 0:4.11.0-1.el7_2 will be updated
---> Package nspr.x86_64 0:4.13.1-1.0.el7_3 will be an update
---> Package nss-sysinit.x86_64 0:3.21.0-17.el7 will be updated
---> Package nss-sysinit.x86_64 0:3.28.4-1.2.el7_3 will be an update
---> Package nss-tools.x86_64 0:3.21.0-17.el7 will be updated
---> Package nss-tools.x86_64 0:3.28.4-1.2.el7_3 will be an update
---> Package nss-util.x86_64 0:3.21.0-2.2.el7_2 will be updated
---> Package nss-util.x86_64 0:3.28.4-1.0.el7_3 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================
Installing:
java-1.8.0-openjdk-devel x86_64 1:1.8.0.141-1.b16.el7_3 updates 9.7 M
Updating for dependencies:
java-1.8.0-openjdk x86_64 1:1.8.0.141-1.b16.el7_3 updates 234 k
java-1.8.0-openjdk-headless x86_64 1:1.8.0.141-1.b16.el7_3 updates 31 M
nspr x86_64 4.13.1-1.0.el7_3 updates 126 k
nss x86_64 3.28.4-1.2.el7_3 updates 872 k
nss-sysinit x86_64 3.28.4-1.2.el7_3 updates 58 k
nss-tools x86_64 3.28.4-1.2.el7_3 updates 496 k
nss-util x86_64 3.28.4-1.0.el7_3 updates 73 k
Transaction Summary
=========================================================================================================================
Install 1 Package
Upgrade ( 7 Dependent packages)
Total size: 43 M
Total download size: 9.7 M
Downloading packages:
java-1.8.0-openjdk-devel-1.8.0.141-1.b16.el7_3.x86_64.rpm | 9.7 MB 00:00:10
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : nspr-4.13.1-1.0.el7_3.x86_64 1/15
Updating : nss-util-3.28.4-1.0.el7_3.x86_64 2/15
Updating : nss-3.28.4-1.2.el7_3.x86_64 3/15
Updating : nss-sysinit-3.28.4-1.2.el7_3.x86_64 4/15
Updating : 1:java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64 5/15
Updating : 1:java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64 6/15
warning: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre/lib/security/java.security created as /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64/jre/lib/security/java.security.rpmnew
Installing : 1:java-1.8.0-openjdk-devel-1.8.0.141-1.b16.el7_3.x86_64 7/15
Updating : nss-tools-3.28.4-1.2.el7_3.x86_64 8/15
Cleanup : nss-tools-3.21.0-17.el7.x86_64 9/15
Cleanup : 1:java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 10/15
Cleanup : 1:java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 11/15
Cleanup : nss-sysinit-3.21.0-17.el7.x86_64 12/15
Cleanup : nss-3.21.0-17.el7.x86_64 13/15
Cleanup : nss-util-3.21.0-2.2.el7_2.x86_64 14/15
Cleanup : nspr-4.11.0-1.el7_2.x86_64 15/15
Verifying : nss-tools-3.28.4-1.2.el7_3.x86_64 1/15
Verifying : 1:java-1.8.0-openjdk-devel-1.8.0.141-1.b16.el7_3.x86_64 2/15
Verifying : nss-util-3.28.4-1.0.el7_3.x86_64 3/15
Verifying : nss-3.28.4-1.2.el7_3.x86_64 4/15
Verifying : nspr-4.13.1-1.0.el7_3.x86_64 5/15
Verifying : 1:java-1.8.0-openjdk-1.8.0.141-1.b16.el7_3.x86_64 6/15
Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.141-1.b16.el7_3.x86_64 7/15
Verifying : nss-sysinit-3.28.4-1.2.el7_3.x86_64 8/15
Verifying : nss-tools-3.21.0-17.el7.x86_64 9/15
Verifying : 1:java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 10/15
Verifying : nss-3.21.0-17.el7.x86_64 11/15
Verifying : nss-util-3.21.0-2.2.el7_2.x86_64 12/15
Verifying : nspr-4.11.0-1.el7_2.x86_64 13/15
Verifying : nss-sysinit-3.21.0-17.el7.x86_64 14/15
Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 15/15
Installed:
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.141-1.b16.el7_3
Dependency Updated:
java-1.8.0-openjdk.x86_64 1:1.8.0.141-1.b16.el7_3 java-1.8.0-openjdk-headless.x86_64 1:1.8.0.141-1.b16.el7_3
nspr.x86_64 0:4.13.1-1.0.el7_3 nss.x86_64 0:3.28.4-1.2.el7_3
nss-sysinit.x86_64 0:3.28.4-1.2.el7_3 nss-tools.x86_64 0:3.28.4-1.2.el7_3
nss-util.x86_64 0:3.28.4-1.0.el7_3
Complete!
[root@centos7 ~]# java -version 安装成功后使用此命令此时并查看版本
openjdk version "1.8.0_141"
OpenJDK Runtime Environment (build 1.8.0_141-b16)
OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)
[root@centos7 ~]# java 查看关于Java的相关组件
java:Java进程 javac:Java的编译器 javadoc javah javap javaws javaws.itweb
使用rpm工具;不建议编译安装太麻烦对于Java程序来说
[root@localhost ~]# rpm -ivh jdk-8u144-linux-x64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:jdk1.8.0_144-2000:1.8.0_144-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
安装到这里
[root@localhost ~]# ll /usr/java/
总用量 0
lrwxrwxrwx. 1 root root 16 8月 31 04:06 default -> /usr/java/latest 当存在多半本并存时此路径指定默认运行的程序文件
drwxr-xr-x. 9 root root 268 8月 31 04:06 jdk1.8.0_144 真正程序文件
lrwxrwxrwx. 1 root root 22 8月 31 04:06 latest -> /usr/java/jdk1.8.0_144
目录结构
[root@localhost latest]# ls ../
default jdk1.8.0_144 latest
[root@localhost latest]# ls
bin db javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
[root@localhost latest]# ls bin/
appletviewer java javapackager jdb jmc jstat pack200 serialver xjc
ControlPanel javac java-rmi.cgi jdeps jmc.ini jstatd policytool servertool
extcheck javadoc javaws jhat jps jvisualvm rmic tnameserv
idlj javafxpackager jcmd jinfo jrunscript keytool rmid unpack200
jar javah jconsole jjs jsadebugd native2ascii rmiregistry wsgen
jarsigner javap jcontrol jmap jstack orbd schemagen wsimport
[root@localhost latest]# jps 查看Java进程的命令
2513 Jps
Java路径不在系统环境变量中;需要定义;此外还需要定义一个javahome变量来告诉Java程序Java的路径
[root@localhost latest]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
[root@localhost latest]#. /etc/profile.d/java.sh 让其生效
http的协议诞生促进了cgi 的诞生
Java 2 EE:
CGI: Common Gateway Interface
Servlet:
类库;web app;Servlet container, Servlet Engine
JSP: Java Server Pag
.jsp -->jasper--> .java --> javac --> .class --> jvm
tomcat 的工作介绍
tomcat也是Java语言编写的程序,它需要运行在jdk的环境中;它运行的不是Tomcat进程而是Java(jvm)进程而此进程内部主程序是tomcat;运行后称为tomcat的实例;其内部是需要帮助我们理解解析jsp文件的;运行jsp文件需要指出cgi协议来与http协议交互;而tomcat本身不在使用CGI协议了因为其内部以径支持http协议了;tomcat无论是接收前端用户请求还是代理请求都使用一个http的接口,tomcat自身也是一个完整的webserver,不但支持http还支持https,要想解析http它还需要一个组件,而这个组件也是一个类,此组件有一个抽象的名字连接器;用来连接请求与我们真正服务器组件;连接有三类常用的1类http;2类https;3类ajp,ajp协议是二进制的,ajp有点类似fstcgi协议而他用的是自己专用的协议,如果请求想通过ajp协议进入服务器他必须是一个agp的客户端,Nginx不支持只有 Apache才支持ajp协议;与http和https不同而他们是文本协议。连接器把请求接进来之后,把请求交个jsp容器,把请求翻译成Java代码交给Servlet容器;servlet容器经过Java编译器成类文件,再交给jvm运行的;
连接器把用户请求接进来后到一个可以运行jsp代码的程序中而此程序在tomcat中叫引擎,一个server内部的引擎可以不止一个,通常情况下只运行一个;当运行多个引擎后就存在一些问题,就是一个连接器收到请求后不能分发给多个引擎,只能交给一个引擎,而一个引擎可以接受多个连接器发来的请求;连接器如何与引擎绑定起来,默认引擎无法与连接器做绑绑定,于是引入另外一个组件负责把连接器与引擎建立绑定关系,而此组件我们称之为服务(server);负责把连接器与内部引擎建立关联关系的(一个连接器只能属于一个引擎,而一个引擎可以有多个连接器例如一个人可以属于一个组织,而组织允许有多个人);引擎是真正意义上可以执行jsp代码的组件在tomcat中叫engine;引擎内部允许有多个虚拟主机host,当存在多个host才能实现多主机的概念;引擎根据请求的主机名及端口负责把代码交个对应的host主机处理用户请求;一个主机也支持部署多个应用程序,每一个应用放置在对应得URL目录下就可以了;但是与PHP不同的地方在于Java代码有一个特点都是类文件,这个类文件可能还依赖其他类库中的类文件,所以只有类加载器加载完备后才能运行的;而虚拟主机上可能跑多个应用程序;所以我们应该分开独立管理才可以,为了分开而独立管理每一个应用程序,还需要在内部在引入一层组件;来分开管理各应用程序;这个组件称为上下文context;每一个context用来专门配置一个应用程序及其运行环境;用户请求到达主机后还要路由到与之匹配的应用程序服务器;配置context最显著的标准就是通过URL来实现
单tomcat使用的内存空间不能超过32G,所以在生产环境中一般开多个实例,那么大家都不能使用同一个端口了,http默认使用80端口,因为他是Java程序,为了安全起见这种程序的运行者的身份一般是普通用户,非管理员就不能使用1024以内的特权端口,所有tomcat默认使用的端口是8080,所以tomcat天生就是被代理的命,编辑配置文件重启的话会对我们正在运行的主机会有影响;为避免此问题它允许我们热部署,tomcat内部有api,为了调用API他开发了一个命令行接口与图形化接口叫host-manager,用来管理主机的,而主机应用程序还需要部署,而此操作就是api输出的,命令行接口叫manager
安装tomcat
[root@centos7 ~]# yum list all tomcat* 查看关于tomcat相关的进程
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Packages
tomcat.noarch 主程序 7.0.69-12.el7_3 updates
tomcat-admin-webapps.noarch 管理程序 7.0.69-12.el7_3 updates
tomcat-docs-webapp.noarch 使用文档 7.0.69-12.el7_3 updates
tomcat-el-2.2-api.noarch 7.0.69-12.el7_3 updates
tomcat-javadoc.noarch 7.0.69-12.el7_3 updates
tomcat-jsp-2.2-api.noarch jsp类库 7.0.69-12.el7_3 updates
tomcat-jsvc.noarch 7.0.69-12.el7_3 updates
tomcat-lib.noarch 库文件 7.0.69-12.el7_3 updates
tomcat-native.x86_64 1.1.34-1.el7 epel
tomcat-servlet-3.0-api.noarch servlet 类库 7.0.69-12.el7_3 updates
tomcat-webapps.noarch 提供样例测试页面的包 7.0.69-12.el7_3 updates
tomcatjss.noarch 7.1.2-3.el7 base
[root@centos7 ~]# yum -y install tomcat-lib tomcat-docs tomcat tomcat-admin-webapps tomcat-webapps 使用yum安装
[root@centos7 ~]# systemctl start tomcat.service 启动服务
[root@centos7 ~]# ss -lnt 查看监听端口
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 5 192.168.122.1:53 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 100 :::8080 服务端口 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
开放防火墙端口8080
客户端测试
文档查看
二进制安装方式解压至 /usr/local目录下
[root@localhost ~]# tar xf apache-tomcat-7.0.78.tar.gz -C /usr/local/ 解压到指定的目录下
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls /usr/local/
apache-tomcat-7.0.78 bin etc games include lib lib64 libexec sbin share src
[root@localhost local]# ln -s apache-tomcat-7.0.78/ tomcat创建符号链接
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 9 root root 160 8月 31 18:58 apache-tomcat-7.0.78
drwxr-xr-x. 2 root root 6 11月 5 2016 bin
drwxr-xr-x. 2 root root 6 11月 5 2016 etc
drwxr-xr-x. 2 root root 6 11月 5 2016 games
drwxr-xr-x. 2 root root 6 11月 5 2016 include
drwxr-xr-x. 2 root root 6 11月 5 2016 lib
drwxr-xr-x. 2 root root 6 11月 5 2016 lib64
drwxr-xr-x. 2 root root 6 11月 5 2016 libexec
drwxr-xr-x. 2 root root 6 11月 5 2016 sbin
drwxr-xr-x. 5 root root 49 7月 28 04:34 share
drwxr-xr-x. 2 root root 6 11月 5 2016 src
lrwxrwxrwx. 1 root root 21 8月 31 18:59 tomcat -> apache-tomcat-7.0.78/
[root@localhost local]# cd tomcat/切入tomcat路径下
[root@localhost tomcat]# ll
总用量 96
drwxr-xr-x. 2 root root 4096 8月 31 18:58 bin
drwxr-xr-x. 2 root root 158 5月 10 23:05 conf
drwxr-xr-x. 2 root root 4096 8月 31 18:58 lib
-rw-r--r--. 1 root root 56846 5月 10 23:05 LICENSE
drwxr-xr-x. 2 root root 6 5月 10 23:02 logs
-rw-r--r--. 1 root root 1239 5月 10 23:05 NOTICE
-rw-r--r--. 1 root root 8965 5月 10 23:05 RELEASE-NOTES
-rw-r--r--. 1 root root 16195 5月 10 23:05 RUNNING.txt
drwxr-xr-x. 2 root root 30 8月 31 18:58 temp
drwxr-xr-x. 7 root root 81 5月 10 23:04 webapps
drwxr-xr-x. 2 root root 6 5月 10 23:02 work
[root@localhost tomcat]# ls bin/ bin目录下的文件属于程序
bootstrap.jar自举的程序 commons-daemon-native.tar.gz digest.sh startup.bat tool-wrapper.sh
catalina.bat configtest.bat setclasspath.bat startup.sh启动tomcat的脚本 version.bat
catalina.sh configtest.sh 检查语法 setclasspath.sh tomcat-juli.jar version.sh 查看版本
catalina-tasks.xml daemon.sh shutdown.bat tomcat-native.tar.gz
commons-daemon.jar digest.bat shutdown.sh停止tomcat的脚本 tool-wrapper.bat
[root@localhost tomcat]# bin/version.sh 查看版本
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.78
Server built: May 10 2017 15:02:19 UTC
Server number: 7.0.78.0
OS Name: Linux
OS Version: 3.10.0-514.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_144-b01
JVM Vendor: Oracle Corporation
定义环境变量
[root@localhost tomcat]# vim /etc/profile.d/tomcat.sh
export CATALINA_BASE=/usr/local/tomcat
export PATH=$CATALINA_BASE/bin:$PATH
[root@localhost tomcat]# . /etc/profile.d/tomcat.sh 让其生效
[root@localhost tomcat]# catalina.sh --help 查看此脚本的使用方法
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Usage: catalina.sh ( commands ... )
commands:
debug Start Catalina in a debugger
debug -security Debug Catalina with a security manager
jpda start Start Catalina under JPDA debugger
run Start Catalina in the current window
run -security Start in the current window with security manager
start Start Catalina in a separate window
start -security 安全启动 Start in a separate window with security manager
stop Stop Catalina, waiting up to 5 seconds for the process to end
stop n Stop Catalina, waiting up to n seconds for the process to end
stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running
stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running
configtest Run a basic syntax check on server.xml - check exit code for result
version What version of tomcat are you running?
Note: Waiting for the process to end and use of the -force option require that $CATALINA_PID is defined
启动服务
[root@localhost tomcat]# 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/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
查看端口
[root@localhost tomcat]# ss -nlt
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 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 100 :::8009 :::*
客户端测试
安装后生成的文件
tomcat的目录结构
bin:脚本,及启动时用到的类;
conf:配置文件目录;
lib:库文件,Java类库,jar;
logs:日志文件目录;
temp:临时文件目录;
webapps:webapp的默认目录;
work:工作目录;
[root@localhost tomcat]# ps aux
root 2431 1.3 11.6 2295052 116540 pts/0 Sl 19:20 0:11 /usr/java/latest/bin/java -Djava.util.logging.config.fi 启动是应管理员启动的;应该用普通用户运行的
停掉服务
[root@localhost tomcat]# catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
创建普通用户
[root@localhost tomcat]# useradd -r tomcat 创建用户
[root@localhost tomcat]# chown -R tomcat.tomcat /usr/local/tomcat/* 创建用户并授权
[root@localhost tomcat]# su tomcat -c 'catalina.sh start' su到普通用户运行启动命令
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/latest
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.ja
r:/usr/local/tomcat/bin/tomcat-juli.jarTomcat started.
查看端口
[root@localhost tomcat]# ss -lnt
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 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 :::8009 :::*
rpm包安装的程序环境:
配置文件目录:/etc/tomcat
主配置文件:server.xml
webapps存放位置:/var/lib/tomcat/webapps/
examples
manager
host-manager
docs
Unit File:tomcat.service
环境配置文件:/etc/sysconfig/tomcat
网友评论