Install Memcached and linuxmemcached on Linux.
Download and install the Memcache Server
The server is mainly used to install the memcache server.
Download: http://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
In addition, Memcache uses the libevent library for Socket processing, so you also need to install libevent, the latest version of libevent is the libevent-1.3. (If your system has already installed libevent, you do not need to install it)
Official Website: http://www.monkey.org /~ Provos/libevent/
Download: http://www.monkey.org /~ Provos/libevent-1.3.tar.gz
Use the wget command to directly download these two items.
1. Install libevent first. During configuration, You need to specify an installation path, that is,./configure-prefix =/usr; then make install;
2. install memcached again. You only need to specify the installation path of libevent during configuration, that is,./configure-with-libevent =/usr; then make install;
This completes the installation of the Memcache server in Linux. The detailed method is as follows:
1. Download memcached and libevent respectively and put them in the/tmp directory:
# Cd/tmp
# Wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz
# Wget http://www.monkey.org /~ Provos/libevent-1.2.tar.gz
2. Install libevent first:
# Tar zxvf libevent-1.2.tar.gz
# Cd libevent-1.2
#./Configure-prefix =/usr
# Make
# Make install
3. test whether the libevent is successfully installed:
# Ls-al/usr/lib | grep libevent
Lrwxrwxrwx 1 root 21 11 ?? Libevent-1.2.so.1> libevent-1.2.so.1.0.3
-Rwxr-xr-x 1 root 263546 11 ?? Libevent-1.2.so.1.0.3
-Rw-r-1 root 454156 11 ?? 12 libevent.
-Rwxr-xr-x 1 root 811 11 ?? Libevent. la
Lrwxrwxrwx 1 root 21 11 ?? 12 libevent. so-> libevent-1.2.so.1.0.3
Not bad. They all have been installed.
4. Install memcached and specify the libevent installation location during installation:
# Cd/tmp
# Tar zxvf memcached-1.2.0.tar.gz
# Cd memcached-1.2.0
#./Configure-with-libevent =/usr
# Make
# Make install
If an error is reported in the middle, check the error information carefully and configure or add the corresponding library or path according to the error information.
After the installation is complete, the memcached will be placed in/usr/local/bin/memcached,
5. Test whether memcached is successfully installed:
# Ls-al/usr/local/bin/mem *
-Rwxr-xr-x 1 root 137986 11 ?? 12 :39/usr/local/bin/memcached
-Rwxr-xr-x 1 root 140179 11 ?? 12 :39/usr/local/bin/memcached-debug
Start Memcached Service:
1. Start the Memcache Server:
#/Usr/local/bin/memcached-d-m 10-u root-l 192.168.141.64-p 12000-c 256-P/tmp/memcached. pid
-D option is to start a daemon,
-M indicates the amount of memory allocated to Memcache. The unit is MB. Here I am 10 MB,
-U is the user who runs Memcache. Here I am root,
-L is the IP address of the listening server. If there are multiple IP addresses, I have specified the IP address 192.168.0.200,
-P is the port for Memcache listening. I have set port 12000 here, preferably port 1024 or above,
-The "c" option is the maximum number of concurrent connections. The default value is 1024. I have set 256 here, which is based on the load of your server,
-P is the pid file for saving Memcache. Here I save it in/tmp/memcached. pid,
2. to end the Memcache process, run:
# kill `cat /tmp/memcached.pid`
You can also start multiple daemon processes, but the ports cannot be repeated.
Test Memcached:
[Root @ localhost/] # telnet 192.168.141.64 12000.
Trying 192.168.141.64...
Connected to 192.168.141.64 (192.168.141.64 ).
Escape character is '^]'.
Set key1 0 60 4
Zhou
STORED
Get key1
VALUE key1 0 4
Zhou
END
So far, Memcached has been installed successfully!
FAQs:
1. If the Memcached service is started
/Usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory;
Solution:
[Root @ localhost bin] # LD_DEBUG = libs memcached-v
[Root @ localhost bin] # ln-s/usr/lib/libevent-1.2.so.1/usr/lib64/libevent-1.2.so.1
[Root @ localhost bin] # // usr/local/bin/memcached-d-m 100-u root-p 12000-c 1000-P/tmp/memcached. pid
[Root @ localhost bin] # ps-aux
You can see the Memcached service started.
2. Load the Memcached service to the Linux Startup item. In case of a power failure, the Memcached will be automatically started.
Assume that the command on the server that starts Memcache is:
#/Usr/local/bin/memcached-d-m 10-u root-l 192.168.141.64-p 12000-c 256-P/tmp/memcached. pid from 17 jquery
To enable Automatic startup, add a line in/etc/rc. d/rc. local. The following command
/Usr/local/memcached/bin/memcached-d-m 10-p 12000-u apache-c 256
Some of the above can be referred to: that is, when the ip address is not specified, the default is local. User: The best choice is apache or deamon.
In this way, it is the service of the user and the user who starts the service.