Different from web1.0, web1.0 is content-centered. Therefore, web1.0 only needs to cache content for load. Using reverse proxy to cache pages can solve most of the problems. Web encourages user interaction, and the content is dynamic. If only reverse proxy is used, the rate is low, and the database is frequently written, which puts a lot of pressure on the database. Therefore, web2.0 needs to use the memory cache for web1.0.
Memcached's high-performance, distributed memory object cache system reduces database load in dynamic applications and improves access speed. Memcached has been widely used in various software, such as nginx and mysql.
1. Server Installation
Use weget to download libevent and memcached
Libevent: http://monkey.org /~ Provos/libevent-1.4.9-stable.tar.gz
Memcached: http://www.danga.com/memcached/dist/memcached-1.2.6.tar.gz
1. Install the libevent Java code first.
- Tar zxvf libevent-1.4.9-stable.tar.gz
- Cd libevent-1.4.9-stable
- ./Configure
- Make
- Make install
tar zxvf libevent-1.4.9-stable.tar.gz cd libevent-1.4.9-stable./configuremakemake install
2. Install memcached Java code
- Tar zxvf memcached-1.2.6.tar.gz
- Cd memcached-1.2.6
- ./Configure -- enable-threads
- Make
- Make install
tar zxvf memcached-1.2.6.tar.gzcd memcached-1.2.6./configure --enable-threadsmakemake install
NOTE: If "memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open
Shared object file: No such file or directory, which indicates that memcached cannot find the libevent location.
Therefore, use whereis libevent to obtain the location, and then connect to the Java code in the memcached path.
- [Root @ localhost tools] # whereis libevent
- Libevent:/usr/local/lib/libevent. la/usr/local/lib/libevent. so/usr/local/lib/libevent.
- [Root @ localhost tools] # LD_DEBUG = libs memcached-v 2> & 1>/dev/null | less
- 3848: find library = libevent-1.4.so.2 [0]; searching
- 3848: search cache =/etc/ld. so. cache
- 3848: search path =/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64 :/
- Usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64
- (System search path)
- 3848: trying file =/lib64/tls/x86_64/libevent-1.4.so.2
- 3848: trying file =/lib64/tls/libevent-1.4.so.2
- 3848: trying file =/lib64/x86_64/libevent-1.4.so.2
- 3848: trying file =/lib64/libevent-1.4.so.2
- 3848:
- 3848: find library = libc. so.6 [0]; searching
- 3848: search cache =/etc/ld. so. cache
- 3848: trying file =/lib64/libc. so.6
- 3848:
- 3848: find library = libnsl. so.1 [0]; searching
- 3848: search cache =/etc/ld. so. cache
- 3848: trying file =/lib64/libnsl. so.1
- 3848:
- 3848: find library = librt. so.1 [0]; searching
- 3848: search cache =/etc/ld. so. cache
- 3848: trying file =/lib64/librt. so.1
- 3848:
- 3848: find library = libresolv. so.2 [0]; searching
- 3848: search cache =/etc/ld. so. cache
- [Root @ localhost tools] # ln-s/usr/local/lib/libevent-1.4.so.2/lib64/
[root@localhost tools]# whereis libeventlibevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a[root@localhost tools]# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less 3848: find library=libevent-1.4.so.2 [0]; searching 3848: search cache=/etc/ld.so.cache 3848: search path=/lib64/tls/x86_64:/lib64/tls:/lib64/x86_64:/lib64:/usr/lib64/tls/x86_64:/usr/lib64/tls:/usr/lib64/x86_64:/usr/lib64 (system search path) 3848: trying file=/lib64/tls/x86_64/libevent-1.4.so.2 3848: trying file=/lib64/tls/libevent-1.4.so.2 3848: trying file=/lib64/x86_64/libevent-1.4.so.2 3848: trying file=/lib64/libevent-1.4.so.2 3848: 3848: find library=libc.so.6 [0]; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/libc.so.6 3848: 3848: find library=libnsl.so.1 [0]; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/libnsl.so.1 3848: 3848: find library=librt.so.1 [0]; searching 3848: search cache=/etc/ld.so.cache 3848: trying file=/lib64/librt.so.1 3848: 3848: find library=libresolv.so.2 [0]; searching 3848: search cache=/etc/ld.so.cache[root@localhost tools]# ln -s /usr/local/lib/libevent-1.4.so.2 /lib64/
Ii. memcached support for php installation
Php has two versions of memcached Client
1. memcached
This is the new version of the client based on libmemcached, so you must install libmemcached
Install libmemcached first
: Http://download.tangent.org/libmemcached-0.26.tar.gz
Java code
- [Root @ localhost tools] # tar zxvf libmemcached-0.26.tar.gz
- [Root @ localhosttools] # cd libmemcached-0.26
- [Root @ localhost libmemcached-0.26] #./configure -- prefix =/usr/local/libmemcached/-- with-libmemcached-dir =/usr/local/libmemcached/
- [Root @ localhost libmemcached-0.26] # make
- [Root @ localhost libmemcached-0.26] # make install
[root@localhost tools]# tar zxvf libmemcached-0.26.tar.gz[root@localhost tools]# cd libmemcached-0.26[root@localhost libmemcached-0.26]# ./configure --prefix=/usr/local/libmemcached/ --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost libmemcached-0.26]# make[root@localhost libmemcached-0.26]# make install
Install the php memcached Client
: Http://pecl.php.net/get/memcached
Java code
- [Root @ localhost tools] # tar zxvf memcached-0.1.4.tgz
- [Root @ localhosttools] # cd memcached-0.1.4
- [Root @ localhost memcached-0.1.4] #. /configure -- with-php-config =/usr/local/php/bin/php-config -- with-libmemcached-dir =/usr/local/libmemcached/
- [Root @ localhost memcached-0.1.4] # make
- [Root @ localhost memcached-0.1.4] # make install
[root@localhost tools]# tar zxvf memcached-0.1.4.tgz[root@localhost tools]# cd memcached-0.1.4[root@localhost memcached-0.1.4]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/[root@localhost memcached-0.1.4]# make[root@localhost memcached-0.1.4]# make install
Modify php. ini and add extension = "memcached. so.
If an error occurs
Java code
- Checking for libmemcached location... configure: error: memcached support requires libmemcached. Use -- with-libmemcached-dir = <DIR> to specify the prefix where libmemcached headers and library are located
checking for libmemcached location... configure: error: memcached support requires libmemcached. Use --with-libmemcached-dir=<DIR> to specify the prefix where libmemcached headers and library are located
Please first find the path with whereis libmemcached, and then add the option -- with-libmemcached-dir = libmemcached path
2. memcache
: Http://pecl.php.net/get/memcache Java code
- [Root @ localhost tools] # tar zxvf memcache-3.0.3.tgz
- [Root @ localhosttools] # cd memcache-3.0.3
- [Root @ localhost tools] #/usr/local/php/bin/phpize
- [Root @ localhost tools] #./configure -- with-php-config =/usr/local/php/bin/php-config
- [Root @ localhost tools] # make
- [Root @ localhost tools] # make install
[root@localhost tools]# tar zxvf memcache-3.0.3.tgz [root@localhost tools]# cd memcache-3.0.3[root@localhost tools]# /usr/local/php/bin/phpize[root@localhost tools]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@localhost tools]# make[root@localhost tools]# make install
Modify php. ini and add extension = "memcache. so.
Tip: If the so file cannot be found in php, set extension_dir.
Ps: This article has been in the draft box for a long time. Finally, I decided to write more articles. It seems much faster.
References:
Http://www.danga.com/memcached/ http://willko.javaeye.com/blog/332993