#!/bin/bash # 手动注册服务到Keystone service catalog # 用于在没有region服务的情况下注册基础服务 set -e # 加载数据库配置 if [ -f "../.env.local" ]; then source ../.env.local elif [ -f ".env.local" ]; then source .env.local fi DB_HOST=${DB_HOST:-localhost} DB_PORT=${DB_PORT:-3306} DB_USER=${DB_USER:-root} DB_PASSWORD=${DB_PASSWORD} DB_NAME="yunioncloud" echo "=== 注册服务到Keystone Service Catalog ===" # 注册服务和端点 mysql -h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASSWORD $DB_NAME << 'EOF' -- 清理可能存在的旧数据 DELETE FROM endpoint; DELETE FROM service; -- 1. 注册 identity 服务 (keystone) INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('identity-service-id', 'keystone', 'identity', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('identity-endpoint-public', 'identity-service-id', 'default', 'public', 'http://localhost:35357/v3', 1, NOW(), NOW(), 0, 0, 'keystone'), ('identity-endpoint-internal', 'identity-service-id', 'default', 'internal', 'http://localhost:35357/v3', 1, NOW(), NOW(), 0, 0, 'keystone'), ('identity-endpoint-admin', 'identity-service-id', 'default', 'admin', 'http://localhost:35357/v3', 1, NOW(), NOW(), 0, 0, 'keystone'); -- 2. 注册 image 服务 (glance) INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('image-service-id', 'glance', 'image', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('image-endpoint-public', 'image-service-id', 'default', 'public', 'http://localhost:9292', 1, NOW(), NOW(), 0, 0, 'glance'), ('image-endpoint-internal', 'image-service-id', 'default', 'internal', 'http://localhost:9292', 1, NOW(), NOW(), 0, 0, 'glance'), ('image-endpoint-admin', 'image-service-id', 'default', 'admin', 'http://localhost:9292', 1, NOW(), NOW(), 0, 0, 'glance'); -- 3. 注册 yunionconf 服务 INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('yunionconf-service-id', 'yunionconf', 'yunionconf', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('yunionconf-endpoint-public', 'yunionconf-service-id', 'default', 'public', 'http://localhost:30889', 1, NOW(), NOW(), 0, 0, 'yunionconf'), ('yunionconf-endpoint-internal', 'yunionconf-service-id', 'default', 'internal', 'http://localhost:30889', 1, NOW(), NOW(), 0, 0, 'yunionconf'), ('yunionconf-endpoint-admin', 'yunionconf-service-id', 'default', 'admin', 'http://localhost:30889', 1, NOW(), NOW(), 0, 0, 'yunionconf'); -- 4. 注册 monitor 服务 INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('monitor-service-id', 'monitor', 'monitor', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('monitor-endpoint-public', 'monitor-service-id', 'default', 'public', 'http://localhost:30093', 1, NOW(), NOW(), 0, 0, 'monitor'), ('monitor-endpoint-internal', 'monitor-service-id', 'default', 'internal', 'http://localhost:30093', 1, NOW(), NOW(), 0, 0, 'monitor'), ('monitor-endpoint-admin', 'monitor-service-id', 'default', 'admin', 'http://localhost:30093', 1, NOW(), NOW(), 0, 0, 'monitor'); -- 5. 注册 scheduledtask 服务 INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('scheduledtask-service-id', 'scheduledtask', 'scheduledtask', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('scheduledtask-endpoint-public', 'scheduledtask-service-id', 'default', 'public', 'http://localhost:30891', 1, NOW(), NOW(), 0, 0, 'scheduledtask'), ('scheduledtask-endpoint-internal', 'scheduledtask-service-id', 'default', 'internal', 'http://localhost:30891', 1, NOW(), NOW(), 0, 0, 'scheduledtask'), ('scheduledtask-endpoint-admin', 'scheduledtask-service-id', 'default', 'admin', 'http://localhost:30891', 1, NOW(), NOW(), 0, 0, 'scheduledtask'); -- 6. 注册 compute 服务 (region) - 使用compute_v2类型 INSERT INTO service (id, name, type, enabled, created_at, updated_at, update_version, deleted, is_emulated, config_version) VALUES ('compute-service-id', 'region', 'compute_v2', 1, NOW(), NOW(), 0, 0, 0, 0); INSERT INTO endpoint (id, service_id, region_id, interface, url, enabled, created_at, updated_at, update_version, deleted, name) VALUES ('compute-endpoint-public', 'compute-service-id', 'default', 'public', 'http://localhost:30888', 1, NOW(), NOW(), 0, 0, 'region'), ('compute-endpoint-internal', 'compute-service-id', 'default', 'internal', 'http://localhost:30888', 1, NOW(), NOW(), 0, 0, 'region'), ('compute-endpoint-admin', 'compute-service-id', 'default', 'admin', 'http://localhost:30888', 1, NOW(), NOW(), 0, 0, 'region'); -- 7. 注册 region 表(即使region服务未运行,也需要有region记录) INSERT INTO region (id, name, created_at, updated_at, update_version, deleted) VALUES ('default', 'default', NOW(), NOW(), 0, 0) ON DUPLICATE KEY UPDATE updated_at=NOW(); SELECT 'Services registered successfully' as status; SELECT COUNT(*) as service_count FROM service; SELECT COUNT(*) as endpoint_count FROM endpoint; EOF echo "" echo "✓ 服务注册完成" echo "" echo "已注册的服务:" echo " - identity (keystone) - http://localhost:35357/v3" echo " - compute (region) - http://localhost:30888" echo " - image (glance) - http://localhost:9292" echo " - yunionconf - http://localhost:30889" echo " - monitor - http://localhost:30093" echo " - scheduledtask - http://localhost:30891" echo "" echo "注意: 需要重启服务以加载新的service catalog"