ubuntu安装redis_在Ubuntu上安装Redis

ubuntu安装redis

Redis is key-value storage known for its flexibility, performance, and wide language support.

Redis是键值存储,以其灵活性,性能和广泛的语言支持而闻名。

This tutorial will show you how you can install and set up Redis on your Ubuntu 18.04 machine from the Command Line, in just a few steps!.

本教程将向您展示如何通过命令行在Ubuntu 18.04计算机上安装和设置Redis。



步骤1:从Ubuntu来源安装Redis (Step 1: Install Redis from Ubuntu sources)

Since the official Ubuntu repository has source links to Redis (redis-server), we can install them using the apt package manager itself.

由于官方的Ubuntu存储库具有指向Redis的源链接( redis-server ),因此我们可以使用apt软件包管理器本身安装它们。

As always, update your system critical packages before installing an external package.

与往常一样,在安装外部软件包之前,请先更新系统关键软件包。


sudo apt update
sudo apt install redis-server
Ubuntu Install Redis Server
Ubuntu Install Redis Server
Ubuntu安装Redis服务器

Now, Redis will have been installed in your system. Let us verify our installation now.

现在,Redis将已安装在您的系统中。 现在让我们验证安装。

步骤2:验证Redis安装 (Step 2: Verify Redis Installation)

If our installation has completed successfully, a service called redis.service would have automatically started to run.

如果我们的安装成功完成,则名为redis.service的服务将自动开始运行。

Let us check if the Redis service is active or not, using:

让我们使用以下命令检查Redis服务是否处于活动状态:


sudo systemctl status redis

If the service is indeed running, you will see an output similar to the screenshot below.

如果该服务确实在运行,您将看到类似于以下屏幕截图的输出。

Ubuntu Redis Service Status Check
Ubuntu Redis Service Status Check
Ubuntu Redis服务状态检查

步骤3:配置Redis (Step 3: Configure Redis)

Before using Redis, there are some configuration tweaks we need to do from the default config.

在使用Redis之前,我们需要从默认配置中进行一些配置调整。

We will make our changes in the Redis Configuration File, which is located at /etc/redis/redis.conf.

我们将在Redis配置文件中进行更改,该文件位于/etc/redis/redis.conf

Open this file using a text editor (vi, nano, etc), using sudo, since we need to edit the file.

使用sudo使用文本编辑器(vi,nano等)打开此文件,因为我们需要编辑该文件。


root@ubuntu:~ # sudo vi /etc/redis/redis.conf

Go to the line which configures the supervised configuration option.

转到配置监督配置选项的行。

By default, the option would be no.

默认情况下,该选项为no

Ubuntu Redis Change Supervised Configuration Option
Ubuntu Redis Change Supervised Configuration Option
Ubuntu Redis更改监督配置选项

Change this to systemd, since we have an Ubuntu System, and we need to supervise this server.

将其更改为systemd ,因为我们有一个Ubuntu系统,我们需要监督该服务器。

Ubuntu Redis Supervised Option Changed
Ubuntu Redis Supervised Option Changed
Ubuntu Redis监督选项已更改

After changing this option, there are no further changes to be made. So exit the editor after saving changes.

更改此选项后,将不再进行任何更改。 因此,保存更改后退出编辑器。

Now, to apply our configuration change on redis-server, we need to restart the already running service. (We can also reboot)

现在,要将配置更改应用于redis-server ,我们需要重新启动已经运行的服务。 (我们也可以重启)

Use systemctl to restart redis.service.

使用systemctl重新启动redis.service。


sudo systemctl restart redis.service

If this returns to the Shell prompt, we have successfully applied the configuration change to our Redis server!

如果返回到Shell提示符,则说明我们已将配置更改成功应用于我们的Redis服务器!



步骤4:测试Redis (Step 4: Test Redis)

Now, just to make sure, let us check the status of redis again.

现在,为了确保确定,让我们再次检查redis的状态。


sudo systemctl status redis

We should get the same output as before, indicating that it is active without any errors.

我们应该获得与以前相同的输出,表明它是活动的,没有任何错误。

Now, let us connect to the Redis server using the Redis command-line interface (redis-cli).

现在,让我们使用Redis命令行界面( redis-cli )连接到Redis服务器。

Simply type the below command to connect to Redis Server:

只需键入以下命令即可连接到Redis Server:


redis-cli

We will get a prompt like this, with the Server address and Port (which can be found using sudo systemctl status redis)

我们将得到这样的提示,其中包含服务器地址和端口(可以使用sudo systemctl status redis

Ubuntu Redis Connect To Server
Ubuntu Redis Connect To Server
Ubuntu Redis连接到服务器

4.1)发送ping消息 (4.1) Send ping messages)

Let us send a ping message to the Server. If it is active, we will get a response from the Server.

让我们向服务器发送ping消息。 如果它处于活动状态,我们将收到服务器的响应。

You should get a similar output on typing ping and ping Hello.

在键入pingping Hello时,您应该得到类似的输出。

Ubuntu Redis Server Ping
Ubuntu Redis Server Ping
Ubuntu Redis服务器Ping

4.2)验证键值存储 (4.2) Verify key-value storage)

Now, let us check that we can be able to set Keys.

现在,让我们检查一下是否可以设置密钥。

Let us set a Key called test with a value called “Sample Key

让我们设置一个名为test的键,并将其值称为“ Sample Key

Run:

跑:


127.0.0.1:6379> set test "Sample Key"

Output

输出量


OK

Retrieve the value of the test using:

使用以下方法检索测试的值:


127.0.0.1:6379> get test

Output

输出量


"Sample Key"
Ubuntu Redis Check Key Value Pair
Ubuntu Redis Check Key-Value Pair
Ubuntu Redis检查键值对

Type exit to go back to the Shell Prompt.

键入exit返回到Shell提示符。

Now, we have successfully verified that our Redis Server is working properly, and can respond to our queries as expected!

现在,我们已经成功验证了Redis Server是否可以正常工作,并且可以按预期响应我们的查询!



结论 (Conclusion)

In this tutorial, we learned how to install and configure Redis Server on Ubuntu 18.04, which is used for storing key-value pairs efficiently.

在本教程中,我们学习了如何在Ubuntu 18.04上安装和配置Redis Server ,该服务器用于有效地存储键值对。

I hope this was useful to you for setting up your own Redis Server!

我希望这对您设置自己的Redis Server有用!

翻译自: https://www.journaldev.com/33819/install-redis-on-ubuntu

ubuntu安装redis

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值