16.1 Tomcat介绍 - 16.2 安装jdk - 16.3 安装Tomcat
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了16.1 Tomcat介绍 - 16.2 安装jdk - 16.3 安装Tomcat相关的知识,希望对你有一定的参考价值。
16.1 Tomcat介绍
16.2 安装jdk
16.3 安装Tomcat
扩展
http://www.360doc.com/content/11/0618/21/16915_127901371.shtml
j2ee、j2se、ejb、javabean、serverlet、jsp之间关系 http://bbs.csdn.net/topics/50015576
tomcat server.xml配置详解 http://blog.csdn.net/yuanxuegui2008/article/details/6056754
tomcat常用数据库连接的方法 http://wjw7702.blog.51cto.com/5210820/1109263
16.1 Tomcat介绍
LNMP针对的开发语言是php语言,php 是一门开发web程序比较流行的语言,早起是asp,在Windows上运行的,安全性差,就网站开发人员就开始转到php,并习惯于用php开发了,而且相对的比较安全
java是一门比较庞大的开发语言,不仅仅可以开发建站,也可以开发大型软件和游戏 Tomcat介绍
Tomcat是Apache软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。
java程序写的网站用tomcat+jdk来解析、运行
tomcat是一个中间件,真正起作用的,解析java脚本的是jdk
jdk(java development kit)是整个java的核心,它包含了java运行环境和一堆java相关的工具以及java基础库。
最主流的jdk为sun公司发布的jdk,除此之外,其实IBM公司也有发布JDK,CentOS上也可以用yum安装openjdk java写的网页是jsp后缀,解析需要jdk
16.2 安装jdk
jdk版本1.6,1.7,1.8
官网下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载jdk8,放到/usr/local/src/目录下
tar zxvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /usr/local/jdk1.8
vi /etc/profile //最后面增加
JAVA_HOME=/usr/local/jdk1.8/JAVA_BIN=/usr/local/jdk1.8/binJRE_HOME=/usr/local/jdk1.8/jrePATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
source /etc/profile
java -version
安装tomcat ,需要先安装jdk,因为tomcat依赖于jdk的环境变量
jdk版本1.6,1.7,1.8,检查6、7、8
官网下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
下载对应版本(x86、x64)的后缀为 tar.gz的
进入官方网站,允许协议,开始下载,下载到指定的Windows目录下,然后使用xftp传到机器上
已经在root下面了 再把安装包挪到/usr/local/src 目录下
[[email protected] ~]# ls aming.txt anaconda-ks.cfg jdk-8u101-linux-x64.tar.gz [[email protected] ~]# cd /usr/local/src [[email protected] src]# ls apr-1.6.2 httpd-2.4.27.tar.gz php-5.6.30.tar.gz apr-1.6.2.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6apr-util-1.6.0 nginx-1.12.1 php-7.1.6.tar.bz2 apr-util-1.6.0.tar.gz nginx-1.12.1.tar.gz phpredis-develop httpd-2.4.27 php-5.6.30 phpredis-develop.zip [[email protected] src]# mv /root/jdk-8u101-linux-x64.tar.gz . [[email protected] src]# ls apr-1.6.2 jdk-8u101-linux-x64.tar.gz php-7.1.6apr-1.6.2.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2 apr-util-1.6.0 nginx-1.12.1 phpredis-develop apr-util-1.6.0.tar.gz nginx-1.12.1.tar.gz phpredis-develop.zip httpd-2.4.27 php-5.6.30httpd-2.4.27.tar.gz php-5.6.30.tar.gz [[email protected] src]#
解压
[[email protected] src]# tar zxvf jdk-8u101-linux-x64.tar.gz jdk1.8.0_101/man/ja_JP.UTF-8/man1/jcmd.1jdk1.8.0_101/man/ja_JP.UTF-8/man1/javapackager.1jdk1.8.0_101/man/ja_JP.UTF-8/man1/jstat.1 [[email protected] src]# du -sh jdk1.8.0_101/352M jdk1.8.0_101/ [[email protected] src]#
挪到/usr/local/ 下面然后改名字jdk1.8
[[email protected] src]# mv jdk1.8.0_101/ /usr/local/jdk1.8[[email protected] src]#
接下来需要编辑/etc/profile
vi /etc/profile //最后面增加
JAVA_HOME=/usr/local/jdk1.8/ JAVA_BIN=/usr/local/jdk1.8/bin JRE_HOME=/usr/local/jdk1.8/jre PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar
进入目录下/etc/profile 这个目录是设置环境变量的
[[email protected] src]# vi /etc/profile export PATH=$PATH:/usr/local/mysql/bin/ JAVA_HOME=/usr/local/jdk1.8/ JAVA_BIN=/usr/local/jdk1.8/bin JRE_HOME=/usr/local/jdk1.8/jre PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charsets.jar :wq [[email protected] src]# vi /etc/profile [[email protected] src]#
这几行内容,主要用于定义环境变量 编辑完之后刷新环境变量文件,使他立即生效
添加完了之后用source /etc/profile 使其立即生效
[[email protected] src]# source /etc/profile [[email protected] src]#
怎么去检验jdk 有没有安装成功,使用java -version
[[email protected] src]# java -version java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) [[email protected] src]#
假设如果提示的不是下载的版本号,需要检查是否系统安装有openjdk之类的包了 如果安装有之类的包的时候,显示版本号就会有区别,但也不要随意卸载,因为系统可能又其他程序再调用
16.3 安装Tomcat
安装完了jdk之后下面是安装tomcat
cd /usr/local/src
wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
tar zxvf apache-tomcat-8.5.20.tar.gz
mv apache-tomcat-8.5.20 /usr/local/tomcat
/usr/local/tomcat/bin/startup.sh
ps aux|grep tomcat
netstat -lntp |grep java
三个端口8080为提供web服务的端口,8005为管理端口,8009端口为第三方服务调用的端口,比如httpd和Tomcat结合时会用到
tomcat虽然是jdk和java 的中间件,但是如果没有了它,就不能去监听8080或者80端口,也没办法让客户端或者浏览器去访问,tomcat就是一个java的webserver, tomcat依赖于jdk ,所以需要先安装jdk
下载包(二进制免编译包)进入/usr/local/src/ 目录下
如果下载不了,就把文件先放到windows里面,再用xftp 工具 ctrl alt f 把文件移到linux服务器上
解压
[[email protected] src]# ls apache-tomcat-8.5.8.tar.gz httpd-2.4.27.tar.gz php-5.6.30.tar.gz apr-1.6.2 jdk-8u101-linux-x64.tar.gz php-7.1.6apr-1.6.2.tar.gz mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz php-7.1.6.tar.bz2 apr-util-1.6.0 nginx-1.12.1 phpredis-develop apr-util-1.6.0.tar.gz nginx-1.12.1.tar.gz phpredis-develop.zip httpd-2.4.27 php-5.6.30[[email protected] src]# [[email protected]-01 src]# tar zxvf apache-tomcat-8.5.8.tar.gz apache-tomcat-8.5.8/bin/setclasspath.sh apache-tomcat-8.5.8/bin/shutdown.sh apache-tomcat-8.5.8/bin/startup.sh apache-tomcat-8.5.8/bin/tool-wrapper.sh apache-tomcat-8.5.8/bin/version.sh [[email protected] src]#
移动到/usr/local/ 改名tomcat
[[email protected] src]# mv apache-tomcat-8.5.8 /usr/local/tomcat [[email protected] src]#
之后就可以启动起来了,把tomcat启动 /usr/local/tomcat/bin/startup.sh
[[email protected] src]# /usr/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/local/jdk1.8Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. [[email protected] src]#
看看有没有java的进程,如果有 tomcat就已经正常启动了
[[email protected] src]# ps aux|grep java root 3112 31.8 8.1 2271432 81784 pts/0 Sl 21:00 0:19 /usr/local/jdk1.8/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 -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 3182 0.0 0.0 112680 976 pts/0 S+ 21:01 0:00 grep --color=auto java [[email protected] src]#
怎么关闭tomcat ,它不支持restart
[[email protected] src]# /usr/local/tomcat/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/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar [[email protected] src]# !psps aux|grep java root 3213 0.0 0.0 112680 976 pts/0 R+ 21:03 0:00 grep --color=auto java [[email protected] src]#
再把tomcat启动
[[email protected] src]# /usr/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/local/jdk1.8 Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. [[email protected] src]#
可以看下监听端口
[[email protected] src]# netstat -lntp |grep java tcp6 0 0 :::8080 :::* LISTEN 3228/java tcp6 0 0 :::8009 :::* LISTEN 3228/java [r[email protected] src]#
三个端口8080为提供web服务的端口(为常用),8005为管理端口,8009端口为第三方服务调用的端口,比如httpd和Tomcat结合时会用到
测试tomcat 访问页面
关闭firlewalld
systemctl stop firewalld
systemctl disable firewalld
[[email protected] src]# systemctl stop firewalld[[email protected] src]# systemctl disable firewalldRemoved symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. [[email protected] src]#
再来看下防火墙
[[email protected] src]# iptables -nvL Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination [[email protected] src]#
没有防火墙了,在浏览器打开页面 192.168.202.131:8080(这个是我的虚拟机地址)
出现这个页面就证明服务搭建好了
[[email protected] src]# netstat -lntp |grep javatcp6 0 0 :::8080 :::* LISTEN 3228/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 3228/java tcp6 0 0 :::8009 :::* LISTEN 3228/java [[email protected] src]#
三个端口8080为提供web服务的端口(常用的),8005为管理端口,8009端口为第三方服务调用的端口,比如httpd和Tomcat结合时会用到
扩展
http://www.360doc.com/content/11/0618/21/16915_127901371.shtml
j2ee、j2se、ejb、javabean、serverlet、jsp之间关系 http://bbs.csdn.net/topics/50015576
tomcat server.xml配置详解 http://blog.csdn.net/yuanxuegui2008/article/details/6056754
tomcat常用数据库连接的方法 http://wjw7702.blog.51cto.com/5210820/1109263
以上是关于16.1 Tomcat介绍 - 16.2 安装jdk - 16.3 安装Tomcat的主要内容,如果未能解决你的问题,请参考以下文章
16.1 Tomcat介绍 16.2 安装jdk 16.3 安装Tomcat
16.1 Tomcat介绍16.2 安装jdk16.3 安装Tomcat