• CentOS 6 安装配置JDK+tomcat环境


    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 # 安装
    

    执行:

    [root@localhost ~]# 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!
    

    ④检查安装结果

    [root@localhost ~]# 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账户里

    [root@localhost ftpuser]# ls
    222  apache-tomcat-9.0.13.tar.gz  dir1-0  dir1-1
    

    然后复制此文件到/usr/local/tomcat/目录下

    tomcat目录为自己创建,安装对路径并无要求

    [root@localhost ftpuser]# cp apache-tomcat-9.0.13.tar.gz /usr/local/tomcat/
    [root@localhost ftpuser]# cd /usr/local/tomcat
    [root@localhost tomcat]# ls
    apache-tomcat-9.0.13.tar.gz
    

    进入文件所在目录解压即可

    [root@localhost tomcat]# tar zxvf apache-tomcat-9.0.13.tar.gz
    

    ③启动tomcat

    [root@localhost tomcat]# cd apache-tomcat-9.0.13/bin
    [root@localhost 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

    开启端口
    [root@localhost ~]# /sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT #开启8080端口 
    [root@localhost ~]# /etc/rc.d/init.d/iptables save #保存配置 
    [root@localhost ~]# /etc/rc.d/init.d/iptables restart #重启防火墙
    关闭防火墙
    service iptables stop #暂时关闭
    chkconfig iptables off #设置成开启不自启
    

    如我在自己电脑的浏览器输入 服务器ip:8080

    ④查看tomcat版本

    [root@localhost 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
    [root@localhost bin]# 
    

    ⑤关闭tomcat

    查看tomcat是否运行

    ps -ef | grep tomcat
    [root@localhost bin]# ps -ef | grep tomcat
    root      6975  6663  0 11:43 pts/1    00:00:00 grep tomcat
    

    关闭tomcat(执行shutdown.sh脚本)

    [root@localhost apache-tomcat-9.0.13]# cd bin
    [root@localhost 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
  • 相关阅读:
    Storyboard里面的几种Segue区别和视图的切换
    2014年12月英语单词
    测试和调试的区别
    黑苹果安装教程(一)
    IOS基础——IOS学习路线图(一)
    遇到Wampserver遇到的问题
    产生不重复的数字
    简单的布局
    2014年8月
    算法小全
  • 原文地址:https://www.cnblogs.com/lifan1998/p/10107067.html
Copyright © 2020-2023  润新知