1.去官网查看,可以看到安装步骤
--下载,提取和编译Redis
$ wget https://download.redis.io/releases/redis-6.0.9.tar.gz
$ tar xzf redis-6.0.9.tar.gz
$ cd redis-6.0.9
$ make
-- 编译的二进制文件可以在src目录中找到,运行Redis
$ src/redis-server
--使用内置客户端与Redis交互
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
2.使用官网给的命令下载并解压redis,结果如下图
3.为了方便管理,后续的所有软件统一放在/usr/local/文件夹下
--把redis-6.0.9移动到/usr/local/下并改名为redis
mv /home/redis-6.0.9 /usr/local/redis
4.编译
cd /usr/local/redis/
make
5.编译成功后,进入src文件夹,执行make install进行Redis安装
[root@xxx redis]# cd ./src/
[root@xxx src]# make install
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
[root@xxx src]#
6.为了方便管理,将Redis文件中的conf配置文件和常用命令移动到统一文件中
[root@xxx src]# cd ../
[root@xxx redis]# mkdir etc
[root@xxx redis]# mkdir bin
[root@xxx redis]# ls
00-RELEASENOTES BUGS COPYING etc Makefile README.md runtest runtest-moduleapi sentinel.conf tests utils
bin CONTRIBUTING deps INSTALL MANIFESTO redis.conf runtest-cluster runtest-sentinel src TLS.md
[root@xxx redis]# mv ./redis.conf ./etc/
[root@xxx redis]# cd ./src/
[root@xxx src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server ../bin/
[root@xxx src]# cd ../bin/
[root@xxx bin]# ls
mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server
[root@xxx bin]#
7.执行redis-server 启动redis
[root@xxx bin]# ./redis-server
526:C 01 Dec 2020 15:54:51.171 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
526:C 01 Dec 2020 15:54:51.171 # Redis version=6.0.9, bits=64, commit=00000000, modified=0, pid=526, just started
526:C 01 Dec 2020 15:54:51.171 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.0.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 526
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
526:M 01 Dec 2020 15:54:51.172 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
526:M 01 Dec 2020 15:54:51.172 # Server initialized
526:M 01 Dec 2020 15:54:51.172 # 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.
526:M 01 Dec 2020 15:54:51.172 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never').
526:M 01 Dec 2020 15:54:51.173 * Ready to accept connections
至此redis安装成功
8.设置后台启动redis
--编辑conf文件,将daemonize属性改为yes(表明需要在后台运行)
[root@xxx bin]# vim ../etc/redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes
9.再次启动redis服务,并指定启动服务配置文件,连接客户端试试看
[root@xxx bin]# ./redis-server ../etc/redis.conf
[root@xxx bin]# ./redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
10.对外开放6379端口号
[root@xxx bin]# sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@xxx bin]# sudo firewall-cmd --reload
success
[root@xxx bin]#
11.开启远程连接并设置密码
--打开配置文件把 bind 127.0.0.1 注释掉,找到 # requirepass foobared放开并把foobared替换成自己的密码
[root@xxx bin]# vim ../etc/redis.conf
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 loopback interface address (this means Redis will only be able to
# accept client connections from the same host that it is running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 允许远程访问
#bind 127.0.0.1
# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# requirepass foobared
requirepass abc
# Command renaming (DEPRECATED).
12.再次启动redis服务,并指定启动服务配置文件重新测试
[root@xxx bin]# ./redis-cli
127.0.0.1:6379> shutdown
not connected>
[root@xxx bin]# ./redis-server ../etc/redis.conf
[root@xxx bin]# ./redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth abc
OK
127.0.0.1:6379> ping
PONG
[root@xxx bin]#
13.打开本地dos窗口测试
C:\Redis-x64-3.2.100>redis-cli.exe -h [xxx你自己的服务器公网ip] -p 6379 -a abc
xxx:6379> ping
PONG
xxx:6379>
至此大功告成!