Linux-Apache-MySQL-PHP website architecture solution analysis_PHP tutorial

WBOY
Release: 2016-07-13 10:37:58
Original
904 people have browsed it

LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和Java/J2EE架构相比,LAMP具有Web资源丰富、轻量、快速开发等特点,微软的.NET架构相比,LAMP具有通用、跨平台、高性能、低价格的优势,因此LAMP无论是性能、质量还是价格都是企业搭建网站的首选平台。

对于大流量、大并发量的网站系统架构来说,除了硬件上使用高性能的服务器、负载均衡、CDN等之外,在软件架构上需要重点关注下面几个环节:使用高性能的操作系统(OS)、高性能的网页服务器(Web Server)、高性能的数据库(Databse)、高效率的编程语言等。下面我将从这几点对其一一讨论。

 

操作系统

Linux操作系统有很多个不同的发行版,如Red Hat Enterprise Linux、SUSE Linux Enterprice、Debian、Ubuntu、CentOS等,每一个发行版都有自己的特色,比如RHEL的稳定,Ubuntu的易用,基于稳定性和性能的考虑,操作系统选择CentOS(Community ENTerprise Operating System)是一个理想的方案。

CentOS(Community ENTerprise Operating System)是Linux发行版之一,是RHEL/Red Hat Enterprise Linux的精简免费版,和RHEL为同样的源代码,不过,RHEL和SUSE LE等企业版,提供的升级服务均是收费升级,无法免费在线升级,因此要求免费的高度稳定性的服务器可以用CentOS替代Red Hat Enterprise Linux使用。

Linux-Apache-MySQL-PHP website architecture solution analysis_PHP tutorial

LAMP网站架构图

Web服务器、缓存和PHP加速

Apache是LAMP架构最核心的Web Server,开源、稳定、模块丰富是Apache的优势。但Apache的缺点是有些臃肿,内存和CPU开销大,性能上有损耗,不如一些轻量级的Web服务器(例如nginx)高效,轻量级的Web服务器对于静态文件的响应能力来说远高于Apache服务器。

Apache做为Web Server是负载PHP的最佳选择,如果流量很大的话,可以采用nginx来负载非PHP的Web请求。nginx是一个高性能的HTTP和反向代理服务器,Nginx以它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。Nginx不支持PHP和CGI等动态语言,但支持负载均衡和容错,可和Apache配合使用,是轻量级的HTTP服务器的首选。

Web服务器的缓存也有多种方案,Apache提供了自己的缓存模块,也可以使用外加的Squid模块进行缓存,这两种方式均可以有效的提高Apache的访问响应能力。Squid Cache是一个Web缓存服务器,支持高效的缓存,可以作为网页服务器的前置cache服务器缓存相关请求来提高Web服务器的速度,把Squid放在Apache的前端来缓存Web服务器生成的动态内容,而Web应用程序只需要适当地设置页面实效时间即可。如访问量巨大则可考虑使用memcache作为分布式缓存。

PHP的加速使用eAccelerator加速器,eAccelerator是一个自由开放源码PHP加速器,优化和动态内容缓存,提高了性能PHP脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。它还有对脚本起优化作用,以加快其执行效率。使PHP程序代码执效率能提高1-10倍。

具体的解决方案有以下几种:

1、squid + Apache + PHP + eAccelerator

使用Apache负载PHP,使用squid进行缓存,html或图片的请求可以直接由squid返回给用户。很多大型网站都采用这种架构。

2、nginx/Apache + PHP(fastcgi) + eAccelerator

使用nginx或Apache负载PHP,PHP使用fastcgi方式运行,效率较高。

3、nginx + Apache + PHP + eAccelerator

此方案综合了nginx和Apache的优点,使用Apache负载PHP,nginx负责解析其他Web请求,使用nginx的rewrite模块,Apache端口不对外开放。

 

数据库

开源的数据库中,MySQL在性能、稳定性和功能上是首选,可以达到百万级别的数据存储,网站初期可以将MySQL和Web服务器放在一起,但是当访问量达到一定规模后,应该将MySQL数据库从Web Server上独立出来,在单独的服务器上运行,同时保持Web Server和MySQL服务器的稳定连接。

当数据库访问量达到更大的级别,可以考虑使用MySQL Cluster等数据库集群或者库表散列等解决方案。

In general, the website performance of LAMP architecture will be far better than that of websites such as Windows IIS + ASP + Access (such as Moonlight Blog), and the number of visits that can be loaded is also very large. If a large number of domestic personal websites want To support large traffic, adopting LAMP architecture is a good solution.

In summary, the design based on LAMP architecture has the characteristics of low cost, flexible deployment, rapid development, security and stability, etc., and is an excellent combination of Web network applications and environments.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735139.htmlTechArticleLAMP (Linux-Apache-MySQL-PHP) website architecture is currently an internationally popular Web framework. The framework includes: Linux operating system, Apache web server, MySQL database, Perl, PHP or Python...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!