使用cloudformation搭建一套完善的最有架构服务器集群

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Deploy a VPC",
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsHostnames": true,
"Tags": [
{
"Key": "Name",
"Value": "Lab VPC"
}
]
}
},
"EIP1": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"EIP2": {
"Type": "AWS::EC2::EIP",
"Properties": {
"Domain": "VPC"
}
},
"NAT1": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"AllocationId": {
"Fn::GetAtt": [
"EIP1",
"AllocationId"
]
},
"SubnetId": {
"Ref": "PublicSubnet1"
},
"Tags": [
{
"Key": "Name",
"Value": "NAT1"
}
]
}
},
"NAT2": {
"Type": "AWS::EC2::NatGateway",
"Properties": {
"AllocationId": {
"Fn::GetAtt": [
"EIP2",
"AllocationId"
]
},
"SubnetId": {
"Ref": "PublicSubnet2"
},
"Tags": [
{
"Key": "Name",
"Value": "NAT2"
}
]
}
},
"InternetGateway": {
"Type": "AWS::EC2::InternetGateway",
"Properties": {
"Tags": [
{
"Key": "Name",
"Value": "Lab Internet Gateway"
}
]
}
},
"AttachGateway": {
"Type": "AWS::EC2::VPCGatewayAttachment",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"InternetGatewayId": {
"Ref": "InternetGateway"
}
}
},
"WebSG": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupName": "sg_demo",
"GroupDescription": "sg for web",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "7777",
"ToPort": "7777",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "22",
"ToPort": "22",
"CidrIp": "0.0.0.0/0"
}
],
"SecurityGroupEgress": [
{
"IpProtocol": "tcp",
"FromPort": "0",
"ToPort": "65535",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "VPC"
}
}
},
"memcacheSG": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupName": "sg_memcached",
"GroupDescription": "sg for memcached",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "11211",
"ToPort": "11211",
"CidrIp": "0.0.0.0/0"
}
],
"SecurityGroupEgress": [
{
"IpProtocol": "tcp",
"FromPort": "0",
"ToPort": "65535",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "VPC"
}
}
},
"elbSG": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupName": "sg_elb",
"GroupDescription": "sg for elb",
"SecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "80",
"ToPort": "80",
"CidrIp": "0.0.0.0/0"
}
],
"SecurityGroupEgress": [
{
"IpProtocol": "tcp",
"FromPort": "0",
"ToPort": "65535",
"CidrIp": "0.0.0.0/0"
}
],
"VpcId": {
"Ref": "VPC"
}
}
},
"PublicSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"MapPublicIpOnLaunch": true,
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": "cn-northwest-1a",
"Tags": [
{
"Key": "Name",
"Value": "Public Subnet 1"
}
]
}
},
"PublicSubnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"MapPublicIpOnLaunch": true,
"CidrBlock": "10.0.1.0/24",
"AvailabilityZone": "cn-northwest-1b",
"Tags": [
{
"Key": "Name",
"Value": "Public Subnet 2"
}
]
}
},
"Instance1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"ImageId": "ami-05a85395c8ff37b18",
"InstanceType": "t3.micro",
"KeyName" :{"Ref" : "KeyPair"},
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"#!/bin/bash -xe\n",
"yum -y update\n",
"yum -y install wget\n",
"wget https://server-tzjs.s3-ap-southeast-1.amazonaws.com/lbServer -O /root/lbServer\n",
"wget https://server-tzjs.s3-ap-southeast-1.amazonaws.com/conf.toml -O /root/conf.toml\n",
"chmod +x /root/lbServer\n",
"/root/lbServer\n"
]
]
}
},
"NetworkInterfaces": [
{
"DeviceIndex": "0",
"GroupSet": [
{
"Ref": "WebSG"
}
],
"SubnetId": {
"Ref": "PublicSubnet1"
}
}
]
}
},
"PrivateSubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.2.0/24",
"AvailabilityZone": "cn-northwest-1a",
"Tags": [
{
"Key": "Name",
"Value": "Private Subnet 1"
}
]
}
},
"PrivateSubnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.3.0/24",
"AvailabilityZone": "cn-northwest-1b",
"Tags": [
{
"Key": "Name",
"Value": "Private Subnet 2"
}
]
}
},
"PublicRouteTable": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": "Public Route Table"
}
]
}
},
"PublicRoute": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "PublicRouteTable"
},
"DestinationCidrBlock": "0.0.0.0/0",
"GatewayId": {
"Ref": "InternetGateway"
}
}
},
"PublicSubnetRouteTableAssociation1": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet1"
},
"RouteTableId": {
"Ref": "PublicRouteTable"
}
}
},
"PublicSubnetRouteTableAssociation2": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PublicSubnet2"
},
"RouteTableId": {
"Ref": "PublicRouteTable"
}
}
},
"PrivateRouteTable1": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": "Private Route Table1"
}
]
}
},
"PrivateRouteTable2": {
"Type": "AWS::EC2::RouteTable",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"Tags": [
{
"Key": "Name",
"Value": "Private Route Table2"
}
]
}
},
"PrivateRoute1": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "PrivateRouteTable1"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "NAT1"
}
}
},
"PrivateRoute2": {
"Type": "AWS::EC2::Route",
"Properties": {
"RouteTableId": {
"Ref": "PrivateRouteTable2"
},
"DestinationCidrBlock": "0.0.0.0/0",
"NatGatewayId": {
"Ref": "NAT2"
}
}
},
"PrivateSubnetRouteTableAssociation1": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet1"
},
"RouteTableId": {
"Ref": "PrivateRouteTable1"
}
}
},
"PrivateSubnetRouteTableAssociation2": {
"Type": "AWS::EC2::SubnetRouteTableAssociation",
"Properties": {
"SubnetId": {
"Ref": "PrivateSubnet2"
},
"RouteTableId": {
"Ref": "PrivateRouteTable2"
}
}
},
"CacheSubnetGroup" : {
"Type" : "AWS::ElastiCache::SubnetGroup",
"Properties" : {
"CacheSubnetGroupName" : "demo",
"Description" : "memcache for demo",
"SubnetIds" : [
{"Ref":"PrivateSubnet1"},
{"Ref":"PrivateSubnet2"}
]
}
},
"ElastiCache": {
"Type" : "AWS::ElastiCache::CacheCluster",
"Properties" : {
"AZMode" : "cross-az",
"CacheNodeType" : "cache.t3.micro",
"CacheSubnetGroupName" : {"Ref": "CacheSubnetGroup"},
"ClusterName" : "elasticache-memcached",
"Engine" : "memcached",
"NumCacheNodes" : "2",
"Port" : "11211",
"PreferredAvailabilityZones" : [ "cn-northwest-1a", "cn-northwest-1b" ],
"VpcSecurityGroupIds" :[
{
"Fn::GetAtt": [
"memcacheSG",
"GroupId"
]
}
]
}
}
},
"Parameters":{
"KeyPair":{
"Type":"AWS::EC2::KeyPair::KeyName",
"Default":"keypair"
}
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值