微服務實現win系統一鍵安裝

2022-09-18 23:00:12 字數 4389 閱讀 4185

背景:內網環境,微服務搭建的專案需要在客戶電腦部署,實現一鍵安裝,開機自啟等功能

專案打包exe使用nsis(hm vnisedit) 

win系統可能需要的.net服務

一鍵安裝內容:mysql5.7 jdk1.8 nacos nginx-1.19.2 redis-5.0.9 gateway 專案應用

基本流程是 1.安裝時配置mysql jdk執行環境,並設定mysql開機自啟,2.安裝nacos、nginx、redis gateway 專案應用為系統服務 3.安裝完成開啟相應**進行使用

一.安裝mysql服務並實現開機自啟,安裝包使用的綠色版免安裝版本,資料使用db檔案

1.安裝mysql為系統服務

@echo off

@echo 正在安裝mysql服務......

cd /d %~dp0

cd ../echo %cd%set startdir=%cd%set myini=%startdir%\mysql-5.7.22-winx64\my.ini

cd "%startdir%\mysql-5.7.22-winx64\bin"

%startdir%\mysql-5.7.22-winx64\bin\mysqld --install mysql "--defaults-file=%myini%"@echo mysql服務安裝成功

2.設定mysql服務開機自啟

@echo off

net start mysql

sc config mysql start=auto

net stop mysql

net start mysql

3.設定使用者密碼

@echo off

set sqlpath=%~dp0mysql\

cd ../set startdir=%cd%set sqlfile=%cd%\mysql-5.7.22-winx64\initsql.sql

cd "%startdir%\mysql-5.7.22-winx64\bin"mysqld --initialize-insecure --user=mysql

mysqld -install

@echo net start mysql

mysql -uroot < %sqlfile%

set password for root@localhost = password('123456');

use mysql;

update user set host='%' where user='root';

flush privileges;

4.服務停止及解除安裝

@echo off

@echo 正在解除安裝mysql服務......

cd /d %~dp0

cd ../set startdir=%cd%set myini=%cd%\mysql-5.7.22-winx64\my.ini

cd "%startdir%\mysql-5.7.22-winx64\bin"net stop mysql

%startdir%\mysql-5.7.22-winx64\bin\mysqld --remove mysql

@echo 解除安裝mysql服務成功

二.jdk 環境配置

@echo off

@echo 正在配置jdk環境......

setx "j**a_home" /m "%cd%\jdk8"setx /m classpath ".;%%j**a_home%%\lib;%%j**a_home%%\lib\tools.jar;"setx /m path "%path%;%%j**a_home%%\bin;%%j**a_home%%\jre\bin;"@echo jdk環境配置完成

三.redis、nacos、nginx配置為系統服務

1.1redis 設定系統服務並啟動 

@echo off

cd "%cd%\redis-x64-5.0.9"redis-server --service-install redis.windows-service.conf --loglevel verbose 註冊服務

timeout /nobreak /t 2 等待2秒redis-server --service-start 啟動服務

1.2 redis服務停止及解除安裝

@echo off

cd ..

cd "%~dp0redis-x64-5.0.9" redis安裝包檔案路徑redis-server --service-stop 停服務

redis-server --service-uninstall 解除安裝服務

2.1 nacos設定系統服務並啟動 

@echo off

cd ..

cd "%cd%\nacos"nacosserver.exe install

timeout /nobreak /t 2net start nacos

2.2 nacos服務停止並解除安裝

@echo off

cd ..

cd "%~dp0nacos"net stop nacos

nacosserver.exe uninstall

3.1 nginx設定系統服務並啟動 

@echo off

cd ..

cd "%cd%\nginx-1.19.2"nginxserver.exe install

timeout /nobreak /t 2net start nginx

3.2 nginx服務停止並解除安裝

@echo off

cd ..

cd "%~dp0nginx-1.19.2"net stop nginx

nginxserver.exe uninstall

四.應用服務註冊為win系統服務

1.2把xml和exe放到需要註冊服務的同一目錄,修改exe檔名稱與服務名保持一直,修改xml文化名與服務名稱保持一直

1.3修改xml配置

sys-gateway   //與jar服務名稱保持一直

sys-gateway //註冊到系統服務的名稱

this service is a sys-gateway-1.0.0 created from a minimal configuration //說明文字

//需要執行的命令檔案

j**a

-jar sys-gateway-1.0.0.jar

1.4應用服務的服務註冊及啟動

@echo off

cd ..

cd "%cd%\sys-gateway"sys-gateway-1.0.0.exe install

timeout /nobreak /t 2net start sys-gateway

@echo off

1.5應用服務的停止與解除安裝

@echo off

echo "%~dp0sys-gateway"cd "%~dp0sys-gateway"net stop sys-gateway

sys-gateway-1.0.0.exe uninstall

五.使用nsis把檔案目錄打包為exe,安裝過程中執行對應的bat指令碼

nsis使用嚮導模式就可以,具體能多操作檢視操作文件

主要執行編碼

section "mainsection"sec01

setoutpath "$instdir"setoverwrite ifnewer

file /r "..\one\ghztest\*.*" //目錄下所有檔案打包並轉移的新的目錄(類似於copy)execwait "$instdir/bin/my.bat" // 執行對應的指令碼服務execwait "$instdir/bin/start.bat"execwait "$instdir/bin/init.bat"execwait "$instdir/jdk.bat"execwait "$instdir/install.bat"sectionend

bat批處理檔案知識:

當前碟符     %~d0

當前路徑 %cd%當前執行命令列 %0當前bat檔案路徑 %~dp0

注釋 rem

列印 echo

空格確認 pause

安卓系統一鍵root

root詳細過程 關機 最好取下記憶體卡 4.開機,開啟usb除錯 5.執行superoneclick 直接點選第乙個按鈕 root 6.靜待root過程,大約20 30秒吧 到這個地方已經root成功,問你要不要做乙個測試,點 是 吧 7.拆掉資料線,重啟 以上是root過程 以下驗證root是否...

實現微服務統一認證鑑

參考 spring cloud實戰 最七篇 spring cloud gateway spring security oauth2整合統一認證授權平台下實現登出使jwt失效方案 oauth 2.0 是目前最流行的授權機制,用來授權第三方應用,獲取使用者資料。阮一峰 oauth 2.0 的乙個簡單解釋...

預警系統一鍵自動公升級 校園一鍵報警系統設計方案

系統介紹 在學校各防範點 如大門口 教學樓 教職工宿舍 公共活動場所等地 分布式安裝該監控裝置,遇到突發事件時按動警情按鈕,報警器將通過網路把報警資訊傳輸給監控報警管理主機,監控報警主機接收到報警資訊後,會實現啟動現場對講裝置,告知師生突發事件來臨,師生便可根據不同的警報聲或廣播提示採取相應的自救自...