|
|
Posted on 10/5/2014 11:16:39 PM
|
|
|

The server side mainly installs memcache on the server side
Memcache uses the libevent library for socket processing, so you also need to install libevent.
Download address: http://www.monkey.org/~provos/libevent
Memcache download address: http://danga.com/memcached/download.bml
The detailed method is as follows:
1. Install libevent first:
# tar zxvf libevent-1.4.6-stable.tar.gz
# ./configure --prefix=/usr
# make
# make install
2. Test whether libevent is installed successfully:
# ls -al /usr/lib | grep libevent
[root@localhost soft]# ls -al /usr/lib | grep libevent
lrwxrwxrwx 1 root root 21 Dec 30 11:00 libevent-1.4.so.2 -> libevent-1.4.so.2.1.1
-rwxr-xr-x 1 root root 280179 Dec 30 11:00 libevent-1.4.so.2.1.1
-rw-r--r-- 1 root root 366946 Dec 30 11:00 libevent.a
lrwxrwxrwx 1 root root 26 Dec 30 11:00 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.1
-rwxr-xr-x 1 root root 107523 Dec 30 11:00 libevent_core-1.4.so.2.1.1
-rw-r--r-- 1 root root 146944 Dec 30 11:00 libevent_core.a
-rwxr-xr-x 1 root root 860 Dec 30 11:00 libevent_core.la
lrwxrwxrwx 1 root root 26 Dec 30 11:00 libevent_core.so -> libevent_core-1.4.so.2.1.1
lrwxrwxrwx 1 root root 27 Dec 30 11:00 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.1
-rwxr-xr-x 1 root root 219483 Dec 30 11:00 libevent_extra-1.4.so.2.1.1
-rw-r--r-- 1 root root 281326 Dec 30 11:00 libevent_extra.a
-rwxr-xr-x 1 root root 867 Dec 30 11:00 libevent_extra.la
lrwxrwxrwx 1 root root 27 Dec 30 11:00 libevent_extra.so -> libevent_extra-1.4.so.2.1.1
-rwxr-xr-x 1 root root 825 Dec 30 11:00 libevent.la
lrwxrwxrwx 1 root root 21 Dec 30 11:00 libevent.so -> libevent-1.4.so.2.1.1
3. Install memcached, and specify the installation location of libevent in the installation:
# tar zxvf memcached-1.2.6.tar.gz
# ./configure --with-libevent=/usr
# make
# make install
After the installation is complete, memcached will be placed in /usr/local/bin/memcached
4. Test whether the memcached is installed successfully:
# ls -al /usr/local/bin/mem*
-rwxr-xr-x 1 root root 121261 Dec 30 11:02 /usr/local/bin/memcached
-rwxr-xr-x 1 root root 130191 Dec 30 11:02 /usr/local/bin/memcached-debug
5. Install the PHP extension for Memcache
In http://pecl.php.net/package/memcache, select the version of memcache you want to download.
# tar vxzf memcache-2.2.4
# cd memcache-2.2.4
# /usr/local/php/bin/phpize
# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
# make
# make install
6. After the above installation, there will be a prompt like this:
Installing shared extensions: "/usr/local/php/lib/php/extensions/no-debug-non-zts-2006xxxx/"
7. Change the extension_dir = "./" in the php.ini to
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
8. Add a line to load the memcache extension:
extension=memcache.so
9. Start and stop Memcache on the server side:
# /usr/local/bin/memcached -d -m 200 -u root -l 192.168.1.91 -p 12000 -c 1000 -P /tmp/memcached.pid
memcached -m 256 -u www -p 11211 -d
The relevant explanation is as follows:
-d option is to start a daemon,
-m is the amount of memory allocated to Memcache for use, in MB, here 200MB
-u is the user running Memcache, I'm root here
-l is the IP address of the server that is listening, if there are multiple addresses, I specify the IP address of the server here 192.168.1.91
-p is the port where Memcache is set to listen, I set 12000 here, preferably a port above 1024
The -c option is the maximum number of concurrent connections running, the default is 1024, I set it to 256 here
-P is the pid file that is set to save Memcache, and I save it here in /tmp/memcached.pid
Stop the Memcache process:
# kill `cat /tmp/memcached.pid`
Multiple daemons can also be started, but the ports cannot be repeated
10. Restart Apache
service httpd restart
11. Memcache environment test:
Run the following php file, if there is output This is a test!, it means that the environment is successfully built.
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>
php test code:
<?php
ini_set("memcache.hash_function","crc32");
$memcache = new Memcache;
$memcache->addServer('192.168.1.91', 12000);
$memcache->flush();
for($i=0; $i<120000; $i++){
$memcache->set($i,
"hi memcache, i want to use memcache, you good", 0, 1000);
}
?>
Perl's test code:
#!/usr/bin/perl
use Cache::Memcached::Fast;
my $memd = new Cache::Memcached::Fast({
servers => [ { address => '192.168.1.91:12000', weight => 2.5 } ],
});
$memd->flush_all;
for($i=0; $i<120000; $i++){
$memd->set($i, "hi memcache, i want to use memcache, you good");
}
$memd = undef;
The perl here uses the Cache::Memcached::Fast module, not Cache::Memcached, because the Cache::Memcached::Fast module is written in C, so the perl module tested by many people is not as efficient as php, and this is the reason.
|
Previous:Python 2.7 Getting Started GuideNext:Now the forum is in closed beta, everyone is welcome to give their opinions
|