Skip to main content

HAP Microservices

Download Images

In a Kubernetes cluster environment, this operation needs to be performed separately on the server where each microservice node is located.

crictl pull registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-hap:7.3.4
crictl pull registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-doc:2.0.0
crictl pull registry.cn-hangzhou.aliyuncs.com/mdpublic/mingdaoyun-command:node1018-python36

Deployment Manager

By default, operate only on the first Kubernetes Master server.

  1. Download the manager

    wget https://pdpublic.mingdao.com/private-deployment/7.3.4/mingdaoyun_private_deployment_captain_linux_amd64.tar.gz
  2. Create a directory and extract the manager into the newly created directory

    mkdir /usr/local/MDPrivateDeployment/
    tar -zxvf mingdaoyun_private_deployment_captain_linux_amd64.tar.gz -C /usr/local/MDPrivateDeployment/
  3. Set up the systemd unit file for the manager service required by the HAP Manager

    cat > /etc/systemd/system/hap-manager.service <<'EOF'
    [Unit]
    Description=HAP Manager
    After=network-online.target
    Wants=network-online.target

    [Service]
    Type=oneshot
    WorkingDirectory=/usr/local/MDPrivateDeployment
    ExecStart=/usr/bin/bash ./service.sh start
    RemainAfterExit=yes

    [Install]
    WantedBy=multi-user.target
    EOF
  4. Comment out the docker-related check items in the manager script

    sed -ri '/^function check\(\)/,/^}/{s/^([[:space:]]*)(checkExecList|checkDockerRuntime|checkDockerVersion)/\1# \2/}' /usr/local/MDPrivateDeployment/service.sh
  5. Run the manager startup check

    bash /usr/local/MDPrivateDeployment/service.sh check
  6. Start the manager service

    systemctl daemon-reload
    systemctl start hap-manager
    systemctl enable hap-manager

Deploy Microservices

