magento + redis 安装

来源:互联网 发布:淘宝违规出售假冒商品 编辑:程序博客网 时间:2024/05/20 17:09
1

////////////wget http://redis.googlecode.com/files/redis-2.4.11.tar.gz

wget http://redis.googlecode.com/files/redis-2.6.14.tar.gztar xzf redis-2.6.14.tar.gzcd redis-2.6.14make

2
cd srccp redis-server /usr/local/bin/cp redis-cli /usr/local/bin/


3
mkdir /etc/redismkdir /var/redismkdir /var/redis/6379


4
cd ..cp utils/redis_init_script /etc/init.d/redis_6379cp redis.conf /etc/redis/6379.conf

开机启动:

/etc/init.d/redis_6379 start


5

vim /etc/redis/6379.confdaemonize to yespidfile to /var/run/redis_6379.pidlogfile to /var/log/redis_6379.logdir to /var/redis/6379maxmemory 268435456

maxmemory to some value appropriate for your system (otherwise it will gobble it all up) example:268435456(256MB)


6

上面下载的文件和下面这个,可以在资源里面下载:http://download.csdn.net/download/terry_water/6775255,我已经下载好了

//如果下面的git运行报错,找不到命令,那么安装git  yum install git
git clone git://github.com/owlient/phprediscd phpredis
/usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmake && make install 


如果安装了php的多线程模块,上面的地址可能会报错:/www/tools/phpredis/redis.c:4284: error: too many arguments to function ‘redis_serialize’

那么使用这个地址:下载redis的地址:

 git clone git://github.com/nicolasff/phpredis


/etc/php.ini  添加:
extension=redis.so 

7
git clone git://github.com/colinmollenhour/Cm_Cache_Backend_Redis.gitmkdir /www/web/test/magento/app/code/community/Cm/Cachemkdir /www/web/test/magento/app/code/community/Cm/Cache/Backend/mv Cm_Cache_Backend_Redis/Cm/Cache/Backend/* /www/web/test/magento/app/code/community/Cm/Cache/Backend/ 

上面就是 app/code/community/Cm/Cache/Backend/Redis.php

可以直接来这里下载:

下载一:原始版本:http://download.csdn.net/detail/terry_water/7695041

下载二:如果原始版本报错sAdd 4paramster,那么使用下载二:在Client.php 860行,注释代码:

 // if($argsFlat !== NULL) {                    //    $args = $argsFlat;                    //    $argsFlat = NULL;                    //}



8
修改配置文件
vim /etc/sysctl.conf
添加
vm.overcommit_memory=1

刷新配置使之生效

sysctl vm.overcommit_memory=1 

app/ect/local.xml:

global标签内添加:

<session_save>db</session_save>        <redis_session>                       <!-- All options seen here are the defaults -->            <host>127.0.0.1</host>            <!-- Specify an absolute path if using a unix socket -->            <port>6379</port>            <password></password>             <!-- Specify if your Redis server requires authentication -->            <timeout>2.5</timeout>            <!-- This is the Redis connection timeout, not the locking timeout -->            <persistent></persistent>         <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->            <db>0</db>                        <!-- Redis database number; protection from accidental loss is improved by using a unique DB number for sessions -->            <compression_threshold>2048</compression_threshold>  <!-- Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 -->            <compression_lib>gzip</compression_lib>              <!-- gzip, lzf, lz4 or snappy -->            <log_level>1</log_level>               <!-- 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) -->            <max_concurrency>6</max_concurrency>                 <!-- maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes -->            <break_after_frontend>5</break_after_frontend>       <!-- seconds to wait for a session lock in the frontend; not as critical as admin -->            <break_after_adminhtml>30</break_after_adminhtml>            <first_lifetime>600</first_lifetime>                 <!-- Lifetime of session for non-bots on the first write. 0 to disable -->            <bot_first_lifetime>60</bot_first_lifetime>          <!-- Lifetime of session for bots on the first write. 0 to disable -->            <bot_lifetime>7200</bot_lifetime>                    <!-- Lifetime of session for bots on subsequent writes. 0 to disable -->            <disable_locking>0</disable_locking>                 <!-- Disable session locking entirely. -->        </redis_session><cache>  <backend>Cm_Cache_Backend_Redis</backend>  <backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket --><port>6379</port><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><database>0</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases --><password></password> <!-- Specify if your Redis server requires authentication --><force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP --><connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures; a value of 1 will not retry after the first failure --><read_timeout>10</read_timeout>         <!-- Set read timeout duration; phpredis does not currently support setting read timeouts --><automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --><compress_data>1</compress_data>  <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_tags>1</compress_tags>  <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_threshold>20480</compress_threshold>  <!-- Strings below this size will not be compressed --><compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf, lz4 (as l4z) and snappy --><use_lua>0</use_lua> <!-- Set to 1 if Lua scripts should be used for some operations -->  </backend_options></cache><!-- This is a child node of config/global for Magento Enterprise FPC --><full_page_cache>  <backend>Cm_Cache_Backend_Redis</backend>  <backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket --><port>6379</port><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><database>1</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases --><password></password> <!-- Specify if your Redis server requires authentication --><force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP --><connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures --><lifetimelimit>57600</lifetimelimit>    <!-- 16 hours of lifetime for cache record --><compress_data>0</compress_data>        <!-- DISABLE compression for EE FPC since it already uses compression -->  </backend_options></full_page_cache>

