1、libevent安装。为啥先安装它?因为不先装,memcached这座房子就没打地基:
yum install libevent-devel
敲回车后出现:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB ::
epel | 4.7 kB ::
extras | 3.4 kB ::
updates | 3.4 kB ::
(/): epel/x86_64/updateinfo | kB ::
(/): updates//x86_64/primary_db | 2.5 MB ::
(/): epel/x86_64/primary_db | 6.6 MB ::
Resolving Dependencies
--> Running transaction check
---> Package libevent-devel.x86_64 :2.0.-.el7 will be installed
--> Processing Dependency: libevent = 2.0.-.el7 for package: libevent-devel-2.0.-.el7.x86_64
--> Processing Dependency: libevent_pthreads-2.0.so.()(64bit) for package: libevent-devel-2.0.-.el7.x86_64
--> Processing Dependency: libevent_openssl-2.0.so.()(64bit) for package: libevent-devel-2.0.-.el7.x86_64
--> Processing Dependency: libevent_extra-2.0.so.()(64bit) for package: libevent-devel-2.0.-.el7.x86_64
--> Processing Dependency: libevent_core-2.0.so.()(64bit) for package: libevent-devel-2.0.-.el7.x86_64
--> Processing Dependency: libevent-2.0.so.()(64bit) for package: libevent-devel-2.0.-.el7.x86_64
--> Running transaction check
---> Package libevent.x86_64 :2.0.-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
libevent-devel x86_64 2.0.-.el7 base k
Installing for dependencies:
libevent x86_64 2.0.-.el7 base k Transaction Summary
===================================================================================================================================
Install Package (+ Dependent package) Total download size: k
Installed size: 1.1 M
Is this ok [y/d/N]: y
Downloading packages:
(/): libevent-devel-2.0.-.el7.x86_64.rpm | kB ::
(/): libevent-2.0.-.el7.x86_64.rpm | kB ::
-----------------------------------------------------------------------------------------------------------------------------------
Total 3.5 MB/s | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libevent-2.0.-.el7.x86_64 /
Installing : libevent-devel-2.0.-.el7.x86_64 /
Verifying : libevent-devel-2.0.-.el7.x86_64 /
Verifying : libevent-2.0.-.el7.x86_64 / Installed:
libevent-devel.x86_64 :2.0.-.el7 Dependency Installed:
libevent.x86_64 :2.0.-.el7 Complete!
我们可以看到它自动把libevent-devel和libevent两个包一起安装好了。我们可以到安装包下看一看:
ls /usr/lib64 | grep libevent
libevent-2.0.so.5
libevent-2.0.so.5.1.9
libevent_core-2.0.so.5
libevent_core-2.0.so.5.1.9
libevent_core.so
libevent_extra-2.0.so.5
libevent_extra-2.0.so.5.1.9
libevent_extra.so
libevent_openssl-2.0.so.5
libevent_openssl-2.0.so.5.1.9
libevent_openssl.so
libevent_pthreads-2.0.so.5
libevent_pthreads-2.0.so.5.1.9
libevent_pthreads.so
libevent.so
2、安装memcached:
yum install memcached
敲完回车后:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package memcached.x86_64 :1.4.-.el7_3. will be installed
--> Finished Dependency Resolution Dependencies Resolved ===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
Installing:
memcached x86_64 1.4.-.el7_3. base k Transaction Summary
===================================================================================================================================
Install Package Total download size: k
Installed size: k
Is this ok [y/d/N]: y
Downloading packages:
memcached-1.4.-.el7_3..x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : memcached-1.4.-.el7_3..x86_64 /
Verifying : memcached-1.4.-.el7_3..x86_64 / Installed:
memcached.x86_64 :1.4.-.el7_3. Complete!
3、去官方网站(http://memcached.org)下载memcached最新版本的源码包:
wget http://memcached.org/latest
敲完回车后:
---- ::-- http://memcached.org/latest
Resolving memcached.org (memcached.org)... 107.170.231.145
Connecting to memcached.org (memcached.org)|107.170.231.145|:... connected.
HTTP request sent, awaiting response... Moved Temporarily
Location: https://www.memcached.org/files/memcached-1.5.12.tar.gz [following]
---- ::-- https://www.memcached.org/files/memcached-1.5.12.tar.gz
Resolving www.memcached.org (www.memcached.org)... 107.170.231.145
Connecting to www.memcached.org (www.memcached.org)|107.170.231.145|:... connected.
HTTP request sent, awaiting response... OK
Length: (447K) [application/octet-stream]
Saving to: 鈥榣atest鈥 %[=========================================================================================>] , 153KB/s in .9s -- :: ( KB/s) - 鈥榣atest鈥saved [/]
我们看到下载的最新源码包叫memcached-1.5.12.tar.gz,但wget命令却把包名叫成了latest,把下载包的名称改回去
mv latest memcached-1.5..tar.gz
然后解压、配置、编译和安装
tar -zxvf memcached-1.5..tar.gz
cd memcached-1.5.12
./configure --prefix=/usr/local/memcached
make && make test
sudo make install
此时已大功告成,接下来启动memcached:
/usr/local/memcached/bin/memcached -p -m 64m -u root -d
这里以root用户、端口号11211、并分配了64兆内存将memcached作为守护进程在后台启动了,可以看下进程:
ps -ef | grep memcached
root : ? :: /usr/local/memcached/bin/memcached -p -m 64m -u root -d
最后连上memcached试一把:
telnet 127.0.0.1
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set foo
hello world
STORED
get foo
VALUE foo
hello world
END