1.Redis安装指南
1.1 官网地址
下载地址:Downloads - Redis
中文文档:redis中文文档
Redis在线练习:https://try.redis.io/
参考手册:http://doc.redisfans.com/
1.2 Linux版安装 (redis-7.2)
1.2.1 配置gcc环境
检查有没有gcc:gcc -v
若没有,安装gcc:yum -y install gcc-c++
1.2.2 安装redis
解压压缩包至 /opt
目录下
安装:make && make install
(默认安装目录:usr/local/bin
)
(出现Hint: It's a good idea to run 'make test' ;)
,则安装成功)
redis-benchmark:性能测试工具,服务启动后运行该命令
redis-check-aof:修复有问题的AOF文件
redis-check-rdb:修复有问题的rdb文件
redis-cli:客户端,操作入口
redis-sentinel:redis集群使用
redis-server:redis服务器启动命令
1.2.3 配置文件
配置文件在 /opt/redis-7.2/redis.conf
是先拷贝一份默认的conf文件保存着
[root@localhost redis-7.2]# mkdir /myredis
[root@localhost redis-7.2]# cp redis.conf /myredis/redis7.conf
修改 /opt/redis-7.2/redis.conf
配置文件
修改前 | 修改后 |
---|---|
daemonize no | daemonize yes |
protected-mode yes | protected-mode no |
bind 127.0.0.1 | # bind 127.0.0.1 |
# requirepass foobared | requirepass 自定义密码 |
根据配置文件启动redis服务
redis-server /myredis/redis7.conf
若报错:
WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
执行:
echo 1 > /proc/sys/vm/overcommit_memory
然后重新启动redis
1.2.4 连接redis客户端
redis-cli -a 密码 [-p 端口号]
或
redis-cli
auth 密码
端口号默认为6379
1.2.5 查看Redis版本
redis-server -v
1.2.6 检查
127.0.0.1:6379> ping
PONG
安装配置成功
1.2.7 关闭Redis客户端
quit
1.2.8 关闭Redis服务器
(1)客户端内部退出
SHUTDOWN
(2)客户端外部退出
单实例关闭:
redis-cli -a 密码 shutdown
多实例关闭(指定端口关闭):
redis-cli -p 端口号 shutdown
1.2.9 卸载
停止Redis服务
rm -rfv /usr/local/bin/redis-*
删除 /usr/local/lib
目录下与redis相关的文件