HTML/JavaScript

Thứ Năm, 14 tháng 11, 2013

Cài đặt Memcached Object Cache Plugin để tăng tốc wordpress

Làm thế nào để cài đặt plugin bộ nhớ cache memcached dưới UNIX / Linux để tăng tốc độ cơ sở dữ liệu theo định hướng blog wordpress của tôi bằng bộ nhớ đệm dữ liệu và các đối tượng trong bộ nhớ RAM để giảm số lần đọc dữ liệu.

Bạn cần phải cài đặt máy chủ bộ nhớ đệm memcached chỉ khi blog wordpress của bạn có số lượng lớn người truy cập lớn. Bạn cần phải cài đặt các phần mềm sau đây (s) trên máy chủ :

1.memcached server  : Đây là một daemon bộ nhớ đệm được thiết kế đặc biệt cho các ứng dụng web động để giảm tải cơ sở dữ liệu bằng cách lưu trữ các đối tượng trong bộ nhớ .
2. php- pecl - memcache : PHP mở rộng để làm việc với các bộ nhớ đệm daemon memcached thông qua giao diện OO và thủ tục thuận tiện . Memcache có thể được sử dụng như một điều khiển phiên PHP quá .
3.WordPress memcached object cache plugin: Plugin này cung cấp một phụ trợ liên tục cho các đối tượng bộ nhớ cache WordPress .

Cài đặt mẫu của chúng tôi

Our Sample Setup

Internet
    \\
      \\
  ISP Router             +--------+
     //          +-------| mysql1 | 10.10.1.1
     //          |       +--------+
     //          |
  +-----+        |       +------+
  | lb0 |--------+-------| www1 |  10.10.1.2
  +-----+        |       +------+
vip:202.54.1.1   |
                 |       +------+
                 |-------| www2 | 10.10.1.3
                 |       +------+
                 |
                 |       +------+
  +-----+        |-------| www3 | 10.10.1.4
  | lb1 |--------+       +------+
  +-----+        |
                 |       +-----------+
                 |-------| memcache1 |  10.10.1.5
                         +-----------+
   
Giải thích:
lb0 : Nó là một máy chủ proxy ngược được cài đặt trên một Unix / Linux trước của máy chủ Apache Web lưu trữ trên www1 , www2 , www3 . Bạn có thể sử dụng nginx hoặc bất kỳ máy chủ proxy ngược khác với ip ảo ( dự phòng kết nối ) bởi Keepalived quản lý . Đây là cân bằng tải tổng thể .
LB1 : Đây là sao lưu cân bằng tải với nginx và keepalived .
www1 , www2 , www3 : máy chủ web Apache với php . Bạn cần cài đặt " php- pecl - memcache " và " memcached đối tượng cache wordpress plugin" trên cả ba máy chủ .
mysql1 : Đây là máy chủ MySQL với RAID10 và nhanh SCSI / đĩa SAS . Máy chủ này trong dưới tải và bạn sẽ giảm tải của bộ nhớ đệm truy vấn trong bộ nhớ RAM.
memcache1 : máy chủ này chạy memcached với nhiều bộ nhớ RAM và nó sẽ lưu lại mysql1 truy vấn để giảm tải cơ sở dữ liệu bằng cách lưu trữ các đối tượng trong bộ nhớ . Bạn cần phải cài đặt máy chủ memcached trên memcahce1 . Bạn có thể thêm memcach2 cho mục đích dự phòng.
Tất cả các hướng dẫn sau đây được kiểm tra trên RHEL và CentOS 5.x máy chủ 64 bit .

Cài đặt Memcached Server

Type the following command on memache1 server. First, you need to turn on EPEL repo:
# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
Now, install memcached using the yum command, enter:
# yum install memcached

Cấu hình memcached

You need to edit /etc/sysconfig/memcached file, enter:
# vi /etc/sysconfig/memcached
Edit as follows:
 
PORT="11211"
USER="memcached"
MAXCONN="2048"
CACHESIZE="4096"
OPTIONS="-l 10.10.1.5"
 
  • PORT: Listen on TCP port # 11211, the default is port 11211.
  • USER: Run memcached server as memcached user.
  • MAXCONN: Use 2048 max simultaneous connections; the default is 1024.
  • CACHESIZE: Use 4096 MB (4GB) memory max to use for object storage; the default is 64 megabytes.
  • OPTIONS="-l 10.10.1.5": Listen on 10.10.1.5. This is an important option to consider as there is no other way to secure the installation. Binding to an internal or firewalled network interface is suggested. In this example, IP address 10.10.1.5 is only accessible using LAN and is behind firewalled host.
