Distributed memcached Learning (1) -- compile memcahed and memcachedmemcahed in linux
Install dependency tools
[Root @ localhost upload] # yum install gcc make cmake autoconf libtool
Download and upload files
Memcached depends on the libevent library. Therefore, we need to install the libevent., ibevent and memcached download paths first.
Http://sourceforge.net/projects/levent? Source = typ_redirect
Https://github.com/memcached/memcached/wiki/ReleaseNotes1425
[Root @ localhost upload] # ls
Libevent-2.0.22-stable libevent-2.0.22-stable.tar.gz memcached-1.4.25.tar.gz
[Root @ localhost upload] #
Decompress and compile
[Root @ localhost upload] # tar zxvf libevent-2.0.21-stable.tar.gz
[Root @ localhost upload] # cd libevent-2.0.22-stable
[Root @ localhost upload] #./configure -- prefix =/usr/local/libevent
[Root @ localhost upload] # make & make install
[Root @ localhost upload] # tar zxvf memcached-1.4.25.tar.gz
[Root @ localhost upload] # cd memcached-1.4.25
[Root @ localhost upload] #./configure -- prefix =/usr/local/memcached
Error:
Checking for libevent directory... configure: error: libevent is required. You can get it from http://www.monkey.org /~ Provos/libevent/
If it's already installed, specify its path using -- with-libevent =/dir/
Prompt that the libevent is required. Specify the installation directory of the libevent.
[Root @ localhost upload] #
./Configure -- prefix =/usr/local/memcached -- with-libevent =/usr/local/libevent
[Root @ localhost memcached-1.4.25] # make & make install
If there is no error message, the compilation is successful.
Memcached has been successfully installed in the/usr/local/memcached/bin/memcached directory.
Start memcached
[Root @ localhost memcached-1.4.25] #/usr/local/memcached/bin/memcached-m 64-p 11211-u nobody-vv
Slab class 1: chunk size 80 perslab 13107
Slab class 2: chunk size 104 perslab 10082
Slab class 3: chunk size 136 perslab 7710
Slab class 4: chunk size 176 perslab 5957
Slab class 5: chunk size 224 perslab 4681
Slab class 6: chunk size 280 perslab 3744
Slab class 7: chunk size 352 perslab 2978
......
You can see that memcached has been started and the information is output to the console.
Parameter Parsing:
-M memory size
-P Port
-U user
-Vv details
If you want memcached to run in the background as a daemon, you only need to add the-d option.
[Root @ localhost memcached-1.4.25] #/usr/local/memcached/bin/memcached
-M 64-p 11211-u nobody-d
Several important parameters
Several important parameters taken from the Internet
-P <num> TCP port of the listener (default: 11211)
-D runs as a daemon.
-U <username> specifies the user to which the process belongs. (Only root users can use this parameter)
-M <num> maximum memory available for all slab classes, in MB. (Default: 64 MB)
(Note: The memory size allocated to the memcached instance .)
-C <num> maximum number of concurrent connections. (Default: 1024)
-V prompt information (print error/warning information in the event loop .)
-Vv details (also prints client commands/responses)
-Vvv super detailed information (also prints internal status changes)
-H: print the help information and exit.
-F <factor> growth rate (growth factor) of chunk size in different slab classes ). (Default: 1.25)
(Note: Each slab class has the same number of slab pages, each of which has a chunk, And the chunk size in the current slab class is fixed.
The chunk size in different slab classes is inconsistent. The specific difference is that the magnification of this parameter is increasing and the allocated memory is exhausted .)
-N <bytes> Minimum chunk space (default: 48)
(Note: The chunk data structure itself consumes 48 bytes, so the actual memory consumed by a chunk is n + 48 .)
Next we will introduce the connection of memcached.
Install
Telnet Tool
The communication between the memcached client and the server is simple. It uses a text-based protocol instead of a binary protocol.
(The same is true for http), so we can use telnet to interact with memcached.
[Root @ localhost libevent-2.0.22-stable] # yum install telnet *
Linux
Connect to memcached
[Root @ localhost libevent-2.0.22-stable] # telnet 192.168.1.112 11211
Trying 192.168.1.112...
Connected to 192.168.1.112.
Escape character is '^]'.
Press Ctrl +] to enable the echo function. Enter:
[Root @ localhost libevent-2.0.22-stable] # telnet 192.168.1.112 11211
Trying 192.168.1.112...
Connected to 192.168.1.112.
Escape character is '^]'.
^]
Telnet>
The memcached console displays the client connection information.
<34 server listening (udp)
<35 server listening (udp)
<36 new auto-negotiating client connection
Windows
Connect to memcached
If you connect to memcached in linux from the windows console, You need to enable access to port 11211 of linux, as shown below:
[Root @ localhost libevent-2.0.22-stable] #/sbin/iptables-I INPUT-p tcp -- dport 11211-j ACCEPT
Similarly, in the windows console, enter telnet 192.168.1.112 11211 to connect.