【CentOS 7.3】redis 安装部署

本文档详细介绍了在Linux环境中下载、解压Redis 5.0.8安装包,然后进行编译安装、设置为系统服务并后台启动的步骤。此外,还演示了如何修改配置文件以允许远程连接和设置访问密码,确保服务器安全运行。
摘要由CSDN通过智能技术生成

1、准备 redis 安装包

这里下载的是 redis-5.0.8.tar.gz 安装包,并将其直接放在了 root 目录下

2、解压安装包

在 /usr/local/ 目录下创建 redis ⽂件夹

[root@localhost ~]# cd /usr/local/
[root@localhost local]# mkdir redis

将 redis 安装包解压到 /usr/local/redis 中

[root@localhost ~]# tar -zxvf redis-5.0.8.tar.gz -C /usr/local/redis

解压完之后, /usr/local/redis 目录中会出现⼀个 redis-5.0.8 的目录

3、编译并安装

进入 redis-5.0.8 目录编译安装

[root@localhost ~]# cd /usr/local/redis/redis-5.0.8
[root@localhost redis-5.0.8]# make && make install

4、将 redis 安装为系统服务并后台启动

进入 utils ⽬录,并执行如下脚本:
注意:我这里全部选择的是默认配置(直接回车),有需要可以按需配置

[root@localhost redis-5.0.8]# cd utils/
[root@localhost utils]# ./install_server.sh

Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selected default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] 
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] 
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

5、查看 redis 服务启动情况

执行如下命令查看 redis 启动结果:

[root@localhost utils]# systemctl status redis_6379.service
● redis_6379.service - LSB: start and stop redis_6379
   Loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
   Active: active (running) since Thu 2021-05-06 11:48:47 CST; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 13382 ExecStop=/etc/rc.d/init.d/redis_6379 stop (code=exited, status=0/SUCCESS)
  Process: 13385 ExecStart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/redis_6379.service
           └─13388 /usr/local/bin/redis-server 0.0.0.0:6379

May 06 11:48:47 localhost:localdomain systemd[1]: Starting LSB: start and stop redis_6379...
May 06 11:48:47 localhost:localdomain redis_6379[13385]: Starting Redis server...
May 06 11:48:47 localhost:localdomain systemd[1]: Started LSB: start and stop redis_6379.

6、启动 redis 客户端并测试

启动自带的 redis-cli 客户端,测试通过:

[root@localhost utils]# redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"

但此时只能在本地访问,无法远程连接,因此还需要做部分设置

6、设置允许远程连接和访问密码

编辑 redis 配置文件

[root@localhost utils]# vim /etc/redis/6379.conf

将其中的 bind 127.0.0.1 修改为 bind 0.0.0.0
找到如下内容:

#requirepass foobared

去掉注释,将 foobared 修改为自己的密码,如:

requirepass 123456

保存,重启 redis 服务:

[root@localhost utils]# systemctl restart redis_6379.service

这样后续的访问需要先输入密码认证通过

[root@localhost utils]# redis-cli
127.0.0.1:6379> get foo
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> get foo
"bar"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值