本文摘选至 fc@肥你个陈
给自己和各位同行提供个方便
1、Yum 方式安装最新版本 Redis
1、安装 redis-rpm源
[root@qfedu.com ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
2、安装 Redis
[root@qfedu.com ~]# yum -y --enablerepo=remi install redis
3、开机自启 Redis
[root@qfedu.com ~]# systemctl enable redis
4、设置redis.conf
- 允许远程登录: bind 127.0.0.1 改为 bind 0.0.0.0 (可选)
[root@qfedu.com ~]# vim /etc/redis.conf
5、查看 redis 版本
[root@qfedu.com ~]# redis-cli --version
redis-cli 6.0.5
[root@qfedu.com ~]# redis-server --version
Redis server v=6.0.5 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9a4d86f46872a5a6
6、连接 redis
[root@qfedu.com ~]# redis-cli -h 192.168.152.161 -p 6379
192.168.152.161:6379>
2、编译安装最新版本redis
1、编译安装 Redis
1、安装gcc套装
[root@qfedu.com ~]# yum -y install gcc glibc glibc-kernheaders glibc-common glibc-devel make
2、升级gcc
[root@qfedu.com ~]# yum -y install centos-release-scl
[root@qfedu.com ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@qfedu.com ~]# scl enable devtoolset-9 bash
3、设置永久升级
[root@qfedu.com ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
4、安装redis
[root@qfedu.com ~]# wget http://download.redis.io/releases/redis-6.0.5.tar.gz
[root@qfedu.com ~]# tar -zxvf redis-6.0.5.tar.gz -C /usr/local
[root@qfedu.com ~]# cd /usr/local/redis-6.0.5
[root@qfedu.com redis-6.0.5]# make
[root@qfedu.com redis-6.0.5]# make all
2、启动 Redis 实例
[root@qfedu.com src]# ./redis-server
21522:C 17 Jun 2019 15:36:52.038 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21522:C 17 Jun 2019 15:36:52.038 # Redis version=6.0.5, bits=64, commit=00000000, modified=0, pid=21522, just started
21522:C 17 Jun 2019 15:36:52.038 # 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.5 (00000000/0) 64 bit.-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379| `-._ `._ / _.-' | PID: 21522`-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 出现以上界面说明安装成功[root@qfedu.com src]# ./redis-cli --version # 查询是安装的最新版本的redis
redis-cli 6.0.5
[root@qfedu.com src]# ./redis-server --version
Redis server v=6.0.5 sha=00000000:0 malloc=libc bits=64 build=4db47e2324dd3c5
3、配置启动数据库
1、开启 Redis 服务守护进程
# 以./redis-server 启动方式,需要一直打开窗口,不能进行其他操作,不太方便,以后台进程方式启动 redis
[root@qfedu.com src]# vim /usr/local/redis-6.0.5/redis.conf # 默认安装好的配置文件并不在这个目录下,需要找到复制到该目录下
daemonize no 改为 daemonize yes # 以守护进程运行 [root@qfedu.com src]# ./redis-server /usr/local/redis-6.0.5/redis.conf
21845:C 17 Jun 2019 15:44:14.129 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21845:C 17 Jun 2019 15:44:14.129 # Redis version=6.0.5, bits=64, commit=00000000, modified=0, pid=21845, just started
21845:C 17 Jun 2019 15:44:14.129 # Configuration loaded
2、关闭redis进程
[root@qfedu.com src]# ps -ef|grep redis
root 21846 1 0 15:44 ? 00:00:00 ./redis-server 127.0.0.1:6379
root 22042 6950 0 15:46 pts/1 00:00:00 grep --color=auto redis
[root@qfedu.com src]# kill -9 21846# 此方法启动关闭较为麻烦,且不能设置开机自启动
3、验证redis
[root@qfedu.com redis-6.0.5]# ./src/redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set name luoyinsheng
OK
127.0.0.1:6379> get name
"luoyinsheng"
127.0.0.1:6379> exit