http://www.cnblogs.com/liaolongjun/p/5638740.html
http://www.awspack.com/os/linux/yum-install-tomcat/
在服務器跑Java程序的時候,經常用的Web服務器就是Tomcat,今天用yum命令試着安裝了一下。
編譯安裝的時候需要安裝JDK和Tomcat,而yum安裝Tomcat直接把OpenJDK也給安裝上了。
yum安裝Tomcat
先查看一下yum安裝時的Tomcat版本
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               
                 5 
                 
               
                 6 
                 
               
                 7 
                 
               
                 8 
                 
               
                 9 
                 
               
                 10 
                 
               
                 11 
                 
               
                 12 
                 
               
                 13 
                 
               
                 14 
                 
               
                 15 
                 
               
                 16 
                 
               
                 17 
                 
               
                 18 
                 
               
                 19 
                 
               
                 20 
                 
               |  
              
                
                # yum info tomcat 
                 
                
                Loaded plugins: security 
                 
                
                Available Packages 
                 
                
                Name        : tomcat 
                 
                
                Arch        : noarch 
                 
                
                Version     : 7.0.33 
                 
                
                Release     : 4.el6 
                 
                
                Size        : 86 k 
                 
                
                Repo        : epel 
                 
                
                Summary     : Apache Servlet/JSP Engine, RI for Servlet 3.0/JSP 2.2 API 
                 
                
                URL         : http://tomcat.apache.org/ 
                 
                
                License     : ASL 2.0 
                 
                
                Description : Tomcat is the servlet container that is used in the official Reference 
                 
                
                            : Implementation for the Java Servlet and JavaServer Pages technologies. 
                 
                
                            : The Java Servlet and JavaServer Pages specifications are developed by 
                 
                
                            : Sun under the Java Community Process. 
                 
                
                            : 
                 
                
                            : Tomcat is developed in an open and participatory environment and 
                 
                
                            : released under the Apache Software License version 2.0. Tomcat is intended 
                 
                
                            : to be a collaboration of the best-of-breed developers from around the world. 
                 
               |  
            
Tomcat最新版本是2015/11/24發布的Tomcat8.0.29,而yum安裝版本是2012/11/21發布的7.0.33(版本確實低了)。
安裝Tomcat
安裝Tomcat之后,查看安裝的版本。
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               
                 5 
                 
               
                 6 
                 
               
                 7 
                 
               
                 8 
                 
               
                 9 
                 
               
                 10 
                 
               
                 11 
                 
               |  
              
                
                # yum install tomcat 
                 
                
                # tomcat version 
                 
                
                Server version: Apache Tomcat/7.0.33 
                 
                
                Server built:   Apr 30 2014 09:16:58 
                 
                
                Server number:  7.0.33.0 
                 
                
                OS Name:        Linux 
                 
                
                OS Version:     2.6.32-573.8.1.el6.x86_64 
                 
                
                Architecture:   amd64 
                 
                
                JVM Version:    1.8.0_65-b17 
                 
                
                JVM Vendor:     Oracle Corporation 
                 
               |  
            
安裝Tomcat時直接把OpenJDK也安裝了
在這里可以看到安裝的JDK不是Oracle的JDK而是OpenJDK。
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               |  
              
                
                # java -version 
                 
                
                openjdk version "1.8.0_65" 
                 
                
                OpenJDK Runtime Environment (build 1.8.0_65-b17) 
                 
                
                OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode) 
                 
               |  
            
可以使用alternatives切換使用的Java版本。
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               
                 5 
                 
               
                 6 
                 
               
                 7 
                 
               
                 8 
                 
               |  
              
                
                # alternatives --config java 
                 
                
                There are 2 programs which provide 'java'. 
                 
                
                  Selection    Command 
                 
                
                ----------------------------------------------- 
                 
                
                   1           /usr/lib/jvm/jre-1.5.0-gcj/bin/java 
                 
                
                *+ 2           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java 
                 
               |  
            
