集群管理 #
一、集群概述 #
1.1 Neptune集群架构 #
text
Neptune集群组成:
├── 主实例(Primary)
│ ├── 处理写入请求
│ └── 处理读取请求
├── 读副本(Read Replicas)
│ ├── 处理读取请求
│ └── 最多15个
├── 集群存储
│ ├── 自动复制
│ └── 跨可用区
└── 集群端点
├── 写入端点
└── 读取端点
1.2 实例类型 #
text
实例类型:
├── db.r5.large:2 vCPU, 16GB RAM
├── db.r5.xlarge:4 vCPU, 32GB RAM
├── db.r5.2xlarge:8 vCPU, 64GB RAM
├── db.r5.4xlarge:16 vCPU, 128GB RAM
├── db.r5.8xlarge:32 vCPU, 256GB RAM
└── db.r5.12xlarge:48 vCPU, 384GB RAM
二、创建集群 #
2.1 使用AWS CLI创建 #
bash
# 创建子网组
aws neptune create-db-subnet-group \
--db-subnet-group-name my-neptune-subnet \
--db-subnet-group-description "My Neptune subnet group" \
--subnet-ids subnet-xxx subnet-yyy
# 创建集群
aws neptune create-db-cluster \
--db-cluster-identifier my-neptune-cluster \
--engine neptune \
--engine-version 1.3.0.0 \
--db-subnet-group-name my-neptune-subnet \
--vpc-security-group-ids sg-xxx \
--storage-encrypted \
--backup-retention-period 7
# 创建主实例
aws neptune create-db-instance \
--db-instance-identifier my-neptune-primary \
--db-instance-class db.r5.large \
--engine neptune \
--db-cluster-identifier my-neptune-cluster
2.2 使用CloudFormation创建 #
yaml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
NeptuneCluster:
Type: AWS::Neptune::DBCluster
Properties:
Engine: neptune
EngineVersion: 1.3.0.0
DBClusterIdentifier: my-neptune-cluster
DBSubnetGroupName: !Ref NeptuneSubnetGroup
VpcSecurityGroupIds:
- !Ref NeptuneSecurityGroup
StorageEncrypted: true
BackupRetentionPeriod: 7
NeptunePrimaryInstance:
Type: AWS::Neptune::DBInstance
Properties:
DBClusterIdentifier: !Ref NeptuneCluster
DBInstanceClass: db.r5.large
Engine: neptune
NeptuneSubnetGroup:
Type: AWS::Neptune::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Neptune subnet group
SubnetIds:
- !Ref PrivateSubnet1
- !Ref PrivateSubnet2
三、扩缩容 #
3.1 垂直扩展(实例类型升级) #
bash
# 修改实例类型
aws neptune modify-db-instance \
--db-instance-identifier my-neptune-primary \
--db-instance-class db.r5.xlarge \
--apply-immediately
3.2 水平扩展(添加读副本) #
bash
# 添加读副本
aws neptune create-db-instance \
--db-instance-identifier my-neptune-replica-1 \
--db-instance-class db.r5.large \
--engine neptune \
--db-cluster-identifier my-neptune-cluster
# 删除读副本
aws neptune delete-db-instance \
--db-instance-identifier my-neptune-replica-1
3.3 Neptune Serverless #
bash
# 创建无服务器集群
aws neptune create-db-cluster \
--db-cluster-identifier my-serverless-cluster \
--engine neptune \
--engine-mode serverless \
--serverless-scaling-configuration MinCapacity=1,MaxCapacity=128
四、参数配置 #
4.1 参数组管理 #
bash
# 创建参数组
aws neptune create-db-cluster-parameter-group \
--db-cluster-parameter-group-name my-params \
--db-parameter-group-family neptune1 \
--description "My Neptune parameter group"
# 修改参数
aws neptune modify-db-cluster-parameter-group \
--db-cluster-parameter-group-name my-params \
--parameters "ParameterName=neptune_query_timeout,ParameterValue=300000"
# 应用参数组
aws neptune modify-db-cluster \
--db-cluster-identifier my-neptune-cluster \
--db-cluster-parameter-group-name my-params \
--apply-immediately
4.2 关键参数 #
text
关键参数:
├── neptune_query_timeout:查询超时(毫秒)
├── neptune_lab_mode:实验性功能
├── neptune_enable_slow_query_log:慢查询日志
├── neptune_streams:启用流
└── neptune_result_cache:结果缓存
五、集群维护 #
5.1 维护窗口 #
bash
# 设置维护窗口
aws neptune modify-db-cluster \
--db-cluster-identifier my-neptune-cluster \
--preferred-maintenance-window "sun:03:00-sun:04:00"
5.2 版本升级 #
bash
# 升级引擎版本
aws neptune modify-db-cluster \
--db-cluster-identifier my-neptune-cluster \
--engine-version 1.3.1.0 \
--apply-immediately
5.3 重启实例 #
bash
# 重启实例
aws neptune reboot-db-instance \
--db-instance-identifier my-neptune-primary
六、集群端点 #
6.1 端点类型 #
text
端点类型:
├── 集群端点(写入)
│ └── 指向主实例
├── 读取端点
│ └── 负载均衡到读副本
├── 实例端点
│ └── 指向特定实例
└── 自定义端点
└── 自定义路由
6.2 获取端点 #
bash
# 获取集群端点
aws neptune describe-db-clusters \
--db-cluster-identifier my-neptune-cluster \
--query 'DBClusters[0].Endpoint'
# 获取读取端点
aws neptune describe-db-clusters \
--db-cluster-identifier my-neptune-cluster \
--query 'DBClusters[0].ReaderEndpoint'
七、高可用配置 #
7.1 多可用区部署 #
bash
# 创建多可用区集群
aws neptune create-db-cluster \
--db-cluster-identifier my-neptune-cluster \
--engine neptune \
--availability-zones us-east-1a us-east-1b us-east-1c
7.2 故障转移 #
text
故障转移机制:
├── 自动检测主实例故障
├── 提升读副本为新主实例
├── 更新集群端点
└── 通常在60-120秒内完成
7.3 全球数据库 #
bash
# 创建全球集群
aws neptune create-global-cluster \
--global-cluster-identifier my-global-cluster \
--engine neptune
# 添加区域集群
aws neptune create-db-cluster \
--db-cluster-identifier my-eu-cluster \
--engine neptune \
--global-cluster-identifier my-global-cluster \
--region eu-west-1
八、集群监控 #
8.1 CloudWatch指标 #
text
关键指标:
├── CPUUtilization:CPU使用率
├── FreeableMemory:可用内存
├── VolumeReadIOPs:存储读IOPS
├── VolumeWriteIOPs:存储写IOPS
├── GremlinRequestsPerSec:Gremlin请求/秒
├── GremlinHttp100s:100ms内响应数
├── GremlinHttp200s:200ms内响应数
└── GremlinHttp400s:400ms内响应数
8.2 告警配置 #
bash
# 创建CPU告警
aws cloudwatch put-metric-alarm \
--alarm-name neptune-high-cpu \
--metric-name CPUUtilization \
--namespace AWS/Neptune \
--threshold 80 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 3
九、最佳实践 #
9.1 集群设计 #
text
集群设计建议:
├── 生产环境使用多可用区
├── 合理配置读副本数量
├── 选择合适的实例类型
├── 启用自动备份
└── 配置维护窗口
9.2 性能优化 #
text
性能优化建议:
├── 监控关键指标
├── 合理设置参数
├── 使用读取端点分担读负载
├── 控制并发连接数
└── 定期维护
十、总结 #
集群管理要点:
| 项目 | 说明 |
|---|---|
| 创建 | 使用CLI或CloudFormation |
| 扩展 | 垂直扩展和水平扩展 |
| 参数 | 参数组配置 |
| 高可用 | 多可用区部署 |
| 监控 | CloudWatch指标 |
最佳实践:
- 生产环境使用多可用区
- 合理配置读副本
- 监控关键指标
- 定期备份
- 及时升级版本
下一步,让我们学习备份与恢复!
最后更新:2026-03-27