Library Search
结果页服务注册发现与健康检查
在 知识库 中找到 8 个匹配结果。
知识库
知识库
8 个 服务注册发现与健康检查 # Consul 服务注册发现与健康检查
## 目标
使用 Python consul 库注册服务、查询服务、配置健康检查。
## 环境准备
```bash
pip install python-consul
# 确保 Consul 运行中
docker run -d --name consul -p 8500:8500 consul:latest agent -dev -client=0.0… 2% 入门教程 - 服务网格与多数据中心 # Consul 入门教程:服务网格与多数据中心
## 1. Consul vs ZooKeeper vs etcd
| 维度 | Consul | ZooKeeper | etcd |
|------|--------|-----------|------|
| 协议 | Raft + Gossip | ZAB | Raft |
| 服务发现 | 原生 DNS/HTTP API | 需框架封… 2% Nacos 微服务注册与配置中心入门 | 模式 | 适用场景 | 取舍 |
|------|----------|------|
| **AP** | 一般微服务注册发现 | 网络分区时各节点可独立工作,恢复后自动合并 |
| **CP** | 金融/支付等强一致场景 | 网络分区时少数节点拒绝写入 |
> 这是 Nacos 相比 Eureka(纯 AP)和 ZooKeeper(纯 CP)的核心优势。
### 2.3 健康检查机制… 2% 入门到进阶教程 @Modifying
@Query("UPDATE User u SET u.email = :email WHERE u.id = :id")
int updateEmail(@Param("id") Long id, @Param("email") String email);
}
```
## 第四章:Actuator 监控
### 4.1 启用端点
```proper… 2% 02-dependency-injection-auth @app.get("/public/health")
async def health_check():
"""公开接口 —— 无需认证"""
return {"status": "healthy", "users_count": len(fake_users_db)}
```
## 测试
```bash
# 1. 获取 Token(alice / secret123)
cur… 2% 03-实战数据处理与Web-API # 搜索
curl "http://localhost:8000/api/books?keyword=Python&page=1&per_page=5"
# 更新
curl -X PUT http://localhost:8000/api/books/1 \
-H "Content-Type: application/json" \
-d '{"title":"Python编程从入门到实… 1% etcd 分布式锁与服务发现实战 # 3. 测试服务发现(终端1)
python service_discovery.py server
# [Register] hostname:8080 registered (TTL=10s)
# 4. 测试服务发现(终端2)
python service_discovery.py discover
# [Discover] Found 1 instances:
# - hostnam… 1% 图书 API——Query、Mutation 与嵌套类型 // ── Resolver ──
const resolvers = {
Query: {
books: () => books,
book: (_, { id }) => books.find(b => b.id === id),
authors: () => authors,
author: (_, { id }) => authors.find(a =>… 1%