本文介绍了redis的安装与启动。
工具 | 版本 |
linux | centos8 |
redis | 5.0.7 |
(1)redis下载
第一种方式:redis下载地址https://redis.io/download ,下载当前稳定版redis-5.0.7 tar包,发送至安装目标虚拟机。
第二种方式:通过wget工具直接从镜像地址获取 http://download.redis.io/releases/
[root@master local]# wget http://download.redis.io/releases/redis-5.0.7.tar.gz
--2020-02-29 22:15:06-- http://download.redis.io/releases/redis-5.0.7.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
redis-5.0.7.tar.gz 100%[===================>] 1.89M 5.80KB/s 用时 5m 45s
2020-02-29 22:20:52 (5.61 KB/s) - 已保存 “redis-5.0.7.tar.gz” [1984203/1984203])
(2)安装与启动
1)解压tar包
[root@master local]# tar -zxvf redis-5.0.7.tar.gz
2)编译安装
[root@master local]# cd redis-5.0.7/
#安装make工具
[root@master redis-5.0.7]# yum -y install make
#安装gcc库
[root@master redis-5.0.7]# yum -y install gcc
#编译,如果此前有编译失败的情况先使用make distclean命令清一下原编译失败文件
[root@master redis-5.0.7]# make
Hint: It's a good idea to run 'make test' ;)
make[1]: 离开目录“/usr/local/redis-5.0.7/src”
编译成功后,进入redis的src路径下进行安装操作
[root@master src]# make install
CC Makefile.dep
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
3)部署
[root@master src]# cd ../
#在redis-5.0.7路径下创建etc与bin路径用于放置管理一些常用文件
[root@master redis-5.0.7]# mkdir etc
[root@master redis-5.0.7]# mkdir bin
[root@master redis-5.0.7]# mv redis.conf /usr/local/redis-5.0.7/etc/
[root@master redis-5.0.7]# cd src/
[root@master src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis-5.0.7/bin/
4)启动redis
[root@master src]# cd ../
[root@master redis-5.0.7]# cd bin/
[root@master bin]# ls
mkreleasehdr.sh redis-check-aof redis-cli
redis-benchmark redis-check-rdb redis-server
[root@master bin]# ./redis-server
32128:C 29 Feb 2020 22:59:26.977 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
32128:C 29 Feb 2020 22:59:26.977 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=32128, just started
32128:C 29 Feb 2020 22:59:26.977 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
32128:M 29 Feb 2020 22:59:26.977 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 32128
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
#查看redis的进程信息
[root@master ~]# ps -ef|grep redis
root 32128 1247 0 22:59 pts/0 00:00:00 ./redis-server *:6379
root 32171 32149 0 23:04 pts/1 00:00:00 grep --color=auto redis
5)配置redis
[root@master etc]# cd /usr/local/redis-5.0.7/etc
#所有关于redis的参数配置都可在conf文件中进行,在这我修改了redis访问地址、访问密码、后台运行参数
[root@master etc]# vi redis.conf
bind 192.168.225.100 #绑定访问ip,远程连接地址
daemonize yes #开启后台运行
requirepass 123456 #设置密码
protected mode no #关闭安全保护(远程访问需要关闭,因设置了redis访问密码,故问题不大)
6)配置结束再次启动redis
[root@master etc]# cd ../
[root@master redis-5.0.7]# cd bin/
[root@master bin]# redis-server /usr/local/redis/etc/redis.conf
#再次启动redis服务,并指定启动服务配置文件,注意这儿不指定会导致配置文件失效,其他服务器无法连接redis
[root@master bin]# ./redis-server /usr/local/redis-5.0.7/etc/redis.conf
32696:C 01 Mar 2020 00:02:42.565 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
32696:C 01 Mar 2020 00:02:42.565 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=32696, just started
32696:C 01 Mar 2020 00:02:42.565 # Configuration loaded
[root@master bin]# ps -ef|grep redis
root 32697 1 0 00:02 ? 00:00:00 ./redis-server 192.168.225.100:6379
root 32702 1247 0 00:02 pts/0 00:00:00 grep --color=auto redis
到此,redis安装及配置结束。