LoginSignup
3
0

More than 5 years have passed since last update.

AlibabaCloudのロードバランサーを動かしてみる(ROS版)

Last updated at Posted at 2018-05-29

はじめに

AlibabaCloudのロードバランサーを動かしてみる

をROSで起動してみます。

AlibabaCloudのECSを東京リージョンの最安値で起動してみる!(ROS版)

にSLB、ロードバランサーを一緒にしたものです。

ROSテンプレート

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Description": "poc",
  "Metadata": {
    "RosGraphicElement-1": {
      "x": 21,
      "y": 87,
      "width": 361,
      "height": 320
    },
    "RosGraphicElement-2": {
      "x": 31,
      "y": 39
    },
    "RosGraphicElement-3": {
      "x": 29,
      "y": 131
    },
    "RosGraphicElement-4": {
      "x": 147,
      "y": 39
    },
    "RosGraphicElement-5": {
      "x": 278,
      "y": 39
    },
    "RosGraphicElement-6": {
      "x": 29,
      "y": 229
    },
    "RosGraphicElement-7": {
      "x": 549,
      "y": 126
    },
    "RosGraphicElement-8": {
      "x": 453,
      "y": 199
    },
    "RosGraphicElement-9": {
      "x": 677,
      "y": 199
    },
    "RosGraphicElement-10": {
      "x": 549,
      "y": 261
    },
    "RosGraphicElement-11": {
      "x": 549,
      "y": 355
    }
  },
  "Parameters": {
    "CidrBlock": {
      "Type": "String",
      "AllowedValues": [
        "192.168.0.0/16",
        "172.16.0.0/12",
        "10.0.0.0/8"
      ],
      "Default": "10.0.0.0/8"
    },
    "ImageId": {
      "Type": "String",
      "Description": "ECS Image",
      "Label": "ECS Image",
      "Default": "centos_7_04_64_20G_alibase_201701015.vhd"
    },
    "InstanceType": {
      "Type": "String",
      "Description": "ECS Instance Type",
      "AllowedValues": [
        "ecs.xn4.small"
      ],
      "Label": "ECS Instance Type",
      "Default": "ecs.xn4.small"
    },
    "KeyPair": {
      "Type": "String",
      "Description": "ECS Key Pair",
      "Label": "ECS Key Pair",
      "Default": "aliyun-ap-northeast-1"
    }
  },
  "Mappings": {},
  "Conditions": {},
  "Resources": {
    "VPC": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-1"
      },
      "Type": "ALIYUN::ECS::VPC",
      "Properties": {
        "VpcName": {
          "Ref": "ALIYUN::StackName"
        },
        "CidrBlock": "10.0.0.0/8"
      }
    },
    "VSwitch-ECS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-2"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "ecs",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.0.0/24",
        "Description": "ecs",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "VSwitch-SLB": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-3"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "slb",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.1.0/24",
        "Description": "slb",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "ECS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-4"
      },
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "SystemDiskCategory": "cloud_ssd",
        "IoOptimized": "optimized",
        "InternetChargeType": "PayByTraffic",
        "PrivateIpAddress": "10.0.0.2",
        "KeyPairName": {
          "Ref": "KeyPair"
        },
        "VpcId": {
          "Ref": "VPC"
        },
        "HostName": {
          "Ref": "ALIYUN::StackName"
        },
        "ImageId": {
          "Ref": "ImageId"
        },
        "InstanceChargeType": "Postpaid",
        "VSwitchId": {
          "Ref": "VSwitch-ECS"
        },
        "InstanceType": {
          "Ref": "InstanceType"
        },
        "InternetMaxBandwidthOut": 1,
        "InstanceName": {
          "Ref": "ALIYUN::StackName"
        },
        "InternetMaxBandwidthIn": 200,
        "SecurityGroupId": {
          "Ref": "SG"
        },
        "Period": 1,
        "AllocatePublicIP": "true"
      }
    },
    "SG": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-5"
      },
      "Type": "ALIYUN::ECS::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "VPC"
        },
        "SecurityGroupName": {
          "Fn::Join": [
            "-",
            [
              {
                "Ref": "ALIYUN::StackName"
              },
              "ecs-sg"
            ]
          ]
        },
        "SecurityGroupEgress": [
          {
            "PortRange": "-1/-1",
            "Priority": 1,
            "IpProtocol": "all",
            "DestCidrIp": "0.0.0.0/0",
            "NicType": "intranet",
            "SecurityGroupId": "0"
          }
        ],
        "SecurityGroupIngress": [
          {
            "PortRange": "-1/-1",
            "Priority": 1,
            "SourceCidrIp": "0.0.0.0/0",
            "IpProtocol": "all",
            "NicType": "intranet",
            "SecurityGroupId": "0"
          }
        ]
      }
    },
    "VSwitch-RDS": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-6"
      },
      "Type": "ALIYUN::ECS::VSwitch",
      "Properties": {
        "VSwitchName": "rds",
        "VpcId": {
          "Ref": "VPC"
        },
        "CidrBlock": "10.0.2.0/24",
        "Description": "rds",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    },
    "SLB": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-7"
      },
      "Type": "ALIYUN::SLB::LoadBalancer",
      "Properties": {
        "Bandwidth": 1,
        "AddressType": "internet",
        "LoadBalancerName": {
          "Ref": "ALIYUN::StackName"
        },
        "InternetChargeType": "paybytraffic"
      }
    },
    "SLB-Listener": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-8"
      },
      "Type": "ALIYUN::SLB::Listener",
      "Properties": {
        "Protocol": "http",
        "ListenerPort": 80,
        "Bandwidth": 1,
        "BackendServerPort": 80,
        "Scheduler": "wrr",
        "LoadBalancerId": {
          "Ref": "SLB"
        },
        "VServerGroupId": {
          "Ref": "SLB-VServerGroup"
        }
      }
    },
    "SLB-BackendServerAttachment": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-9"
      },
      "Type": "ALIYUN::SLB::BackendServerAttachment",
      "Properties": {
        "BackendServers": [
          {
            "ServerId": {
              "Ref": "ECS"
            },
            "Weight": "100"
          }
        ],
        "LoadBalancerId": {
          "Ref": "SLB"
        }
      }
    },
    "SLB-VServerGroup": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-10"
      },
      "Type": "ALIYUN::SLB::VServerGroup",
      "Properties": {
        "VServerGroupName": {
          "Ref": "ALIYUN::StackName"
        },
        "BackendServers": [
          {
            "ServerId": {
              "Ref": "ECS"
            },
            "Port": "80",
            "Weight": "100"
          }
        ],
        "LoadBalancerId": {
          "Ref": "SLB"
        }
      }
    },
    "SLB-BackendServerToVServerGroupAddition": {
      "Metadata": {
        "GraphicId": "RosGraphicElement-11"
      },
      "Type": "ALIYUN::SLB::BackendServerToVServerGroupAddition",
      "Properties": {
        "VServerGroupId": {
          "Ref": "SLB-VServerGroup"
        },
        "BackendServers": [
          {
            "ServerId": {
              "Ref": "ECS"
            },
            "Port": "80",
            "Weight": "100"
          }
        ]
      }
    }
  },
  "Outputs": {
    "VRouterId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "VRouterId"
        ]
      }
    },
    "VSwitch-ECS": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-ECS",
          "VSwitchId"
        ]
      }
    },
    "RouteTableId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "RouteTableId"
        ]
      }
    },
    "VpcId": {
      "Value": {
        "Fn::GetAtt": [
          "VPC",
          "VpcId"
        ]
      }
    },
    "VSwitch-SLB": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-ECS",
          "VSwitchId"
        ]
      }
    },
    "VSwitch-RDS": {
      "Value": {
        "Fn::GetAtt": [
          "VSwitch-RDS",
          "VSwitchId"
        ]
      }
    },
    "EcsZoneId": {
      "Description": "Ecs Zone id of created instance.",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "ZoneId"
        ]
      }
    },
    "InstanceId": {
      "Description": "ECS Instance Id",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "InstanceId"
        ]
      }
    },
    "PublicIp": {
      "Description": "Public IP address",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "PublicIp"
        ]
      }
    },
    "PrivateIp": {
      "Description": "ECS Private IP address",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "PrivateIp"
        ]
      }
    },
    "HostName": {
      "Description": "ECS Host Name",
      "Value": {
        "Fn::GetAtt": [
          "ECS",
          "HostName"
        ]
      }
    }
  }
}

ROSビジュアルデザイナーの画像

ce05c406.png

このテンプレートで起動しますと、SLBとECS(VPC上)のリソースが作成されます。

起動後の仕上げ

ロードバランサーとサーバがつながってますが
80ポートのヘルスチェックに落ちてます。
ECSに入って、nginxかhttpdを起動します。

[root@poc ~]# yum -y install nginx
[root@poc ~]# /bin/systemctl start nginx.service

さいごに

ロードバランサーのIPアドレスをブラウザで開く

aa3c9951.png

となります。

ROSなので、削除すると一回で消えます。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0