无法在 Amazon 的 Lightsail 实例中安装 CodeDeploy Linux 2
Can't install CodeDeploy in Lightsail instance with Amazon Linux 2
由于对 不是特别满意(也想使用 Amazon Linux 2),使用两个 OS 版本创建了两个实例并添加了相同的脚本
mkdir /etc/codedeploy-agent/
mkdir /etc/codedeploy-agent/conf
cat <<EOT >> /etc/codedeploy-agent/conf/codedeploy.onpremises.yml
---
aws_access_key_id: ACCESS
aws_secret_access_key: SECRET
iam_user_arn: arn:aws:iam::525221857828:user/GeneralUser
region: eu-west-2
EOT
wget https://aws-codedeploy-us-west-2.s3.us-west-2.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
我注意到两者之间的区别是,在具有 Linux 2 的实例中,文件夹 /etc/codedeploy-agent/conf/
只有一个文件
并且在Linux中有两个文件
知道了这一点,我在Linux2实例中创建了一个同名的新文件
touch codedeployagent.yml
,更改了其权限
-rw-r--r-- 1 root root 261 Oct 2 10:43 codedeployagent.yml
至
-rwxr-xr-x 1 root root 261 Oct 2 10:43 codedeployagent.yml
,并添加了相同的内容
:log_aws_wire: false
:log_dir: '/var/log/aws/codedeploy-agent/'
:pid_dir: '/opt/codedeploy-agent/state/.pid/'
:program_name: codedeploy-agent
:root_dir: '/opt/codedeploy-agent/deployment-root'
:verbose: false
:wait_between_runs: 1
:proxy_uri:
:max_revisions: 5
然后重启机器。尽管如此,这并没有解决我 运行
时的问题
sudo service codedeploy-agent status
仍会得到
Redirecting to /bin/systemctl status codedeploy-agent.service Unit
codedeploy-agent.service could not be found.
同时确保所有更新都已到位,重新启动机器,但这也没有用。
我可以提供我的 Amazon 设置的详细信息 Linux 2 个要部署的实例 CodeDeployGitHubDemo (based on past )。
1。 CodeDeploy 代理
使用以下作为UserData
(如果不是us-east-1
,您可能需要调整区域):
#!/bin/bash
yum update -y
yum install -y ruby wget
cd /home/ec2-user
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
./install auto
它不需要 hard-coding 凭据。以下内容在我使用的 Amazon Linux 2
个实例上运行良好。
2。实例角色
您的实例需要适合 CodeDeploy 的角色。我使用了一个包含策略的 EC2 实例角色 here:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
3。部署组
我在一个名为 myasg
:
的 AutoScaling 组中有三个用于测试的实例
4。部署
我在没有负载均衡器的情况下从 S3 部署:
5。结果
没有发现问题,部署成功:
以及网站运行ning(需要在安全组中开放80端口):
更新
亚马逊手动安装Linux 2.登录后可以sudo su -
成为root
mkdir -p /etc/codedeploy-agent/conf
cat <<EOT >> /etc/codedeploy-agent/conf/codedeploy.onpremises.yml
---
aws_access_key_id: ACCESS
aws_secret_access_key: SECRET
iam_user_arn: arn:aws:iam::525221857828:user/GeneralUser
region: eu-west-2
EOT
yum install -y wget ruby
wget https://aws-codedeploy-us-west-2.s3.us-west-2.amazonaws.com/latest/install
chmod +x ./install
env AWS_REGION=eu-west-2 ./install rpm
检查其状态:
systemctl status codedeploy-agent
有了这个你应该得到这样的东西
● codedeploy-agent.service - AWS CodeDeploy Host Agent
Loaded: loaded (/usr/lib/systemd/system/codedeploy-agent.service; enabled; vendor prese
t: disabled)
Active: active (running) since Sat 2020-10-03 07:18:57 UTC; 3s ago
Process: 3609 ExecStart=/bin/bash -a -c [ -f /etc/profile ] && source /etc/profile; /opt
/codedeploy-agent/bin/codedeploy-agent start (code=exited, status=0/SUCCESS)
Main PID: 3623 (ruby)
CGroup: /system.slice/codedeploy-agent.service
├─3623 codedeploy-agent: master 3623
└─3627 codedeploy-agent: InstanceAgent::Plugins::CodeDeployPlugin::CommandPo...
Oct 03 07:18:57 ip-172-26-8-137.eu-west-2.compute.internal systemd[1]: Starting AWS Cod...
Oct 03 07:18:57 ip-172-26-8-137.eu-west-2.compute.internal systemd[1]: Started AWS Code...
Hint: Some lines were ellipsized, use -l to show in full.
如果你运行
sudo service codedeploy-agent status
你会得到(意味着它按预期工作)
The AWS CodeDeploy agent is running as PID 3623
若未运行宁开始:
systemctl start codedeploy-agent
由于对
mkdir /etc/codedeploy-agent/
mkdir /etc/codedeploy-agent/conf
cat <<EOT >> /etc/codedeploy-agent/conf/codedeploy.onpremises.yml
---
aws_access_key_id: ACCESS
aws_secret_access_key: SECRET
iam_user_arn: arn:aws:iam::525221857828:user/GeneralUser
region: eu-west-2
EOT
wget https://aws-codedeploy-us-west-2.s3.us-west-2.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
我注意到两者之间的区别是,在具有 Linux 2 的实例中,文件夹 /etc/codedeploy-agent/conf/
只有一个文件
并且在Linux中有两个文件
知道了这一点,我在Linux2实例中创建了一个同名的新文件
touch codedeployagent.yml
,更改了其权限
-rw-r--r-- 1 root root 261 Oct 2 10:43 codedeployagent.yml
至
-rwxr-xr-x 1 root root 261 Oct 2 10:43 codedeployagent.yml
,并添加了相同的内容
:log_aws_wire: false
:log_dir: '/var/log/aws/codedeploy-agent/'
:pid_dir: '/opt/codedeploy-agent/state/.pid/'
:program_name: codedeploy-agent
:root_dir: '/opt/codedeploy-agent/deployment-root'
:verbose: false
:wait_between_runs: 1
:proxy_uri:
:max_revisions: 5
然后重启机器。尽管如此,这并没有解决我 运行
时的问题sudo service codedeploy-agent status
仍会得到
Redirecting to /bin/systemctl status codedeploy-agent.service Unit codedeploy-agent.service could not be found.
同时确保所有更新都已到位,重新启动机器,但这也没有用。
我可以提供我的 Amazon 设置的详细信息 Linux 2 个要部署的实例 CodeDeployGitHubDemo (based on past
1。 CodeDeploy 代理
使用以下作为UserData
(如果不是us-east-1
,您可能需要调整区域):
#!/bin/bash
yum update -y
yum install -y ruby wget
cd /home/ec2-user
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
./install auto
它不需要 hard-coding 凭据。以下内容在我使用的 Amazon Linux 2
个实例上运行良好。
2。实例角色
您的实例需要适合 CodeDeploy 的角色。我使用了一个包含策略的 EC2 实例角色 here:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:Get*",
"s3:List*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
3。部署组
我在一个名为 myasg
:
4。部署
我在没有负载均衡器的情况下从 S3 部署:
5。结果
没有发现问题,部署成功:
以及网站运行ning(需要在安全组中开放80端口):
更新
亚马逊手动安装Linux 2.登录后可以sudo su -
成为root
mkdir -p /etc/codedeploy-agent/conf
cat <<EOT >> /etc/codedeploy-agent/conf/codedeploy.onpremises.yml
---
aws_access_key_id: ACCESS
aws_secret_access_key: SECRET
iam_user_arn: arn:aws:iam::525221857828:user/GeneralUser
region: eu-west-2
EOT
yum install -y wget ruby
wget https://aws-codedeploy-us-west-2.s3.us-west-2.amazonaws.com/latest/install
chmod +x ./install
env AWS_REGION=eu-west-2 ./install rpm
检查其状态:
systemctl status codedeploy-agent
有了这个你应该得到这样的东西
● codedeploy-agent.service - AWS CodeDeploy Host Agent
Loaded: loaded (/usr/lib/systemd/system/codedeploy-agent.service; enabled; vendor prese
t: disabled)
Active: active (running) since Sat 2020-10-03 07:18:57 UTC; 3s ago
Process: 3609 ExecStart=/bin/bash -a -c [ -f /etc/profile ] && source /etc/profile; /opt
/codedeploy-agent/bin/codedeploy-agent start (code=exited, status=0/SUCCESS)
Main PID: 3623 (ruby)
CGroup: /system.slice/codedeploy-agent.service
├─3623 codedeploy-agent: master 3623
└─3627 codedeploy-agent: InstanceAgent::Plugins::CodeDeployPlugin::CommandPo...
Oct 03 07:18:57 ip-172-26-8-137.eu-west-2.compute.internal systemd[1]: Starting AWS Cod...
Oct 03 07:18:57 ip-172-26-8-137.eu-west-2.compute.internal systemd[1]: Started AWS Code...
Hint: Some lines were ellipsized, use -l to show in full.
如果你运行
sudo service codedeploy-agent status
你会得到(意味着它按预期工作)
The AWS CodeDeploy agent is running as PID 3623
若未运行宁开始:
systemctl start codedeploy-agent