使用自定义镜像快速创建计算巢服务

本文介绍通过自定义镜像创建ECS部署物的方式,创建计算巢私有部署服务。

前提条件

申请成为软件服务商

操作步骤

一、制作服务镜像

  1. 云服务器ECS-实例页面中,根据您的服务要求创建实例

  2. 将您的服务部署到ECS实例中,并测试。请参见部署自建项目

  3. 测试完成后,根据您的需求使用快照创建自定义镜像使用实例创建自定义镜像

  4. 创建完成后如下图所示。

    image

二、创建计算巢部署物

  1. 进入计算巢-服务部署物页面。根据提示填写部署物信息。

  2. 部署物内容区域中,选择ECS镜像,勾选自定义镜像并选择您制作的服务镜像

  3. 根据业务需求设置分发的地域。本节以全部地域为例。

  4. 单击发布部署物,完成创建。

    image

详细操作,请参见ECS镜像部署物

三、使用ECS部署物创建私有部署服务

  1. 进入计算巢-我的服务-创建新服务页面。

  2. 选择自定义创建服务,并在服务类型处,选择私有部署服务,然后单击下一步:配置服务

  3. 基本信息区域,上传服务图标,填写服务名称、服务简介和版本描述。

  4. 服务部署区域,配置服务部署信息。

    1. 选择模板类型为ROS模板。

    2. 在部署地域选择全部地域

    3. 模板内容选择YAML,并填入服务模板,您可以使用如下示例模板。

      示例模板

      ROSTemplateFormatVersion: '2015-09-01'
      Conditions:
        CreateVpcConditions:
          Fn::Equals:
            - NewVPC
            - Ref: VpcOption
      Parameters:
        Model:
          Type: String
          Label:
            en: Model
            zh-cn: 内置模型
          AssociationPropertyMetadata:
            ValueLabelMapping:
              DeepSeek-R1_32b:
                zh-cn: DeepSeek-R1:32b
                en: DeepSeek-R1:32b
          AllowedValues:
            - DeepSeek-R1_32b
          Default: DeepSeek-R1_32b
        VpcOption:
          Type: String
          AllowedValues:
            - NewVPC
            - ExistingVPC
          AssociationPropertyMetadata:
            ValueLabelMapping:
              NewVPC:
                zh-cn: 新建专有网络
                en: New VPC
              ExistingVPC:
                zh-cn: 已有专有网络
                en: Existing VPC
          Label:
            en: Select Existing or New VPC
            zh-cn: 选择已有/新建的专有网络
          Required: true
          Default: NewVPC
        VpcCidrBlock:
          Type: String
          Label:
            en: VPC CIDR IPv4 Block
            zh-cn: 专有网络IPv4网段
          Description:
            zh-cn: VPCip地址段范围,<br>您可以使用以下的ip地址段或其子网:<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
            en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
          Default: 192.168.0.0/16
          Required:
            Fn::Equals:
              - NewVPC
              - ${VpcOption}
          AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
          AssociationPropertyMetadata:
            Visible:
              Condition:
                Fn::Equals:
                  - NewVPC
                  - ${VpcOption}
        VSwitchCidrBlock:
          Type: String
          Label:
            en: VSwitch CIDR Block
            zh-cn: 交换机子网网段
          Description:
            zh-cn: 必须属于VPC的子网段。
            en: Must belong to the subnet segment of VPC.
          Default: 192.168.1.0/24
          Required:
            Fn::Equals:
              - NewVPC
              - ${VpcOption}
          AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
          AssociationPropertyMetadata:
            VpcCidrBlock: VpcCidrBlock
            Visible:
              Condition:
                Fn::Equals:
                  - NewVPC
                  - ${VpcOption}
        PayType:
          Type: String
          Label:
            en: ECS Instance Charge Type
            zh-cn: 付费类型
          Default: PostPaid
          AllowedValues:
            - PostPaid
            - PrePaid
          AssociationProperty: ChargeType
          AssociationPropertyMetadata:
            LocaleKey: InstanceChargeType
        PayPeriodUnit:
          Type: String
          Label:
            en: Pay Period Unit
            zh-cn: 购买资源时长周期
          Default: Month
          AllowedValues:
            - Month
            - Year
          AssociationProperty: PayPeriodUnit
          AssociationPropertyMetadata:
            Visible:
              Condition:
                Fn::Not:
                  Fn::Equals:
                    - ${PayType}
                    - PostPaid
        PayPeriod:
          Type: Number
          Label:
            en: Period
            zh-cn: 购买资源时长
          Default: 1
          AllowedValues:
            - 1
            - 2
            - 3
            - 4
            - 5
            - 6
            - 7
            - 8
            - 9
          AssociationProperty: PayPeriod
          AssociationPropertyMetadata:
            Visible:
              Condition:
                Fn::Not:
                  Fn::Equals:
                    - ${PayType}
                    - PostPaid
        EcsInstanceType:
          Type: String
          Label:
            en: Instance Type
            zh-cn: 实例类型
          AssociationProperty: ALIYUN::ECS::Instance::InstanceType
          AssociationPropertyMetadata:
            InstanceChargeType: ${PayType}
            AllowedValues:
              - ecs.g9i.48xlarge
          Default: ecs.g9i.48xlarge
        InstancePassword:
          NoEcho: true
          Type: String
          Description:
            en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
            zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
          AllowedPattern: '^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$'
          Label:
            en: Instance Password
            zh-cn: 实例密码
          ConstraintDescription:
            en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)
            zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)
          MinLength: 8
          MaxLength: 30
          AssociationProperty: ALIYUN::ECS::Instance::Password
        ZoneId:
          Type: String
          Label:
            en: Zone ID
            zh-cn: 可用区ID
          AssociationProperty: ALIYUN::ECS::Instance::ZoneId
          AssociationPropertyMetadata:
            DefaultValueStrategy: random
            InstanceChargeType: ${PayType}
            SystemDiskCategory: cloud_essd
            InstanceType: ${EcsInstanceType}
        VpcId:
          Type: String
          Label:
            en: VPC ID
            zh-cn: 专有网络VPC实例ID
          AssociationProperty: 'ALIYUN::ECS::VPC::VPCId'
          Required:
            Fn::Equals:
              - ExistingVPC
              - ${VpcOption}
          Default: ''
          AssociationPropertyMetadata:
            AutoSelectFirst: true
            Visible:
              Condition:
                Fn::Equals:
                  - ExistingVPC
                  - ${VpcOption}
        VSwitchId:
          Type: String
          Label:
            en: VSwitch ID
            zh-cn: 交换机实例ID
          Default: ''
          AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
          Required:
            Fn::Equals:
              - ExistingVPC
              - ${VpcOption}
          AssociationPropertyMetadata:
            AutoSelectFirst: true
            VpcId: ${VpcId}
            ZoneId: ${ZoneId}
            Visible:
              Condition:
                Fn::Equals:
                  - ExistingVPC
                  - ${VpcOption}
      Resources:
        # 新建vpc
        EcsVpc:
          Type: ALIYUN::ECS::VPC
          Condition: CreateVpcConditions
          Properties:
            VpcName:
              Ref: ALIYUN::StackName
            CidrBlock:
              Ref: VpcCidrBlock
        # 新建vswitch
        EcsVSwitch:
          Condition: CreateVpcConditions
          Type: ALIYUN::ECS::VSwitch
          Properties:
            VSwitchName:
              Ref: ALIYUN::StackName
            VpcId:
              Ref: EcsVpc
            ZoneId:
              Ref: ZoneId
            CidrBlock:
              Ref: VSwitchCidrBlock
        SecurityGroup:
          Type: ALIYUN::ECS::SecurityGroup
          Properties:
            SecurityGroupName:
              Ref: ALIYUN::StackName
            VpcId:
              Fn::If:
                - CreateVpcConditions
                - Ref: EcsVpc
                - Ref: VpcId
            SecurityGroupIngress:
              - PortRange: 8000/8000
                Priority: 1
                SourceCidrIp: 0.0.0.0/0
                IpProtocol: tcp
                NicType: internet
              - PortRange: 11434/11434
                Priority: 1
                SourceCidrIp: 0.0.0.0/0
                IpProtocol: tcp
                NicType: internet
        EcsInstanceGroup:
          Type: ALIYUN::ECS::InstanceGroup
          Properties:
            # 付费类型
            InstanceChargeType:
              Ref: PayType
            PeriodUnit:
              Ref: PayPeriodUnit
            Period:
              Ref: PayPeriod
            VpcId:
              Fn::If:
                - CreateVpcConditions
                - Ref: EcsVpc
                - Ref: VpcId
            VSwitchId:
              'Fn::If':
                - CreateVpcConditions
                - Ref: EcsVSwitch
                - Ref: VSwitchId
            ZoneId:
              Ref: ZoneId
            SecurityGroupId:
              Ref: SecurityGroup
            Password:
              Ref: InstancePassword
            InstanceType:
              Ref: EcsInstanceType
            SystemDiskCategory: cloud_essd
            SystemDiskSize: 1024
            MaxAmount: 1
            # 镜像
            ImageId: centos_7
            InternetMaxBandwidthOut: 5
            IoOptimized: optimized
        RunInstallCommand:
          Type: ALIYUN::ECS::RunCommand
          Properties:
            InstanceIds:
              Fn::GetAtt:
                - EcsInstanceGroup
                - InstanceIds
            Type: RunShellScript
            Sync: true
            Timeout: 3600
            CommandContent: |-
              bash /root/run.sh
              
      Metadata:
        ALIYUN::ROS::Interface:
          TemplateTags:
            - 'acs:integrate:计算巢:ModelScope'
          # 分组信息
          ParameterGroups:
            - Parameters:
                - Model
              Label:
                default:
                  zh-cn: 选择模型
                  en: Choose Model
            - Parameters:
                - PayType
                - PayPeriodUnit
                - PayPeriod
              Label:
                default:
                  en: PayType Configuration
                  zh-cn: 付费类型配置
            - Parameters:
                - EcsInstanceType
                - InstancePassword
              Label:
                default:
                  en: Instance
                  zh-cn: ECS实例配置
            - Parameters:
                - ZoneId
                - VpcOption
                - VpcId
                - VSwitchId
                - VpcCidrBlock
                - VSwitchCidrBlock
              Label:
                default:
                  zh-cn: 选择网络配置
                  en: Choose existing Infrastructure Configuration

      您可根据场景修改示例模板的参数:

      • 服务实例所用规格:修改InstacneType参数限制。

      • 服务在安全组的端口:修改SecurityGroup资源中的端口。

      • 服务启动命令:替换RunInstallCommand属性中的命令。

      • 服务输出:调整Outpus属性中的IP和端口。

    4. 部署物关联区域中,单击选择部署物

      image

    5. 在弹框中,选择已创建的部署物,并单击确定

      image

    6. (可选)若您需要将模板中的资源进行分组,可单击创建应用分组,对资源分组。

    7. 服务运维(选填)区域,设置服务配置运维功能。

      1. 选择需要用户授予的权限。若要启用代运维功能,则选择的权限中,必须包含全部权限报警权限其中的一个权限。

      2. 监控处的资源监控处,并在统一设置云监控告警模板处,选择配置的告警模板。

    8. 单击创建服务

四、后续操作

  1. 测试服务。

    服务创建完成后,您需要对创建的服务进行测试,保证其正常可用。更多信息,请参见测试服务

  2. 上线服务。

    服务测试通过后,再提交审核,审核通过后即可发布上线。更多信息,请参见上线服务

  3. 上传服务文档。

    您需要将服务文档上传至计算巢GitHub文档库中,可供用户查看。具体操作,请参见服务文档上线流程