如何在Mac OS上安装Memcached Server

时间:2020-02-23 14:44:59  来源:igfitidea点击:

Memcached是一个开源的高性能分布式内存对象缓存系统。
它是WordPress.com和LiveJournal.com等一些大型使用的最广泛使用的缓存机制之一。

VBulletin软件也使用它来提高性能,这是论坛最好的软件之一。
它易于安装,并且互联网上有许多不同语言的客户端程序可用。

在Mac OS上安装Memcached

Memcached是基于内存的缓存机制,并使用C语言进行构建。
要在Mac OS上安装memcached服务器,我们需要C库。
其中我假设系统中已经存在C库。
如果不是,那么您可以下载并编译C编译器,也可以安装XCode来安装GCC编译器。

之后,您需要安装lib事件库。

步骤是;

$curl -OL https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz

$tar -xvf libevent-2.1.8-stable.tar.gz 

$cd libevent-2.1.8-stable

$./configure --prefix=/usr/local

$make

$sudo make install

一旦安装了libevents,就可以安装Memcached服务器。

步骤是;

$curl -O https://memcached.org/files/memcached-1.5.0.tar.gz

$tar -xvf memcached-1.5.0.tar.gz 

$cd memcached-1.5.0

$./configure --prefix=/usr/local

$make

$sudo make install
Password:
$

现在,您的系统中已安装Memcached服务器。
如果未安装libevent库,则configure命令将给出以下错误。

$./configure --prefix=/usr/local
...
checking for libevent directory... configure: error: libevent is required.  You can get it from https://www.monkey.org/~provos/libevent/

    If it's already installed, specify its path using --with-libevent=/dir/

hyman:memcached-1.5.0 hyman$

Memcached服务器在不同的端口上

默认情况下,memcached服务器在TCP端口11211上运行,并在UDP端口11211上侦听,并且您可以从一个安装中运行多个memcached服务器实例。

$memcached -d

上面的命令将在TCP端口11211上启动Memcached服务器,并在UDP端口11211上侦听作为守护进程。

$memcached -p 11111 -U 11111 -d

上面的命令将在TCP端口11111上启动Memcached服务器,并在UDP端口11111上侦听作为守护进程。

使用Telnet测试Memcached服务器

下一步是使用memcached telnet命令测试其是否正常运行。

在某些Linux系统中,还需要在路径中添加libevent库的位置。

如果在启动memcached服务器时出现以下错误:

<p>./memcached: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory</p>

然后在用户配置文件中添加以下配置(例如.bash_profile或者.profile)

$export LD_LIBRARY_PATH= /usr/local/lib

或者,在configure命令中使用--with-libevent选项提供路径。