完整例子:

<config>    <global>        <install>            <date><![CDATA[Sat, 13 Mar 2010 18:57:07 +0000]]></date>        </install>        <crypt>            <key><![CDATA[7c72ab01696d4d5fab2d1e609cdac317]]></key>        </crypt>        <disable_local_modules>false</disable_local_modules>        <resources>            <db>                <table_prefix><![CDATA[]]></table_prefix>            </db>            <default_setup>                <connection>                    <host><![CDATA[]]></host>                    <username><![CDATA[]]></username>                    <password><![CDATA[]]></password>                    <dbname><![CDATA[]]></dbname>                    <active>1</active>                </connection>            </default_setup>        </resources><!--        <session_save><![CDATA[files]]></session_save>-->        <!--        <cache>                                                                                                                                                                                         <backend>apc</backend>            <prefix>tomtopcom_</prefix>        </cache>        --><!-- <session_save><![CDATA[redis]]></session_save> <        <session_save_path><![CDATA[tcp://10.12.167.132:11211?persistent=1&weight=2&timeout=10&retry_interval=10]]></session_save_path>        <session_cache_limiter><![CDATA[82174]]></session_cache_limiter>        --><session_save>db</session_save>        <redis_session>                       <!-- All options seen here are the defaults -->            <host>127.0.0.1</host>            <!-- Specify an absolute path if using a unix socket -->            <port>6379</port>            <password></password>             <!-- Specify if your Redis server requires authentication -->            <timeout>2.5</timeout>            <!-- This is the Redis connection timeout, not the locking timeout -->            <persistent></persistent>         <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 -->            <db>0</db>                        <!-- Redis database number; protection from accidental loss is improved by using a unique DB number for sessions -->            <compression_threshold>2048</compression_threshold>  <!-- Set to 0 to disable compression (recommended when suhosin.session.encrypt=on); known bug with strings over 64k: https://github.com/colinmollenhour/Cm_Cache_Backend_Redis/issues/18 -->            <compression_lib>gzip</compression_lib>              <!-- gzip, lzf, lz4 or snappy -->            <log_level>1</log_level>               <!-- 0 (emergency: system is unusable), 4 (warning; additional information, recommended), 5 (notice: normal but significant condition), 6 (info: informational messages), 7 (debug: the most information for development/testing) -->            <max_concurrency>6</max_concurrency>                 <!-- maximum number of processes that can wait for a lock on one session; for large production clusters, set this to at least 10% of the number of PHP processes -->            <break_after_frontend>5</break_after_frontend>       <!-- seconds to wait for a session lock in the frontend; not as critical as admin -->            <break_after_adminhtml>30</break_after_adminhtml>            <first_lifetime>600</first_lifetime>                 <!-- Lifetime of session for non-bots on the first write. 0 to disable -->            <bot_first_lifetime>60</bot_first_lifetime>          <!-- Lifetime of session for bots on the first write. 0 to disable -->            <bot_lifetime>7200</bot_lifetime>                    <!-- Lifetime of session for bots on subsequent writes. 0 to disable -->            <disable_locking>0</disable_locking>                 <!-- Disable session locking entirely. -->        </redis_session><cache>  <backend>Cm_Cache_Backend_Redis</backend>  <backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket --><port>6379</port><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><database>0</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases --><password></password> <!-- Specify if your Redis server requires authentication --><force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP --><connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures; a value of 1 will not retry after the first failure --><read_timeout>10</read_timeout>         <!-- Set read timeout duration; phpredis does not currently support setting read timeouts --><automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --><compress_data>1</compress_data>  <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_tags>1</compress_tags>  <!-- 0-9 for compression level, recommended: 0 or 1 --><compress_threshold>20480</compress_threshold>  <!-- Strings below this size will not be compressed --><compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf, lz4 (as l4z) and snappy --><use_lua>0</use_lua> <!-- Set to 1 if Lua scripts should be used for some operations -->  </backend_options></cache><!-- This is a child node of config/global for Magento Enterprise FPC --><full_page_cache>  <backend>Cm_Cache_Backend_Redis</backend>  <backend_options><server>127.0.0.1</server> <!-- or absolute path to unix socket --><port>6379</port><persistent></persistent> <!-- Specify unique string to enable persistent connections. E.g.: sess-db0; bugs with phpredis and php-fpm are known: https://github.com/nicolasff/phpredis/issues/70 --><database>1</database> <!-- Redis database number; protection against accidental data loss is improved by not sharing databases --><password></password> <!-- Specify if your Redis server requires authentication --><force_standalone>0</force_standalone>  <!-- 0 for phpredis, 1 for standalone PHP --><connect_retries>1</connect_retries>    <!-- Reduces errors due to random connection failures --><lifetimelimit>57600</lifetimelimit>    <!-- 16 hours of lifetime for cache record --><compress_data>0</compress_data>        <!-- DISABLE compression for EE FPC since it already uses compression -->  </backend_options></full_page_cache>    </global>    <admin>        <routers>            <adminhtml>                <args>                    <frontName><![CDATA[tomtopadmin]]></frontName>                </args>            </adminhtml>        </routers>    </admin><frontend>          <events> <!--             <controller_action_predispatch>                  <observers><log><type>disabled</type></log></observers>              </controller_action_predispatch>                          <controller_action_postdispatch>                  <observers><log><type>disabled</type></log></observers>              </controller_action_postdispatch>              -->            <customer_login>                  <observers><log><type>disabled</type></log></observers>              </customer_login>              <customer_logout>                  <observers><log><type>disabled</type></log></observers>              </customer_logout>              <sales_quote_save_after>                  <observers><log><type>disabled</type></log></observers>              </sales_quote_save_after>              <checkout_quote_destroy>                  <observers><log><type>disabled</type></log></observers>              </checkout_quote_destroy>          </events>      </frontend> </config>


9
重启linux(上面的所有配置都重启了,笨办法)
启动:

redis-server /etc/redis/6379.conf

关闭redis

/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown

清空缓存redis

redis-cli flushall

如果想清空缓存,重启redis是没有作用的,需要执行清空缓存命令,这点和memcache不一样

10
查看:
redis-cli info
使用参考资料


命令中文参考:

http://redis.readthedocs.org/en/latest/



1

http://www.magentocommerce.com/boards/viewthread/278526/P0/

http://www.searchdatabase.com.cn/showcontent_70423.htm
2
http://blog.nosqlfan.com/html/4166.html
3
http://redis.readthedocs.org/en/latest/server/info.html




其他:
redis-server:Redis服务器的daemon启动程序
    redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
    redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
    redis-stat:Redis状态检测工具,可以检测Redis当前状态参数及延迟状况 


内核参数说明如下:


overcommit_memory文件指定了内核针对内存分配的策略,其值可以是0、1、2。
0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
2, 表示内核允许分配超过所有物理内存和交换空间总和的内存


 **编辑redis.conf配置文件(/etc/redis.conf),按需求做出适当调整,比如:
daemonize yes #转为守护进程,否则启动时会每隔5秒输出一行监控信息
save 60 1000 #减小改变次数,其实这个可以根据情况进行指定
maxmemory 256000000 #分配256M内存


在我们成功安装Redis后,我们直接执行redis-server即可运行Redis,此时它是按照默认配置来运行的(默认配置甚至不是后台运 行)。我们希望Redis按我们的要求运行,则我们需要修改配置文件,Redis的配置文件就是我们上面第二个cp操作的redis.conf文件,目前 它被我们拷贝到了/usr/local/redis/etc/目录下。修改它就可以配置我们的server了。如何修改?下面是redis.conf的主 要配置参数的意义:


    daemonize:是否以后台daemon方式运行
    pidfile:pid文件位置
    port:监听的端口号
    timeout:请求超时时间
    loglevel:log信息级别
    logfile:log文件位置
    databases:开启数据库的数量
    save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。
    rdbcompression:是否使用压缩
    dbfilename:数据快照文件名(只是文件名,不包括目录)
    dir:数据快照的保存目录(这个是目录)
    appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。
    appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)











0 0