1.下载
#获取安装包
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
#解压
tar -xzvf redis-5.0.7.tar.gz
#在编译之前确认是否安装gcc
#如未安装,可以执行这个命令安装:yum install gcc
#在编译之前确认是否安装tcl
#如未安装,可以执行这个命令安装:yum install tcl
2.编译
[root@localhost source]# cd redis-5.0.7/
[root@localhost redis-5.0.7]# make MALLOC=libc
说明:make 后加 MALLOC的参数的原因:
避免提示找不到 jemalloc/jemalloc.h
3.测试编译
make test
如果看到以下字样:表示无错误:
\o/ All tests passed without errors!
启动服务为src 下 redis-server 配置文件为根目录下 redis.conf
配置: redis.conf 设置以下三个个地方:
#是否在后台执行,yes:后台运行;no:不是后台运行(老版本默认)
daemonize yes
# maxmemory <bytes>
maxmemory 128MB
#指定 redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求
bind 0.0.0.0
#redis的进程文件
pidfile /var/run/redis/redis-server.pid
#redis监听的端口号。
port 6379
# 此参数为设置客户端空闲超过timeout,服务端会断开连接,为0则服务端不会主动断开连接,不能小于0。
timeout 0
#数据库的数量,默认使用的数据库是DB 0。可以通过”SELECT “命令选择一个db
databases 16
#数据目录,数据库的写入会在这个目录。rdb、aof文件也会写在这个目录
dir /var/lib/redis
说明:分别是以daemon方式独立运行 / 内存的最大使用限制 /
4,运行:
[root@localhost conf]# /usr/home/redis/redis-5.0.7/src/redis-server /usr/home/redis/redis-5.0.7/redis.conf
5.检查端口是否在使用中
[root@localhost conf]# netstat -anp | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 16073/redis-server
6.查看redis的当前版本:
[root@localhost conf]# /usr/local/soft/redis5/bin/redis-server -v
Redis server v=5.0.7 sha=00000000:0 malloc=libc bits=64 build=8e31d2ed9a4c9593
7.使redis可以用systemd方式启动和管理
1,编辑service文件
[root@localhost liuhongdi]# vim /lib/systemd/system/redis.service
#service文件内容:
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
8.重载系统服务
[root@localhost liuhongdi]# systemctl daemon-reload
9.用来管理redis
启动
systemctl start redis
查看状态
systemctl status redis
使开机启动
systemctl enable redis
10 查看本地centos的版本:
[root@localhost lib]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)