当前位置: 首页 > news >正文

福州台江区网站建设廊坊网站推广排名

福州台江区网站建设,廊坊网站推广排名,wordpress 模板 删除,企业邮箱怎么查找🧱 Windows 系统搭建 Redis 原生集群详细图文指南 适用于:Redis 单机多实例集群部署(伪分布式集群) 📁 一、目录结构规划 我们将使用以下路径来组织 Redis 集群: C:\software\redis # Redis 安…

🧱 Windows 系统搭建 Redis 原生集群详细图文指南

适用于:Redis 单机多实例集群部署(伪分布式集群)


📁 一、目录结构规划

我们将使用以下路径来组织 Redis 集群:

C:\software\redis            # Redis 安装目录
C:\RedisCluster               # 集群主目录
C:\RedisCluster\6380          # 实例1配置目录(端口6380)
C:\RedisCluster\6381          # 实例2配置目录(端口6381)
...
C:\RedisCluster\6385          # 实例6配置目录(端口6385)

🔧 二、环境准备

1. 下载并解压 Redis

前往官方归档地址下载 Redis for Windows:

🔗 https://github.com/microsoftarchive/redis/releases

推荐下载版本:

  • Redis-x64-3.2.100.zip(稳定性最好)
  • Redis-x64-5.0.14.1.zip(功能更全)

将下载的压缩包解压至:

C:\software\redis

确保包含以下关键文件:

  • redis-server.exe
  • redis-cli.exe

🧰 三、创建六个 Redis 实例(端口从 6380 到 6385)

打开 PowerShell(任意身份),依次执行以下步骤:

创建主目录

mkdir C:\RedisCluster

实例 1: 端口 6380

mkdir C:\RedisCluster\6380
$conf = @"
port 6380
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6380\redis-6380.conf" -Value $conf

实例 2: 端口 6381

mkdir C:\RedisCluster\6381
$conf = @"
port 6381
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6381\redis-6381.conf" -Value $conf

实例 3: 端口 6382

mkdir C:\RedisCluster\6382
$conf = @"
port 6382
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6382.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6382\redis-6382.conf" -Value $conf

实例 4: 端口 6383

mkdir C:\RedisCluster\6383
$conf = @"
port 6383
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6383.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6383\redis-6383.conf" -Value $conf

实例 5: 端口 6384

mkdir C:\RedisCluster\6384
$conf = @"
port 6384
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6384.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6384\redis-6384.conf" -Value $conf

实例 6: 端口 6385

mkdir C:\RedisCluster\6385
$conf = @"
port 6385
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-6385.conf
cluster-node-timeout 5000
appendonly yes
requirepass 123456
masterauth 123456
"@
Set-Content -Path "C:\RedisCluster\6385\redis-6385.conf" -Value $conf

▶️ 四、启动所有 Redis 实例

在 PowerShell 中依次运行以下命令:

启动实例 6380

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6380\redis-6380.conf'"

启动实例 6381

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6381\redis-6381.conf'"

启动实例 6382

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6382\redis-6382.conf'"

启动实例 6383

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6383\redis-6383.conf'"

启动实例 6384

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6384\redis-6384.conf'"

启动实例 6385

cd "C:\software\redis"
Start-Process powershell.exe "-NoExit", "& '$PWD\redis-server.exe' 'C:\RedisCluster\6385\redis-6385.conf'"

🌐 五、创建 Redis 集群

等待上面所有实例成功运行后,在一个新的 PowerShell 窗口中执行下面命令来创建集群:

cd "C:\software\redis"
.\redis-cli.exe --cluster create 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 --cluster-replicas 1 -a 123456 --cluster-yes

🔍 六、验证 Redis 集群状态

继续在同一窗口中执行:

$commands = @"
cluster info
cluster nodes
exit
"@echo $commands | .\redis-cli.exe -c -p 6380 -a 123456

输出示例:

cluster_state:ok
cluster_slots_assigned:16384
cluster_known_nodes:6
...

表示集群已经正确生成!


📜 七、附录:完整 .ps1 脚本一键部署(带路径检测)

你可以将此脚本保存为 setup-redis-cluster.ps1 并运行:

