美文网首页
Linux服务器:安装 Redis

Linux服务器:安装 Redis

作者: 啊肉怪 | 来源:发表于2019-04-18 08:47 被阅读0次

Redis 是完全开源免费、遵守 BSD 协议的一个高性能 key-value 数据库。

Redis 与其他 key - value 缓存产品有以下三个特点

  • Redis 支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用
  • Redis 不仅仅支持简单的 key-value 类型的数据,同时还提供 list,set,zset,hash 等数据结构的存储
  • Redis 支持数据的备份,即 master-slave 模式的数据备份

安装 redis

下载 redis 安装包

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 428px; background: rgb(247, 247, 247);">wget http://download.redis.io/releases/redis-5.0.4.tar.gz
</pre>

|

解压压缩包

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 221px; background: rgb(247, 247, 247);">tar -xzvf redis-5.0.4.tar.gz
</pre>

|

yum 安装 gcc 依赖

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 128px; background: rgb(247, 247, 247);">yum install gcc
</pre>

|

这边我在配置 nginx 服务器的时候安卓过,所以此步略过

编译安装

先进入 redis 目录

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 121px; background: rgb(247, 247, 247);">cd redis-5.0.4
</pre>

|

编译安装

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 49px; background: rgb(247, 247, 247);">make
</pre>

|

测试编译结果

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 85px; background: rgb(247, 247, 247);">make test
</pre>

|

启动 redis

切换到 redis/src 目录下

直接启动

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 121px; background: rgb(247, 247, 247);">./redis-server
</pre>

|

image

如上图:redis 启动成功,但这种启动方式需要一直打开窗口,不能进行其他操作。按 ctrl + c 可以关闭窗口。

后台进程启动

修改 redis.conf 文件

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 228px; background: rgb(247, 247, 247);">daemonize no => daemonize yes
</pre>

|

image

指定配置文件运行 redis

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 221px; background: rgb(247, 247, 247);">./redis-server ../redis.conf
</pre>

|

使用自带的 redis-cli 客户端连接 redis-server 进行测试:

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(134, 145, 148); line-height: 1.6; border: none; text-align: right; background: rgb(239, 242, 243);">1
</pre>

|

<pre style="overflow: auto; font-family: consolas, Menlo, 'PingFang SC', 'Microsoft YaHei', monospace; font-size: 13px; margin: 0px; padding: 10px; color: rgb(77, 77, 76); line-height: 1.6; border: none; width: 99px; background: rgb(247, 247, 247);">./redis-cli
</pre>

|

image

关闭 redis 进程

首先使用 ps -aux | grep redis 查看 redis 进程

使用 kill 命令杀死进程

image

相关文章

网友评论

      本文标题:Linux服务器:安装 Redis

      本文链接:https://www.haomeiwen.com/subject/amnawqtx.html