先把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进行测试