diff --git a/DockerComposeShells/.env b/DockerComposeShells/.env index 689aaa3..c27faa2 100644 --- a/DockerComposeShells/.env +++ b/DockerComposeShells/.env @@ -25,4 +25,4 @@ ADMIN_WEB_PORT=30711 PULSAR_ADMIN_USER=admin PULSAR_ADMIN_PASSWORD=0fd7afb8b0d04e6abc4fdfdac2190a79 IOTDB_ROOT_PASSWORD=Lixiao@1980 -MYSQL_ROOT_PASSWORD=JiShe!aqG#5kGgh&0 +MYSQL_ROOT_PASSWORD='JiShe!aqG#5kGgh&0' \ No newline at end of file diff --git a/DockerComposeShells/docker-compose.yml b/DockerComposeShells/docker-compose.yml index 8003f82..4d9a698 100644 --- a/DockerComposeShells/docker-compose.yml +++ b/DockerComposeShells/docker-compose.yml @@ -34,7 +34,7 @@ services: hostname: pulsar-cluster-init command: > /bin/bash -c - "bin/pulsar initialize-cluster-metadata --cluster pulsar-cluster-1 --zookeeper zookeeper:${PULSAR_ZOOKEEPER_PORT} --configuration-store zookeeper:${PULSAR_ZOOKEEPER_PORT} --web-service-url http://\${SERVER_IP}:\${PULSAR_ADMIN_PORT} --broker-service-url pulsar://\${SERVER_IP}:\${PULSAR_BROKER_PORT} || echo 'Cluster metadata already exists'" + "bin/pulsar initialize-cluster-metadata --cluster pulsar-cluster-1 --zookeeper zookeeper:${PULSAR_ZOOKEEPER_PORT} --configuration-store zookeeper:${PULSAR_ZOOKEEPER_PORT} --web-service-url http://${SERVER_IP}:${PULSAR_ADMIN_PORT} --broker-service-url pulsar://${SERVER_IP}:${PULSAR_BROKER_PORT} || echo 'Cluster metadata already exists'" depends_on: zookeeper: condition: service_healthy @@ -136,23 +136,23 @@ services: /bin/bash -c " # 等待broker就绪 - until bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' clusters list; do + until bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' clusters list; do echo 'Waiting for Pulsar broker to be ready...' sleep 5 done; # 创建租户和命名空间 - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' tenants create public --allowed-clusters pulsar-cluster-1 -r admin || echo 'Tenant public already exists'; - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' namespaces create public/default || echo 'Namespace public/default already exists'; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' tenants create public --allowed-clusters pulsar-cluster-1 -r admin || echo 'Tenant public already exists'; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' namespaces create public/default || echo 'Namespace public/default already exists'; # 创建非持久化主题 - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' topics create non-persistent://public/default/default-topic || echo 'Topic non-persistent://public/default/default-topic already exists'; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' topics create non-persistent://public/default/default-topic || echo 'Topic non-persistent://public/default/default-topic already exists'; # 设置命名空间策略 echo 'Setting namespace policies...'; - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-subscription-types-enabled public/default --types NonDurable; - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-message-ttl public/default --messageTTL 0; - bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"\${PULSAR_ADMIN_USER}\",\"password\":\"\${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-retention public/default --sizeLimit -1 --timeLimit -1; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-subscription-types-enabled public/default --types NonDurable; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-message-ttl public/default --messageTTL 0; + bin/pulsar-admin --admin-url http://pulsar-broker:${PULSAR_ADMIN_PORT} --auth-plugin org.apache.pulsar.client.impl.auth.AuthenticationBasic --auth-params '{\"userId\":\"${PULSAR_ADMIN_USER}\",\"password\":\"${PULSAR_ADMIN_PASSWORD}\"}' namespaces set-retention public/default --sizeLimit -1 --timeLimit -1; echo 'Pulsar initialization completed with Basic Authentication!'; " @@ -263,10 +263,14 @@ services: stdin_open: true tty: true depends_on: - - mysql-service - - redis-service - - iotdb-standalone-service - - pulsar-init + mysql-service: + condition: service_started + redis-service: + condition: service_started + iotdb-standalone-service: + condition: service_started + broker: + condition: service_started networks: - pulsar-net @@ -285,7 +289,8 @@ services: stdin_open: true tty: true depends_on: - - admin-api-service + admin-api-service: + condition: service_completed_successfully networks: - pulsar-net diff --git a/DockerComposeShells/start-pulsar.sh b/DockerComposeShells/start-pulsar.sh index a939967..3a31b7e 100644 --- a/DockerComposeShells/start-pulsar.sh +++ b/DockerComposeShells/start-pulsar.sh @@ -198,15 +198,15 @@ echo "" echo "🎉 Pulsar 基本认证集群启动完成!" echo "" echo "📋 连接信息:" -echo " Pulsar Broker: \${SERVER_IP}:\${PULSAR_BROKER_PORT}" -echo " Pulsar Admin: http://\${SERVER_IP}:\${PULSAR_ADMIN_PORT}" -echo " IoTDB: \${SERVER_IP}:\${IOTDB_PORT} (root/\${IOTDB_ROOT_PASSWORD})" -echo " Redis: \${SERVER_IP}:6379" -echo " MySQL: \${SERVER_IP}:\${MYSQL_PORT}" -echo " Admin API: http://\${SERVER_IP}:\${ADMIN_API_PORT}" -echo " Admin UI: http://\${SERVER_IP}:\${ADMIN_WEB_PORT}" -echo " 用户名: \${PULSAR_ADMIN_USER}" -echo " 密码: \${PULSAR_ADMIN_PASSWORD}" +echo " Pulsar Broker: ${SERVER_IP}:$PULSAR_BROKER_PORT}" +echo " Pulsar Admin: http://${SERVER_IP}:$PULSAR_ADMIN_PORT}" +echo " IoTDB: ${SERVER_IP}:${IOTDB_PORT} (root/${IOTDB_ROOT_PASSWORD})" +echo " Redis: ${SERVER_IP}:6379" +echo " MySQL: ${SERVER_IP}:$MYSQL_PORT}" +echo " Admin API: http://${SERVER_IP}:$ADMIN_API_PORT}" +echo " Admin UI: http://${SERVER_IP}:$ADMIN_WEB_PORT}" +echo " 用户名: ${PULSAR_ADMIN_USER}" +echo " 密码: ${PULSAR_ADMIN_PASSWORD}" echo "" echo "🔧 常用命令:" echo " 查看状态: docker compose ps" @@ -214,9 +214,9 @@ echo " 查看日志: docker compose logs -f" echo " 停止服务: docker compose down" echo "" echo "🧪 测试连接:" -echo " Pulsar: curl -u \${PULSAR_ADMIN_USER}:\${PULSAR_ADMIN_PASSWORD} http://\${SERVER_IP}:\${PULSAR_ADMIN_PORT}/admin/v2/clusters" -echo " Redis: redis-cli -h \${SERVER_IP} -p 6379 ping" -echo " MySQL: mysql -h \${SERVER_IP} -P \${MYSQL_PORT} -u root -p\${MYSQL_ROOT_PASSWORD} -e 'SELECT 1'" +echo " Pulsar: curl -u $PULSAR_ADMIN_USER}:$PULSAR_ADMIN_PASSWORD} http://$SERVER_IP}:$PULSAR_ADMIN_PORT}/admin/v2/clusters" +echo " Redis: redis-cli -h ${SERVER_IP} -p 6379 ping" +echo " MySQL: mysql -h ${SERVER_IP} -P ${MYSQL_PORT} -uroot -p${MYSQL_ROOT_PASSWORD} -e 'SELECT 1'" echo " IoTDB: docker exec -it iotdb-standalone ./start-cli.sh -h iotdb-standalone -u root -p Lixiao@1980" echo "" echo "🎯 等待服务启动完成..."