mgmt/docs/vault/vault_deployment_guide.md

117 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Vault 通过 Nomad 部署指南
本文档提供了使用 Nomad 的 exec 驱动部署 HashiCorp Vault 的详细步骤,类似于 Consul 的部署方式。
## 部署架构
- **驱动方式**:使用 Nomad 的 `exec` 驱动
- **节点分布**在三个节点上部署kr-master、us-ash3c、bj-warden
- **存储后端**:使用本地 Consul 作为存储后端
- **网络设置**API 端口为 8200集群通信端口为 8201
## 自动部署方法
我们提供了一个自动化脚本来简化部署过程。该脚本会:
1. 使用 Ansible 在所有节点上安装 Vault
2. 通过 Nomad 部署 Vault 服务
3. 初始化和解封 Vault如果需要
### 使用自动部署脚本
```bash
# 确保脚本有执行权限
chmod +x scripts/deploy_vault.sh
# 运行部署脚本
./scripts/deploy_vault.sh
```
脚本执行完成后Vault 将在主节点上初始化并解封。您需要在其他节点上手动执行解封操作。
## 手动部署步骤
如果您想手动部署,请按照以下步骤操作:
### 1. 安装 Vault
使用 Ansible 在所有节点上安装 Vault
```bash
ansible-playbook -i configuration/inventories/production/vault.ini configuration/playbooks/install/install_vault.yml
```
### 2. 部署 Vault 服务
使用 Nomad 部署 Vault 服务:
```bash
nomad job run jobs/vault-cluster-exec.nomad
```
### 3. 初始化 Vault
在一个节点上初始化 Vault
```bash
export VAULT_ADDR='http://127.0.0.1:8200'
vault operator init -key-shares=5 -key-threshold=3
```
请安全保存生成的解封密钥和根令牌!
### 4. 解封 Vault
在每个节点上解封 Vault
```bash
export VAULT_ADDR='http://127.0.0.1:8200'
vault operator unseal <解封密钥1>
vault operator unseal <解封密钥2>
vault operator unseal <解封密钥3>
```
## 验证部署
验证 Vault 状态:
```bash
export VAULT_ADDR='http://127.0.0.1:8200'
vault status
```
## 配置文件说明
### Nomad 作业文件
`jobs/vault-cluster-exec.nomad` 定义了 Vault 服务的 Nomad 作业配置,使用 exec 驱动在三个节点上部署 Vault。
### Ansible Playbook
`configuration/playbooks/install/install_vault.yml` 负责在目标节点上安装 Vault 软件包和创建必要的目录结构。
## 故障排除
### Vault 无法启动
- 检查 Nomad 作业状态:`nomad job status vault-cluster-exec`
- 检查 Nomad 分配日志:`nomad alloc logs <allocation_id>`
- 确保 Consul 正在运行:`consul members`
### Vault 无法解封
- 确保使用正确的解封密钥
- 检查 Vault 状态:`vault status`
- 检查 Consul 中的 Vault 数据:`consul kv get -recurse vault/`
## 后续步骤
成功部署 Vault 后,您可能需要:
1. 配置访问策略
2. 启用密钥引擎
3. 与 Nomad 集成
4. 配置审计日志
5. 设置自动解封机制(生产环境)
请参考 `docs/vault/vault_setup_guide.md` 获取更多信息。