Make changes as per your setup and requirements. Save and close the file.

Bật dịch vụ

Type the following chkconfig command to turn memcached service, enter:
/sbin/chkconfig memcached on
## command to START the server ##
/sbin/service memcached start
## command to STOP the server ##
/sbin/service memcached stop
## command to RESTART the server ##
/sbin/service memcached restart

Cài đặt php-pecl-memcache

Type the following commands on www1, www2, and www3 Apache server:
# yum -y install php-pecl-memcache
# /sbin/service httpd restart

Cài đặt Memcached Object Cache Plugin

Type the following command on www1, www2, and www3 Apache server (if you are using some sort of cluster aware file system such as GFS2 or OCFS2, than just type it on any one apache web server node):
Visit this url and grab the plugin, enter:
$ cd /tmp/
$ wget http://downloads.wordpress.org/plugin/memcached.2.0.zip
unzip memcached.2.0.zip

Edit object-cache.php, enter:
$ vi object-cache.php
Edit memcahe server and port connection information:
 
$buckets = array('10.10.1.5:11211');
 
Save and close the file. Finally, copy object-cache.php into your wp-content directory. In our example /var/www/html/wp-content/ directory:
$ cp object-cache.php /var/www/html/wp-content/

Kiểm tra nó đã làm việc hay chưa?

Type the following commands to display memcache slabs (please note that the following output is taken from a small memcached server with just 512MB cache for demonstration purpose only):
# memcached-tool 10.10.1.5:11211 display
Sample outouts:
  #  Item_Size  Max_age   Pages   Count   Full?  Evicted Evict_Time OOM
  1      96B     38302s       1      42      no        0        0    0
  2     120B     37571s       1       4      no        0        0    0
  3     152B       335s       1     232      no        0        0    0
  4     192B     37763s       1      40      no        0        0    0
  5     240B     37804s       1      36      no        0        0    0
  6     304B     37595s       1      86      no        0        0    0
  7     384B       829s       4   10401      no        0        0    0
  8     480B       228s       1     972      no        0        0    0
  9     600B       106s       1     387      no        0        0    0
 10     752B     38298s       1     288      no        0        0    0
 11     944B       404s       1     143      no        0        0    0
 12     1.2K     38319s       1     258      no        0        0    0
 13     1.4K     12739s       1     176      no        0        0    0
 14     1.8K     38322s       1     230      no        0        0    0
 15     2.3K      1500s       2     491      no        0        0    0
 16     2.8K      1500s       2     648      no        0        0    0
 17     3.5K       828s       3     600      no        0        0    0
 18     4.4K     37660s       2     322      no        0        0    0
 19     5.5K     38035s       1     171      no        0        0    0
 20     6.9K     38458s       1     102      no        0        0    0
 21     8.7K     39002s       1      39      no        0        0    0
 22    10.8K     42068s       1      35      no        0        0    0
 23    13.6K     24184s       1      15      no        0        0    0
 24    16.9K     41626s       1      11      no        0        0    0
 25    21.2K     43426s       1       1      no        0        0    0
 26    26.5K     43392s       1       1      no        0        0    0
 37   308.5K      1493s       1       3     yes        0        0    0
To shows general stats, enter:
# memcached-tool 10.10.1.5:11211 stats
Sample outputs:
#10.10.1.5:11211   Field       Value
         accepting_conns           1
               auth_cmds           0
             auth_errors           0
                   bytes    14945401
              bytes_read  1320187573
           bytes_written  3180772729
              cas_badval           0
                cas_hits           0
              cas_misses           0
               cmd_flush           0
                 cmd_get     1280549
                 cmd_set     1262345
             conn_yields           0
   connection_structures          73
        curr_connections          72
              curr_items       15724
               decr_hits           0
             decr_misses           0
             delete_hits       11296
           delete_misses       24284
               evictions           0
                get_hits     1156788
              get_misses      123761
               incr_hits           0
             incr_misses           0
          limit_maxbytes   536870912
     listen_disabled_num           0
                     pid       42690
            pointer_size          64
               reclaimed           2
           rusage_system   51.550163
             rusage_user   20.861828
                 threads           4
                    time  1284368953
       total_connections         558
             total_items       75121
                  uptime       43527
                 version       1.4.5
To dumps keys and values, enter:
# memcached-tool 10.10.1.5:11211 dump | less


Không có nhận xét nào:

Đăng nhận xét