本文共 5814 字,大约阅读时间需要 19 分钟。
有相关知识的读者可以跳过此部分内容
云计算作为一种资源, 它的可扩展性是指关于如何处理可变规模业务的能力. 包括 水平扩展 和 垂直扩展.
什么意思呢?
水平扩展(horizontal scaling) 也称为横向扩展, 指能够连接多个软硬件的特性,这样可以将多个服务器从逻辑上看成一个实体.垂直扩展(vertical scaling) 当一个现有IT资源被具有更大或更小容量的资源所代替,则为垂直扩展. 也就是对当前服务器的CPU性能等进行原地的扩大和缩小. 由于在进行垂直扩展的时候服务器需要停机(就如同我们平时使用虚拟机时, 要重新分配它的内存或CPU的时候需要先关机, 因此在云环境中这类扩展并不常见.
在亚马逊云服务中部署被盛赞为是一个很好的方式来实现高扩展性, 并且你只需要支付你所使用的云计算机性能即可。那么,如何从这项技术中获得最佳的扩展性呢?
Deploying in the Amazon cloud is touted as a great way to achieve high scalability while paying only for the computing power you use. How do you get the best scalability from the technology?
亚马逊的EC2产品提供弹性伸缩这一云计算的独特功能。像往常一样为你的应用程序设置一个负载均衡器和几个Web服务器。在模板AMI的基础上设计你将不断复用的Web服务器。然后设置弹性伸缩并根据你预测的流量设置阈值。当超过阈值时,AWS将启动你的Web服务器的新实例,并自动将其置于负载均衡器池中。一旦流量低于最低阈值,亚马逊将从负载均衡器池中为你移除一台服务器。
Auto-scaling is a unique feature of cloud computing and Amazon's EC2 offering. Setup a load balancer and a couple of webservers for your application as you normally would. Design your webserver based on a template AMI that you'll reuse over and over. Then setup auto-scaling and set thresholds based on the traffic you forecast. When a threshold is passed, AWS will spinup a new instance of your webserver, and roll it into the load balancer pool automatically. Once traffic falls below the scale back threshold, Amazon will take a server out of the pool for you.
请务必要监视此活动的开始,并为之运行一些负载和压力测试。你需要确保它能如你所期望地正常运转,并且没有异常的情况就不会不必要地运转服务器。
Be sure to monitor this activity to start with, and also run some load and stress tests on it. You want to ensure that it behaves as you expect, and no anomalous cases will cause you to spinup servers unnecessarily.
MySQL在这里提供了一系列的解决方案。你可以在Master-Master(主对主)主动被动集群(也称为循环复制)中配置MySQL。在这种配置中,MySQL将把所有已完成的事务发送到集群中的其他服务器。你的被动服务器也可以处理你的应用程序的读取流量。在实现高可用性的同时,你也可以通过将大部分的SELECT操作流量发送到另一个服务器来获得可扩展性。
MySQL offers a number of solutions here. You can configure MySQL in a master-master active passive cluster, also known as circular replication. In this configuration, MySQL will send all completed transactions to the other server in the cluster. Your passive server can also handle read traffic for your application. At the same time as you achieve high availability, you also get scalability by sending much of the SELECT traffic off to another server.
随着负载的进一步增长,将额外的只读的从盘(read-only slave) 转入你的设置, 你就可以进一步扩大读取操作的规模。在执行此操作时,你可以继续将所有写入的内容发送到单个处于活动状态的主数据库。
As the load grows further, roll in an additional read-only slave into your setup. You can then further scale out reads. As you do this, you'll continue to send all writes to the single active master database.
[注]我们为PC配置额外硬盘时, 原有的装有系统的盘可以称为主盘(Master)作为扩展的硬盘称为从盘(Slave), 在服务器上类似.
或者,你希望采用基于MySQL社区版( community)服务器的亚马逊RDS解决方案,但需要某些设置保持锁定。在这个配置中,你将不能使用诸如Percona的高速服务器之类的另一种MySQL发行版。这个配置提供的是multi-az(多可用区)配置。请记住,任何你启动的MySQL服务器都将有一个区域和可用性空间作为其配置的一部分,所以你可以在亚马逊网络服务中自由使用这些功能来提高可用性。
As an alternative, you may wish to employ Amazon's RDS solution, which is based on the MySQL community server, but with certain locked in settings. In this configuration you will not be able to use an alternate MySQL distribution such as Percona's high speed server. What this configuration does offer is multi-az configuration. Keep in mind though that any MySQL server you spinup will have a region and availability zone as part of it's configuration, so you are always free to use those features of Amazon's network to increase availability.
如果单个主数据库上的负载仍存在问题,那么可以垂直扩展该节点。通过在EBS的根卷(root volume)上实例化一个新的更大的EC2实例来完成此操作。然后分离该root volume,停止你的旧实例,分离旧实例的root volume,并将其移动到新的服务器。当你将那个活动的root volume附加上去,新的更大的EC2实例将是你原来的服务器,也就是你的服务器就地扩大了!
If the load on the single master database continues to be a problem, you can vertically scale that node in place. Do this by spinning up a new larger EC2 instance on and EBS root volume. Then detach that root volume, stop your old instance, detach it's root volume and move it over to the new server. Once you attach that live root volume, your new larger EC2 instance will be your original server, scaled UP in place!
[注] EBS, Elastic Block Store, 即弹性块存储
EBS是一项非常棒的技术,因为它为每个EC2实例带来了存储区域网络的灵活性。这不是没有挑战,并且有时在磁盘I / O (input/output) 的吞吐量上还会有很大的变化。这个变化对数据库层而言是一个挑战。请记住,亚马逊的基础架构虚拟化层将根据实例的大小增加或减少实例接收的磁盘I / O数量。
EBS is a great technology, as it brings the flexibility of a storage area network to each of your EC2 instances. It's not without it's challenges though, and at times you will experience great variability in disk I/O throughput. This can pose a challenge for the database tier especially. Keep in mind too, that Amazon's infrastructure virtualization layer will dial up or dial down the amount of disk I/O your instance receives based on how large the instance is.
另一个获得更好EBS性能的方法是使用Linux软件的RAID技术。由于EBS内置冗余,因此你可以简单地在多个EBS卷上使用Striping或RAID 0 -- 我们推荐使用4个。
One additional way to get better EBS performance is by using Linux's software raid technology. Since EBS already has redundancy built in, you can simply use striping or RAID 0 across a number of EBS volumes - we recommend four.
[注] RAID, Redundant Arrays of Independent Disks即磁盘阵列, 利用数组方式来作磁盘组, 将数据切割成许多区段分别存放在各个硬盘上, 在数组中任意一个硬盘故障时,仍可读出数据一共有0~6一共7种,这其中RAID 0、RAID1、RAID 5和RAID6比较常用。RAID 0 又称为Stripe(条带化,串列)或Striping它代表了所有RAID级别中最高的存储性能RAID 0:如果你有n块磁盘,原来只能同时写一块磁盘,写满了再下一块,做了RAID 0之后,n块可以同时写,速度提升很快,但由于没有备份,可靠性很差。n最少为2。引自知乎作者:孙小霞链接:https://www.zhihu.com/question/20131784/answer/28026813来源:知乎
要小心地进行这些配置,因为现在每个EBS卷都不能自动操作,但要求四个都要完成。这也会影响EBS快照备份。
Be careful with such configurations as each of your EBS volumes won't operate by themselves now, but require all four to be complete. This will impact EBS snapshot backups, as well.
翻译人:FesonX文章链接 : https://cloud.tencent.com/developer/article/1020235原文链接:https://dzone.com/articles/3-ways-boost-cloud-scalability原文作者:Sean Hull封面图案:Julien Deveaux
转载地址:http://fvqbx.baihongyu.com/