Home > Database > Mysql Tutorial > centos下tomcat+mysql的配置和项目部署_MySQL

centos下tomcat+mysql的配置和项目部署_MySQL

WBOY
Release: 2016-06-01 13:11:13
Original
1005 people have browsed it

CentOSTomcat

TOMCAT服务器的配置

1. jre的安装

1.1 查看centos中原来自带的JDK并卸载

[root@balakids home]# java -version|grep gcj [root@balakids home]# yum -y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Copy after login

1.2 复制jre-6u38-linux-x64-rpm.bin到目录/opt中

cp /home/jre-6u38-linux-x64-rpm.bin /opt/.
Copy after login

1.3 为该文件赋予执行权限

chmod +x /opt/jre-6u38-linux-x64-rpm.bin
Copy after login

1.4 执行此文件即安装jre

[root@balakids jre]# ./jre-6u38-linux-x64-rpm.bin  Unpacking... Checksumming... Extracting... UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).  inflating: jre-6u38-linux-amd64.rpm  Preparing...                ########################################### [100%]    1:jre                    ########################################### [100%] Unpacking JAR files...     rt.jar...     jsse.jar...     charsets.jar...     localedata.jar...     plugin.jar...     javaws.jar...     deploy.jar...   Done.
Copy after login

1.5 查看java版本

[root@balakids jre]# java -versionjava version "1.6.0_38" Java(TM) SE Runtime Environment (build 1.6.0_38-b05) Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)
Copy after login

2 tomcat的配置

2.1 解压tomcat的压缩包并移动到想要放置的位置

[root@balakids home]# tar -xvf apache-tomcat-6.0.39.tar.gz [root@balakids home]# mv apache-tomcat-6.0.39 /usr/local/tomcat
Copy after login

2.2 复制tomcat的启动脚本

[root@balakids conf]# cd /usr/local/tomcat/bin [root@balakids bin]# cp catalina.sh /etc/init.d/tomcatd[root@balakids bin]# chmod +x /etc/init.d/tomcatd
Copy after login

2.3 更改tomcat的启动脚本,指向JRE和TOMCAT的目录

[root@balakids ROOT]# rpm -ql jre    //查询JRE安装的位置[root@balakids conf]# vim /etc/init.d/tomcatd JRE_HOME=/usr/java/jre1.6.0_38 CATALINA_HOME=/usr/local/tomcat
Copy after login

2.4 为tomcat配置用户管理 //可有可无的操作

[root@balakids conf]# vim /usr/local/tomcat/conf/tomcat-users.xml  <tomcat-users>     <role rolename="manager-gui"/>   <role rolename="admin-gui"/>   <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/> </tomcat-users>  [root@balakids conf]# /etc/init.d/tomcatd start
Copy after login

2.5 测试 在浏览器中使用IP进行测试,本机IP:10.10.54.178,端口号为8080

centos下tomcat+mysql的配置和项目部署_MySQL

刚才所配置的用户管理则是访问这个页面中的选项时使用,如下访问status时弹出来的用户登录

centos下tomcat+mysql的配置和项目部署_MySQL

3 安装mysql5.1.50 3.1 安装所需依赖包

//之前先做了yum源

[root@balakids mysql-5.1.50]#yum install gcc-c++ gcc libtermcap-devel.x86_64 -y
Copy after login


3.2 mysql的解压、编译、安装

[root@balakids home]# tar xvf mysql-5.1.50.tar.gz[root@balakids home]# cd mysql-5.1.50 [root@balakids mysql-5.1.50]#./configure --prefix=/usr/local/mysql --datadir=/data/mysql --with-charset=utf8 /--with-extra-charsets=complex / --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock / --with-pthread --enable-assembler --with-mysqld-ldflags=-all-static / --with-client-ldflags=-all-static / --with-plugins=partition,archive,csv,federated,heap,innobase,myisam,myisammrg,innodb_plugin,ndbcluster / --with-mysqld-user=mysql[root@balakids mysql-5.1.50]# make && make install
Copy after login

3.3 创建mysql用户并更改目录所属用户

[root@balakids mysql-5.1.50]# useradd mysql -s /sbin/nologin [root@balakids mysql-5.1.50]# chown mysql.mysql /usr/local/mysql/ -R [root@balakids mysql-5.1.50]# chown mysql.mysql /data/  -R
Copy after login

3.4 复制配置文件和启动脚本 --在解压缩的包中复制

[root@balakids mysql-5.1.50]# cp support-files/my-large.cnf /etc/my.cnf [root@balakids mysql-5.1.50]# cp support-files/mysql.server /etc/init.d/mysqld [root@balakids mysql-5.1.50]# chmod +x /etc/init.d/mysqld  //更改配置文件,加入datadir的目录 Vim /etc/my.cnf  [mysqld]datadir=/data/mysql
Copy after login

3.4 初始化数据库

[root@balakids mysql-5.1.50]# /usr/local/mysql/bin/mysql_install_db --user=mysql
Copy after login

如果再初始化的时候指定basedir的目录则会报以下错误: FATAL ERROR: Could not find errmsg.sys

3.5 添加环境变量

[root@balakids mysql-5.1.50]# vim /etc/profile.d/mysql.sh PATH=$PATH:/usr/local/mysql/bin [root@balakids mysql-5.1.50]# source /etc/profile.d/mysql.sh
Copy after login

4 balakids项目部署,本机IP:10.10.54.178

把项目复制到tomcat下的webapps下

4.1 对mysql数据库的更改 Balakids项目登录数据库用户为root,密码为mysql,即依此更改数据库

[root@balakids lib]# mysqladmin -uroot -p123456 password 'mysql' mysql> update user set host='10.10.54.178' where host='localhost';
Copy after login

//当然可以自己重新创建用户,但是要注意的时不要忘了对项目中的一些文件进行更改,下面介绍项目中所要配置的内容 4.2 tomcat配置文件的更改 更改tomcat的配置文件

[root@balakids tomcat]# vim /usr/local/tomcat/conf/server.xml
Copy after login
<Engine name="Catalina" defaultHost="10.10.54.178"><Host name="10.10.54.178"  appBase="webapps"             unpackWARs="true" autoDeploy="true"             xmlValidation="false" xmlNamespaceAware="false">
Copy after login

//上面配置文件中的defaultHost默认为localhost,更改为本机IP

4.3 项目中需注意的文件 项目中最值得注意的文件莫过于对数据库的连接了也就时context.xml

绝对路径: /usr/local/tomcat/webapps/balakids/META-INF/context.xml

其内容为:

<?xml version="1.0" encoding="UTF-8"?><!-- 配置数据源 --> <Context path="/balakids" reloadable="true">         <Resource name="balakids/jdbc"         auth="Container"         type="javax.sql.DataSource"          username="root"                //用户名        password="mysql"                //密码         driverClassName="com.mysql.jdbc.Driver"          url="jdbc:mysql://10.10.54.178:3306/balakids"  //连接数据库     maxActive="8"     maxIdle="4"/><!-- 测试JNDI --> <Environment name="onlineexam_jndi" value="Hello JNDI" type="java.lang.String"/></Context>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template