Centos 6.7 Tomcat基本安装测试

Tomcat基本安装测试

/==============================基本安装使用=========================================>/

Tomcat A 设置

安装jdk

http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html下载JDK

1.1安装jdk

~]# rpm -ivh jdk-7u67-linux-x64.rpm

Preparing...               ########################################### [100%]

1:jdk                   ########################################### [100%]

Unpacking JAR files...

rt.jar...

jsse.jar...

charsets.jar...

tools.jar...

localedata.jar...

jfxrt.jar...

1.2 配置Java环境

~]# vi /etc/profile.d/java.sh

1..3 加载java环境

~]# source /etc/profile.d/java.sh

~]# java -version

java version "1.7.0_67"

Java(TM) SE Runtime Environment (build1.7.0_67-b01)

Java HotSpot(TM) 64-Bit Server VM (build24.65-b04, mixed mode)

安装tomcat

2.1下载tomcat

http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.65/bin/apache-tomcat-7.0.57.tar.gz

2.2 解压安装

~]# tar xf apache-tomcat-7.0.57.tar.gz -C/usr/local/

~]# cd /usr/local/

创建连接

]# ln -sv apache-tomcat-7.0.57 tomcat

`tomcat‘ -> `apache-tomcat-7.0.57‘

2.3 创建用户修改属主


]# useradd -M -d /usr/local/tomcat tomcat

]# chown -R tomcat /usr/local/tomcat*

2.4 创建启动脚本


]# vim /etc/rc.d/init.d/tomcat

#!/bin/bash

# Tomcat7: Start/Stop Tomcat 7

#

# chkconfig: - 90 10

# description: Tomcat is a Java  application Server.

. /etc/init.d/functions

. /etc/sysconfig/network

CATALINA_HOME=/usr/local/tomcat

TOMCAT_USER=tomcat

LOCKFILE=/var/lock/subsys/tomcat

RETVAL=0

start(){

echo "Starting Tomcat7: "

su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch $LOCKFILE

return $RETVAL

}

RETVAL=0

start(){

echo "Starting Tomcat: "

su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch $LOCKFILE

return $RETVAL

}

stop(){

echo "Shutting down Tomcat: "

$CATALINA_HOME/bin/shutdown.sh

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f $LOCKFILE

return $RETVAL

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo $"Usage: $0 {start|stop|restart}"

exit 1

;;

esac

exit $?

2.5 修改属性

]# chmod 755 /etc/rc.d/init.d/tomcat

2.6 测试启动脚本


l]# /etc/rc.d/init.d/tomcat start

Starting Tomcat:

Using CATALINA_BASE:   /usr/local/tomcat

Using CATALINA_HOME:   /usr/local/tomcat

Using CATALINA_TMPDIR:  /usr/local/tomcat/temp

Using JRE_HOME:        /usr/java/default

Using CLASSPATH:        /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Tomcat started.

2.7 添加到服务列表

]# chkconfig --add tomcat

2.8 开机自动启动

]# chkconfig tomcat on

]# chkconfig--list tomcat

tomcat            0:off 1:off 2:on 3:on 4:on 5:on 6:off

3.测试

3.1 测试主页
3.2 创建自定义的网页文件

]# mkdir -pv  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

