# Redis安装指南
# 1. 安装G++编译器
yum install -y gcc-c++
# 2. 下载Redis
下载Redis
wget http://download.redis.io/releases/redis-6.2.5.tar.gz
解压
tar -zvxf redis-6.2.5.tar.gz
移动到指定目录
mv redis-6.2.5 redis /usr/local/redis
# redis安装
# 1. 编译
cd /usr/local/redis
make
例如:
[root@192 redis]# pwd
/usr/local/redis
[root@192 redis]# make
# 2. 安装
make install PREFIX=/usr/local/redis/ 后面的是你想要安装的路径
例如:
[root@192 redis]# make install PREFIX=/usr/local/redis
cd src && make install
make[1]: Entering directory `/usr/local/redis/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/src'
make[1]: Entering directory `/usr/local/redis/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis/src'
这里多了一个关键字 PREFIX= 这个关键字的作用是编译的时候用于指定程序存放的路径。比如我们现在就是指定了redis必须存放在/usr/local/redis目录。假设不添加该关键字Linux会将可执行文件存放在/usr/local/bin目录,库文件会存放在/usr/local/lib目录。配置文件会存放在/usr/local/etc目录。其他的资源文件会存放在usr/local/share目录。这里指定号目录也方便后续的卸载,后续直接rm -rf /usr/local/redis 即可删除redis。
# 3. 修改配置
- redis配置文件修改,将源代码目录中的配置文件redis.conf拷贝到redis安装路径目录下
- 将bind配置修改为:
bind * -::*
说明:bind属性为:绑定的IP。与protected-mode属性关联使用,此处暂且取消IP绑定,可根据实际情况而定!
- 将notify-keyspace-events属性的值改为K$g
说明:notify-keyspace-events属性为:事件通知
- 将protected-mode属性的值由yes改为no
说明:protected-mode属性为:是否开启保护模式。如关闭,则外部网络可直接访问;如开启,则需配置bind ip或者设置访问密码。此处暂且关闭,可根据实际情况而定!
- 将daemonize属性的值由no改为yes
说明:daemonize属性为:是否开启后台启动。开启后可确保控制台关闭后,进程在后台继续正常运行!
- 将logfile属性的值改为本机日志存放路径
此路径需要先创建,只需创建到log即可
- 将dir属性的值改为本机rdb/AOF文件的存放路径
此路径需要先创建
# 4 . redis验证
启动redis 根据上面的操作已经将redis安装完成了。在目录/usr/local/redis 输入下面命令启动redis
./bin/redis-server ./redis.conf
启动后界面
[root@192 redis]# ./bin/redis-server ./redis.conf 8305:C 14 Jul 2022 03:11:47.631 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 8305:C 14 Jul 2022 03:11:47.631 # Redis version=5.0.12, bits=64, commit=00000000, modified=0, pid=8305, just started 8305:C 14 Jul 2022 03:11:47.631 # Configuration loaded 8305:M 14 Jul 2022 03:11:47.631 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.12 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 8305 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 8305:M 14 Jul 2022 03:11:47.634 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 8305:M 14 Jul 2022 03:11:47.634 # Server initialized 8305:M 14 Jul 2022 03:11:47.634 # 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. 8305:M 14 Jul 2022 03:11:47.634 # 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 never > /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. 8305:M 14 Jul 2022 03:11:47.634 * Ready to accept connections
安装成功 按ctrl+c即可退出
常用命令
bin/redis-server redis.conf 根据配置文件启动 bin/redis-cli shutdown 停止