如何在 cloudformation 中部署我的堆栈后安装软件



创建堆栈后,如何在实例上安装软件或创建文件或更新文件。AWS::CloudFormation::Init如果我们使用它,我们需要运行 Userdata 脚本,这将重新启动服务器(或终止第一个实例并创建一个新实例(,但我不想创建或删除第一个实例。

他们有什么办法直接安装软件从云形成。

请帮忙

下面是正在创建的 Ceph 实例的示例。 UserData脚本用于安装软件,您将看到它创建文件/etc/logrotate.d/allvarlogs的示例。 它只是在云层中编码的bash脚本。

"CephServerInstance1" : {
"Type" : "AWS::EC2::Instance",
"DependsOn" : "StaticIPAddress1",
"Properties": {
"BlockDeviceMappings": [
{
"DeviceName" : "/dev/sda1",
"Ebs" : { "VolumeSize" : { "Ref": "EbsDeviceSize" } }
},
{
"DeviceName" : "/dev/sda2",
"Ebs" : {
"VolumeSize" : { "Ref": "DataDeviceSize" },
"DeleteOnTermination" : true,
"Encrypted" : false
}
}
],
"IamInstanceProfile" : { "Ref" : "InstanceProfile"},
"Tags": [
{
"Key" : "Name",
"Value" : "ceph-1"
}
],
"ImageId" : { "Ref" : "ImageId" },
"InstanceType": { "Ref" : "InstanceType" },
"KeyName"  : { "Ref": "KeyName" },
"SourceDestCheck": false,
"NetworkInterfaces": [
{
"NetworkInterfaceId": { "Ref": "StaticIPAddress1" },
"DeviceIndex": 0
}
],
"CreditSpecification": {
"CPUCredits": "standard"
},
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bashn",
"yum -y updaten",
"yum -y install epel-releasen",
"yum install -y htopn",
"yum install -y vimn",
"curl -O https://bootstrap.pypa.io/get-pip.pyn",
"python get-pip.py --usern",
"export PATH=~/.local/bin:$PATHn",
"pip install awscli --upgrade --usern",
"yum erase -y 'ntp*'n",
"yum -y install chronyn",
"echo 'server 169.254.169.123 prefer iburst' >> /etc/chrony.confn",
"systemctl restart chronydn",
"# Set up log rotationn",
"cat <<EOF >/etc/logrotate.d/allvarlogsn",
"/var/log/*.log {n",
"rotate ${LOGROTATE_FILES_MAX_COUNT:-5}n",
"copytruncaten",
"missingokn",
"notifemptyn",
"compressn",
"maxsize ${LOGROTATE_MAX_SIZE:-100M}n",
"dailyn",
"dateextn",
"dateformat -%Y%m%d-%sn",
"create 0644 root rootn",
"}n",
"EOFn",
"echo done > /home/centos/done.txtn"
]]}}
}
},

最新更新