目前有很多网站使用jsp的程序编写,所以解析jsp的程序就必须要有相关的软件来完成。Tomcat就是用来解析jsp程序的一个软件,Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta项目中的一个核心项目,由Apache、Sun和其他一些公司及个人共同开发而成。因为Tomcat技术先进、性能稳定,而且免费,因而深受Java爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。
Tomcat是一个轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache服务器,可利用它响应对HTML 页面的访问请求。实际上Tomcat 部分是Apache服务器的扩展,但它是独立运行的,所以当你运行tomcat时,它实际上作为一个与Apache 独立的进程单独运行的
浏览器打开:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
存放在/usr/local/src中
解压:
[root@zhangfei src]# tar zxvf jdk-8u144-linux-x64.tar.gz
查看目录大小:
[root@zhangfei src]# du -sh jdk1.8.0_144/
363M jdk1.8.0_144/
移动目录:
[root@zhangfei src]# mv jdk1.8.0_144/ /usr/local/jdk1.8
定义环境变量:
[root@zhangfei src]# vim /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
配置生效:
[root@zhangfei src]# source /etc/profile
检查jdk是否安装成功:
[root@zhangfei src]# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
出现以上结果代表安装成功
若结果不同,则要搜索是否安装过openjdk:
[root@zhangfei src]# rpm -qa |grep openjdk
下载tmocat:
[root@zhangfei src]# wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
解压:
[root@zhangfei src]# tar zxvf apache-tomcat-8.5.20.tar.gz
移动目录:
[root@zhangfei src]# mv apache-tomcat-8.5.20 /usr/local/tomcat
启动(二进制包不用编译):
[root@zhangfei 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.
查看是否启动成功:
[root@zhangfei src]# ps aux | grep java
root 2557 31.8 8.1 2296136 82288 pts/0 Sl 22:48 0:17 /usr/local/jdk1.8/bin/java -java.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 2601 0.0 0.0 112664 972 pts/0 S+ 22:49 0:00 grep --color=auto java
不支持restart,必须要先stop然后start
[root@zhangfei 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
[root@zhangfei src]# !ps
ps aux | grep java
root 2638 0.0 0.0 112664 976 pts/0 S+ 22:51 0:00 grep --color=auto java
[root@zhangfei 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.
[root@zhangfei src]# netstat -lntp |grep java
tcp6 0 0 :::8080 :::* LISTEN 2653/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2653/java
tcp6 0 0 :::8009 :::* LISTEN 2653/java
清空规则:
[root@zhangfei src]# iptables -F
然后在浏览器输入192.168.137.20:8080 则会看到tomcat的界面
tomcat支持自定义端口
配置tomcat监听端口为80:
[root@zhangfei ~]# vim
/usr/local/tomcat/conf/server.xml
重启服务:
[root@zhangfei ~]# /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
[root@zhangfei ~]# /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.
查看监听端口有没有变:
[root@zhangfei ~]# netstat -lntp |grep java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2636/java
tcp6 0 0 :::8009 :::* LISTEN 2636/java
没有80端口
查看80端口:
[root@zhangfei ~]# netstat -lntp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1573/nginx: master
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2636/java
tcp6 0 0 :::8009 :::* LISTEN 2636/java
可以看到80端口被nginx占用
停掉nginx:
[root@zhangfei ~]# /etc/init.d/nginx stop
Stopping nginx (via systemctl): [ 确定 ]
再次查看80端口是被占用:
[root@zhangfei ~]# !net
netstat -lntp |grep 80
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 2636/java
tcp6 0 0 :::8009 :::* LISTEN 2636/java
重启tomcat:
[root@zhangfei ~]# /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
[root@zhangfei ~]# /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.
[root@zhangfei ~]# !net
netstat -lntp |grep 80
tcp6 0 0 :::80 :::* LISTEN 2766/java
tcp6 0 0 :::8009 :::* LISTEN 2766/java
打开配置文件:
[root@zhangfei ~]# vim /usr/local/tomcat/conf/server.xml
在Host这一块后面增加:
第一行的"www.123.cn"后面原本有个;
网站的程序放在/data/wwwroot/123.cn/里
下载zrlog:
[root@zhangfei src]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
拷贝到自动解压的目录:
[root@zhangfei src]# cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
查看是否自动解压:
[root@zhangfei src]# ls /usr/local/tomcat/webapps/
docs host-manager ROOT zrlog-1.7.1-baaecb9-release.war
examples manager zrlog-1.7.1-baaecb9-release
改名:
[root@zhangfei webapps]# mv zrlog-1.7.1-baaecb9-release zrlog
[root@zhangfei webapps]# ls
docs host-manager ROOT zrlog-1.7.1-baaecb9-release
examples manager zrlog zrlog-1.7.1-baaecb9-release.war
可以看到,此时压缩包又解压了一次
在浏览器访问http://192.168.137.20/zrlog/
查看mysql是否启动:
[root@zhangfei webapps]# ps aux | grep mysql
root 2091 0.0 0.1 115376 1680 ? S 21:49 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/zhangfei.pid
mysql 2284 0.1 45.2 1046784 456148 ? Sl 21:49 0:06 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/zhangfei.err --pid-file=/data/mysql/zhangfei.pid --socket=/tmp/mysql.sock
root 3125 0.0 0.0 112664 972 pts/0 R+ 23:22 0:00 grep --color=auto mysql
进入到数据库:
[root@zhangfei webapps]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)
创建数据库:
mysql> create database zrlog;
Query OK, 1 row affected (0.05 sec)
创建用户:
mysql> grant all on zrlog.* to 'zrlog'@127.0.0.1 identified by '94264334';
Query OK, 0 rows affected (0.00 sec)
不想在指里显示zrlog
[root@zhangfei webapps]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/123.cn/
在windows的hosts绑定 www.123.cn
重启服务:
[root@zhangfei webapps]# /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
[root@zhangfei webapps]# /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.
查看端口:
[root@zhangfei webapps]# netstat -lntp |grep 80
tcp6 0 0 :::80 :::* LISTEN 3297/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 3297/java
tcp6 0 0 :::8009 :::* LISTEN 3297/java
自定义的appbase下也应该有个ROOT目录
查看日志:
[root@zhangfei webapps]# ls /usr/local/tomcat/logs/
catalina.2017-08-28.log host-manager.2017-08-29.log localhost_access_log.2017-08-29.txt
catalina.2017-08-29.log localhost.2017-08-28.log manager.2017-08-28.log
catalina.out localhost.2017-08-29.log manager.2017-08-29.log
host-manager.2017-08-28.log localhost_access_log.2017-08-28.txt