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