Windows 中间件安装
IMPORTANT
- 基于 Windows 10/11 或 Windows Server 2019/2022
- 链接具有时效性,失效后到官网查找最新地址
- Windows 使用服务(Services)或任务计划程序
- 本页全部命令均为 PowerShell(管理员身份) 语法
- $env:USERPROFILE\Downloads是当前Windows系统登录用户的「下载」文件夹绝对路径,类似
C:\Users\你的用户名\Downloads - 配置文件路径注意正斜杠
/或双反斜杠\\ - 端口占用:`netstat -ano | findstr :端口号
环境准备
安装 Chocolatey 包管理器
指定安装目录后执行(修改 D:\chocolatey 为目标路径):
$chocoPath = "D:\chocolatey"
Remove-Item -Recurse -Force $chocoPath -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $chocoPath -Force | Out-Null
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072
Invoke-WebRequest -Uri "https://community.chocolatey.org/api/v2/package/chocolatey" -OutFile "$env:TEMP\choco.zip"
Expand-Archive -Path "$env:TEMP\choco.zip" -DestinationPath "$chocoPath\temp" -Force
Copy-Item -Path "$chocoPath\temp\tools\chocolateyInstall\*" -Destination $chocoPath -Recurse -Force
Remove-Item -Recurse -Force "$chocoPath\temp", "$env:TEMP\choco.zip"
[Environment]::SetEnvironmentVariable("ChocolateyInstall", $chocoPath, "Machine")
$env:ChocolateyInstall = $chocoPath
$machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine")
$machinePath = ($machinePath -split ';' | Where-Object { $_ -and $_ -notlike '*chocolatey*' }) -join ';'
[Environment]::SetEnvironmentVariable("Path", "$machinePath;$chocoPath;$chocoPath\bin;$chocoPath\shims", "Machine")
$env:Path = "$chocoPath;$chocoPath\bin;$chocoPath\shims;" + (($env:Path -split ';' | Where-Object { $_ -and $_ -notlike '*chocolatey*' }) -join ';')
choco feature enable -n allowGlobalConfirmation验证:
choco --version常用工具
choco install nssm -y配置 Windows 防火墙
外部访问需在防火墙添加入站规则
# 查看状态
Get-NetFirewallProfile | Select Name, Enabled
# 临时关闭
Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
# 开放指定端口
New-NetFirewallRule -DisplayName "Allow Port 8080" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow服务管理命令
Get-Service
Get-Service <服务名>
Start-Service <服务名>
Stop-Service <服务名>
Restart-Service <服务名>
Set-Service <服务名> -StartupType Automatic
Set-Service <服务名> -StartupType Manual
Set-Service <服务名> -StartupType Disabled
New-Service -Name "MyService" -BinaryPathName "C:\path\to\exe" -DisplayName "My Service" -Description "Description" -StartupType Automatic环境变量管理
Get-ChildItem Env:
[Environment]::SetEnvironmentVariable("VAR_NAME", "value", "User")
[Environment]::SetEnvironmentVariable("VAR_NAME", "value", "Machine")
[Environment]::SetEnvironmentVariable("VAR_NAME", $null, "Machine")
$env:VAR_NAME = [Environment]::GetEnvironmentVariable("VAR_NAME", "Machine")JDK
下载地址:https://adoptium.net/zh-CN/temurin/releases/
GUI 安装
使用 Windows MSI 安装程序运行交互式安装的说明:
- 双击
.msi,启动安装向导。 - 接受许可协议 → Next。
- 自定义设置(Custom Setup):
- 安装目录改为
C:\Java\jdk-11.0.26+4 - 勾选以下功能:
- Add to PATH(将安装添加到 PATH 环境变量)
- Associate .jar(将 .jar 与 Java 关联)
- Set JAVA_HOME variable(更新 JAVA_HOME 环境变量)
- 安装目录改为
- 点击 Next → Install。
- 安装完成后点击 Finish。
- 新开 PowerShell 验证:
java -version。
压缩包安装
文件:OpenJDK11U-jdk_x64_windows_hotspot_11.0.26_4.zip
New-Item -ItemType Directory -Path C:\Java -Force | Out-Null
Expand-Archive -Path "$env:USERPROFILE\Downloads\OpenJDK11U-jdk_x64_windows_hotspot_11.0.26_4.zip" -DestinationPath C:\Java -Force
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Java\jdk-11.0.26+4", "Machine")
$env:JAVA_HOME = "C:\Java\jdk-11.0.26+4"
$machinePath = [Environment]::GetEnvironmentVariable("Path", "Machine")
[Environment]::SetEnvironmentVariable("Path", "$machinePath;%JAVA_HOME%\bin", "Machine")
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
java -versionTomcat
下载地址:https://tomcat.apache.org/download-90.cgi
GUI 安装
- 双击
.exe,启动安装向导 → Next。 - 接受许可协议 → I Agree。
- 选择组件(Choose Components),保持默认(Service、Scripts、Tomcat Webapps 全选)→ Next。
- 配置(Configuration):
- Service Name:
Tomcat9 - Shutdown Port:
8005,HTTP/1.1 Connector Port:8080,AJP/1.3 Connector Port:8009 - 勾选 Auto-start service(开机自启)
- Service Name:
- Java Virtual Machine:指定为
C:\Java\jdk-11.0.26+4→ Next。 - 安装目录改为
C:\Tomcat\apache-tomcat-9.0.99→ Install → Finish(可取消勾选 Run / Show Readme)。
安装调整 JVM 参数:C:\Tomcat\apache-tomcat-9.0.99\bin 目录下,双击 Tomcat9w.exe 在 Java 选项卡下调整。
或者
[Environment]::SetEnvironmentVariable("CATALINA_HOME", "C:\Tomcat\apache-tomcat-9.0.99", "Machine")
cd C:\Tomcat\apache-tomcat-9.0.99\bin
.\tomcat9.exe //US//Tomcat9 --JvmMs=1024 --JvmMx=2048 --JavaHome="C:\Java\jdk-11.0.26+4"
Start-Service Tomcat9
Set-Service Tomcat9 -StartupType Automatic
Get-Service Tomcat9压缩包安装
文件:apache-tomcat-9.0.99-windows-x64.zip
New-Item -ItemType Directory -Path C:\Tomcat -Force | Out-Null
Expand-Archive -Path "$env:USERPROFILE\Downloads\apache-tomcat-9.0.99-windows-x64.zip" -DestinationPath C:\Tomcat -Force
[Environment]::SetEnvironmentVariable("CATALINA_HOME", "C:\Tomcat\apache-tomcat-9.0.99", "Machine")
[Environment]::SetEnvironmentVariable("JAVA_HOME", "C:\Java\jdk-11.0.26+4", "Machine")
cd C:\Tomcat\apache-tomcat-9.0.99\bin
.\service.bat install Tomcat9
.\tomcat9.exe //US//Tomcat9 --JvmMs=1024 --JvmMx=2048
Start-Service Tomcat9
Set-Service Tomcat9 -StartupType Automatic
Get-Service Tomcat9开放防火墙
New-NetFirewallRule -DisplayName "Tomcat 8080" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allowserver.xml 调整
修改 conf\server.xml,将 <Connector port="8080" protocol="HTTP/1.1".../> 替换为:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
URIEncoding="UTF-8"
maxKeepAliveRequests="150"
minSpareThreads="20"
maxConnections="1000"
maxThreads="150"
acceptCount="100"
acceptorThreadCount="2"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript,application/javascript"
redirectPort="8443"
relaxedPathChars="|{}[]"
relaxedQueryChars="|{}[]"/>MySQL
下载地址:https://dev.mysql.com/downloads/mysql/ 文件:mysql-installer-community-8.0.39.0.msi
GUI 安装
- 双击
.msi,启动 MySQL Installer。 - Choosing a Setup Type:选择 Server only(仅装服务端,避免 Workbench 等附加组件)→ Next。
- Installation:检查清单里出现 MySQL Server 8.0.x,点击 Execute 开始下载并安装 → 状态全部变为 Complete 后 → Next。
- Product Configuration:直接 Next(不需要在 Installer 内执行 Configurator)。
- Installation Complete:取消勾选 Start MySQL Configurator(我们手动配置 my.ini + 初始化)→ Finish。
IMPORTANT
初始化 data 目录前必须先创建好 my.ini(lower_case_table_names=1 初始化后不可修改)
创建配置文件 C:\Program Files\MySQL\MySQL Server 8.0\my.ini:
[mysqld]
basedir=C:/Program Files/MySQL/MySQL Server 8.0
datadir=C:/ProgramData/MySQL/MySQL Server 8.0/Data
lower_case_table_names=1
max_connections=3000
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
innodb_buffer_pool_size=2147483648
default_authentication_plugin=mysql_native_password
log_timestamps=SYSTEM
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
max_allowed_packet=1024M
default-time-zone="+8:00"
wait_timeout=1814400
interactive_timeout=1814400
skip-name-resolve
symbolic-links=0
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
innodb_lock_wait_timeout=100
sync_binlog=1000
innodb_flush_log_at_trx_commit=2
bind-address=0.0.0.0
port=3306
[client]
default-character-set=utf8mb4
port=3306初始化并注册服务:
$defaultsFile = "C:\Program Files\MySQL\MySQL Server 8.0\my.ini"
New-Item -ItemType Directory -Path "C:\ProgramData\MySQL\MySQL Server 8.0\Data" -Force | Out-Null
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
.\mysqld --defaults-file="$defaultsFile" --initialize-insecure --console
.\mysqld --install MySQL80 --defaults-file="$defaultsFile"
Start-Service MySQL80
Set-Service MySQL80 -StartupType Automatic
Get-Service MySQL80
.\mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '111111'; CREATE USER 'y9user'@'%' IDENTIFIED WITH mysql_native_password BY '111111'; GRANT ALL PRIVILEGES ON *.* TO 'y9user'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
New-NetFirewallRule -DisplayName "MySQL 3306" -Direction Inbound -LocalPort 3306 -Protocol TCP -Action Allow压缩包安装
文件:mysql-8.0.39-winx64.zip
Expand-Archive -Path "$env:USERPROFILE\Downloads\mysql-8.0.39-winx64.zip" -DestinationPath C:\ -Force
Move-Item "C:\mysql-8.0.39-winx64" "C:\mysql"创建 C:\mysql\my.ini(basedir=C:/mysql、datadir=C:/mysql/data,其余参数同 MSI 章节),然后:
$defaultsFile = "C:\mysql\my.ini"
cd C:\mysql\bin
.\mysqld --defaults-file="$defaultsFile" --initialize-insecure --console
.\mysqld --install MySQL80 --defaults-file="$defaultsFile"
Start-Service MySQL80
Set-Service MySQL80 -StartupType Automatic
Get-Service MySQL80
.\mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; CREATE USER 'y9user'@'%' IDENTIFIED WITH mysql_native_password BY 'Y9Pass4!'; GRANT ALL PRIVILEGES ON *.* TO 'y9user'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
New-NetFirewallRule -DisplayName "MySQL 3306" -Direction Inbound -LocalPort 3306 -Protocol TCP -Action AllowNGINX
压缩包安装
下载地址:https://nginx.org/en/download.html 文件:nginx-1.31.2.zip
Expand-Archive -Path "$env:USERPROFILE\Downloads\nginx-1.31.2.zip" -DestinationPath C:\ -Force
Move-Item "C:\nginx-1.31.2" "C:\nginx"
cd C:\nginx
start nginxChocolatey 安装
choco install nginx -y
# 3 个候选路径一起查(Get-ChildItem Path 参数本身支持数组)
$NGINX_HOME = Get-ChildItem "C:\tools","$env:ChocolateyInstall\lib\nginx\tools","$env:ChocolateyInstall\lib\nginx" `
-Directory -Filter "nginx-*" -ErrorAction SilentlyContinue |
Sort-Object Name -Descending | Select-Object -First 1 -ExpandProperty FullName
if (-not $NGINX_HOME) { Write-Error "未找到 nginx 解压目录,检查 choco install 是否完成"; return }
# 写系统环境变量 NGINX_HOME(当前会话+新开窗口都可用,后续管理不用记路径)
[Environment]::SetEnvironmentVariable("NGINX_HOME", $NGINX_HOME, "Machine"); $env:NGINX_HOME = $NGINX_HOME
$s = $ErrorActionPreference; $ErrorActionPreference = 'Continue'
try {
& "$NGINX_HOME\nginx.exe" -p $NGINX_HOME -t
if ($LASTEXITCODE -ne 0) { throw "nginx 配置语法校验失败" }
Start-Process "$NGINX_HOME\nginx.exe" -ArgumentList "-p",$NGINX_HOME
} finally { $ErrorActionPreference = $s }
Write-Host "nginx 启动完成:$NGINX_HOME。浏览器访问 http://localhost 验证,或 netstat -ano | findstr :80 查看监听。" -ForegroundColor Green管理(新开 PowerShell 直接用 $env:NGINX_HOME):
& "$env:NGINX_HOME\nginx.exe" -p $env:NGINX_HOME -t # 校验语法
& "$env:NGINX_HOME\nginx.exe" -p $env:NGINX_HOME -s reload # 重载配置
& "$env:NGINX_HOME\nginx.exe" -p $env:NGINX_HOME -s stop # 快速停止
& "$env:NGINX_HOME\nginx.exe" -p $env:NGINX_HOME -s quit # 优雅停止注册为服务(前提:已执行 choco install nssm -y):
nssm install nginx "$env:NGINX_HOME\nginx.exe"
nssm set nginx AppDirectory "$env:NGINX_HOME"
nssm set nginx Description "NGINX Web Server"
nssm set nginx AppParameters "-p `"$env:NGINX_HOME`"" # 防止服务启动时用 C:\Windows\System32 作为 prefix
nssm set nginx Start SERVICE_AUTO_START
Start-Service nginx开放防火墙:
New-NetFirewallRule -DisplayName "NGINX 80" -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "NGINX 443" -Direction Inbound -LocalPort 443 -Protocol TCP -Action AllowFTP 服务
下载地址:https://filezilla-project.org/download.php?type=server文件:FileZilla_Server_x64_setup-1.12.6.exe
GUI 安装
- 双击
.exe,启动安装向导 →I Agree。 - 选择组件(Choose Components),保持默认全选 →
Next。 - 安装目录改为
C:\Program Files\FileZilla Server→Next。 - 启动选项(Choose Startup Options):
- Service Name:
FileZilla Server - 管理后台端口:
14148(保持默认) - 勾选
Install as a Service, started automatically - 勾选
Start Server after setup completes
- Service Name:
- 开始菜单文件夹保持默认 →
Next→Install。 - 安装完成后点击
Finish,自动启动 FileZilla Server Interface。
安装后配置
Connection 登录框:Host
127.0.0.1,Port14148,管理员密码按刚设的填;勾选Save the password和Automatically connect to this server at startup→OK。首次连接提示设置管理员密码 → 输入密码 →
OK。左侧
Server listeners:看Port列实际端口(记住,后面访问全用它)。Address 保持0.0.0.0和::,Protocol 保持默认。左侧
Protocols settings → FTP and FTP over TLS (FTPS):- 勾
Use custom port range:Min =49152,Max =65535 - External Server IP Address:本机/内网留空;外网填公网 IP 或域名
- 点
Apply
- 勾
左侧
Administration:勾Start the server with Windows / Automatic startup→Apply。开放防火墙 ,远程可访问
powershell$FTP_PORT = 21 # 改成你 Server listeners 里 Port 列的实际端口(21 或 14107) New-NetFirewallRule -DisplayName "FileZilla FTP $FTP_PORT" -Direction Inbound -LocalPort $FTP_PORT -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "FileZilla FTP Admin 14148" -Direction Inbound -LocalPort 14148 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "FileZilla FTP PASV 49152-65535" -Direction Inbound -LocalPort 49152-65535 -Protocol TCP -Action Allow左侧
Rights management → Users:点Add→ 输入用户名y9admin→OK。右侧
General页签:- 勾
User is enabled - Authentication 下拉选
Require a password to log in - 密码填
111111 Mount points区域点Add:- Native path:
D:\y9FileStore - Virtual path:
/ - Access mode:
Read + Write - 3 个勾全部勾上:
Apply permissions to subdirectoriesWritable directory structureCreate native directory if it does not exist
- Native path:
- 勾
点对话框右下角的
Apply保存 →OK关闭。重启服务 + 验证:
- 重启服务:
Win + R输入services.msc→ 右键FileZilla Server→重启动 - 验证:资源管理器地址栏输入
ftp://y9admin:111111@127.0.0.1:<FTP_PORT>(<FTP_PORT>用第 3 步的实际端口替换)→ 回车。
- 重启服务:
Kafka (Zookeeper)
压缩包安装
下载地址:https://kafka.apache.org/downloads 文件:kafka_2.13-3.6.2.tgz(Binary downloads → Scala 2.13,官方推荐 2.13;不要下 Source download 的 src.tgz 源码包)
tar -xzf "$env:USERPROFILE\Downloads\kafka_2.13-3.6.2.tgz" -C C:\
Move-Item "C:\kafka_2.13-3.6.2" "C:\kafka"编辑 C:\kafka\config\server.properties:
broker.id=0
listeners=PLAINTEXT://127.0.0.1:9092
advertised.listeners=PLAINTEXT://127.0.0.1:9092
log.dirs=C:/kafka/kafka-logs
zookeeper.connect=localhost:2181编辑 C:\kafka\config\zookeeper.properties:
dataDir=C:/kafka/zookeeper-data启动 Zookeeper:
cd C:\kafka
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties新窗口启动 Kafka:
cd C:\kafka
.\bin\windows\kafka-server-start.bat .\config\server.properties注册为服务:
nssm install zookeeper "C:\kafka\bin\windows\zookeeper-server-start.bat"
nssm set zookeeper AppDirectory "C:\kafka"
nssm set zookeeper AppParameters "C:\kafka\config\zookeeper.properties"
nssm set zookeeper Description "Apache Zookeeper"
nssm install kafka "C:\kafka\bin\windows\kafka-server-start.bat"
nssm set kafka AppDirectory "C:\kafka"
nssm set kafka AppParameters "C:\kafka\config\server.properties"
nssm set kafka Description "Apache Kafka"
Start-Service zookeeper
Start-Service kafka
Set-Service zookeeper -StartupType Automatic
Set-Service kafka -StartupType Automatic常见报错处理:'wmic' 不是内部或外部命令
原因:Windows 11 / Server 2022 默认移除了 wmic.exe,Kafka 3.6.x 的 Windows 启动脚本中两处用到了它。
以下方式二选一执行
修复(改 bat,无系统依赖):
编辑
C:\kafka\bin\windows\kafka-server-start.bat,找到并替换:batchrem 注释掉原 wmic 行(通常在第28行附近) rem wmic os get osarchitecture |find/i "32-bit" >nul 2>&1 set KAFKA_HEAP_OPTS=-Xmx1G -Xms1G编辑
C:\kafka\bin\windows\kafka-run-class.bat,在IF ["%ISKAFKASTARTEDUP%"] EQU [""]上面一行加:batchset ISKAFKASTARTEDUP=YES
修复(系统层面,备选):
Win + I打开「设置」→ 左侧「系统」→ 拉到底部点「可选功能」- 点顶部「查看功能」→ 搜索框输入
WMIC→ 勾选结果里的 Wmic(Windows Management Instrumentation Command-line) → 下一步 → 「添加」 - 安装完成后,新开 PowerShell 执行
wmic os get osarchitecture验证,能输出OSArchitecture列即成功。
修复后重启服务:
Restart-Service zookeeper
Start-Sleep 8
Restart-Service kafka
netstat -ano | findstr ":2181 :9092"开放防火墙:
New-NetFirewallRule -DisplayName "Zookeeper 2181" -Direction Inbound -LocalPort 2181 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "Kafka 9092" -Direction Inbound -LocalPort 9092 -Protocol TCP -Action AllowRedis
压缩包安装
下载地址:https://github.com/redis-windows/redis-windows/releases 文件:Redis-7.2.14-Windows-x64-msys2-with-Service.zip(或更高版本同格式)
# 解压到 C:\Redis
Expand-Archive -Path "$env:USERPROFILE\Downloads\Redis-*-Windows-x64-msys2-with-Service.zip" -DestinationPath "C:\RedisTemp" -Force
$redisDir = Get-ChildItem "C:\RedisTemp" -Directory | Where-Object { $_.Name -like "Redis-*" } | Sort-Object Name -Descending | Select-Object -First 1 -ExpandProperty FullName
Move-Item $redisDir "C:\Redis" -Force
Remove-Item "C:\RedisTemp" -Recurse -Force
New-Item -ItemType Directory -Path "C:\Redis\data" -Force | Out-Null配置
编辑 C:\Redis\redis.conf:
bind 0.0.0.0
port 6379
requirepass 111111
dir C:/Redis/data注册服务并启动
cd C:\Redis
.\RedisService.exe install -c "C:\Redis\redis.conf" --dir "C:\Redis\data" --port 6379 --start-mode auto --service-name Redis
Start-Service Redis
Set-Service Redis -StartupType Automatic验证
cd C:\Redis
.\redis-cli -a 111111 ping返回 PONG 即成功。
服务管理
Get-Service Redis
Start-Service Redis
Stop-Service Redis
# 卸载服务
cd C:\Redis
.\RedisService.exe uninstall也可通过 GUI 安装: https://github.com/MicrosoftArchive/redis/releases 下载Redis-x64-3.0.504.msi文件,双击安装即可。这个版本是微软官方维护的Windows专属Redis稳定版本。
开放防火墙:
New-NetFirewallRule -DisplayName "Redis 6379" -Direction Inbound -LocalPort 6379 -Protocol TCP -Action AllowElasticSearch
压缩包安装
下载地址:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-17-25/ 文件:elasticsearch-7.17.25-windows-x86_64.zip
# 解压到 C:\elasticsearch
Expand-Archive -Path "$env:USERPROFILE\Downloads\elasticsearch-7.*-windows-x86_64.zip" -DestinationPath "C:\ESTemp" -Force
$esDir = Get-ChildItem "C:\ESTemp" -Directory | Where-Object { $_.Name -like "elasticsearch-7.*" } | Sort-Object Name -Descending | Select-Object -First 1 -ExpandProperty FullName
Move-Item $esDir "C:\elasticsearch" -Force
Remove-Item "C:\ESTemp" -Recurse -Force编辑 C:\elasticsearch\config\elasticsearch.yml:
# 集群名称(所有要加入同一集群的节点必须完全一致)
cluster.name: y9elasticsearch
# 节点名称(集群内每个节点必须唯一,建议跟主机名对应)
node.name: y9Node
path.data: C:\elasticsearch\data
path.logs: C:\elasticsearch\logs
# 监听地址
# · 对外访问 / 生产 / 准备扩集群:写 0.0.0.0 或者本机实际网卡 IP(例 192.168.3.116)
network.host: 127.0.0.1
# 设置对外服务的 http 端口,默认为 9200
http.port: 9200
# ② 初始 master 节点列表:仅用于「全新集群第一次启动」做 master 选举引导
# 写所有初次参与选举的节点的 node.name,初次启动成功、集群形成后必须删掉或注释掉
# 后续节点重启 / 扩容节点都不要再带,保留会有选举异常风险
cluster.initial_master_nodes: ['y9Node']
# 浏览器插件访问配置(ElasticSearch-Head 等前端工具连)
http.cors.enabled: true
http.cors.allow-origin: '*'
http.cors.allow-headers: Authorization注册并启动服务:
cd C:\elasticsearch\bin
.\elasticsearch-service.bat install
Start-Service elasticsearch-service-x64
Set-Service elasticsearch-service-x64 -StartupType AutomaticChocolatey 安装
choco install elasticsearch --version=7.17.25 -y
Start-Service elasticsearch-service-x64
Set-Service elasticsearch-service-x64 -StartupType Automatic编辑 C:\elasticsearch\config\elasticsearch.yml:参考 ZIP 安装
测试:
curl http://localhost:9200修改内存
方式一:配置文件(服务/命令行均生效)
编辑 C:\elasticsearch\config\jvm.options,找到并修改:
-Xms2g
-Xmx2g建议
Xms与Xmx设为相同值,且不超过物理内存的 50%,最大不超过 31GB(避免 JVM 指针压缩失效)。
方式二:服务管理器 GUI
cd C:\elasticsearch\bin
.\elasticsearch-service.bat manager在弹出的窗口中切换到 Java 选项卡:
- Initial memory pool (MB): 例如
2048 - Maximum memory pool (MB): 例如
2048
点击「应用」→「确定」后重启服务:
Restart-Service elasticsearch-service-x64验证内存:
curl http://localhost:9200/_nodes/jvm?pretty开启验证
生成证书:
cd C:\elasticsearch
.\bin\elasticsearch-certutil cert -out config\elastic-certificates.p12 -pass ""编辑 config\elasticsearch.yml:
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12设置密码:
cd C:\elasticsearch\bin
.\elasticsearch-setup-passwords interactive重启服务后验证:
curl -u elastic http://localhost:9200开放防火墙:
New-NetFirewallRule -DisplayName "ElasticSearch 9200" -Direction Inbound -LocalPort 9200 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "ElasticSearch 9300" -Direction Inbound -LocalPort 9300 -Protocol TCP -Action AllowNacos
压缩包安装
下载地址:https://github.com/alibaba/nacos/releases 文件:nacos-server-2.2.1.zip(选择 nacos-server-*-zip 包)
Expand-Archive -Path "$env:USERPROFILE\Downloads\nacos-server-2.2.1.zip" -DestinationPath C:\ -Force
Move-Item "C:\nacos" "C:\nacos-server-2.2.1"
New-Item -ItemType Directory -Path "C:\nacos-server-2.2.1\data" -Force | Out-Null编辑 C:\nacos-server-2.2.1\conf\application.properties:
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
db.user.0=y9user
db.password.0=111111
nacos.core.auth.enabled=true
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789创建数据库(MySQL 中执行):
CREATE DATABASE nacos_config CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;执行 C:\nacos-server-2.3.2\conf\nacos-mysql.sql 初始化表结构。
注册并启动服务:
nssm install nacos "C:\nacos-server-2.2.1\bin\startup.cmd"
nssm set nacos AppDirectory "C:\nacos-server-2.2.1\bin"
nssm set nacos AppParameters "-m standalone"
nssm set nacos Description "Nacos Service Discovery & Configuration"
nssm set nacos Start SERVICE_AUTO_START
Start-Service nacos管理后台: 浏览器访问 http://localhost:8848/nacos,默认用户名密码均为 nacos。
开放防火墙:
New-NetFirewallRule -DisplayName "Nacos 8848" -Direction Inbound -LocalPort 8848 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "Nacos 9848" -Direction Inbound -LocalPort 9848 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "Nacos 9849" -Direction Inbound -LocalPort 9849 -Protocol TCP -Action AllowMongoDB
MSI安装
下载地址:
https://www.mongodb.com/try/download/community
选择版本5.X系列,下载MSI安装包进行安装。
修改配置文件
编辑 mongod.conf,注释掉 bind_ip 配置以允许远程访问:
# bind_ip: 127.0.0.1设置用户验证
设置用户验证需要先关闭验证,否则无法登录。以MongoDB5.X为例:
1、进入MongoDB
cd D:\MongoDB\bin
.\mongo2、创建管理员用户
use admin
db.createUser({user:"y9admin",pwd:"83204585",roles:["root"],mechanisms:["SCRAM-SHA-1"]})3、创建业务数据库用户
use y9database
db.createUser({user:"y9admin",pwd:"83204585",roles:[{role:"readWrite",db:"y9database"}],mechanisms:["SCRAM-SHA-1"]})
db.auth("y9admin", "83204585")
exit4、启用身份验证
编辑 mongod.conf,添加以下配置:
security:
authorization: enabled5、重启MongoDB服务
Restart-Service MongoDB6、验证身份验证
未认证登录会提示无权限:
.\mongo
> use admin
> show dbs
Error: not authorized on admin to execute command { listDatabases: 1.0 }使用用户名密码登录:
.\mongo localhost:27017/admin -u y9admin -p 83204585
> show dbs
admin 0.000GB
local 0.000GB
y9database 0.001GB配置防火墙
New-NetFirewallRule -DisplayName "MongoDB 27017" -Direction Inbound -LocalPort 27017 -Protocol TCP -Action AllowConsul
压缩包安装
下载地址:
https://www.consul.io/downloads.html
下载Windows 64-bit版本。
解压配置
$ mkdir D:\consul\config
$ mkdir D:\consul\data在 D:\consul\config\ 目录下创建 config.json 文件:
{
"bind_addr": "127.0.0.1",
"client_addr": "127.0.0.1",
"bootstrap_expect": 1,
"ports": {
"dns": -1,
"http": 8500,
"server": 8300
},
"log_level": "INFO",
"server": true
}启动方式
方式一:临时启动(开发模式)
在consul文件夹下创建 dev.bat 文件:
consul agent -dev双击 dev.bat 启动(窗口不能关闭)。
方式二:以服务方式启动
以管理员身份打开PowerShell,执行以下命令:
sc.exe create "Consul-dev" binPath="D:\consul\consul agent -dev"注册成功后,手动启动服务或设置开机自启:
Start-Service "Consul-dev"管理后台
启动成功后,浏览器访问 http://localhost:8500/ui。
配置防火墙
New-NetFirewallRule -DisplayName "Consul 8500" -Direction Inbound -LocalPort 8500 -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "Consul 8300" -Direction Inbound -LocalPort 8300 -Protocol TCP -Action Allow