天天看点

[转]magento性能优化

 ​

magento性能优化 

14个快速加载web页面的技巧:

减少HTTP请求数

使用CDN

增加过期头信息

gzip压缩传输内容

将css样式表放在页首

将js文件放在页尾

不使用css表达式

尽量少用内联式的css和js,将其放置在外部资源文件中

减少DNS检索次数

压缩js文件

避免页面重定向

移除重复脚本

配置实体标签

缓存ajax请求

简单的linux优化提示:

系统采用最小化安装,仅安装必需的软件包,不装GUI/X-Window等

停止或禁用无需使用的服务,比如cups

调优内核参数: (例如)

# echo '8192' > /proc/sys/fs/file-max

# echo '32768' > /proc/sys/fs/inode-max

# echo 268435456 > /proc/sys/kernel/shmall (SHMALL可用共享内存的总数量 单位:字节or页面[如果是字节,就和 SHMMAX 一样;如果是页面,ceil(SHMMAX/PAGE_SIZE)] )

# echo 268435456 > /proc/sys/kernel/shmmax

#ulimit -n 4096

编译 apache HTTP服务器 

编译必须模块时使用静态编译的方式来取代DSO(动态共享对象)方式,并且禁用无需使用的模块:

./configure --prefix=/usr/local/apache2 --disable-status --disable-userdir --disable-threads 

--disable-ipv6 --enable-modules='ssl so rewrite deflate headers expires'

启用 mod_deflate 模块

说明: DEFLATE 输出过滤器,允许服务器在将输出内容发送到客户端以前进行压缩,以节约带宽

打开 magento 根目录下的 .htaccess文件,定位到<IfModule mod_deflate.c></IfModule>块之间,

将 其中的注释行开启,例如:

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

    BrowserMatch ^Mozilla/4 gzip-only-text/html

    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

    Header append Vary User-Agent env=!dont-vary

</IfModule>

启用 Header Expires 模块

打开 magento 根目录下的 .htaccess文件,定位到<IfModule mod_expires.c></IfModule>块之间,例如

<IfModule mod_expires.c>

    ExpiresActive On

    ExpiresDefault "access plus 1 month"

    ExpiresByType image/x-icon "access plus 1 month"

    ExpiresByType text/html "access plus 1 month"

    ExpiresByType text/plain "access plus 1 month"

    ExpiresByType text/css "access plus 1 month"

    ExpiresByType application/x-javascript "access plus 1 month"

    ExpiresByType application/x-shockwave-flash "access plus 1 month"

禁用 Etag,启用 KeepAlive

打开 magento 根目录下的 .htaccess文件,移除FileETage None行的注释,如果在httpd.conf没有启用KeepAlive,可在此处新增几行,例如

FileETage None

KeepAlive On

MaxKeepAliveRequests 200

KeepAliveTimeout 5

Mysql 快速优化

在 my.conf 中变更以下参数:

skip-name-resolve

innodb_buffer_pool_size=768M

innodb_flush_log_at_trx_commit=2

时常使用Tuning Primer程序监测mysql运行状态并调整相应的配置参数

PHP编译

类似apache编译方式,采取静态编译的方式来编译扩展,并禁用无需的模块:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs 

--with-config-file-path=/etc/php --with-png-dir --with-jpeg-dir --with-gd 

--with-curl --with-zlib --enable-mbstring --with-mcrypt --with-freetype-dir=/usr 

--with-mysql=/usr/bin/mysql --with-mysqli --enable-pdo --with-pdo-mysql=/usr/bin/mysql 

--without-pdo-sqlite --with-openssl

为PHP安装 eAccelerator 插件

从 eAccelerator.net 下载最新的稳定版本,编译时启用共享内存:

./configure --with-eaccelerator-shared-memory --enable-eaccelerator=shared 

--with-php-config=/usr/local/php/bin/php-config

完成上述操作之后,我们已经完成了步骤A:

添加 过期头信息

gzip压缩组件配置

此时我们拥有了:

一个能最大程度促进站点性能的轻量级的LAMP环境

一个足够快的运行Magento的环境

现在 让我们正式进入到Magento调优阶段

先看看Magento系统内置的优秀的性能优化模块:

多种适配器缓存

编译

合并css和js文件

并行下载

启用 Magento 缓存

管理面板->System->Cache Management

All Cache -> Enable

Layered Navigation(层次化导航) -> Yes

管理面板->System->Configuration->Catalog->Frontend

Use Flat Catalog Category -> Yes

Use Flat Catalog Product -> Yes

启用eAccelerator适配器

打开 {Magento_root}/app/etc/local.xml,在里面增加如下3行

...

    </resources>

    <session_save><![CDATA[files]]></session_save>

    <cache>

        <backend>eaccelerator</backend>

    </cache>

启用编译

管理面板->System->Tools->Compilation(编译)->Run compilation Process

合并 CSS & JS 文件

管理面板->System->Configuration->Developer

js 设置->合并js文件->YES

css 设置->合并css文件->YES

并行下载设置

通过虚拟主机将magento下的资源目录划分成几个子域名,例如:

js.iamsese.cn -> {Magento_root}/js

media.iamsese.cn -> {Magento_root}/media

skin.iamsese.cn -> {Magento_root}/skin

然后去管理面板->System->Configuration->Website->Unsecure(不安全的,非加密的),and configure the basic URLs accordingly(相应的)

现在你完成了:

现在把它们拼凑在一起:

现在 你已经完成了 12/14,这就能足够为初学者使用了

工具&程序:

Firebug:     

YSlow:

Page Speed:

Tuning Primer: