1. Redis的tar安装
1.1 下载与安装
1.1.1 redis官网下载tar文件
进入到redis官网复制下载地址
到linux指定目录下下载tar文件:
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
1.1.2 下载gcc编译器
yum install gcc
[root@yhx redis]# gcc --version
gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1.1.3 解压
tar -zxvf redis-6.2.5.tar.gz
[root@yhx redis]# ls
redis-6.2.5 redis-6.2.5.tar.gz
1.1.4 编译与安装
# 编译
[root@yhx redis]# cd redis-6.2.5/
[root@yhx redis-6.2.5]# make
# 安装
make install
1.1.5 安装目录
安装完成后,安装目录在 /usr/local/bin
- redis-benchmark:性能测试工作,可以在自己本子运行,看看自己本子性能如何
- redis-check-aof:修复有问题的AOF文件
- redis-check-dump:修复有问题的dump.rdb文件
- redis-sentinel:redis集群使用
- redis-server:Redis服务器启动命令
- redis-cli:客户端,操作入口
1.2 启动
1.2.1 前台启动
不建议,退出后就会关闭
[root@yhx bin]# redis-server
64161:C 27 Jul 2021 19:52:31.377 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
64161:C 27 Jul 2021 19:52:31.377 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=64161, just started
64161:C 27 Jul 2021 19:52:31.377 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
64161:M 27 Jul 2021 19:52:31.377 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 64161
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
64161:M 27 Jul 2021 19:52:31.378 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
64161:M 27 Jul 2021 19:52:31.378 # Server initialized
64161:M 27 Jul 2021 19:52:31.378 # 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.
64161:M 27 Jul 2021 19:52:31.378 * Ready to accept connections
1.2.2 后台启动
- 到文件目录下复制redis.conf(关于redis.conf的配置详解,可以参考:redis.conf详解)
[root@yhx redis-6.2.5]# cp redis.conf /etc/redis.conf
- 后台启动设置daemonize no 改为yes
################################# GENERAL #####################################
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize yes
- redis 启动
[root@yhx bin]# redis-server /etc/redis.conf
[root@yhx bin]# ps -ef |grep redis
root 64539 1 0 20:01 ? 00:00:00 redis-server 127.0.0.1:6379
root 64578 59151 0 20:01 pts/0 00:00:00 grep --color=auto redis
- 客户端访问与测试
[root@yhx bin]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
1.3 配置systemctl控制
在 /etc/systemd/system 下新建redis.service,并添加一下内容
注意 /usr/local/redis 路径修改成自己安装的redis路径
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecReload=/usr/local/bin/redis-server -s reload
ExecStop=/usr/local/bin/redis-server -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置完以后就可以 运行 systemctl start redis 启动redis
systemctl的一些其他命令
systemctl enable redis # 开机自启redis服务
systemctl disable redis # 取消开机自启
systemctl start redis # 启动redis服务
systemctl stop redis # 停止服务
systemctl restart redis # 重新启动服务
systemctl status redis # 查看服务当前状态
systemctl list-units --type=service # 查看所有已启动的服务
systemctl daemon-reload # 加载服务配置文件
2. yum安装(不是redis6)
1. 安装redis数据库:yum install redis
2. 下载fedora的epel仓库:yum install epel-release
(第三方软件包,提供了大量的rpm包具体见:)
3.启动redis服务:systemctl start redis
4.查看redis状态:systemctl status redis
systemctl stop redis 停止服务
systemctl restart redis 重启服务
5.查看redis进程:
6.设置开机自启动:systemctl enable redis
7.开放端口号::(先开启防火墙)
firewall-cmd --znotallow=public --add-port=80/tcp --permanent
firewall-cmd --znotallow=public --add-port=6379/tcp --permanent
注意:80端口是必须要开放的
重启防火墙:systemctl restart firewalld
8.查看端口:netstat -lnp|grep 6379
注意:如果出现这种报错
先执行命令 yum install net-tools 和 yum search ifconfig下载依赖插件
然后再重新执行命令netstat -lnp|grep 6379 就可以了9.设置redis 远程连接和密码:
输入命令vi /etc/redis.conf进入编辑模式:
将这部注释掉,否则只有本机才能访问
保护模式修改为no
如果修改端口号,修改这里就可以了,本文默认6379端口
修改密码为 123456
保存并退出编辑10.重启redis:systemctl restart redis
11.进入redis
命令redis-cli -h 127.0.0.1 -p 6379
然后输入info,提示必须验证
输入用户名和密码(auth 123456)
然后再输入info
通过key * 查看所有的键(因为还没有使用,所以是空)
12.客户端连接redis:下载一个RedisDesktopManager
配置一下连接信息,并测试连接,连接成功则可以使用了