使用Tomcat管理頁面
訪問Tomcat管理頁面(http://localhost:8080/manager/html)需要安裝tomcat-admin-webapps和修改tomcat-users.xml文件。
安裝tomcat-admin-webapps
|  
               
                 1 
                 
               |  
              
                
                # yum install tomcat-admin-webapps 
                 
               |  
            
修改tomcat-users.xml文件
修改tomcat-users.xml文件(默認安裝目錄是/etc/tomcat),添加46-48行的內容。
|  
               
                 1 
                 
               
                 2 
                 
               
                 3 
                 
               
                 4 
                 
               
                 5 
                 
               
                 6 
                 
               
                 7 
                 
               
                 8 
                 
               
                 9 
                 
               
                 10 
                 
               
                 11 
                 
               
                 12 
                 
               
                 13 
                 
               
                 14 
                 
               
                 15 
                 
               
                 16 
                 
               
                 17 
                 
               
                 18 
                 
               
                 19 
                 
               
                 20 
                 
               
                 21 
                 
               
                 22 
                 
               
                 23 
                 
               
                 24 
                 
               
                 25 
                 
               
                 26 
                 
               
                 27 
                 
               
                 28 
                 
               
                 29 
                 
               
                 30 
                 
               
                 31 
                 
               
                 32 
                 
               
                 33 
                 
               
                 34 
                 
               
                 35 
                 
               
                 36 
                 
               
                 37 
                 
               
                 38 
                 
               
                 39 
                 
               
                 40 
                 
               
                 41 
                 
               
                 42 
                 
               
                 43 
                 
               
                 44 
                 
               
                 45 
                 
               
                 46 
                 
               
                 47 
                 
               
                 48 
                 
               
                 49 
                 
               |  
              
                
                <?xml version='1.0' encoding='utf-8'?> 
                 
                
                <!-- 
                 
                
                  Licensed to the Apache Software Foundation (ASF) under one or more 
                 
                
                  contributor license agreements.  See the NOTICE file distributed with 
                 
                
                  this work for additional information regarding copyright ownership. 
                 
                
                  The ASF licenses this file to You under the Apache License, Version 2.0 
                 
                
                  (the "License"); you may not use this file except in compliance with 
                 
                
                  the License.  You may obtain a copy of the License at 
                 
                
                      http://www.apache.org/licenses/LICENSE-2.0 
                 
                
                  Unless required by applicable law or agreed to in writing, software 
                 
                
                  distributed under the License is distributed on an "AS IS" BASIS, 
                 
                
                  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
                 
                
                  See the License for the specific language governing permissions and 
                 
                
                  limitations under the License. 
                 
                
                --> 
                 
                
                <tomcat-users> 
                 
                
                <!-- 
                 
                
                  NOTE:  By default, no user is included in the "manager-gui" role required 
                 
                
                  to operate the "/manager/html" web application.  If you wish to use this app, 
                 
                
                  you must define such a user - the username and password are arbitrary. 
                 
                
                --> 
                 
                
                <!-- 
                 
                
                  NOTE:  The sample user and role entries below are wrapped in a comment 
                 
                
                  and thus are ignored when reading this file. Do not forget to remove 
                 
                
                  <!.. ..> that surrounds them. 
                 
                
                --> 
                 
                
                <!-- 
                 
                
                  <role rolename="tomcat"/> 
                 
                
                  <role rolename="role1"/> 
                 
                
                  <user username="tomcat" password="tomcat" roles="tomcat"/> 
                 
                
                  <user username="both" password="tomcat" roles="tomcat,role1"/> 
                 
                
                  <user username="role1" password="tomcat" roles="role1"/> 
                 
                
                --> 
                 
                
                <!-- <role rolename="admin"/> --> 
                 
                
                <!-- <role rolename="admin-gui"/> --> 
                 
                
                <!-- <role rolename="admin-script"/> --> 
                 
                
                <!-- <role rolename="manager"/> --> 
                 
                
                <!-- <role rolename="manager-gui"/> --> 
                 
                
                <!-- <role rolename="manager-script"/> --> 
                 
                
                <!-- <role rolename="manager-jmx"/> --> 
                 
                
                <!-- <role rolename="manager-status"/> --> 
                 
                
                <!-- <user name="admin" password="adminadmin" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" /> --> 
                 
                
                <role rolename="admin-gui"/> 
                 
                
                <role rolename="manager-gui"/> 
                 
                
                  <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/> 
                 
                
                </tomcat-users> 
                 
               |  
            
訪問Tomcat管理頁面
訪問http://localhost:8080/manager/html,並輸入48行里設定的username和password,就可以了。
