AWSCloudFormation - cfn-init 未能执行 运行 命令
AWSCloudFormation - cfn-init failed to run command
我正在使用 cloudformation 安装 elasticsearch。
我正在下载并解压 tar.gz。
以下是我的 EC2 实例部分:
"masterinstance": {
"Type": "AWS: : EC2: : Instance",
"Metadata": {
"AWS: : CloudFormation: : Init": {
"configSets" : {
"ascending" : [ "config1" , "config2" ]
},
"config1": {
"sources": {
"/home/ubuntu/": "https: //s3.amazonaws.com/xxxxxxxx/elasticsearch.tar.gz"
},
"files": {
"/home/ubuntu/elasticsearch/config/elasticsearch.yml": {
"content": {
"Fn: : Join": [
"",
[
xxxxxxxx
]
]
}
}
}
},
"config2" : {
"commands": {
"runservice": {
"command": "~/elasticsearch/bin/elasticsearch",
"cwd" : "~",
"test" : "~/elasticsearch/bin/elasticsearch > test.txt",
"ignoreErrors" : "false"
}
}
}
}
},
"Properties": {
"ImageId": "ami-xxxxxxxxxx",
"InstanceType": {
"Ref": "InstanceTypeParameter"
},
"Tags": [
xxxxxxxx
],
"KeyName": "everybody",
"NetworkInterfaces": [
{
"GroupSet": [
{
"Ref": "newSecurity"
}
],
"AssociatePublicIpAddress": "true",
"DeviceIndex": "0",
"SubnetId": {
"Ref": "oneSubnet"
}
}
],
"UserData": {
"Fn: : Base64": {
"Fn: : Join": [
"",
[
"#!/bin/bash\n",
"sudo add-apt-repository-yppa: webupd8team/java\n",
"sudo apt-get update\n",
"echo'oracle-java8-installershared/accepted-oracle-license-v1-1selecttrue'|sudo debconf-set-selections\n",
"sudo apt-getinstall-yoracle-java8-installer\n",
"apt-get update\n",
"apt-get-y installpython-setuptools\n",
"easy_installhttps: //s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
"/usr/local/bin/cfn-init",
"--stack Elasticsearch",
"--resource masterinstance",
"--configsets ascending",
"-v\n"
]
]
}
}
}
}
我正在使用 AWS::CloudFormation::Init
进行配置和其他设置。
提取 tar 后,我想通过 AWS::CloudFormation::Init
中的 command
部分进行 start elasticsearch 但是,
在我通过 ssh 进入我的实例时完成堆栈创建后,我无法看到我的 elasticsearch 服务 运行。
提取 tar 和创建文件等所有其他操作均正常。
我已经检查了 cfn-init.log ,它给了我以下信息:
2016-07-19 05:53:15,776 P2745 [INFO] Test for Command runservice
2016-07-19 05:53:15,778 P2745 [INFO] -----------------------Command Output-----------------------
2016-07-19 05:53:15,778 P2745 [INFO] /bin/sh: 1: ~/elasticsearch/bin/elasticsearch: not found
2016-07-19 05:53:15,778 P2745 [INFO] ------------------------------------------------------------
2016-07-19 05:53:15,779 P2745 [ERROR] Exited with error code 127
~
如果我直接在我的实例上触发上述命令 ~/elasticsearch/bin/elasticsearch
那么它就可以正常工作。
我这里做错了什么。
谢谢。
我猜测在尝试 运行 ES 时主目录 (~) 正在评估给不同的用户(不是 Ubuntu)。我认为 CFN-Init 运行s 作为 root 用户而不是 ubuntu/ec2-user。尝试将 config2 命令块中的路径更改为完全限定路径 (/home/ubuntu/elasticsearch)。
我正在使用 cloudformation 安装 elasticsearch。 我正在下载并解压 tar.gz。 以下是我的 EC2 实例部分:
"masterinstance": {
"Type": "AWS: : EC2: : Instance",
"Metadata": {
"AWS: : CloudFormation: : Init": {
"configSets" : {
"ascending" : [ "config1" , "config2" ]
},
"config1": {
"sources": {
"/home/ubuntu/": "https: //s3.amazonaws.com/xxxxxxxx/elasticsearch.tar.gz"
},
"files": {
"/home/ubuntu/elasticsearch/config/elasticsearch.yml": {
"content": {
"Fn: : Join": [
"",
[
xxxxxxxx
]
]
}
}
}
},
"config2" : {
"commands": {
"runservice": {
"command": "~/elasticsearch/bin/elasticsearch",
"cwd" : "~",
"test" : "~/elasticsearch/bin/elasticsearch > test.txt",
"ignoreErrors" : "false"
}
}
}
}
},
"Properties": {
"ImageId": "ami-xxxxxxxxxx",
"InstanceType": {
"Ref": "InstanceTypeParameter"
},
"Tags": [
xxxxxxxx
],
"KeyName": "everybody",
"NetworkInterfaces": [
{
"GroupSet": [
{
"Ref": "newSecurity"
}
],
"AssociatePublicIpAddress": "true",
"DeviceIndex": "0",
"SubnetId": {
"Ref": "oneSubnet"
}
}
],
"UserData": {
"Fn: : Base64": {
"Fn: : Join": [
"",
[
"#!/bin/bash\n",
"sudo add-apt-repository-yppa: webupd8team/java\n",
"sudo apt-get update\n",
"echo'oracle-java8-installershared/accepted-oracle-license-v1-1selecttrue'|sudo debconf-set-selections\n",
"sudo apt-getinstall-yoracle-java8-installer\n",
"apt-get update\n",
"apt-get-y installpython-setuptools\n",
"easy_installhttps: //s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz\n",
"/usr/local/bin/cfn-init",
"--stack Elasticsearch",
"--resource masterinstance",
"--configsets ascending",
"-v\n"
]
]
}
}
} }
我正在使用 AWS::CloudFormation::Init
进行配置和其他设置。
提取 tar 后,我想通过 AWS::CloudFormation::Init
中的 command
部分进行 start elasticsearch 但是,
在我通过 ssh 进入我的实例时完成堆栈创建后,我无法看到我的 elasticsearch 服务 运行。
提取 tar 和创建文件等所有其他操作均正常。
我已经检查了 cfn-init.log ,它给了我以下信息:
2016-07-19 05:53:15,776 P2745 [INFO] Test for Command runservice
2016-07-19 05:53:15,778 P2745 [INFO] -----------------------Command Output-----------------------
2016-07-19 05:53:15,778 P2745 [INFO] /bin/sh: 1: ~/elasticsearch/bin/elasticsearch: not found
2016-07-19 05:53:15,778 P2745 [INFO] ------------------------------------------------------------
2016-07-19 05:53:15,779 P2745 [ERROR] Exited with error code 127
~
如果我直接在我的实例上触发上述命令 ~/elasticsearch/bin/elasticsearch
那么它就可以正常工作。
我这里做错了什么。
谢谢。
我猜测在尝试 运行 ES 时主目录 (~) 正在评估给不同的用户(不是 Ubuntu)。我认为 CFN-Init 运行s 作为 root 用户而不是 ubuntu/ec2-user。尝试将 config2 命令块中的路径更改为完全限定路径 (/home/ubuntu/elasticsearch)。