网站应如何处理数据库崩溃 [英] How a website should handle a database crash

查看:326
本文介绍了网站应如何处理数据库崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在php中创建一个网站,有一个数据库后端(可以是MySQL或SQL Server),我最近意识到,如果我的数据库崩溃在任何时候,我的网站将无法正常运行,可能会导致一些头痛。

I am currently creating a website in php that has a database backend (can be either MySQL or SQL Server) and I realized recently that if my database crashes at any time, my website will not run properly and probably cause some headaches.

那么,如果我的数据库(或任何关键的外部组件)出现故障,那么在网站上显示什么是正确的?我的特定网站很大程度上依赖于其数据库,如果没有它几乎是无用的。

So what is the proper thing to display on the website if my database (or any crucial outside component) goes down? My particular website relies heavily on its database and will be almost useless without it.

我被告知的一个选项是通过电子邮件发送给网站管理员,并显示一个错误500页面,说服务器出了问题,基本上使网站无法使用,直到问题是固定的。还有什么我可以做的来解决这个问题吗?有没有什么方法来设计一个网站,使数据库(任何关键组件)崩溃不是一个问题?

One option I have been told is to email the website admin and display a Error 500 page that says something is wrong with the server and basically make the website unusable till the issue is fixed. Is there anything else I could do to work around this problem? Are there any ways to design a website so that the database (any crucial component) crashing isn't an issue?

我正在寻找一般的经验法则,过去人们如何工作的具体例子。

I am looking for general rules of thumb as well as specific examples of how people have worked around this in the past. Also, these examples don't just have to be for my website example.

推荐答案

如果你只有一个数据库服务器,网站不能工作没有它的数据库,没有魔法:你将不得不显示某种漂亮的错误页通知用户有一个技术问题,

If you only have one database server, and the website cannot work without it's database, there is no magic : you'll have to display some sort of nice error page, informing the users there is a technical problem and that the website will come back shortly.

一般来说:



  • 如果您的网站是一个正常的网站,人们会倾向于偶尔接受一个问题,特别是如果您进行沟通。



如果您负担得起(并有技术知识设置) / em>,您可以使用两个数据库服务器,在它们之间具有复制(MySQL支持此功能):一个主服务器和一个从服务器,被认为是备份。


If you can afford it (and have the technical knowledge to set this up), you could use two database servers, with replication (MySQL supports this) between them : one master, which you use, and a slave, that's considered as a backup.

然后,如果主人跌倒,你的应用程序将使用奴隶。

Then, if the master falls, your application will use the slave.



当然,将大大降低数据库相关问题的风险(同时两个服务器崩溃的可能性不大),但是您仍然会遇到所有其他组件(如您的网络服务器)的问题:如果您只有一个,您可能


Of course, this will greatly reduce the risks of a database-related problem (having two servers crash at the same time is quite unlikely), but you'll still have problems with all other components -- like your webserver : if you only have one, you might want to consider using two, with the second one as a fallback.

在这之后,如果你还有钱(并且认为你需要一个更好的正常运行时间您的网站),您需要考虑数据中心出现问题的情况 - 在两个不同的位置设置服务器...

After that, if you still have money (and think you need an even better uptime for your website), you'll want to think about the case when your datacenter has a problem -- setting up server in two separate locations...

这篇关于网站应如何处理数据库崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