【2018.06.26學習筆記】【linux高級知識 16.1-16.3】

16.1 Tomcat介紹

tomcat是Apache基金會的Jakarta項目中的一個核心項目,由Apache、sun與其餘公司及我的共同開發維護,是一個web服務中間件,真正起做用的解析java腳本的是jdk(java develoment kit):java的核心,它包含了jre、java工具、java基礎庫。php

主流的jdk由sun發佈,IBM公司也有發佈jdk,Centos上yum安裝的是openjdk。html

16.2 安裝jdk

在官網下載tar.gz包,再傳到linux系統裏,不用wget。java

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 
// 下載jdk-8u171-linux-x64.tar.gz。
//使用rz命令,從Windows傳到linux系統裏,存放到/usr/local/src目錄下。

解壓jdk:mysql

[root@nginx src]# tar xzvf jdk-8u171-linux-x64.tar.gz
##省略部分過程
jdk1.8.0_171/jre/bin/unpack200
jdk1.8.0_171/jre/plugin/
jdk1.8.0_171/jre/plugin/desktop/
jdk1.8.0_171/jre/plugin/desktop/sun_java.png
jdk1.8.0_171/jre/plugin/desktop/sun_java.desktop
jdk1.8.0_171/jre/README
jdk1.8.0_171/jre/COPYRIGHT

移動單獨的目錄下,並更名:linux

[root@nginx src]# mv jdk1.8.0_171 /usr/local/jdk1.8
[root@nginx src]# cd ..
[root@nginx local]# ls
bin  etc  games  include  jdk1.8  lib  lib64  libexec  mysql  nginx  php-fpm  sbin  share  src
[root@nginx local]# cd jdk1.8/
[root@nginx jdk1.8]# ls
bin        db       javafx-src.zip  lib      man          release  THIRDPARTYLICENSEREADME-JAVAFX.txt
COPYRIGHT  include  jre             LICENSE  README.html  src.zip  THIRDPARTYLICENSEREADME.txt

修改環境變量:/etc/profile,增長下面幾行nginx

[root@nginx jdk1.8]# 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@nginx jdk1.8]# source /etc/profile //從新加載profile

驗證是否安裝成功:顯示版本號,表明安裝成功web

[root@nginx jdk1.8]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

若是顯示的版本號是1.7,與你安裝的1.8版本不符,查看是否yum安裝過openjdksql

[root@nginx jdk1.8]# rpm -qa|grep openjdk   //若是有,就卸載掉,可是在生成環境中,別亂下載,可能有服務在使用openjdk,能夠升級openjdk到1.8

16.3 安裝Tomcat

下載tomcat:apache

[root@nginx src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz
--2018-06-26 22:48:17--  http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.31/bin/apache-tomcat-8.5.31.tar.gz
正在解析主機 mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 2001:da8:204:2001:250:56ff:fea1:22
正在鏈接 mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:9552281 (9.1M) [application/octet-stream]
正在保存至: 「apache-tomcat-8.5.31.tar.gz」

100%[====================================================================================================================>] 9,552,281    419KB/s 用時 26s    

2018-06-26 22:48:47 (363 KB/s) - 已保存 「apache-tomcat-8.5.31.tar.gz」 [9552281/9552281])

[root@nginx src]# ls
apache-tomcat-8.5.31.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz       nginx-1.14.0         php-5.6.32
jdk-8u171-linux-x64.tar.gz   mysql-test-5.7.18-linux-glibc2.5-x86_64.tar.gz  nginx-1.14.0.tar.gz  php-5.6.32.tar.bz2

解壓並移動更名:bootstrap

[root@nginx src]# tar xzvf apache-tomcat-8.5.31.tar.gz
apache-tomcat-8.5.31/conf/
apache-tomcat-8.5.31/conf/catalina.policy
apache-tomcat-8.5.31/conf/catalina.properties
apache-tomcat-8.5.31/conf/context.xml
apache-tomcat-8.5.31/conf/jaspic-providers.xml
apache-tomcat-8.5.31/conf/jaspic-providers.xsd

[root@nginx src]# mv apache-tomcat-8.5.31 /usr/local/tomcat
[root@nginx src]# cd ..
[root@nginx local]# ls
bin  etc  games  include  jdk1.8  lib  lib64  libexec  mysql  nginx  php-fpm  sbin  share  src  tomcat
[root@nginx local]# cd tomcat/
[root@nginx tomcat]# ls
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  temp  webapps  work

由於是二進制包,能夠直接運行:啓動腳本starup.sh

[root@nginx ~]# /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@nginx ~]# ps aux|grep tomcat
root       1519 29.2  5.2 2997944 97744 pts/0   Sl   22:51   0:04 /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 -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -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       1567  0.0  0.0 112720   972 pts/0    S+   22:52   0:00 grep --color=auto tomcat

若是啓動後沒有進程,要先shutdown.sh,再從新startup.sh。由於tomcat沒有restart命令。

查看監聽端口:8080web服務端口、8009第三方服務調用的端口,如httpd和tomcat結合用、8005管理端口,8005起來纔可以使用tomcat

[root@nginx ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      948/nginx: master p 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      892/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1221/master         
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      948/nginx: master p 
tcp6       0      0 :::8080                 :::*                    LISTEN      1519/java           
tcp6       0      0 :::22                   :::*                    LISTEN      892/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1221/master         
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      1519/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      1519/java           
tcp6       0      0 :::3306                 :::*                    LISTEN      1182/mysqld

訪問驗證:先關閉防火牆firewalld

[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@nginx ~]# curl 127.0.0.1:8080 -I
HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 26 Jun 2018 15:00:10 GMT

瀏覽器訪問:192.168.87.128:8080

相關文章
相關標籤/搜索