mkdir: created directory  `/usr/local/tomcat/webapps/ROOT/WEB-INF/classes‘

修改属主

]# chown tomcat .  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

]# cd  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

创建自定义的主页面

]#vim  daytime.java


import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.Calendar;

public class daytime extends HttpServlet  {

public void doGet(HttpServletRequest request

,HttpServletResponse response)

throws IOException, ServletException{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

Calendar cal = Calendar.getInstance();

out.println("<html>\n<head>\n<title>DayTime-TomcatA</title>\n</head>\n<body>");

out.println("<div style=\"font-size: 40px; text-align:  center; font-weight: bold\">");

out.println(cal.get(Calendar.YEAR) + "/" +  (cal.get(Calendar.MONTH) + 1) + "/" +

cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY)  + ":" + cal.get(Calendar.MINUTE));

out.println("</div>\n</body>\n</html>");

}

}


]# javac -classpath  /usr/local/tomcat/lib/servlet-api.jar daytime.java

3.3 添加自定义的web内容

]# vim  /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml

[[email protected] classes]# cat  /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml

<?xml version="1.0"  encoding="ISO-8859-1"?>

<!--

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.

-->

<web-app  xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0"

metadata-complete="true">

<display-name>Welcome to Tomcat</display-name>

<description>

Welcome to Tomcat

</description>

<!-- start-->

<servlet>

<servlet-name>daytime</servlet-name>

<servlet-class>daytime</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>daytime</servlet-name>

<url-pattern>/daytime</url-pattern>

</servlet-mapping>

<!-- end-->

</web-app>

3.4测试

Tomcat B 设置

1.安装 jdk


~]# rpm -ivh jdk-7u67-linux-x64.rpm

Preparing...                 ########################################### [100%]

1:jdk                     ########################################### [100%]

Unpacking JAR files...

rt.jar...

jsse.jar...

charsets.jar...

tools.jar...

localedata.jar...

jfxrt.jar...

1.2 配置Java环境


~]# vim /etc/profile.d/java.sh

export JAVA_HOME=/usr/java/default

export PATH=$PATH:$JAVA_HOME/bin

export  CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

1.3 加载Java环境


~]# source /etc/profile.d/java.sh

~]# java -version

java version "1.7.0_67"

Java(TM) SE Runtime Environment (build  1.7.0_67-b01)

Java HotSpot(TM) 64-Bit Server VM (build  24.65-b04, mixed mode)

2 安装Tomcat

2.1下载tomcat

2.2 解压安装


[[email protected] ~]#  tar xf apache-tomcat-7.0.57.tar.gz -C  /usr/local/

[[email protected] ~]# cd /usr/local/

创建软连接

[[email protected] local]# ln -sv  apache-tomcat-7.0.57 tomcat

`tomcat‘ -> `apache-tomcat-7.0.57‘

2.3 创建用户修改属主


[[email protected] local]# useradd -M -d  /usr/local/tomcat tomcat

[[email protected] local]# chown -R tomcat  /usr/local/tomcat*

2.4 创建启动脚本


]# vim /etc/rc.d/init.d/tomcat

#!/bin/bash

# Tomcat7: Start/Stop Tomcat 7

#

# chkconfig: - 90 10

# description: Tomcat is a Java  application Server.

. /etc/init.d/functions

. /etc/sysconfig/network

CATALINA_HOME=/usr/local/tomcat

TOMCAT_USER=tomcat

LOCKFILE=/var/lock/subsys/tomcat

RETVAL=0

start(){

echo "Starting Tomcat7: "

su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch $LOCKFILE

return $RETVAL

}

RETVAL=0

start(){

echo "Starting Tomcat: "

su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch $LOCKFILE

return $RETVAL

}

stop(){

echo "Shutting down Tomcat: "

$CATALINA_HOME/bin/shutdown.sh

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f $LOCKFILE

return $RETVAL

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo $"Usage: $0 {start|stop|restart}"

exit 1

;;

esac

exit $?

2.5 修改属性

]# chmod 755 /etc/rc.d/init.d/tomcat

2.6测试启动脚本


]# /etc/rc.d/init.d/tomcat start

Starting Tomcat:

Using CATALINA_BASE:   /usr/local/tomcat

Using CATALINA_HOME:   /usr/local/tomcat

Using CATALINA_TMPDIR:  /usr/local/tomcat/temp

Using JRE_HOME:        /usr/java/default

Using CLASSPATH:        /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

Tomcat started.

2.7 添加到启动服务列表

]# chkconfig --add tomcat

2.8 开机自动启动


]# chkconfig  tomcat on

]# chkconfig  --list tomcat

tomcat           0:off 1:off 2:on 3:on 4:on 5:on 6:off

3. 测试

3.1 测试主页


3.2 创建自定义网页文件


]# mkdir -pv  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

mkdir: created directory  `/usr/local/tomcat/webapps/ROOT/WEB-INF/classes‘

修改属主

]# chown tomcat .  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

创建自定义主页

]# cd  /usr/local/tomcat/webapps/ROOT/WEB-INF/classes

]#vim   daytime.java


import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.util.Calendar;

public class daytime extends HttpServlet  {

public void doGet(HttpServletRequest request

,HttpServletResponse response)

throws IOException, ServletException{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

Calendar cal = Calendar.getInstance();

out.println("<html>\n<head>\n<title>DayTime-TomcatB</title>\n</head>\n<body>");

out.println("<div style=\"font-size: 40px; text-align:  center; font-weight: bold\">");

out.println(cal.get(Calendar.YEAR) + "/" +  (cal.get(Calendar.MONTH) + 1) + "/" +

cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY)  + ":" + cal.get(Calendar.MINUTE));

out.println("</div>\n</body>\n</html>");

}

}


编译

]# javac -classpath  /usr/local/tomcat/lib/servlet-api.jar daytime.java

3.3 添加自定义web内容


]# vim  /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml

<?xml version="1.0"  encoding="ISO-8859-1"?>

<!--

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.

-->

<web-app  xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0"

metadata-complete="true">

<display-name>Welcome to Tomcat</display-name>

<description>

Welcome to Tomcat

</description>

<!-- Start 以下为添加的内容-->

<servlet>

<servlet-name>daytime</servlet-name>

<servlet-class>daytime</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>daytime</servlet-name>

<url-pattern>/daytime</url-pattern>

</servlet-mapping>

<!-- End 结束分割线********-->

</web-app>

3.4 测试


Tomcat A B配置文件

http://down.51cto.com/data/2113380

