Linux安装Redis并进行相关配置(云服务器 Ubuntu 20.04.1)

由于需要在云服务器上快速安装Redis,因此采用apt-get命令安装。

apt-get 命令是 Ubuntu 系统中的包管理工具,可以用来安装、卸载包,也可以用来升级包,还可以用来把系统升级到新的版本。

一、安装Redis

1、安装Redis服务

sudo apt-get install redis-server

2、查看Redis服务的进程以及默认端口号6379
在这里插入图片描述
3、查看Redis服务器状态(3种方式):

sudo netstat -nlt|grep 6379

在这里插入图片描述

sudo /etc/init.d/redis-server status

在这里插入图片描述

sudo systemctl status redis

在这里插入图片描述

相关配置

1、设置密码(可选)

sudo vim /etc/redis/redis.conf

按ESC键,输入:(冒号),并输入如下命令:

/requirepass

在这里插入图片描述

n键向下匹配,按N键向上匹配

i进入编辑模式
去掉requirepass 前面的注释#,在后面添加密码,然后保存即可

Redis服务器默认是不需要密码的,假设设置密码为alicia。
在这里插入图片描述
2、开启远程连接

Redis提供的解决方案:

  1. Just disable protected mode sending the command ‘CONFIG SET
    protected-mode no’ from the loopback interface by connecting to Redis
    from the same host the server is running, however MAKE SURE Redis is
    not publicly accessible from internet if you do so. Use CONFIG REWRITE
    to make this change permanent.

  2. Alternatively you can just disable the protected mode by editing
    the Redis configuration file, and setting the protected mode option to
    ‘no’, and then restarting the server.

  3. If you started the server manually just for testing, restart it
    with the ‘–protected-mode no’ option.

  4. Setup a bind address or an authentication password. NOTE: You only
    need to do one of the above things in order for the server to start
    accepting connections from the outside.

可以看到,允许远程访问需要:
(1)关闭保护模式

sudo vim /etc/redis/redis.conf

按ESC键,输入:(冒号),并输入如下命令:

/protected-mode

n键向下匹配,按N键向上匹配

i进入编辑模式
protected-mode后面的yes改为no,然后保存即可
在这里插入图片描述
(2)bind IP或者设置访问密码
如果没有设置密码,可以注释掉绑定地址:# bind 127.0.0.1或者改成bind 0.0.0.0
在这里插入图片描述
如果未配置远程连接,Java连接Redis会报如下错误(项目地址):
在这里插入图片描述

3、云服务器添加安全组规则

可以通过添加安全组规则,允许或禁止安全组内的ECS实例对公网或私网的访问。

在配置规则页面,单击快速添加
在这里插入图片描述
设置授权策略、授权对象和端口范围
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu 20.04安装Redis,你有两种选择。第一种是使用默认的软件源进行安装,第二种是手动下载安装包并进行安装。 第一种方法是使用默认的软件源进行安装。你可以以root或其他sudo身份运行以下命令来更新软件源并安装Redis服务器: ``` sudo apt update sudo apt install redis-server ``` 这将从默认的Ubuntu 20.04软件源中安装Redis 5.0版本。\[1\] 第二种方法是手动下载安装包并进行安装。你可以将下载的Redis安装包(例如redis-5.0.12.tar.gz)放在Ubuntu系统中的某个位置,比如桌面。然后,你可以使用以下命令解压安装包: ``` tar -zxvf /path/to/redis-5.0.12.tar.gz ``` 接下来,进入解压后的目录,并执行以下命令进行编译和安装: ``` cd /path/to/redis-5.0.12 make sudo make install ``` 这将编译和安装Redis。\[2\] 无论你选择哪种方法,安装完成后,你就可以在Ubuntu 20.04上使用Redis了。 #### 引用[.reference_title] - *1* [如何在 Ubuntu 20.04安装配置 Redis](https://blog.csdn.net/yang_hui1986527/article/details/106608928)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Ubuntu20.04安装Redis](https://blog.csdn.net/m0_63042291/article/details/125686359)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Ubuntu20.04安装redis](https://blog.csdn.net/weixin_40442879/article/details/125175924)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值