项目部署mysql安装_Tomcat7+jdk+mysql安装及项目部署

Tomcat7+jdk+mysql安装及项目部署

1. 下载tomcat7、jdk、mysql

apache-tomcat-7.0.42.tar.gz

jdk-7u25-linux-i586.gz

mysql-5.1.55.tar.gz

2. 安装及配置

[root@localhost ~]# tar zxvf apache-tomcat-7.0.42.tar.gz -C /usr/src/ ##解压tomcat7

[root@localhost ~]# tar zxvf jdk-7u25-linux-i586.gz -C /usr/src/ ##解压jdk

[root@localhost ~]# cd /opt

[root@localhost opt]# mv /usr/src/apache-tomcat-7.0.42 tomcat7

[root@localhost opt]# mv /usr/src/jdk-7u25-linux-i586 jdk

[root@localhost ~]# vi /etc/profile ##设置java的环境变量

export JAVA_HOME=/opt/jdk/ ##设置jdk变量

export PATH=$PATH:$JAVA_HOME/bin

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

[root@localhost ~]# tail -3 /etc/profile ##验证最后三行

export PATH=$PATH:$JAVA_HOME/bin

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

[root@localhost ~]#

[root@localhost ~]# source /etc/profile ##读取文件使变量生效

[root@localhost chapter07]# tar zxvf mysql-5.1.55.tar.gz -C /usr/src ##解压mysql

[root@localhost chapter07]# cd /usr/src/mysql-5.1.55/

[root@localhost mysql-5.1.55]# ./configure --prefix=/opt/mysql ##配置并指定安装的目录

[root@localhost mysql-5.1.55]# make &&make install ##编译及安装

[root@localhost mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf ##创建mysql的配置文件

[root@localhost mysql-5.1.55]# cd /opt/mysql/

[root@localhost mysql]# useradd -u 26 -M -s /sbin/nologin mysql

[root@localhost mysql]# bin/mysql_install_db --user=mysql ##使用mysql用户初始化数据库

[root@localhost mysql]# chown -R root:mysql /opt/mysql

[root@localhost mysql]# chown -R mysql /opt/mysql/var/

优化执行路径、程序库路径:

[root@localhost mysql]# ln -s /opt/mysql/bin/* /usr/local/bin/

[root@localhost mysql]# ln -s /opt/mysql/lib/mysql/* /usr/lib/

[root@localhost mysql]# ln -s /opt/mysql/include/mysql/* /usr/include/

添加mysql为系统服务:

[root@localhost mysql]# cp /usr/src/mysql-5.1.55/support-files/mysql.server /etc/init.d/mysqld

[root@localhost mysql]# chmod +x /etc/init.d/mysqld

[root@localhost mysql]#chkconfig --add mysqld ##添加为系统服

[root@localhost mysql]# /etc/init.d/mysqld start ##启动服务

设置mysql的字符集:

[root@localhost ~]# vi /etc/my.cnf

default-character-set=utf8 ##将这一项添加到【msyql】【mysqld】模块中

[root@localhost ~]#/etc/init.d/mysqld restart ##重启mysql

使用mysql:

[root@localhost ~]# mysqladmin -uroot password ‘123123’ ##mysql数据库root的密码为123123

[root@localhost ~]# mysqldump -uroot -p123123 --all-databases >mysql.sql ##备份mysql

[root@localhost ~]# mysql -uroot -p123123

3. 部署项目:

[root@localhost conf]# cd /opt/tomcat7/conf/

[root@localhost conf]# vi server.xml ##修改监听的端口

connectionTimeout="20000"

redirectPort="8443" />

port="80" protocol="HTTP/1.1"

connectionTimeout="20000"

redirectPort="8443" />

上传项目:

在windows的D盘存放项目文件dc、dc.sql及pscp.exe程序,然后在运行(窗口键+R)中、运行cmd打开命令提示符:

C:\Users\shenchengfa>d:

导入项目数据:

[root@localhost bin]# mysql -uroot �p123123 ##登录mysql

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 217

Server version: 5.1.55-log Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

This software comes with ABSOLUTELY NO WARRANTY. This is free software,

and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database dc; ##创项目数据库

mysql>quit

[root@localhost bin]# mysql -uroot -p123123 --databases dc< dc.sql ##导入项目数据

[root@localhost bin]# service mysqld restart ##重启mysql

修改项目数据库密码:此处视特定项目而定、与研发人员沟通确认

[root@localhost bin]# vi /opt/tomcat7/webapps/dc/WEB-INF/web.xml

This is the description of my J2EE component

This is the display name of my J2EE component

ControlServelet

action.ControlServelet

driverString

com.mysql.jdbc.Driver

urlString

jdbc:mysql://127.0.0.1:3306/dc

username

root

password

123123

excelpath

/var/lib/tomcat6/webapps/dc/biao/

jsppath

/var/lib/tomcat6/webapps/dc/

1

[root@localhost ~]# /opt/tomcat7/bin ##重启tomcat

[root@localhost bin]# ./shutdown.sh ##停止tomcat

Using CATALINA_BASE: /opt/tomcat7

Using CATALINA_HOME: /opt/tomcat7

Using CATALINA_TMPDIR: /opt/tomcat7/temp

Using JRE_HOME: /opt/jdk/

Using CLASSPATH: /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar

[root@localhost bin]# ./startup.sh ##启动tomcat

Using CATALINA_BASE: /opt/tomcat7

Using CATALINA_HOME: /opt/tomcat7

Using CATALINA_TMPDIR: /opt/tomcat7/temp

Using JRE_HOME: /opt/jdk/

Using CLASSPATH: /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar

4. 测试验证

在浏览器中访问测试,访问时注意iptables、及selinux的限制,可以将其关闭,等测试无误后在做调整

[root@localhost ~]# setenforce 0 ##设置selinux的状态为允许、默认是1为强制限制

[root@localhost ~]# /etc/init.d/iptables stop ##关闭防火墙

Tomcat默认使用8080端口、但是上文已经改为80端口,直接输入ip加项目名即可,如图:

0818b9ca8b590ca3270a3433284dd417.png

你可能感兴趣的:(项目部署mysql安装)