我正在尝试在 Amazon EC2 实例上安装 Tomcat7,但是没有成功。下面是控制台输出:
[ec2-user@ip-XXX ~]$ sudo yum install tomcat7
Loaded plugins: amazon-id, rhui-lb, security
Setting up Install Process
No package tomcat7 available.
Error: Nothing to do
此外,我还想安装 Tomcat 连接器本机库。
[ec2-user@ip-XXX ~]$ sudo yum repolist
Loaded plugins: amazon-id, rhui-lb, security
rhui-REGION-client-config-server-6 | 2.6 kB 00:00
rhui-REGION-rhel-server-releases | 3.7 kB 00:00
rhui-REGION-rhel-server-releases-optional | 3.5 kB 00:00
repo id repo name status
rhui-REGION-client-config-server-6 Red Hat Update Infrastructure 2.0 Client Configuration Server 6 5
rhui-REGION-rhel-server-releases Red Hat Enterprise Linux Server 6 (RPMs) 11,976
rhui-REGION-rhel-server-releases-optional Red Hat Enterprise Linux Server 6 Optional (RPMs) 6,833
repolist: 18,814
[ec2-user@ip-XXX ~]$ sudo yum list tomcat7*
Loaded plugins: amazon-id, rhui-lb, security
Error: No matching Packages to list
答案1
Tomcat7 在 EC2 上的 yum Repo 中不可用。因此,以下是我在 RHEL 6.4 EC2 实例上安装 tomcat 7 的方法:
首先,我想要 oracle jdk。
Oracle JDK 安装:
删除所有现有的 JDK
# rpm -qa | grep jdk
java-1.6.0-openjdk-1.6.0.0-1.62.1.11.11.90.el6_4.x86_64
java-1.7.0-openjdk-1.7.0.25-2.3.10.4.el6_4.x86_64
# rpm -e java-1.6.0-openjdk-1.6.0.0-1.62.1.11.11.90.el6_4.x86_64 java-1.7.0-openjdk-1.7.0.25-2.3.10.4.el6_4.x86_64
下载并安装 Oracle JDK
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm"
# mv jdk-7u45-linux-x64.rpm\?AuthParam\=1385533795_9ebb9bbbd4d15a8ca5d17a0dab41fedc jdk-7u45-linux-x64.rpm
# rpm -ivh jdk-7u45-linux-x64.rpm
确认
# java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
# javac -version
javac 1.7.0_45
设置 JAVA_HOME
# echo "export JAVA_HOME=/usr/java/default" >> /etc/profile
# source /etc/profile
Tomcat 7 安装:
下载 Tomcat
# wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz
# tar -xvzf apache-tomcat-7.0.47.tar.gz
# mv apache-tomcat-7.0.47 /usr/share/
使 tomcat 作为脚本运行。
# cat > /etc/init.d/tomcat < EOF
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/default
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.47/
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
EOF
Tomcat 服务命令:
# chmod 755 /etc/init.d/tomcat
# chkconfig --add tomcat
# chkconfig tomcat on
# chkconfig --list tomcat
# service tomcat start
Using CATALINA_BASE: /usr/share/apache-tomcat-7.0.47
Using CATALINA_HOME: /usr/share/apache-tomcat-7.0.47
Using CATALINA_TMPDIR: /usr/share/apache-tomcat-7.0.47/temp
Using JRE_HOME: /usr/java/default
Using CLASSPATH: /usr/share/apache-tomcat-7.0.47/bin/bootstrap.jar:/usr/share/apache-tomcat-7.0.47/bin/tomcat-juli.jar
JAVA_OPTS
在第二行添加如下内容/usr/share/apache-tomcat-7.0.47/bin/catalina.sh
,使其看起来像:
#!/bin/sh
JAVA_OPTS="-Xms1024m -Xmx2048m"
重启 Tomcat
# service tomcat restart
确认:
# netstat -anp | grep 8080
tcp 0 0 :::8080 :::* LISTEN 1792/java
您也可以将 tomcat 配置为以普通用户身份运行。我的情况不需要这样做,因此我没有这样做。希望这能有所帮助。
答案2
只需搜索 tomcat 而不是 tomcat7*
#yum search tomcat
apache-tomcat-apis.noarch : Tomcat Servlet and JSP APIs
jakarta-commons-dbcp-tomcat5.noarch : DBCP dependency for Tomcat5
jakarta-commons-pool-tomcat5.x86_64 : Pool dependency for Tomcat5
tomcat6-jsp-2.1-api.noarch : Apache Tomcat JSP API implementation classes
tomcat6-lib.noarch : Libraries needed to run the Tomcat Web container
tomcat6-servlet-2.5-api.noarch : Apache Tomcat Servlet API implementation classes
tomcatjss.noarch : JSSE implementation using JSS for Tomcat
tomcat6.noarch : Apache Servlet/JSP Engine, RI for Servlet 2.5/JSP 2.1 API
tomcat6-el-2.1-api.noarch : Expression Language v1.0 API