Memcached notes-(i) Installation & General error & Monitoring

Source: Internet
Author: User
Tags chmod memcached
In 08, when contacted Memcached, it also sniffed at its client products, after all, manual code does not have a variety of ORM Native XML configuration convenient. Still, memcached is now an integral part of the server architecture.

RELATED Links:
Memcached notes-(i) Installation & General error & Monitoring
Memcached Notes--(ii) xmemcached&spring integration
Memcached Notes--(iii) Summary of the use of memcached
Memcached Notes--(iv) responding to high concurrent attacks


First, download
1. Libevent
Simply put, is an event triggered by the network library, memcached inseparable from it.
Shell Code wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz
wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.17-stable.tar.gz

2. Memcached
The protagonist of the day
Shell Code wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz

second, the installation
1. Libevent
Decompression
Shell Code tar zxvf libevent-2.0.17-stable.tar.gz
Tar zxvf libevent-2.0.17-stable.tar.gz

Compiling, installing
Shell code./configure--prefix=/usr && make && make install

It must be noted here that the specified --prefix, it is necessary to configure memcached later.
2. Memcached
Extract
Shell Code tar zxvf memcached-1.4.13.tar.gz
Tar zxvf memcached-1.4.13.tar.gz

Compiling, installing
Shell code./configure--with-libevent=/usr/lib && make && make install
./configure--with-libevent=/usr/lib && make && make install

It must be specified here libeventThe path, otherwise start the time to have not found the libevent so file error.
Start
Shell code memcached-d-M 512-p 11211-u root-c 256-p/var/run/memcached.pid
Memcached-d-M 512-p 11211-u root-c 256-p/var/run/memcached.pid

Parameters
Reference
-P <num> TCP port number to listen on (default:11211)
-U <num> UDP port number to listen on (default:11211, 0 are off)
-L <addr> interface to listen on (Default:inaddr_any, all addresses)
<addr> May is specified as Host:port. If you don ' t specify
A port number, the value you specified With-p or-u is
Used. Specify multiple addresses separated by comma
or by using-l multiple times
-D Run as a daemon
-U <username> assume identity of <username> (only when run as root)
-M <num> max memory to use for items in megabytes (default:64 MB)
-M return error on memory exhausted (rather than removing items)
-C <num> Max simultaneous connections (default:1024)
-V Verbose (print errors/warnings while in event loop)
-P <file> Save PID in <file>, only used with-d option

To turn off the memcached.
Shell code kill-9 ' Cat/var/run/memcached.pid '
Kill-9 ' Cat/var/run/memcached.pid '  

is normal. Let's go telnet.
Shell Code telnet xxx.xxx.xxx.xxx 11211
Telnet xxx.xxx.xxx.xxx 11211

Then enter the shell code stats
Stats

Then you can see:
Reference
STAT PID 3021
STAT Uptime 3621
STAT Time 1331261509
STAT version 1.4.13
STAT libevent 2.0.17-stable
STAT Pointer_size 64
STAT Rusage_user 0.000000
STAT Rusage_system 0.000999
STAT Curr_connections 6
STAT Total_connections 7
STAT Connection_structures 7
STAT Reserved_fds 20
STAT Cmd_get 0
STAT Cmd_set 0
STAT Cmd_flush 0
STAT Cmd_touch 0
STAT Get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT Delete_hits 0
STAT incr_misses 0
STAT Incr_hits 0
STAT decr_misses 0
STAT Decr_hits 0
STAT cas_misses 0
STAT Cas_hits 0
STAT Cas_badval 0
STAT Touch_hits 0
STAT touch_misses 0
STAT Auth_cmds 0
STAT auth_errors 0
STAT Bytes_read 72
STAT Bytes_written 1038
STAT limit_maxbytes 52428800
STAT Accepting_conns 1
STAT Listen_disabled_num 0
STAT Threads 4
STAT Conn_yields 0
STAT Hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 0
STAT Curr_items 0
STAT Total_items 0
STAT Evictions 0
STAT reclaimed 0
End

The above condition indicates that the memcached service is normal.
You can also try get, set, delete, replace
Reference to set foo 0 0 3 (Save command)
Bar (data)
STORED (Result)
Get foo (take command)
VALUE Foo 0 3 (data)
Bar (data)