# 设置变量
$redisPath = "C:\software\redis"
$clusterDir = "C:\RedisCluster"
$instances = @(6380, 6381, 6382, 6383, 6384, 6385)
$password = "123456"# 检查 Redis 是否安装正确
if (-Not (Test-Path "$redisPath")) {Write-Host "❌ 错误:未找到 Redis 安装目录,请检查路径是否为:$redisPath" -ForegroundColor Redexit
}if (-Not (Test-Path "$redisPath\redis-server.exe") -or -Not (Test-Path "$redisPath\redis-cli.exe")) {Write-Host "❌ 错误:未找到 redis-server.exe 或 redis-cli.exe,请确认是否已正确解压 Redis 到该目录。" -ForegroundColor Redexit
}# 创建主目录
New-Item -ItemType Directory -Force -Path $clusterDir | Out-Null# 创建每个实例的目录和配置文件
foreach ($port in $instances) {$dir = "$clusterDir\$port"New-Item -ItemType Directory -Force -Path $dir | Out-Null$confFile = "$dir\redis-$port.conf"$content = @"
port $port
bind 127.0.0.1
cluster-enabled yes
cluster-config-file nodes-$port.conf
cluster-node-timeout 5000
appendonly yes
requirepass $password
masterauth $password
"@Set-Content -Path $confFile -Value $contentWrite-Host "✅ 已创建配置文件:$confFile"
}# 启动实例
foreach ($port in $instances) {$confFile = "$clusterDir\$port\redis-$port.conf"Start-Process powershell.exe "-NoExit", "& '$redisPath\redis-server.exe' '$confFile'"Write-Host "🔌 已启动 Redis 实例,端口:$port"
}# 等待启动完成
Write-Host "`n⏳ 正在等待 Redis 实例启动完成(10秒)..." -ForegroundColor Yellow
Start-Sleep -Seconds 10# 创建集群
Write-Host "`n🧱 正在创建 Redis 集群..." -ForegroundColor Green
$nodes = $instances | ForEach-Object { "127.0.0.1:$_" }
& "$redisPath\redis-cli.exe" --cluster create @nodes --cluster-replicas 1 -a $password --cluster-yes# 验证集群
Write-Host "`n🔍 正在验证 Redis 集群状态..." -ForegroundColor Green
$commands = @"
cluster info
cluster nodes
exit
"@echo $commands | & "$redisPath\redis-cli.exe" -c -p 6380 -a $password# 结束提示
Write-Host "`n🎉 Redis 集群搭建完成!" -ForegroundColor Green
Write-Host "你可以通过 redis-cli 连接测试,例如:" -ForegroundColor Cyan
Write-Host "   cd C:\software\redis" -ForegroundColor Cyan
Write-Host "   redis-cli.exe -c -p 6380 -a 123456" -ForegroundColor Cyan

✅ 总结

步骤内容
1Redis 安装路径为:C:\software\redis
2六个配置文件分别创建,不省略任何重复步骤
3每个实例单独启动一个窗口
4使用 redis-cli 创建集群
5验证 cluster infocluster nodes
6提供完整 .ps1 脚本,支持一键运行
http://www.dtcms.com/a/510678.html

相关文章:

  • 呼市做无痛人流z首大网站凡客家居
  • 柳州网站建设psn118营销是做什么
  • 如何把网站上传到网上能源网站建设方案
  • 廊坊网站制作怎么做服务网站
  • 58网站建设多少钱手机怎么创建网页链接
  • 濮阳网站建设pc网站还有必要做吗
  • 做网站签合同移动网站设计上机考试
  • 电商网站开发可行分析网站开发的技术分类
  • 济南区网站开发怎样手机微信登陆网站
  • 互站网怎么样网站差异
  • 建个网站需要多少钱?做英文网站建设
  • 做公众号用什么网站吗海口建设网站建设
  • 株洲建设局网站页面设置标签wordpress
  • 贷款网站模版网站建设文档模板
  • 网站用哪个软件做最有效的线下推广方式
  • 小说网站怎么做seo三种人不适合编程
  • 深圳外贸建站网络推广联客易东营志愿服务网
  • 帮企业建网站步骤成都企业网站网络营销
  • 潍坊网站建设首荐创美网络那个网站做玉石最专业
  • 网站外链隐形框架深圳龙岗网站开发
  • 乐清网站制作推荐枣阳网站建设 枣阳山水数码
  • linux 做网站用哪个版本株洲新站建设
  • 首京建设投资引导基金网站南京网站建设服务公司
  • 广州企业网站推广策划方案长沙高端网站建设品牌
  • 浏阳做网站网站建设系统认证系统
  • 上海 建站做手机旅游网站
  • 营销型网站建设公司比较专业wordpress中文前端
  • 企业网站seo哪里好北京住房与城乡建设厅网站首页
  • php做企业网站需要多久网站建设多少钱京icp备
  • 佛山网站开发公司电话太原网站免费制作