阅读背景:

附加到S3(或任何其他AWS服务)中的日志文件

来源:互联网 

I need to create a log file in AWS S3 (or any other AWS service that can help here). AFAIU there is no way to append a line to an existing log file in S3. This means that I would either need to retrieve and resend the whole log each time a new message comes, or that I will need to create a new object per message. The latter option is complicated when retrieving data.

我需要在AWS S3(或任何其他可以提供帮助的AWS服务)中创建日志文件。 AFAIU无法在S3中的现有日志文件中附加一行。这意味着每次新消息到来时我都需要检索并重新发送整个日志,或者我需要为每条消息创建一个新对象。检索数据时后一选项很复杂。

I have lots of log messages and it is important not to lose them so it is not an option to buffer them in my server memory and send to S3 once in a while.

我有很多日志消息,重要的是不要丢失它们,因此不能在我的服务器内存中缓冲它们并偶尔发送到S3。

Which AWS service would be my best option (also in terms of saving costs).

哪种AWS服务是我的最佳选择(同样在节省成本方面)。

5 个解决方案

#1


18  

What you are looking for is called EBS (Elastic Block Store).

您正在寻找的是EBS(弹性块存储)。

You can attach an EBS drive to any server, and start logging there. If your server dies, the EBS disk will still be around and you can look at the data later.

您可以将EBS驱动器连接到任何服务器,并开始在那里进行日志记录。如果您的服务器死机,EBS磁盘仍然存在,您可以稍后查看数据。

Even better, just create a central syslog server (with an EBS drive), and have all your (stateless) app servers send their logs there.

更好的是,只需创建一个中央系统日志服务器(带有EBS驱动器),并让所有(无状态)应用服务器将其日志发送到那里。

When your EBS drive fills up, archive the day/week/etc into S3 logs. This lets you store fairly large files in S3 (and even do compression if you want).

当您的EBS驱动器填满时,将日/周/等存档到S3日志中。这使您可以在S3中存储相当大的文件(如果需要,甚至可以进行压缩)。

#2


6  

AWS SimpleDB would do what you want:

AWS SimpleDB可以满足您的需求:

https://aws.amazon.com/simpledb/usecases_logging/

https://aws.amazon.com/simpledb/usecases_logging/

Since Amazon SimpleDB allows you to completely offload the work required to run a production database, many developers find it an ideal, low-touch data store for logging information about conditions or events, status updates, recurring activities, workflow processes, or device and application states. Amazon SimpleDB lets you cost-effectively “set and forget” these data logs and use them for diverse purposes, such as:

由于Amazon SimpleDB允许您完全卸载运行生产数据库所需的工作,因此许多开发人员发现它是一个理想的低触摸数据存储,用于记录有关条件或事件,状态更新,重复活动,工作流程或设备和应用程序的信息状态。 Amazon SimpleDB使您可以经济高效地“设置并忘记”这些数据日志,并将其用于各种目的,例如:

Monitoring or tracking Metering Trend of business analysis Auditing Archival or regulation compliance Application examples include:

监控或跟踪计量业务分析趋势审计存档或法规遵从性应用示例包括:

Storing server logs centrally to reduce the space they consume on each running server Logging operational metrics or the results of ongoing performance tests for later analysis Auditing access entries or configuration changes for applications or networked devices Capturing and monitoring environment conditions (temperature, pressure levels, humidity, etc.) at various locations and programming alerts for particular conditions Logging and tracking geolocation information about objects or process status for activities in a workflow Multiple attributes of Amazon SimpleDB make it an attractive data store for data logs:

集中存储服务器日志以减少它们在每个正在运行的服务器上消耗的空间记录操作指标或持续性能测试的结果以供以后分析审计访问条目或应用程序或联网设备的配置更改捕获和监控环境条件(温度,压力水平,湿度) (等)在不同位置和针对特定条件的编程警报记录和跟踪有关对象的地理定位信息或工作流中活动的进程状态Amazon SimpleDB的多个属性使其成为数据日志的有吸引力的数据存储:

Central, with High Availability – If your data logs were previously being trapped locally in multiple devices/objects, applications, or process silos, you’ll enjoy the benefit of being able to access your data centrally in one place in the cloud. What’s more, Amazon SimpleDB automatically and geo-redundantly replicates your data to ensure high availability. This means that unlike a centralized on-premise solution, you’re not creating a single point of failure with Amazon SimpleDB, and your data will be there when you need it. All of the data can be stored via web services requests with one solution and then accessed by any device. Zero Administration – You store your data items with simple web services requests and Amazon Web Services takes care of the rest. The set it and forget it nature of the service means you aren’t spending time on database management in order to store and maintain data logs.

具有高可用性的中央 - 如果您的数据日志以前被本地存储在多个设备/对象,应用程序或流程孤岛中,您将享受到能够在云中的一个位置集中访问您的数据的好处。此外,Amazon SimpleDB会自动和地理冗余地复制您的数据,以确保高可用性。这意味着,与集中式内部部署解决方案不同,您不会使用Amazon SimpleDB创建单点故障,并且您的数据将在您需要时出现。所有数据都可以通过一个解决方案通过Web服务请求存储,然后由任何设备访问。零管理 - 您使用简单的Web服务请求存储数据项,Amazon Web Services负责其余的工作。设置它并忘记它的服务性质意味着您不会花时间在数据库管理上来存储和维护数据日志。

Cost-efficient – Amazon SimpleDB charges inexpensive prices to store and query your data logs. Since you are paying as you go for only the resources you consume, you don’t need to do your own capacity planning or worry about database load. The service simply responds to request volume as it comes and goes, charging you only for the actual resources consumed. To learn more about Amazon Si

经济高效 - Amazon SimpleDB收取低廉的价格来存储和查询您的数据日志。由于您只为所使用的资源付费,因此您无需进行自己的容量规划或担心数据库负载。该服务仅在响应请求量时响应,仅向您收取实际消耗的资源。要了解有关Amazon Si的更多信息

#3


2  

What you are looking for is possible with S3. S3 does not need to have the complete file to begin storing data. You can use the multipart upload to store chunks (5mb blocks) at a time. Once you have finished, say a day's run, you can send the final block and close the multipart upload. and begin logging the next day.

S3可以满足您的需求。 S3不需要有完整的文件来开始存储数据。您可以使用分段上传一次存储块(5mb块)。完成后,比如说一天运行,您可以发送最后一个块并关闭分段上传。并在第二天开始记录。

S3 allows up to 10,000 parts. So by choosing a part-size of 5MiB you will be able to upload dynamic files of up to 50GiB. Should be enough for most use-cases.

S3允许最多10,000个零件。因此,通过选择5MiB的零件尺寸,您将能够上传最高50GiB的动态文件。对于大多数用例来说应该足够了。

Initiate S3 Multipart Upload. Gather data into a buffer until that buffer reaches S3's lower chunk-size limit (5MB). Generate MD5 checksum while building up the buffer. Upload that buffer as a Part, store the ETag. Once you reach EOF of your data, upload the last chunk (which can be smaller than 5MiB). Finalize the Multipart Upload.

启动S3分段上传。将数据收集到缓冲区,直到该缓冲区达到S3的较低块大小限制(5MB)。在构建缓冲区时生成MD5校验和。将该缓冲区作为Part上传,存储ETag。达到数据的EOF后,上传最后一个块(可能小于5MiB)。完成分段上传。

This is a way better solution as it doesn't cost you and EC2 instance or EBS storage costs.

这是一种更好的解决方案,因为它不会花费您和EC2实例或EBS存储成本。

#4


1  

AWS doesn't have a good solution at the moment for logging, but there are a few other cloud services on the market, which collect and organize logs, including papertrailapp.com and loggly.com.

AWS目前还没有很好的解决方案用于日志记录,但市场上还有一些其他云服务可以收集和组织日志,包括papertrailapp.com和loggly.com。

#5


0  

The easiest way to do this is to log to disk and then rotate and ship the logs on an interval that works for you.

最简单的方法是登录磁盘,然后按照适合您的间隔旋转和发送日志。

This might get a bit more complex if you are spot instances or instance backed instances.

如果您是spot实例或实例支持的实例,这可能会更复杂一些。


分享到: