本文的redis安装流程仅供个人学习测试使用,真实生产环境请专业的运维同学去做 !
准备工作
- 知道redis官网,redis.io/
- 在官网中能找到下载链接, download.redis.io/releases/re…
开始安装
- 下载安装包
[root@vhpuccrv4yxgkqwq-0530595 local]# cd /usr/local/
[root@vhpuccrv4yxgkqwq-0530595 local]# wget https://download.redis.io/releases/redis-6.2.6.tar.gz>
- 解压安装包
[root@vhpuccrv4yxgkqwq-0530595 local]# tar -zxf ./redis-6.2.6.tar.gz
- 检查当前gcc版本 redis6 版本对gcc有版本要求,需要5.3以上的版本,所以检查你系统当前版本,并将它升级到最新版本
[root@vhpuccrv4yxgkqwq-0530595 local]# gcc -v
[root@vhpuccrv4yxgkqwq-0530595 local]# yum -y install centos-release-scl
[root@vhpuccrv4yxgkqwq-0530595 local]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@vhpuccrv4yxgkqwq-0530595 local]# scl enable devtoolset-9 bash
#scl命令启用只是临时的,新开的会话默认还是原gcc版本。如果要长期使用gcc 9.1的话执行下面的命令即可:
[root@vhpuccrv4yxgkqwq-0530595 local]# echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
- 进入到redis解压文件目录,准备安装
[root@vhpuccrv4yxgkqwq-0530595 local]# cd redis-6.2.6/
# 该命令的作用是检查,确保 make 安装时不会出错
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# make test
可能存在的问题,执行 make test 后报错,如下所示:
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: 离开目录“/usr/local/redis-6.2.6/src”
make: *** [test] 错误 2
解决办法,执行命令:
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# yum install tcl
- 然后执行命令
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# make install
尝试启动
- 复制一份配置文件 这么做的目的是保留原始配置文件,在你复制出来的文件上进行操作,万一有问题也可以进行参考
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# mkdir conf
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# cp redis.conf ./conf
- 启动
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# ./src/redis-server ./conf/redis.conf
启动日志:
22660:C 21 Feb 2022 23:04:31.036 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
22660:C 21 Feb 2022 23:04:31.036 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=22660, just started
22660:C 21 Feb 2022 23:04:31.036 # Configuration loaded
22660:M 21 Feb 2022 23:04:31.037 * Increased maximum number of open files to 10032 (it was originally set to 1024).
22660:M 21 Feb 2022 23:04:31.037 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 22660
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
\
22660:M 21 Feb 2022 23:04:31.037 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
22660:M 21 Feb 2022 23:04:31.037 # Server initialized
22660:M 21 Feb 2022 23:04:31.037 # 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.
22660:M 21 Feb 2022 23:04:31.037 * Ready to accept connections
到此,说明你的redis已经安装成功了,下面进行一些简单的配置。
redis 相关配置
- 环境变量配置
[root@vhpuccrv4yxgkqwq-0530595 redis-6.2.6]# cd ~
[root@vhpuccrv4yxgkqwq-0530595 ~]# vim .bash_profile
在 .bash_profile 中添加如下配置:
export REDIS_HOME=/usr/local/redis-6.2.6
export PATH=$REDIS_HOME/src:$PATH
source .bash_profile
验证环境变量是否生效
[root@vhpuccrv4yxgkqwq-0530595 ~]# redis-cli -v
redis-cli 6.2.6
- 修改配置
[root@vhpuccrv4yxgkqwq-0530595 ~]# cd /usr/local/redis-6.2.6/conf
vim redis.conf
主要修改下面几项配置:
# 注释掉这句,允许远程连接
bind 127.0.0.1
# 允许后台运行服务
daemonize yes
# 关闭保护模式,否则外部ip无法连接
protected-mode no
# 配置登录验证密码
requirepass 000
密码验证的作用:
[root@vhpuccrv4yxgkqwq-0530595 ~]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6679>
127.0.0.1:6679> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6679> auth 000
OK
127.0.0.1:6679>
127.0.0.1:6679>
你连接上redis后,如果不进行密码验证,你是没有权限进行任何操作的!
写在最后
纸上得来终觉浅,绝知此事要躬行。与君共勉,共同进步~