这篇文章主要介绍了Tomcat+JDK+Mysql如何安装,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
背景
JAVA项目中经常需要同时使用到多个组件,如:tomcat、jdk、mysql、nginx等,为方便客户服务器环境搭建,现需要将相关项目组件进行统一打包,并实现一键安装,为了达到次目标特进行此次试验。
试验方案
(1) 环境说明
操作系统版本:windows 7 x64 sp1
Tomcat版本:apache-tomcat-8.5.47-windows-x64解压版
JDK版本:java 1.7 绿色版
Mysql版本:mysql-5.5.62-winx64解压版
打包工具:innosetup-5.6.1
(2) 试验步骤
① 下载各组件安装包
Mysql下载地址:
https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.62-winx64.zip
JDK下载地址:
链接:https://pan.baidu.com/s/1STRuH2-lInjVN4K4KUKkOg
提取码:tke1
Tomcat下载地址: http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.47/bin/apache-tomcat-8.5.47-windows-x64.zip
Innosetup下载地址:
http://files.jrsoftware.org/is/5/innosetup-5.6.1.exe
② Mysql配置
1) 解压Mysql为C:\test\mysql-5.5.62-winx64,并配置my.ini文件,如下:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
basedir = "C:/test/mysql-5.5.62-winx64"
datadir = "C:/test/mysql-5.5.62-winx64/data/"
character-set-server=utf8
default-storage-engine=INNODB
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 128
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 512K
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
default-character-set=utf8
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
2) 拷贝数据库创建脚本create_db.sql和建表脚本hrdemo.sql到目录C:\test\mysql-5.5.62-winx64\data,并在C:\test\mysql-5.5.62-winx64\bin下,创建数据库安装配置脚本mysql_init.bat,内容如下:
cd /d %~dp0
"%cd%\mysqld.exe" --initialize-insecure --console
echo -----mysql init succee-----
pause;
mysqld install mysql --defaults-file="C:\test\mysql-5.5.62-winx64\my.ini"
echo -----mysql service install succee-----
pause;
net start mysql
sc config mysql start= auto
net stop mysql
net start mysql
echo service install finished
pause;
"%cd%\mysqladmin" -u root password hr_1234
echo change password finished
pause;
cd ..
"%cd%\bin\mysql.exe" -uroot -phr_1234 < "%cd%\data\create_db.sql"
echo create database finished
pause;
"%cd%\bin\mysql.exe" -uroot -phr_1234 < "%cd%\data\hrdemo.sql"
echo create table finished
pause;
echo mysql setup finished
③ JAVA配置
1) 解压JDK1.7到C:\test\apache-tomcat-8.5.47\bin\Java\jdk1.7.0_51,并在C:\test\apache-tomcat-8.5.47\bin\Java\jdk1.7.0_51\bin下创建JDK配置脚本autoInstallJDK.bat,内容如下:
@echo off
echo
cd ..
echo "%~dp0"
echo "%cd%"
set jdkpath=%cd%
echo %jdkpath%
setx JAVA_HOME "%jdkpath%" -m
setx CLASSPATH ".;%%JAVA_HOME%%\lib\tools.jar;%%JAVA_HOME%%\lib\dt.jar" -m
echo %Path%
echo %Path%|find /i "%java_home%" && set IsNull=true || set IsNull=false
echo %IsNull%
if not %IsNull%==true (
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_SZ /d "%Path%;%%JAVA_HOME%%\bin;%%JAVA_HOME%%\jre\bin" /f
setx Path "%%JAVA_HOME%%\bin;%Path%")
exit
④ Tomcat配置
1) 解压Tomcat压缩包到目录C:\test\apache-tomcat-8.5.47中,并在目录C:\test\apache-tomcat-8.5.47\bin下创建配置脚本tomcat_startup.bat,内容如下:
echo
call "%~dp0%service.bat" install tomcat8
echo
sc config tomcat8 start= auto
sc start tomcat8
rem 下面两句是设置到服务里自动启动的
wmic service where name="tomcat8" changestartmode "automatic"
wmic service where name="tomcat8" startservice
exit
2) 在C:\test\apache-tomcat-8.5.47\bin目录下修改service.bat脚本,修改内容如下:
在开始setlocal下,添加:
SET "%JAVA_HOME%"="%cd%\Java\jdk1.7.0_51"
SET "%JRE_HOME%"="%cd%\Java\jdk1.7.0_51\jre"
3) 拷贝项目war包到C:\test\apache-tomcat-8.5.47\webapp中。
⑤ 打包脚本
1) 安装打包工具innosetup,选择默认选项即可,同时在C:\test目录下创建打包脚本pack.iss,内容如下:
; 脚本由 Inno Setup 脚本向导 生成!
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{9E044575-9CD9-4751-B0BE-F6758BA94548}
AppName=Test
AppVersion=V0.01
AppVerName=TestServer V0.01
AppPublisher=TestTechnology
AppPublisherURL=http://www.baidu.com/
AppSupportURL=http://www.baidu.com/
AppUpdatesURL=http://www.baidu.com/
DefaultDirName={pf}\Test
DefaultGroupName=TestSoftWare
AllowNoIcons=yes
OutputBaseFilename=Test
Compression=lzma
SolidCompression=yes
[Files]
;copy tomcat
Source:"C:\test\apache-tomcat-8.5.47\*";DestDir:"{app}\apache-tomcat-8.5.47";Flags:igNoreversion recursesubdirs createallsubdirs
;copy mysql
Source:"C:\test\mysql-5.5.62-winx64\*";DestDir:"{app}\mysql-5.5.62-winx64";Flags:igNoreversion recursesubdirs createallsubdirs
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Icons]
Name: "{group}\{cm:UninstallProgram,OA平台}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\OA平台"; Filename: http://localhost:8080/hr
[INI]
;修改数据库配置文件
Filename:"{app}\mysql-5.5.62-winx64\my.ini";Section:"mysqld";Key:"basedir"; String:"{app}\mysql-5.5.62-winx64"
Filename:"{app}\mysql-5.5.62-winx64\my.ini";Section:"mysqld";Key:"datadir"; String:"{app}\mysql-5.5.62-winx64\data"
Filename:"{app}\mysql-5.5.62-winx64\my.ini";Section:"mysqld";Key:"port"; String:"3306"
Filename:"{app}\mysql-5.5.62-winx64\my.ini";Section:"client";Key:"port"; String:"3306"
[Run]
Filename: "{app}\apache-tomcat-8.5.47\bin\Java\jdk1.7.0_51\bin\autoInstallJDK.bat";
Filename: "{app}\mysql-5.5.62-winx64\bin\mysql_init.bat";
Filename: "{app}\apache-tomcat-8.5.47\bin\tomcat_startup.bat";
[UninstallDelete]
Type:filesandordirs;Name:"{app}\apache-tomcat-8.5.47"
Type:filesandordirs;Name:"{app}\mysql-5.5.62-winx64"
⑥ 统一打包
1) 使用innosetup编译脚本pack.iss,最终会在C:\test下创建目录Output,并生成Test.exe执行程序。
⑦ 安装测试
1) 在纯净的windows 7 x64 sp1系统中,运行Test.exe执行程序,按照步骤进行安装,最终会在桌面生成登录链接,点击链接在浏览器中登录,登录成功,此时试验完成。
感谢你能够认真阅读完这篇文章,希望小编分享的“Tomcat+JDK+Mysql如何安装”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网行业资讯频道,更多相关知识等着你来学习!