memcached 是一个免费开源的、高性能的、具有分布式内存对象的缓存系统,它通过减轻数据库负载加速动态Web应用数据加载。通过 Homebrew 下载的软件都来自于官网,绝对放心软件的安全性。而且它尽可能地利用系统自带的各种库,使得软件包的编译时间大大缩短,基本上不会造成冗余。
前提条件
你的MacOS上已经安装了Homebrew。Homebrew 是 macOS 的套件管理工具,是高效下载软件的一种方法,相当于 Linux 下的 yum
、apt-get
神器,用于下载存在依赖关系的软件包。可以看成是一个软件仓库,可以快速的通过命令安装需要的软件。
如果你的MacOS系统没有安装Homebrew,可以通过如下命令安装:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
国内使用(建议):
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
安装完成后,可以通过如下命令测试Homebrew是否正常安装。
brew -h
安装memcached
查看安装信息
安装之前可以通过如下命令查看安装信息,例如命令如下:
brew info memcached
输出结果类似如下:
==> memcached: stable 1.6.18 (bottled), HEAD
High performance, distributed memory object caching system
https://memcached.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/memcached.rb
License: BSD-3-Clause
==> Dependencies
Required: libevent ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
To restart memcached after an upgrade:
brew services restart memcached
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/memcached/bin/memcached -l localhost
==> Analytics
install: 88 (30 days), 6,292 (90 days), 56,972 (365 days)
install-on-request: 89 (30 days), 6,235 (90 days), 56,241 (365 days)
build-error: 0 (30 days)
sanghg@sanghonangdembp servers % brew install libevent
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 1 tap (shivammathur/php).
Warning: libevent 2.1.12 is already installed and up-to-date.
To reinstall 2.1.12, run:
brew reinstall libevent
安装依赖项libevent
根据提示信息,通过命令安装依赖项:
brew install libevent
安装memcached
brew install memcached
启动
brew services start memcached
运行成功,提示类似如下:
==> Successfully started `memcached` (label: homebrew.mxcl.memcached)
查看是否已经成功启动
ps -ef|grep memcached
输出结果类似如下:
501 70391 1 0 11:30上午 ?? 0:00.03 /opt/homebrew/opt/memcached/bin/memcached -l localhost
501 70455 2821 0 11:31上午 ttys000 0:00.00 grep memcached
测试连接
telnet localhost 11211
正常情况下,你会看到类似如下的结果:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
写在最后
至此,整个memcached使用brew在MacOS上安装的过程就讲解完成了。如果你感兴趣,不妨尝试在自己的MacOS上使用brew来安装memcached试一试吧!
相关阅读: