如何在Ubuntu 18.04上安装和保护Redis

A previous version of this tutorial was written by Justin Ellingwood

本教程的先前版本由Justin Ellingwood撰写

介绍 (Introduction)

Redis is an in-memory key-value store known for its flexibility, performance, and wide language support. This tutorial demonstrates how to install, configure, and secure Redis on an Ubuntu 18.04 server.

Redis是一个内存键值存储,以其灵活性,性能和广泛的语言支持而闻名。 本教程演示了如何在Ubuntu 18.04服务器上安装,配置和保护Redis。

先决条件 (Prerequisites)

To complete this guide, you will need access to an Ubuntu 18.04 server that has a non-root user with sudo privileges and a basic firewall configured. You can set this up by following our Initial Server Setup guide.

要完成本指南,您将需要访问Ubuntu 18.04服务器,该服务器具有具有sudo特权的非root用户和配​​置的基本防火墙。 您可以按照我们的初始服务器安装指南进行设置

When you are ready to begin, log in to your Ubuntu 18.04 server as your sudo user and continue below.

准备开始时,以sudo用户身份登录到Ubuntu 18.04服务器,然后继续。

第1步-安装和配置Redis (Step 1 — Installing and Configuring Redis)

In order to get the latest version of Redis, we will use apt to install it from the official Ubuntu repositories.

为了获得最新版本的Redis,我们将使用apt从官方Ubuntu存储库中安装它。

Update your local apt package cache and install Redis by typing:

通过键入以下内容来更新本地apt软件包缓存并安装Redis:

  • sudo apt update

    sudo apt更新
  • sudo apt install redis-server

    sudo apt安装redis服务器

This will download and install Redis and its dependencies. Following this, there is one important configuration change to make in the Redis configuration file, which was generated automatically during the installation.

这将下载并安装Redis及其依赖项。 然后,在Redis配置文件中进行一项重要的配置更改,该更改是在安装过程中自动生成的。

Open this file with your preferred text editor:

使用首选的文本编辑器打开此文件:

  • sudo nano /etc/redis/redis.conf

    须藤nano /etc/redis/redis.conf

Inside the file, find the supervised directive. This directive allows you to declare an init system to manage Redis as a service, providing you with more control over its operation. The supervised directive is set to no by default. Since you are running Ubuntu, which uses the systemd init system, change this to systemd:

在文件中,找到受supervised指令。 该指令允许您声明一个初始化系统来将Redis作为服务进行管理,从而为您提供对其操作的更多控制。 默认情况下, supervised指令设置为no 。 由于您正在运行使用systemd初始化系统的Ubuntu,请将其更改为systemd

/etc/redis/redis.conf
/etc/redis/redis.conf
. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .

That’s the only change you need to make to the Redis configuration file at this point, so save and close it when you are finished. Then, restart the Redis service to reflect the changes you made to the configuration file:

这是您目前唯一需要对Redis配置文件进行的更改,因此请在完成后保存并关闭它。 然后,重新启动Redis服务以反映您对配置文件所做的更改:

  • sudo systemctl restart redis.service

    sudo systemctl重新启动redis.service

With that, you’ve installed and configured Redis and it’s running on your machine. Before you begin using it, though, it’s prudent to first check whether Redis is functioning correctly.

这样,您已经安装并配置了Redis,并且它在您的计算机上运行。 但是,在开始使用它之前,先检查一下Redis是否运行正常是明智的。

第2步-测试Redis (Step 2 — Testing Redis)

As with any newly-installed software, it’s a good idea to ensure that Redis is functioning as expected before making any further changes to its configuration. We will go over a handful of ways to check that Redis is working correctly in this step.

与任何新安装的软件一样,在对其配置进行任何进一步更改之前,最好确保Redis能够按预期运行。 我们将介绍几种方法来检查Redis在此步骤中是否正常工作。

Start by checking that the Redis service is running:

首先检查Redis服务是否正在运行:

  • sudo systemctl status redis

    sudo systemctl状态redis

If it is running without any errors, this command will produce output similar to the following:

如果它正在运行而没有任何错误,那么此命令将产生类似于以下内容的输出:


   
   
   
Output
● redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2018-06-27 18:48:52 UTC; 12s ago Docs: http://redis.io/documentation, man:redis-server(1) Process: 2421 ExecStop=/bin/kill -s T
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值