CentOS 6 安裝配置JDK+tomcat環境
阿新 • • 發佈:2018-12-12
1.安裝OpenJDK
這裡安裝的OpenJDK,是開源版本的JDK,我們平時自己電腦上安裝的是 Sun JDK(也叫Oracle JDK),OpenJDK可以看作Sun JDK的精簡版。
如果想安裝SunJDK,請參照下方的tomcat安裝方法,步驟是一樣的,注意liunx有些自帶OpenJDK,需解除安裝。
注意,安裝OpenJDK簡單迅速,只需一條命令,且無需配置環境變數
①檢視是否已經安裝了JDK
java -version
rpm -qa |grep java
rpm -qa |grep jdk
②若有如何解除安裝
解除安裝JDK相關檔案輸入:
yum -y remove java-1.8.0-openjdk*
解除安裝tzdata-java輸入:
yum -y remove tzdata-java.noarch
③安裝
yum list java* #檢視版本
yum list java-1.8* #檢視1.8版本
yum install java-1.8.0-openjdk* -y # 安裝
執行:
[[email protected] ~]# yum -y install java-1.8.0-openjdk* Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: repos-lax.psychz.net * elrepo-kernel: repos.lax-noc.com * extras: repos-lax.psychz.net * updates: mirrors.oit.uci.edu Resolving Dependencies --> Running transaction check ---> Package java-1.8.0-openjdk.i686 1:1.8.0.191.b12-0.el6_10 will be installed ... Complete!
④檢查安裝結果
[[email protected] ~]# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK Server VM (build 25.191-b12, mixed mode)
執行java和javac,正常,無需配置環境變數
3.安裝tomcat
①去官網下載安裝包
https://tomcat.apache.org/download-90.cgi
這裡我下的是9.0的版本
②上傳至伺服器然後解壓
這裡我用的FileZilla 上傳到ftp賬戶裡
[[email protected] ftpuser]# ls
222 apache-tomcat-9.0.13.tar.gz dir1-0 dir1-1
然後複製此檔案到/usr/local/tomcat/目錄下
tomcat目錄為自己建立,安裝對路徑並無要求
[[email protected] ftpuser]# cp apache-tomcat-9.0.13.tar.gz /usr/local/tomcat/
[[email protected] ftpuser]# cd /usr/local/tomcat
[[email protected] tomcat]# ls
apache-tomcat-9.0.13.tar.gz
進入檔案所在目錄解壓即可
[[email protected] tomcat]# tar zxvf apache-tomcat-9.0.13.tar.gz
③啟動tomcat
[[email protected] tomcat]# cd apache-tomcat-9.0.13/bin
[[email protected] bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.13/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar
Tomcat started.
關閉防火牆或者開放埠後,即可用任意一臺裝置訪問tomcat
開啟埠
[[email protected] ~]# /sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT #開啟8080埠
[[email protected] ~]# /etc/rc.d/init.d/iptables save #儲存配置
[[email protected] ~]# /etc/rc.d/init.d/iptables restart #重啟防火牆
關閉防火牆
service iptables stop #暫時關閉
chkconfig iptables off #設定成開啟不自啟
如我在自己電腦的瀏覽器輸入 伺服器ip:8080
④檢視tomcat版本
[[email protected] bin]# ./catalina.sh version
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.13/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.13
Server built: Nov 2 2018 14:27:55 UTC
Server number: 9.0.13.0
OS Name: Linux
OS Version: 4.10.4-1.el6.elrepo.i686
Architecture: i386
JVM Version: 1.8.0_191-b12
JVM Vendor: Oracle Corporation
[[email protected] bin]#
⑤關閉tomcat
檢視tomcat是否執行
ps -ef | grep tomcat
[[email protected] bin]# ps -ef | grep tomcat
root 6975 6663 0 11:43 pts/1 00:00:00 grep tomcat
關閉tomcat(執行shutdown.sh指令碼)
[[email protected] apache-tomcat-9.0.13]# cd bin
[[email protected] bin]# ./shutdown.sh
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-9.0.13
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-9.0.13/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-9.0.13/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-9.0.13/bin/tomcat-juli.jar
⑥解除安裝tomcat
直接刪除安裝目錄
rm -rf /usr/local/tomcat/apache-tomcat-9.0.13