Enter the shell code quit
Quit
Exit.

third, System services
Referring to the Nginx system service, you wrote a memcached system service script.
First Build /etc/init.d/memcahedThis file, and then give it executable permissions:
Shell Code touch/etc/init.d/memcached chmod +x/etc/init.d/memcached
touch/etc/init.d/memcached
chmod +x/etc/init.d/memcached

The memcached script is as follows:
Shell Code #!/bin/bash # v.0.0.1 # Create by Snowolf at 2012.5.25 # memcached-this shell script takes care of starting a nd stopping memcached. # Chkconfig:-Description:memcache provides fast memory based storage. # processname:memcached memcached_path= "/usr/local/bin/memcached" memcached_pid= "/var/run/memcached.pid" memcached _memory= "1024" # Source function library. . /etc/rc.d/init.d/functions [-X $memcached _path] | | Exit 0 retval=0 prog= "memcached" # Start daemons. Start () {if [e $memcached _pid-a!-Z $memcached _pid];then echo $prog "already running ..." Exit 1 fi echo-n $ "starti ng $prog "# Single instance to all caches $memcached _path-m $memcached _memory-l 0.0.0.0-p 11211-u root-d-P $MEMCAC Hed_pid retval=$? [$RETVAL-eq 0] && {touch/var/lock/subsys/$prog success $ "$prog"} Echo return $RETVAL} # Stop daemons. Stop () {echo-n $ "stopping $prog" killproc-d $memcached _path echo [$RETVAL = 0] && rm-f $memcached _pid/v ar/lock/subsys/$prog retval=$? Return $RETVAL} # we were called. Case "in Start" start;; stop) stop;; Status $prog retval=$?;; restart) stop start;; * echo $ "Usage: $ {Start|stop|status|restart}" Exit 1 Esac Exit $RETVAL
#!/bin/bash # v.0.0.1 # Create by Snowolf at 2012.5.25 # memcached-this shell script takes care of starting and Stopp
ing memcached.
# Chkconfig:-Description:memcache provides fast memory based storage. # processname:memcached memcached_path= "/usr/local/bin/memcached" memcached_pid= "/var/run/memcached.pid" memcached
_memory= "1024" # Source function library. . /etc/rc.d/init.d/functions [-X $memcached _path] | |
Exit 0 retval=0 prog= "memcached" # Start daemons. 
    Start () {if [e $memcached _pid-a!-Z $memcached _pid];then echo $prog "already running ..." Exit 1 Fi echo-n $ "Starting $prog" # Single instance to all caches $memcached _path-m $memcached _memory-l 0
    .0.0.0-p 11211-u root-d-P $memcached _pid retval=$? [$RETVAL-eq 0] && {touch/var/lock/subsys/$prog success $ "$prog"} Echo return $RE
Tval} # Stop daemons. Stop () {echo-n $ "stopping $prog" killproc-d 10$memcached _path echo [$RETVAL = 0] && rm-f $memcached _pid/var/lock/subsys/$prog retval=$?
Return $RETVAL} # we were called.
        Case "in Start" start;;
        stop) stop;;
            Status $prog retval=$?
        ;;
        restart) stop start;;
 * echo $ "Usage: $ {Start|stop|status|restart}" Exit 1 Esac Exit $RETVAL

Note These lines of configuration, configure the memcached execution file path according to the actual situation, and memcached use memory size:
Reference memcached_path= "/usr/local/bin/memcached"
memcached_memory= "1024"

Append to System services:
Shell Code chkconfig--add memcached chkconfig memcached on
Chkconfig--add memcached
chkconfig memcached on


And then you can go through Service memcached Start|stop|status|restartControl the memcached.

Iv. General Errors
At the beginning without specifying the libevent path to install memcached, start memcached to report this error:
Reference memcached:error while loading shared libraries:libevent-2.0.so.5:cannot open Shared object file:no such file or dir Ectory

In fact, this file is /usr/libUnder Wrong is wrong in Linux is the 64bit system, if not specified libevent path, memcached will go /usr/lib64Get down there.
Find this file
Shell Code Whereis libevent-2.0.so.5
Whereis libevent-2.0.so.5

Reference libevent-2.0.so:/usr/lib/libevent-2.0.so.5
Shell Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.