Linux上安装Redis,配置远程连接等

先把Redis下载导本地,https://redis.io/download
在这里插入图片描述

通过xftp等工具把下载的文件放到Linux上,我这里是放到了 /usr/local 文件夹中

[root@localhost ~]# cd /usr/local
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  redis-6.2.4.tar.gz  sbin  share  src

#解压文件
[root@localhost local]# tar xzf redis-6.2.4.tar.gz 
#进入解压的文件夹
[root@localhost local]# cd redis-6.2.4/
#编译
[root@localhost redis-6.2.4]# make

编译完成后启动Redis服务端

[root@localhost redis-6.2.4]# src/redis-server
7972:C 29 Jun 2021 03:53:50.969 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7972:C 29 Jun 2021 03:53:50.969 # Redis version=6.2.4, bits=64, commit=00000000, modified=0, pid=7972, just started
7972:C 29 Jun 2021 03:53:50.969 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-s
erver /path/to/redis.conf7972:M 29 Jun 2021 03:53:50.969 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7972:M 29 Jun 2021 03:53:50.969 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7972
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7972:M 29 Jun 2021 03:53:50.972 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the 
lower value of 128.7972:M 29 Jun 2021 03:53:50.972 # Server initialized
7972:M 29 Jun 2021 03:53:50.972 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue 
add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.7972:M 29 Jun 2021 03:53:50.972 * Ready to accept connections
7972:M 29 Jun 2021 04:53:51.016 * 1 changes in 3600 seconds. Saving...
7972:M 29 Jun 2021 04:53:51.031 * Background saving started by pid 8683
8683:C 29 Jun 2021 04:53:51.036 * DB saved on disk
8683:C 29 Jun 2021 04:53:51.036 * RDB: 2 MB of memory used by copy-on-write
7972:M 29 Jun 2021 04:53:51.134 * Background saving terminated with success

因为上面使用默认配置,默认配置是没有在后台运行的,所以重新打开一个Termina,启动Redis客户端

#需要在Redis的安装目录启动,否则会报错
[root@localhost ~]# src/redis-cli
-bash: src/redis-cli: No such file or directory
#进入redis的安装目录
[root@localhost ~]# cd /usr/local
[root@localhost local]# cd redis-6.2.4/
#启动客户端
[root@localhost redis-6.2.4]# src/redis-cli
#设置 key value
127.0.0.1:6379> set foo bar
OK
# 获取key得到value
127.0.0.1:6379> get foo
"bar"

通过上面简单操作证明Redis已经安装成功

修改Redis的配置

[root@localhost redis-6.2.4]# vi redis.conf

让Redis后台启动,把daemonize no 改为 daemonize yes
在这里插入图片描述
bind 修改成自己的IP,protected-mode yes改为protected-mode no
在这里插入图片描述
设置密码
把#去掉然后修改成自己想要的密码,如果不改 foobared就是密码
在这里插入图片描述
上面已经配置完毕了,现在来干掉开启启动的Redis进程

[root@localhost redis-6.2.4]# ps -ef|grep redis
root       9370   3579  0 05:55 pts/1    00:00:00 src/redis-server *:6379
root       9384   7994  0 05:57 pts/2    00:00:00 grep --color=auto redis
[root@localhost redis-6.2.4]# kill -9 9370

启动Redis

[root@localhost redis-6.2.4]# ./src/redis-server redis.conf

启动自带客户端 ./src/redis-cli -h 配置的IP -p 6379 -a 密码

[root@localhost redis-6.2.4]# ./src/redis-cli -h 192.168.1.204 -p 6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.204:6379> set aaa bbb
OK
192.168.1.204:6379> get aaa
"bbb"
192.168.1.204:6379> 

也可以用RedisManager进行测试
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值