时间: 2024-11-03 21:52:06

Centos 6.7 Tomcat基本安装测试的相关文章

CentOS学习笔记--Tomcat安装

Tomcat安装 通常情况下我们要配置Tomcat是很容易的一件事情,但是如果您要架设多用户多服务的Java虚拟主机就不那么容易了.其中最大的一个问题就是Tomcat执行权限.普通方式配置的Tomcat是以root超级管理员的身份运行的,显然,这是非常危险的,可想而知,一但网站被挂马,您的整个服务器都可以被黑客控制了.而通过编译或在线(例如redhat系列的yum, debian系列的apt-get)的方式安装,一个服务器上又只能装一个tomcat的服务,如果将多个网站放到同一个tomcat服务

Tomcat免安装版的环境变量配置以及Eclipse下的Tomcat配置和测试

Tomcat是目前比较流行的开源且免费的Web应用服务器,在我的电脑上第一次安装Tomcat,再经过网上教程和自己的摸索后,将这个过程 重新记录下来,以便以后如果忘记了可以随时查看. 注意:首先要明确一点,Tomcat与Java密切相关,因此安装使用之前要先安装JDK并设置JDK的环境变量,由于机子上已经安装好了JDK,也设置好了JDK环境变量,因此这里不再过多叙述,只说明我设置好的环境变量: JAVA_HOME :F:\JDK_Kit CLASSPATH: .;%JAVA_HOME%\lib\

CentOS 6.5玩转自制Linux、远程登录及Nginx安装测试

前言    系统定制在前面的博文中我们就有谈到过了,不过那个裁减制作有简单了点,只是能让系统跑起来而,没有太多的功能,也没的用户登录入口,而这里我们将详细 和深入的来谈谈Linux系统的详细定制过程和实现用户例如.远程登录和Nginx安装过程.一步一步从头开始定制属于我们自己的系统. 正文    首先我们先来简单的介绍一下我们这里定制属于自己的Linux系统的基本元素.而其实一些相关的信息也可以参考我前面写过的博文:总结之:CentOS 6.4系统裁减详解及装载网卡步骤 一个定制的linux内核

Centos 6.7 Tomcat Session集群

规划结构图 nginx接收用户请求反向代理至后端应用服务器 应用服务器或者session服务器其中一台宕机,不影响客户端会话的信息 OS:CentOS release 6.7 (Final) Memcached设置 两台memcached1 2 各进行配置 1.安装memcached [[email protected] ~]# yum install memcached [[email protected] ~]#  yum install memcached 2.启动服务 [[email p

简单记录CentOS服务器配置JDK+Tomcat+MySQL

项目需要部署到一台CentOS的服务器之上,之前这台服务器上面已经安装了一个Nginx和MySQL,跑的是PHP环境,有一个项目正在运行.而我们最新的项目是用Java写的,服务器是用的Tomcat,所以势必需要把Nginx和Tomcat做一次整合,不过目前项目还在开发阶段,我们就先使用Tomcat默认的8080端口,好了,下面就大概你的"终端"(因为我使用的是Mac系统,默认有SSH,如果是Win系统,请选择其他对应的工具,相信G神会帮助你的~~).百牛信息技术bainiu.ltd整理

centos部署简单tomcat及负载均衡

centos部署简单tomcat及负载均衡 实验拓扑: 实验准备: 准备好apache-tomcat及jdk和nginx的软件包,我这里使用的是 jdk-7u65-linux-x64.gz apache-tomcat-7.0.54.tar.gz nginx-1.9.4.tar.gz 实验前停止iptables和selinux sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config /etc/init.d/iptables stop

linux服务之tomcat的安装及配置

CentOS 6.6下安装配置Tomcat环境 [日期:2015-08-25] 来源:Linux社区  作者:tae44 [字体:大 中 小] 实验系统:CentOS 6.6_x86_64 实验前提:防火墙和selinux都关闭 实验软件:apache-tomcat-8.0.24 jdk-8u60-linux-x64 jeecms-v6 一.安装JAVA环境 1.安装JAVA: wget http://download.Oracle.com/otn-pub/java/jdk/8u60-b27/j

转-Tomcat 8 安装和配置、优化

https://github.com/judasn/Linux-Tutorial/blob/master/Tomcat-Install-And-Settings.md Tomcat 8 安装 Tomcat 8 安装 官网:http://tomcat.apache.org/ Tomcat 8 官网下载:http://tomcat.apache.org/download-80.cgi 此时(20160207) Tomcat 8 最新版本为:apache-tomcat-8.0.32.tar.gz 我个

centos 6.9 x64 yum安装PHP 7.1.8

centos 6.9 x64 yum安装PHP 7.1.8 安装源 yum install epel-release rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm 根据你的需要安装PHP的组件,下面我就安装所有的了. yum install php71w php71w-mysql php71w-odbc php71w-common php71w-embedded php71w-pgsql php71w-xml  php71w-lda