【AWS入门】AWS CICD

一 .TASK

创建2台EC2实例,一台名为「ec2-repo」,用作开发环境,将编写好的代码提交至repository(需安装git),一台名为「ec2-wp」,需要通过user data预安装code deploy agent,通过Code Deploy将应用程序部署至「ec2-wp」

二. 环境准备

IAM

创建用户组,将IAM权限赋予给该组
用户组下创建一名用户,生成credential,用于后续代码提交凭证
在这里插入图片描述
创建角色,用于后期的CodeDploy
在这里插入图片描述

创建存储库

在这里插入图片描述

ec2-repo

  1. 创建ec2实例(全流量安全组)
  2. 链接到此实例下载 wordpress 包
# wget https://s3-us-west-2.amazonaws.com/us-west-2-awstraining/courses/spl-82/v1.4.5.prod-2bbeba30/scripts/WordPressmaster.zip
# unzip WordPress-master.zip -d /tmp/WordPress_Temp
# mkdir -p /tmp/WordPress
# cp -paf /tmp/WordPress_Temp/WordPress-master/* /tmp/WordPress
# rm -rf /tmp/WordPress_Temp
# rm -f WordPress-master.zip
# mkdir -p /tmp/WordPress/scripts
  1. 创建 install_dependencies.sh
vi /tmp/WordPress/scripts/install_dependencies.sh
#!/bin/bash
yum install -y httpd wget php-fpm php-mysqli php-json php php-devel mariadb105-
server
  1. 创建 start_server.sh
vi /tmp/WordPress/scripts/start_server.sh
#!/bin/bash
systemctl start httpd
systemctl enable httpd
systemctl start mariadb
systemctl enable mariadb
  1. 创建 stop_server.sh
vi /tmp/WordPress/scripts/stop_server.sh
#!/bin/bash
isExistApp=`pgrep httpd`
if [[ -n $isExistApp ]]; then
 systemctl stop httpd
fi
isExistApp=`pgrep sql`
if [[ -n $isExistApp ]]; then
 systemctl stop mariadb
fi
  1. 创建数据库脚本
vi /tmp/WordPress/scripts/create_test_db.sh
#!/bin/bash
mysql -uroot <<CREATE_TEST_DB
CREATE DATABASE IF NOT EXISTS test;
CREATE_TEST_DB
  1. 创建 change_permissions.sh 脚本
vi /tmp/WordPress/scripts/change_permissions.sh
#!/bin/bash
chmod -R 777 /var/www/html/WordPress
  1. 修改文件属性
chmod +x /tmp/WordPress/scripts/*
ls -la /tmp/WordPress/scripts
  1. 创建 vi /tmp/WordPress/appspec.yml 文件
version: 0.0
os: linux
files:
 - source: /
 destination: /var/www/html/WordPress
hooks:
 BeforeInstall:
 - location: scripts/install_dependencies.sh
 timeout: 300
 runas: root
 AfterInstall:
 - location: scripts/change_permissions.sh
 timeout: 300
 runas: root
 ApplicationStart:
 - location: scripts/start_server.sh
 - location: scripts/create_test_db.sh
 timeout: 300
 runas: root
 ApplicationStop:
 - location: scripts/stop_server.sh
 timeout: 300
 runas: root
  1. 将 wordpress 代码,appspec.yml 和 script 文件夹都 git push 到仓库中
    在这里插入图片描述
    在这里插入图片描述

ec2-wp

  1. 创建ec2实例,预设置如下userdata,安装code deploy agent
#!/bin/bash
yum install ruby -y 
aws s3 cp s3://aws-codedeploy-ap-northeast-2/latest/install . --region ap-northeast-2 
chmod +x install
./install auto

三. Code Deploy

创建应用程序

点击「创建存储库」,进入到创建应用程序页面
自定义应用程序名称
计算平台选择「EC2/本地」

创建部署组

在这里插入图片描述

创建管道

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

部署后的ec2-wp

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值