By default, operate only on the first Kubernetes Master server.

  1. Generate the initial configuration file

    cd /usr/local/MDPrivateDeployment/
    bash ./service.sh install https://hap.domain.com
    echo -n 'StageStart' > installer.stage
  2. Configure the ConfigMap information in the config.yaml file

    • config.yaml is located by default at /data/mingdao/script/kubernetes

    Execute vim config.yaml to edit the file and update the variable values to match your deployment environment:

    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: env-list
    namespace: default
    data:
    ENV_APP_VERSION: "7.3.4"
    ENV_MYSQL_HOST: "192.168.10.2"
    ENV_MYSQL_PORT: "3306"
    ENV_MYSQL_USERNAME: "root"
    ENV_MYSQL_PASSWORD: "123456"
    ENV_MONGODB_URI: "mongodb://hap:123456@192.168.10.4:27017,192.168.10.5:27017,192.168.10.6:27017"
    ENV_MONGODB_OPTIONS: "?maxIdleTimeMS=600000&maxLifeTimeMS=1800000"
    ENV_REDIS_HOST: "192.168.10.13"
    ENV_REDIS_PORT: "6379"
    ENV_REDIS_PASSWORD: "123456"
    ENV_KAFKA_ENDPOINTS: "192.168.10.7:9092,192.168.10.8:9092,192.168.10.9:9092"
    ENV_ELASTICSEARCH_ENDPOINTS: "http://192.168.10.10:9200,http://192.168.10.11:9200,http://192.168.10.12:9200"
    ENV_ELASTICSEARCH_PASSWORD: "elastic:123456"
    ENV_FILE_ENDPOINTS: "192.168.10.16:9001,192.168.10.17:9002,192.168.10.18:9003,192.168.10.19:9004"
    ENV_FILE_ACCESSKEY: "storage"
    ENV_FILE_SECRETKEY: "123456"
    ENV_MINGDAO_INTRANET_ENDPOINT: "www:8880"
    ENV_ADDRESS_MAIN: "https://hap.domain.com"
    ENV_ADDRESS_ALLOWLIST: ""
    ENV_CAPTAIN_ENDPOINT: "http://192.168.10.20:38880"
    ENV_HEALTHCHECK: "off"
    ENV_API_TOKEN: "4PrArcXYquO1sHlV9evsDqFKUUJ1kWVAg7v6oGcTKRNG9fUY"
    ENV_TIME_ZONE: "Asia/Shanghai"
    The above example configures MySQL and Redis in standalone or master-slave mode. If your environment uses MySQL MGR or Redis Sentinel mode, click to expand for configuration instructions.

    MySQL MGR Mode

    If MySQL uses MGR (Group Replication) + Router architecture, update ENV_MYSQL_HOST to the address of any Router node, ENV_MYSQL_PORT to the Router read-write port 6446, and append the following variables:

    ENV_RDB_TYPE: "10"
    ENV_RDB_URI_MDPROJECT: "Server=192.168.15.204,192.168.15.205,192.168.15.206;Port=6446;Database=MDProject;uid=root;password=actual_password;"
    ENV_RDB_URI_MDLOG: "Server=192.168.15.204,192.168.15.205,192.168.15.206;Port=6446;Database=MDLog;uid=root;password=actual_password;"
    ENV_RDB_URI_MDSTRUCTURE: "Server=192.168.15.204,192.168.15.205,192.168.15.206;Port=6446;Database=MDStructure;uid=root;password=actual_password;"
    ENV_RDB_URI_MDCALENDAR: "Server=192.168.15.204,192.168.15.205,192.168.15.206;Port=6446;Database=MDCalendar;uid=root;password=actual_password;"
    ENV_RDB_URI_MDAPPLICATION: "Server=192.168.15.204,192.168.15.205,192.168.15.206;Port=6446;Database=MDApplication;uid=root;password=actual_password;"

    Additional variable descriptions:

    • ENV_RDB_TYPE: Fixed value 10, enables MGR multi-node connection mode
    • ENV_RDB_URI_* connection string fields:
      • Server: All Router node IPs, separated by commas
      • Port: Fixed at 6446 (Router read-write port), do not modify
      • Database: Fixed database name, do not modify
      • uid: MySQL login username
      • password: Login password for the uid user, replace the placeholder with the actual password

    Redis Sentinel Mode

    If Redis uses Sentinel architecture, remove ENV_REDIS_HOST, ENV_REDIS_PORT, and ENV_REDIS_PASSWORD from the example, and replace them with the following three Sentinel variables (the two sets cannot coexist):

    ENV_REDIS_SENTINEL_ENDPOINTS: "192.168.10.21:26379,192.168.10.22:26379,192.168.10.23:26379"
    ENV_REDIS_SENTINEL_MASTER: "mymaster"
    ENV_REDIS_SENTINEL_PASSWORD: "123456"

    Variable descriptions:

    • ENV_REDIS_SENTINEL_ENDPOINTS: All Sentinel node addresses in IP:port format, separated by commas. Default Sentinel port is 26379
    • ENV_REDIS_SENTINEL_MASTER: Redis Sentinel master name, typically mymaster by default
    • ENV_REDIS_SENTINEL_PASSWORD: Redis authentication password, replace the placeholder with the actual password

    Environment variables to configure for initial deployment:

    Variable NameDescription
    ENV_MYSQL_HOST[MySQL standalone or master-slave] Enter the MySQL primary node address; if using MGR + Router architecture, enter the address of any Router node.
    ENV_MYSQL_PORT[MySQL standalone or master-slave] Enter the MySQL service port; if using MGR + Router architecture, enter the Router read-write port 6446.
    ENV_MYSQL_USERNAMEEnter the MySQL database login username.
    ENV_MYSQL_PASSWORDEnter the MySQL database login password.
    ENV_RDB_TYPE[MySQL MGR mode] Fixed value 10, enables MGR multi-node connection mode.
    ENV_RDB_URI_MDPROJECT[MySQL MGR mode] Connection string for the MDProject database, see the MGR configuration above for format.
    ENV_RDB_URI_MDLOG[MySQL MGR mode] Connection string for the MDLog database, see the MGR configuration above for format.
    ENV_RDB_URI_MDSTRUCTURE[MySQL MGR mode] Connection string for the MDStructure database, see the MGR configuration above for format.
    ENV_RDB_URI_MDCALENDAR[MySQL MGR mode] Connection string for the MDCalendar database, see the MGR configuration above for format.
    ENV_RDB_URI_MDAPPLICATION[MySQL MGR mode] Connection string for the MDApplication database, see the MGR configuration above for format.
    ENV_MONGODB_URIEnter the MongoDB connection address, which can be in standalone, replica set, or sharded cluster format.
    ENV_REDIS_HOST[Redis standalone or master-slave mode] Enter the Redis service host address.
    ENV_REDIS_PORT[Redis standalone or master-slave mode] Enter the Redis service port.
    ENV_REDIS_PASSWORD[Redis standalone or master-slave mode] Enter the Redis service access password.
    ENV_REDIS_SENTINEL_ENDPOINTS[Redis Sentinel mode] Enter the Sentinel node addresses, separated by commas (e.g., 192.168.10.21:26379,192.168.10.22:26379,192.168.10.23:26379).
    ENV_REDIS_SENTINEL_MASTER[Redis Sentinel mode] Enter the Redis Sentinel master name.
    ENV_REDIS_SENTINEL_PASSWORD[Redis Sentinel mode] Enter the Redis authentication password.
    ENV_KAFKA_ENDPOINTSEnter the Kafka cluster node addresses, separated by commas (e.g., 192.168.10.7:9092,192.168.10.8:9092).
    ENV_ELASTICSEARCH_ENDPOINTSEnter the Elasticsearch node access addresses; in cluster mode, separate multiple nodes with commas and prepend each with http:// (e.g., http://192.168.10.10:9200,http://192.168.10.11:9200).
    ENV_ELASTICSEARCH_PASSWORDEnter the Elasticsearch access credentials in the format username:password.
    ENV_FILE_ENDPOINTSEnter the HAP file service node addresses, separated by commas (e.g., 192.168.10.16:9001,192.168.10.17:9002).
    ENV_FILE_ACCESSKEYEnter the HAP file service AccessKey.
    ENV_FILE_SECRETKEYEnter the HAP file service SecretKey.
    ENV_ADDRESS_MAINEnter the actual access address for the HAP system (e.g., https://hap.domain.com).
    ENV_ADDRESS_ALLOWLISTOptional. Enter additional allowed access addresses for the HAP system, separated by commas.
    ENV_CAPTAIN_ENDPOINTEnter the deployment manager server address (e.g., http://192.168.10.20:38880).
  3. After modification, save and exit. Ensure all configurations match the current deployment environment before proceeding.

  4. Adjust microservice replicas

    The default Pod replica count for microservices is usually 1. During the initial deployment, you can use the following script to initialize microservice replicas. During later operation, scale out further based on business traffic and server resource usage.

    The replica adjustment script batch modifies Pod replica counts in the microservice YAML files. It provides preset modes by deployment scale, and each mode adjusts different service replica counts.

    1. Download the replica adjustment script

      wget https://pdpublic.mingdao.com/private-deployment/data/set_microservice_replicas.sh
      chmod +x set_microservice_replicas.sh
    2. Select a mode by deployment scale

      The script supports the following three modes:

      Sets daily high-load services to 2 replicas and keeps other services at the default 1 replica.

      bash set_microservice_replicas.sh lite
    3. Run the script

      After selecting the mode by deployment scale, run the corresponding script command above. When the script starts, it prompts you to confirm the directory where the microservice YAML files are located:

      Current Mode: <Mode> (Default: <Replicas>)

      ▶ Directory Confirmation
      Default Path: /data/mingdao/script/kubernetes/
      Press Enter to use default, or input a new path:
      • The default directory corresponds to /data/mingdao/script/kubernetes. If this path has not been customized, press Enter to continue.
      • If the microservice YAML file directory has been customized, enter the actual directory and press Enter to continue.

      After the directory is confirmed, the script prompts again before applying the update:

      Directory in use: /data/mingdao/script/kubernetes/

      ▶ Ready to update all YAML files in the confirmed directory
      Mode: <mode> Path: /data/mingdao/script/kubernetes/

      Please type yes to confirm execution:

      After confirming that the directory and mode are correct, type yes and press Enter to continue. The script first backs up the YAML files and then batch modifies the replica counts. After completion, it displays Operation completed successfully!.

  5. Start the HAP Microservices

    cd /data/mingdao/script/kubernetes/
    bash start.sh

    In the /data/mingdao/script/kubernetes/ directory:

    • start.sh is used to start the HAP microservices
    • stop.sh is used to stop the HAP microservices
  6. Check the status of the HAP Microservices

    kubectl get pod -o wide
    • Under normal circumstances, the Pod status is 2/2 and Running.

    • If a Pod fails to start or has an abnormal status, use the following command to view its restart or error logs:

      kubectl logs -p <pod-name>
  7. Once Nginx completes the proxy configuration for the access address, the HAP system can be accessed via the configured address.