当前位置:首页 » 《关于电脑》 » 正文

Centos6.8服务器上部署tomcat8环境 及 Centos6.8下升级jdk1.7环境至jdk1.8的过程

22 人参与  2024年05月03日 15:34  分类 : 《关于电脑》  评论

点击全文阅读


一、Centos6.8服务器上部署tomcat8环境

    运行java服务器端程序需要tomcat环境,, 最新的版本是Tomcat 10 ,不过是alpha版,我这里先使用的tomcat8,因为tomcat8目前是一个很稳定的版本。Apache Tomcat 8支持Java EE 7规范,包括Java Servlet 3.1、JSP 2.3、Java统一表达式语言EL 3.0等。tomcat8官网下载地址: Apache Tomcat® - Apache Tomcat 8 Software Downloads ,整个安装过程如下:

#下载tomcat解压安装[root@007 ~]# cd /usr/local/[root@007 local]# wget https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-8/v8.5.58/bin/apache-tomcat-8.5.58.tar.gz[root@007 local]# ll | grep tomcat-rw-r--r--   1 root    root    10420837 Sep 11 06:03 apache-tomcat-8.5.58.tar.gz[root@007 local]# tar -zxvf apache-tomcat-8.5.58.tar.gz[root@007 local]# mv apache-tomcat-8.5.58 tomcat8.5[root@007 local]# rm -rf apache-tomcat-8.5.58.tar.gz [root@007 local]# cd tomcat8.5/[root@007 tomcat8.5]# cd bin/[root@007 bin]# pwd/usr/local/tomcat8.5/bin#启动tomcat服务[root@007 bin]# /usr/local/tomcat8.5/bin/startup.sh Using CATALINA_BASE:   /usr/local/tomcat8.5Using CATALINA_HOME:   /usr/local/tomcat8.5Using CATALINA_TMPDIR: /usr/local/tomcat8.5/tempUsing JRE_HOME:        /usrUsing CLASSPATH:       /usr/local/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jarUsing CATALINA_OPTS:   Tomcat started.#查看tomcat进程以及tomcat默认监听的端口8080[root@007 bin]# ps -ef | grep tomcatroot     20300     1 19 10:08 pts/2    00:00:02 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat8.5/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/tomcat8.5/bin/bootstrap.jar:/usr/local/tomcat8.5/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat8.5 -Dcatalina.home=/usr/local/tomcat8.5 -Djava.io.tmpdir=/usr/local/tomcat8.5/temp org.apache.catalina.startup.Bootstrap startroot     20333 19746  0 10:09 pts/2    00:00:00 grep --color tomcat[root@007 bin]# netstat -anp | grep tomcat[root@007 bin]# netstat -anp | grep 8080tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      20300/java  

    此时在浏览器中访问服务器端的8080端口,即可正常请求(防火墙未阻止的情况下)。在页面上看到我安装的版本是Apache Tomcat/8.5.58, 怎么有一个Tomcat 8.5.0 版本呢。原来Tomcat 9绑定到Java EE8了。Java EE 8延了。Tomcat 8.0.x挺稳定的,很多用户不想加大量新功能影响稳定性。所以出来了一个8.5版本,让想用新技术的用户可以用8.5版。先这样,后期还是有必要换成tomcat9甚至是10版本。

二、Centos6.8下升级jdk1.7环境至jdk1.8

    不知道以前什么时候部署过java,很早前服务器也运行过需要java环境的jenkins服务,今天一看上面的java版本是1.7,版本过低,于是升级到1.8。过程如下:

[root@007 ~]# java -version        java version "1.7.0_261"OpenJDK Runtime Environment (rhel-2.6.22.1.el6_10-x86_64 u261-b02)OpenJDK 64-Bit Server VM (build 24.261-b02, mixed mode)[root@007 alternatives]# yum list installed |grep javagraphviz-java.x86_64               2.26.0-10.el6                       @base    java-1.7.0-openjdk.x86_64          1:1.7.0.261-2.6.22.1.el6_10         @updates tzdata-java.noarch                 2020a-1.el6                         @updates [root@007 alternatives]# yum -y install java-1.8.0-openjdk*....-------------------------------------------------------------------------------------------------------------Total                                                                                         5.7 MB/s | 218 MB     00:38     Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : 1:java-1.8.0-openjdk-headless-debug-1.8.0.265.b01-0.el6_10.x86_64    Installing : 1:java-1.8.0-openjdk-debug-1.8.0.265.b01-0.el6_10.x86_64     Installing : 1:java-1.8.0-openjdk-devel-debug-1.8.0.265.b01-0.el6_10.x86_64      Installing : 1:java-1.8.0-openjdk-headless-1.8.0.265.b01-0.el6_10.x86_64     Installing : 1:java-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.x86_64     Installing : 1:java-1.8.0-openjdk-demo-1.8.0.265.b01-0.el6_10.x86_64        Installing : 1:java-1.8.0-openjdk-devel-1.8.0.265.b01-0.el6_10.x86_64         Installing : 1:java-1.8.0-openjdk-src-1.8.0.265.b01-0.el6_10.x86_64  Installing : 1:java-1.8.0-openjdk-demo-debug-1.8.0.265.b01-0.el6_10.x86_64      Installing : 1:java-1.8.0-openjdk-src-debug-1.8.0.265.b01-0.el6_10.x86_64  Installing : 1:java-1.8.0-openjdk-javadoc-1.8.0.265.b01-0.el6_10.noarch  Installing : 1:java-1.8.0-openjdk-javadoc-debug-1.8.0.265.b01-0.el6_10.noarch   Verifying  : 1:java-1.8.0-openjdk-devel-debug-1.8.0.265.b01-0.el6_10.x86_64   Verifying  : 1:java-1.8.0-openjdk-headless-debug-1.8.0.265.b01-0.el6_10.x86_64   Verifying  : 1:java-1.8.0-openjdk-demo-1.8.0.265.b01-0.el6_10.x86_64     Verifying  : 1:java-1.8.0-openjdk-javadoc-debug-1.8.0.265.b01-0.el6_10.noarch   Verifying  : 1:java-1.8.0-openjdk-devel-1.8.0.265.b01-0.el6_10.x86_64   Verifying  : 1:java-1.8.0-openjdk-src-debug-1.8.0.265.b01-0.el6_10.x86_64    Verifying  : 1:java-1.8.0-openjdk-src-1.8.0.265.b01-0.el6_10.x86_64  Verifying  : 1:java-1.8.0-openjdk-headless-1.8.0.265.b01-0.el6_10.x86_64    Verifying  : 1:java-1.8.0-openjdk-debug-1.8.0.265.b01-0.el6_10.x86_64    Verifying  : 1:java-1.8.0-openjdk-javadoc-1.8.0.265.b01-0.el6_10.noarch  Verifying  : 1:java-1.8.0-openjdk-demo-debug-1.8.0.265.b01-0.el6_10.x86_64    Verifying  : 1:java-1.8.0-openjdk-1.8.0.265.b01-0.el6_10.x86_64  Installed:  java-1.8.0-openjdk.x86_64 1:1.8.0.265.b01-0.el6_10                                         java-1.8.0-openjdk-debug.x86_64 1:1.8.0.265.b01-0.el6_10                                          java-1.8.0-openjdk-demo.x86_64 1:1.8.0.265.b01-0.el6_10                                    java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.265.b01-0.el6_10                                     java-1.8.0-openjdk-devel.x86_64 1:1.8.0.265.b01-0.el6_10                                   java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.265.b01-0.el6_10                                    java-1.8.0-openjdk-headless.x86_64 1:1.8.0.265.b01-0.el6_10                                java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.265.b01-0.el6_10                                 java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.265.b01-0.el6_10                                 java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.265.b01-0.el6_10                                  java-1.8.0-openjdk-src.x86_64 1:1.8.0.265.b01-0.el6_10                                     java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.265.b01-0.el6_10                                    Complete![root@007 alternatives]# java -versionopenjdk version "1.8.0_265"OpenJDK Runtime Environment (build 1.8.0_265-b01)OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)[root@007 alternatives]# 

三、tomcat服务器配置用户名和密码登录的403问题

    tomcat服务器搭建好之后,默认未开启管理功能。点击页面上的Manager App进入后会报错:403 Access Denied,其中重要的信息如下:

#If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
#For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/><user username="tomcat" password="s3cret" roles="manager-gui"/>

    报错中提示需要编辑conf/tomcat-users.xml 添加访问的用户账号和角色,编辑之后重启tomcat服务。不过我在进行这样的处理后,发现前台的界面仍然是报403错误。找了找原因发现其实tomcat早就提醒我们了,在上面的403报错界面中还有一句提示:

#By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

    即默认tomcat是只允许本机访问,而不允许远程访问。所以需要修改tomcat8.5/webapps/manager/META-INF/context.xml  文件。将其中的allow这行修改为下方内容(其实就是增加了一个通用IP地址的规则,即允许所有IP地址)

 allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|\d+\.\d+\.\d+\.\d+" />

    然后重启tomcat服务器,进入管理界面就会提示输入账号密码,此时即已成功。


点击全文阅读


本文链接:http://zhangshiyu.com/post/103241.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1