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. 安装及配置 [iyunv@localhost ~]# tar zxvf apache-tomcat-7.0.42.tar.gz -C /usr/src/ ##解压tomcat7 [iyunv@localhost ~]# tar zxvf jdk-7u25-linux-i586.gz -C /usr/src/ ##解压jdk [iyunv@localhost ~]# cd /opt [iyunv@localhost opt]# mv /usr/src/apache-tomcat-7.0.42 tomcat7 [iyunv@localhost opt]# mv /usr/src/jdk-7u25-linux-i586 jdk [iyunv@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 [iyunv@localhost ~]# tail -3 /etc/profile ##验证最后三行 [url=]export JAVA_HOME=/opt/jdk/[/url] export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar [iyunv@localhost ~]# [iyunv@localhost ~]# source /etc/profile ##读取文件使变量生效 [iyunv@localhost chapter07]# tar zxvf mysql-5.1.55.tar.gz -C /usr/src ##解压mysql [iyunv@localhost chapter07]# cd /usr/src/mysql-5.1.55/ [iyunv@localhost mysql-5.1.55]# ./configure --prefix=/opt/mysql ##配置并指定安装的目录 [iyunv@localhost mysql-5.1.55]# make &&make install ##编译及安装 [iyunv@localhost mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf ##创建mysql的配置文件 [iyunv@localhost mysql-5.1.55]# cd /opt/mysql/ [iyunv@localhost mysql]# useradd -u 26 -M -s /sbin/nologin mysql [iyunv@localhost mysql]# bin/mysql_install_db --user=mysql ##使用mysql用户初始化数据库
[iyunv@localhost mysql]# chown -R root:mysql /opt/mysql [iyunv@localhost mysql]# chown -R mysql /opt/mysql/var/ 优化执行路径、程序库路径: [iyunv@localhost mysql]# ln -s /opt/mysql/bin/* /usr/local/bin/ [iyunv@localhost mysql]# ln -s /opt/mysql/lib/mysql/* /usr/lib/ [iyunv@localhost mysql]# ln -s /opt/mysql/include/mysql/* /usr/include/ 添加mysql为系统服务: [iyunv@localhost mysql]# cp /usr/src/mysql-5.1.55/support-files/mysql.server /etc/init.d/mysqld [iyunv@localhost mysql]# chmod +x /etc/init.d/mysqld [iyunv@localhost mysql]#chkconfig --add mysqld ##添加为系统服 [iyunv@localhost mysql]# /etc/init.d/mysqld start ##启动服务 设置mysql的字符集: [iyunv@localhost ~]# vi /etc/my.cnf default-character-set=utf8 ##将这一项添加到【msyql】【mysqld】模块中 [iyunv@localhost ~]#/etc/init.d/mysqld restart ##重启mysql 使用mysql: [iyunv@localhost ~]# mysqladmin -uroot password ‘123123’ ##mysql数据库root的密码为123123 [iyunv@localhost ~]# mysqldump -uroot -p123123 --all-databases >mysql.sql ##备份mysql [iyunv@localhost ~]# mysql -uroot -p123123 上传项目: 在windows的D盘存放项目文件dc、dc.sql及pscp.exe程序,然后在运行(窗口键+R)中、运行cmd打开命令提示符: C:Usersshenchengfa>d: D:>pscp dc dc.sql root@192.168.8.49:/opt/tomcat7/webapps/ 导入项目数据: [iyunv@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 [iyunv@localhost bin]# mysql -uroot -p123123 --databases dc< dc.sql ##导入项目数据 [iyunv@localhost bin]# service mysqld restart ##重启mysql 修改项目数据库密码:此处视特定项目而定、与研发人员沟通确认 [iyunv@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
[iyunv@localhost ~]# /opt/tomcat7/bin ##重启tomcat [iyunv@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 [iyunv@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的限制,可以将其关闭,等测试无误后在做调整 [iyunv@localhost ~]# setenforce 0 ##设置selinux的状态为允许、默认是1为强制限制 [iyunv@localhost ~]# /etc/init.d/iptables stop ##关闭防火墙 Tomcat默认使用8080端口、但是上文已经改为80端口,直接输入ip加项目名即可,如图:
|