创建一个高可用、可扩展、高性能的Wordpress站点(VPC、SG、RDS、EFS、EC2、 S3、CloudFront、ELB、Auto Scaling Group、Route 53)。内容包含:
- 架构的简介
- 创建安全组
- 创建IAM角色
- 创建RDS实例
- 创建EFS文件系统
- 创建EC2实例,关联IAM角色
- 安装Apache, PHP程序
- 挂载EFS文件系统
- 安装Wordpress代码并连接数据库
- 创建一个简单的博文
- 创建S3存储桶
- 创建CloudFront,源为S3存储桶
- 安装Wordpress创建WP Offload S3 Lite
- WordPress多媒体文件自动上传到S3
- URL重写,将本地多媒体文件的URL重写为S3的URL
- URL重写,将本地多媒体文件的URL重写为Cloudfront的URL
- 创建Application Load Balancer
- 创建Route 53并使用Alias记录解析ELB
- 创建AMI镜像
- 创建启动配置(Launch Configuration)
- 创建Auto Scaling组
- 模拟EC2实例故障
- 模拟RDS实例故障
架构图
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress01-918x1024.png)
1. 配置VPC、2个public-subnet、2个private-subnet、NACL、2个安全组
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress02-1024x489.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress03-1024x433.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress04-1024x460.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress05-1024x444.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress06-1024x464.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress07-1024x378.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress08-1024x462.png)
2. 配置IAM
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress09-1024x572.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress10.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress11.png)
3. 配置RDS MySQL
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress30-1024x501.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress31-1024x628.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress12-1024x589.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress13-1024x528.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress14-1024x580.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress15-1024x661.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress16-1-1024x651.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress17-1024x674.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress32-1024x473.png)
4. 创建EFS
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress20-1024x449.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress21-1024x448.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress22-1024x514.png)
5. 创建EC2实例和安装WordPress代码
涉及的内容:
- 创建EC2实例,关联IAM角色
- 安装Apache, PHP程序
- 挂载EFS文件系统
- 安装Wordpress代码并连接数据库
- 创建一个简单的博文
Bootstrap脚本
https://blog.csdn.net/weixin_41980142/article/details/93194646
#!/bin/bash sudo -s yum update -y yum install httpd24 -y chkconfig httpd on 安装EPEL: sudo yum install epel-release 安装remi: sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm ## 安装PHP 7.3 yum –enablerepo=remi-php73 install php ### For PHP 7.3 yum –enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-mysqlnd mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport fs-83e8bde2.efs.ap-northeast-2.amazonaws.com:/ /var/www/html echo " fs-83e8bde2.efs.ap-northeast-2.amazonaws.com:/ /var/www/html nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev,noresvport 0 0" >> /etc/fstab cd /var/www/html echo "<?php phpinfo(); ?>" > phpinfo.php service httpd start wget https://wordpress.org/latest.zip unzip latest.zip mv wordpress/* /var/www/html/ rm -rf wordpress/ latest.zip sudo chown -R apache:apache /var/www/html/* chmod -R 775 /var/www/html |
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress40-1024x476.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress41-1024x464.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress42.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress43-1024x473.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress44-1024x466.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress45-1024x465.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress46-1024x445.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress47-1024x473.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress48-1024x494.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress49-1024x532.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress50-1024x642.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress51-1024x492.png)
6. WordPress配置
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress52-1024x666.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress53.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress54.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress55.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress56.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress57.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress58-1024x483.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress59-1024x429.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress60-1.png)
使用S3保存非结构化数据,使用CloudFront进行内容分发服务
介绍创建和使用S3以及CloudFront来分发网站的静态内容。
内容会包括:
- 创建S3存储桶
- 创建CloudFront,源为S3存储桶
- 安装Wordpress创建WP Offload S3 Lite
- WordPress多媒体文件自动上传到S3
- URL重写,将本地多媒体文件的URL重写为S3的URL
- URL重写,将本地多媒体文件的URL重写为Cloudfront的URL
7. 创建S3存储桶
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress61-1024x557.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress62-1024x562.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress63-1024x428.png)
8. 创建CloudFront
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress64-1024x419.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress65-1024x419.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress66-1024x375.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress67-1024x423.png)
WordPress S3插件
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress70-1024x531.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress83-1024x491.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress71-1024x658.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress72-1024x639.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress73-1024x477.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress74-1024x689.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress75-1024x486.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress76-1024x561.png)
URL重写,将本地多媒体文件的URL重写为S3的URL
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress78-1024x546.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress79-1024x473.png)
URL重写,将本地多媒体文件的URL重写为Cloudfront的URL
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress80-1024x453.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress81-1024x643.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress82-1024x453.png)
使用AutoScaling,Elastic Load Balancer和Route 53
目前的wordpress还是有问题,比如域名没有固定(EC2每次重启都会动态变更IP和域名),没有web的AS组,没有LB等。
创建自动伸缩组、弹性负载均衡器和Route 53服务,搭建高可用、自动修复的系统。包括:
- 创建Application Load Balancer
- 创建Route 53并使用Alias记录解析ELB
- 创建AMI镜像
- 创建启动配置(Launch Configuration)
- 创建Auto Scaling组
创建ELB
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress90-1024x410.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress91-1024x377.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress92-1024x439.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress93-1024x467.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress94.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress95-1024x406.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress96-1024x464.png)
创建Route 53
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress100-1024x389.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress101-1024x566.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress102-1024x477.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress103-1024x679.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress104-1024x757.png)
创建Auto Scalling Group
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress110-1024x465.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress111-1024x472.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress112-1024x471.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress113-1024x422.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress114-1024x460.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress115-1024x467.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress116-1024x460.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress117-1024x273.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress118-1024x465.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress119-1024x465.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress120-1024x391.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress121-1024x431.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress122-1024x462.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress123-1024x452.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/Wordpress124-1024x462.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress125-1024x567.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress126-1024x607.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress127-1024x589.png)
故障转移测试
模拟EC2实例故障、RDS实例故障进行故障转移测试,查看应用程序是否能自动进行切换,保证业务不中断。
模拟EC2实例故障
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress131-1024x465.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress132-1024x472.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress133-1024x477.png)
模拟RDS实例故障
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress141-1024x403.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress142.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress143-1024x470.png)
![](http://www.cloudbin.cn/wp-content/uploads/2020/02/wordpress144-1024x581.png)