积累经验
2014年(55)
分类: 系统运维
2014-01-22 23:17:20
tomcat安装.
安装jdk
tar xf jdk-7u15-linux-x64.tar.gz -C /usr/local
ln -s /usr/local/jdk1.7.0_15/ /usr/local/java
echo 'export JAVA_HOME=/usr/local/java' >> ~/.bashrc //声明全局变量
. ~/.bashrc //调用后生效
安装tomcat
useradd tomcat
tar xf apache-tomcat-7.0.37.tar.gz -C /home/tomcat
ln -s /home/tomcat/ apache-tomcat-7.0.37 /home/tomcat/tomcat
启动测试
/home/tomcat/tomcat/bin/startup.sh
firefox &
通过测试
netstat -ntalp | grep 8080
telnet 192.168.11.131 8080
yum install telnet-0.17-47.el6.x86_64 –y
telnet 192.168.11.131 8080
点击默认网页Server Status需要验证修改以下内容 //可以跳过这一步骤
vim tomcat-users.xml
把tomcat文件复制到以下目录就可以service tomcat start方式启动脚本
cp tomcat /etc/init.d/
vim /etc/init.d/tomcat
sh $CATALINA_HOME/bin/shutdown.sh
sleep 5
sh $CATALINA_HOME/bin/startup.sh
虚拟主机配置
##把端口改为80并添加一虚拟机//可以不改
vim /home/tomcat/tomcat/conf/server.xml
unpackWARs="true" autoDeploy="true">
prefix="jsp.com__access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
Tomcat连接mysql
cp
mysql-connector-java-5.1.23-bin.jar /home/tomcat/tomcat/lib/
vi
/home/tomcat/tomcat/conf/context.xml
在前面加入
maxActive="100" maxIdle="30" maxWait="10000"
username="root"
password="uplooking"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
其中TestDB是资源名,当需要使用此连接时,可以通过资源名调用。root和
uplooking是连接mysql时使用的用户名与密码。localhost是mysql主机地址,3306是
端口。Javatest是库名
登录Mysql授权 创建库、表
mysql> grant all on *.* to
root@'localhost' identified by 'uplooking';
mysql> flush privileges;
mysql> create database javatest;
mysql> use javatest;
create table testdata (
id int not null auto_increment
primary key,
foo varchar(25),
bar int);
insert into testdata values(null,
'hello', 12345);
修改网站配置,调用mysql连接 //可以略过,直接搭论坛
mkdir
-p /home/tomcat/tomcat/jsp.com/TestDB/WEB-INF/
vim
/home/tomcat/tomcat/jsp.com/TestDB/WEB-INF/web.xml
xmlns:xsi=""
xsi:schemaLocation="
/web-app_2_5.xsd"
version="2.5">
Test for
mysql
创建测试页面
vim
/home/tomcat/tomcat/jsp.com/TestDB/test.jsp
<%@ page
contentType="text/html; charset=GBK"%>
<%@ page
import="java.sql.*,javax.sql.DataSource,javax.naming.*"%>
<%
try
{
Context initCtx=new InitialContext();
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/TestDB");
Connection conn=ds.getConnection();
out.println("data
from database:
");
Statement stmt=conn.createStatement();
ResultSet rs =stmt.executeQuery("select id, foo, bar from testdata");
while(rs.next())
{
out.println(rs.getInt("id"));
out.println(rs.getString("foo"));
out.println(rs.getString("bar"));
}
rs.close();
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
通过
安装论坛
删除之前的index.html
rm -f /home/tomcat/tomcat/jsp.com/ROOT/index.html
unzip ejforum-2.3.zip
cp -r ejforum-2.3/ejforum/* /home/tomcat/tomcat/jsp.com/ROOT
chown -R tomcat. /home/tomcat/tomcat/jsp.com/ROOT
论坛数据库导入
mysql javatest < ejforum-2.3/install/script/easyjforum_mysql.sql
#vim /home/tomcat/tomcat/jsp.com/ROOT/WEB-INF/conf/config.xml //局部
vi /home/tomcat/tomcat/conf/context.xml //全局
注示掉该文件原有内容,加入以下内容
username="root"
password="uplooking"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?characterEncoding=gbk&autoReconnect=true&autoReconnectForPools=true&zeroDateTimeBehavior=convertToNull"
sqlAdapter="sql.MysqlAdapter"/>
其中红色部分是mysql登录所使用的用户名,密码,主机地址、端口以及库名。
重启tomcat并测试
注册zhiguozh
uplooking