chore(config): Make Nacos namespace configurable

- Replace hardcoded public namespace with NACOS_NAMESPACE
- Document nacos init container troubleshooting for 1Panel deploy
This commit is contained in:
Toys-A
2026-08-07 03:04:33 +08:00
parent 16e9d7f9bd
commit 05988c4325
21 changed files with 217 additions and 41 deletions
+42
View File
@@ -8,10 +8,16 @@ x-service-env: &service-env
SPRING_PROFILES_ACTIVE: ha
NACOS_HOST: nacos
NACOS_PORT: 8848
NACOS_NAMESPACE: ${NACOS_NAMESPACE:-}
NACOS_GROUP: ${NACOS_GROUP:-DEFAULT_GROUP}
NACOS_USERNAME: ${NACOS_USERNAME:-nacos}
NACOS_PASSWORD: ${NACOS_PASSWORD:-nacos}
SPRING_CLOUD_NACOS_DISCOVERY_NAMESPACE: ${NACOS_NAMESPACE:-}
SPRING_CLOUD_NACOS_DISCOVERY_GROUP: ${NACOS_GROUP:-DEFAULT_GROUP}
SPRING_CLOUD_NACOS_DISCOVERY_USERNAME: ${NACOS_USERNAME:-nacos}
SPRING_CLOUD_NACOS_DISCOVERY_PASSWORD: ${NACOS_PASSWORD:-nacos}
SPRING_CLOUD_NACOS_CONFIG_NAMESPACE: ${NACOS_NAMESPACE:-}
SPRING_CLOUD_NACOS_CONFIG_GROUP: ${NACOS_GROUP:-DEFAULT_GROUP}
SPRING_CLOUD_NACOS_CONFIG_USERNAME: ${NACOS_USERNAME:-nacos}
SPRING_CLOUD_NACOS_CONFIG_PASSWORD: ${NACOS_PASSWORD:-nacos}
MYSQL_HOST: mysql
@@ -103,6 +109,18 @@ services:
MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
JVM_XMS: ${NACOS_JVM_XMS:-512m}
JVM_XMX: ${NACOS_JVM_XMX:-512m}
JAVA_OPT_EXT: >-
--nacos.plugin.datasource-dialect.type=mysql
--spring.datasource.platform=mysql
--spring.sql.init.platform=mysql
--nacos.plugin.datasource.db.num=1
--nacos.plugin.datasource.db.url.0=jdbc:mysql://mysql:3306/nacos_config?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
--nacos.plugin.datasource.db.user=root
--nacos.plugin.datasource.db.password=${MYSQL_ROOT_PASSWORD}
--db.num=1
--db.url.0=jdbc:mysql://mysql:3306/nacos_config?characterEncoding=utf8&connectTimeout=10000&socketTimeout=30000&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
--db.user.0=root
--db.password.0=${MYSQL_ROOT_PASSWORD}
NACOS_AUTH_ENABLE: "true"
NACOS_AUTH_TOKEN: ${NACOS_AUTH_TOKEN}
NACOS_AUTH_IDENTITY_KEY: serverIdentity
@@ -115,6 +133,30 @@ services:
depends_on:
mysql:
condition: service_healthy
nacos-init:
condition: service_completed_successfully
networks:
- haovp-network
nacos-init:
image: mysql:8.0
container_name: haovp-nacos-init
restart: "no"
depends_on:
mysql:
condition: service_healthy
environment:
<<: *common-env
MYSQL_HOST: mysql
MYSQL_PORT: 3306
MYSQL_DB: nacos_config
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- ./sql/nacos-schema.sql:/init-sql/nacos-schema.sql:ro
- ./sql/nacos-config-init.sql:/init-sql/nacos-config-init.sql:ro
- ./sql/nacos-init.sh:/init-sql/nacos-init.sh:ro
entrypoint: ["/bin/sh", "/init-sql/nacos-init.sh"]
networks:
- haovp-network
+1 -1
View File
@@ -158,7 +158,7 @@ spring:
scg:
fallback:
mode: response
response-body: '{"code":500,"message":"服务不可用,请稍后再试"}'
response-body: ''{"code":500,"message":"服务不可用,请稍后再试"}''
gateway:
ignore:
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
set -eu
: "${MYSQL_ROOT_PASSWORD:?MYSQL_ROOT_PASSWORD is required}"
MYSQL_HOST="${MYSQL_HOST:-mysql}"
MYSQL_PORT="${MYSQL_PORT:-3306}"
MYSQL_DB="${MYSQL_DB:-nacos_config}"
MYSQL_USER="${MYSQL_USER:-root}"
export MYSQL_PWD="$MYSQL_ROOT_PASSWORD"
mysql_exec() {
mysql --default-character-set=utf8mb4 -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u"$MYSQL_USER" "$@"
}
echo "Preparing Nacos database ${MYSQL_DB}..."
mysql_exec -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DB}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
mysql_exec "$MYSQL_DB" < /init-sql/nacos-schema.sql
if row_count="$(mysql_exec -N -s -e "SELECT COUNT(*) FROM \`${MYSQL_DB}\`.config_info;" 2>/dev/null)"; then
:
else
row_count=0
fi
if [ "${row_count}" -eq 0 ]; then
echo "Seeding default Nacos configs..."
mysql_exec "$MYSQL_DB" < /init-sql/nacos-config-init.sql
else
echo "Nacos config already exists, skip seeding."
fi
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -14,7 +14,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
# 移除以下健康检查配置
# heart-beat-interval: 5000
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -19,8 +19,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml
@@ -48,16 +48,16 @@
video_id as videoId,
SUM(
CASE
<foreach collection="weights.entrySet()" item="entry">
WHEN behavior_type = #{entry.key} THEN behavior_weight * #{entry.value}
<foreach collection="weights" index="behaviorType" item="weight">
WHEN behavior_type = #{behaviorType} THEN behavior_weight * #{weight}
</foreach>
ELSE behavior_weight
END
) as score
FROM recommend_user_behavior
WHERE
WHERE 1 = 1
<if test="startTime != null">
create_time >= #{startTime}
AND create_time >= #{startTime}
</if>
<if test="behaviorTypes != null and behaviorTypes.size > 0">
AND behavior_type IN
@@ -69,4 +69,4 @@
ORDER BY score DESC
LIMIT #{limit}
</select>
</mapper>
</mapper>
@@ -8,7 +8,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
sentinel:
transport:
@@ -5,7 +5,7 @@ spring:
nacos:
discovery:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
@@ -16,8 +16,8 @@ spring:
register-enabled: true
config:
server-addr: ${NACOS_HOST:nacos}:${NACOS_PORT:8848}
namespace: public
namespace: ${NACOS_NAMESPACE:}
group: DEFAULT_GROUP
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
file-extension: yaml
file-extension: yaml