在CentOS8| rhel 8上安装AWS CloudFormation Helper脚本

时间:2020-02-23 14:30:36  来源:igfitidea点击:

AWS CloudFormation是一项服务,可在AWS云平台上自动配置和管理资源。
CloudFormation使用模板来使用"堆栈"来快速可靠地提供架构师应用程序或者服务。

AWS CloudFormation提供以下Python Helper脚本,我们可以使用我们在Amazon EC2实例上安装软件和启动服务,以便我们作为堆栈的一部分创建:CFN-init:用于检索和解释资源元数据,安装包,创建文件,并启动Services.cfn-signal:用作创建policy或者waitCondition的信号,因此当前提条件资源或者应用程序已正确时,可以同步堆栈中的其他资源.CFN-Get-Metadata:用于检索资源或者路径的元数据对于特定的密钥.CFN-HUP:用于检查更新到元数据并在检测到更改时执行自定义挂钩。

在CentOS8 | rhel 8上安装AWS CloudFormation Helper脚本

在AWS上使用Amazon Linux以外的操作系统模板时,无法从存储库完成AWS-CFN-Bootstrap包,因为它仅适用于Amazon Linux。
在Amazon Linux AMI上,AWS CloudFormation Helper脚本在/opt/AWS/BIN中预先安装。
我们将探讨一旦可以在CentOS 8上安装CloudFormation Helper脚本rhel 8.

第1步:在CentOS 8 | rhel 8上安装Python2

从我以前的测试中,我无法使用Python 3安装CloudFormation Helper脚本3.我必须安装Python 2.

sudo dnf -y update
sudo dnf -y install python2

如果要使Python2 Python的默认版本,请使用命令:

sudo alternatives --set python /usr/bin/python2

确认Python命令版本

$python -V
Python 2.7.16

第2步:在CentOS 8上安装CloudFormation Helper脚本| rhel 8.

安装Python2后,请下载最新的AWS-CFN-Bootstrap文件。

curl -O https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz

提取文件。

tar xvf aws-cfn-bootstrap-latest.tar.gz

安装Python脚本。

cd aws-cfn-bootstrap-*/
sudo python2 setup.py build
sudo python2 setup.py install

为init和scripts创建符号链接:

sudo mkdir -p /opt/aws/bin
sudo ln -s /usr/init/redhat/cfn-hup /etc/init.d/cfn-hup
sudo chmod 775 /usr/init/redhat/cfn-hup
sudo ln -s /usr/bin/cfn-hup /opt/aws/bin/cfn-hup
sudo ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal
sudo ln -s /usr/bin/cfn-init /opt/aws/bin/cfn-init
sudo ln -s /usr/bin/cfn-get-metadata /opt/aws/bin/cfn-get-metadata
sudo ln -s /usr/bin/cfn-signal /opt/aws/bin/cfn-signal
sudo ln -s /usr/bin/cfn-send-cmd-event /opt/aws/bin/cfn-send-cmd-event
sudo ln -s /usr/bin/cfn-send-cmd-result /opt/aws/bin/cfn-send-cmd-result

确认:

$ls -lh /opt/aws/bin/
total 0
lrwxrwxrwx. 1 root root 25 Jun  4 13:28 cfn-get-metadata -> /usr/bin/cfn-get-metadata
lrwxrwxrwx. 1 root root 16 Jun  4 13:27 cfn-hup -> /usr/bin/cfn-hup
lrwxrwxrwx. 1 root root 17 Jun  4 13:28 cfn-init -> /usr/bin/cfn-init
lrwxrwxrwx. 1 root root 27 Jun  4 13:28 cfn-send-cmd-event -> /usr/bin/cfn-send-cmd-event
lrwxrwxrwx. 1 root root 28 Jun  4 13:28 cfn-send-cmd-result -> /usr/bin/cfn-send-cmd-result
lrwxrwxrwx. 1 root root 19 Jun  4 13:28 cfn-signal -> /usr/bin/cfn-signal

第3步:在CentOS 8上安装AWS CodeDeploy代理| rhel 8.

CodeDeploy代理是一个软件包,它在实例上安装和配置时,可以在CodeDeploy部署中使用该实例。

安装AWS CLI:

sudo pip3 install awscli

使用凭据配置:

$aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]:

下载CodeDeploy代理RPM文件。

$aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' .
download: s3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm to ./codedeploy-agent.noarch.rpm

在RHEL 8上安装RUBY | CentOS 8:

sudo dnf -y install @ruby

最后在CentOS 8上安装AWS CodeDeploy代理| RHEL 8:

sudo dnf install ./codedeploy-agent.noarch.rpm

当我们获得提示时,接受安装:

Dependencies resolved.
========================================================================================================================================================
 Package                                  Architecture                   Version                             Repository                            Size
========================================================================================================================================================
Installing:
 codedeploy-agent                         noarch                         1.0-1.1597                          @commandline                         3.3 M
Transaction Summary
========================================================================================================================================================
Install  1 Package
Total size: 3.3 M
Installed size: 17 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                1/1 
  Running scriptlet: codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
 
pre hook : 1
Checking the ruby version.
Checking if there is already a process named codedeploy-agent running.
  Installing       : codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
  Running scriptlet: codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
 
post hook : 1
Check if there is a codedeployagent config file.
Start codedeploy-agent in post hook if this is a first install.
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...
Installing codedeploy-agent auto-update cron in '/etc/cron.d/codedeploy-agent-update'...Complete
  Verifying        : codedeploy-agent-1.0-1.1597.noarch                                                                                             1/1 
Installed:
  codedeploy-agent-1.0-1.1597.noarch                                                                                                                    
Complete!

我们现在可以从为任何CloudFormation自动化工作配置的实例创建AMI。