安装教程
1、下载
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
image.png
2、解压
tar -zxvf redis-5.0.8.tar.gz
解压成功
3、编译
cd redis-5.0.8
make
make install
4、启动
src/redis-server
运行成功
配置教程
1、配置redis服务器允许远程连接
默认情况下,redis只允许本机访问。如果需要外部访问,需要修改配置文件。
修改配置文件redis.conf:
修改第70行,将bind 127.0.0.1 注释
#bind 127.0.0.1
修改第90行,将protected-mode修改为no
protected-mode no
2、配置redis允许后台启动
daemonize yes
3、Redis配置自启动
,在/lib/systemd/system目录下创建一个脚本文件redis.service,里面的内容如下:
[Unit]
Description=Redis
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf --daemonize no
ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown
[Install]
WantedBy=multi-user.target
[Unit] 表示这是基础信息
Description 是描述
After 是在那个服务后面启动,一般是网络服务启动后启动
[Service] 表示这里是服务信息
ExecStart 是启动服务的命令
ExecStop 是停止服务的指令
[Install] 表示这是是安装相关信息
WantedBy 是以哪种方式启动:multi-user.target表明当系统以多用户方式(默认的运行级别)启动时,这个服务需要被自动运行。
./redis-server redis.conf
报错集锦
1、redis make install出错:
[root@localhost redis-5.0.8]# make
cd src && make all
make[1]: 进入目录“/usr/local/redis-5.0.8/src”
CC Makefile.dep
make[1]: 离开目录“/usr/local/redis-5.0.8/src”
make[1]: 进入目录“/usr/local/redis-5.0.8/src”
CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/usr/local/redis-5.0.8/src”
make: *** [all] 错误 2
原因是因为未安装gcc
解决方法:
yum install gcc-c++ -y
2、致命错误:jemalloc/jemalloc.h:没有那个文件或目录
cd src && make all
make[1]: 进入目录“/usr/local/redis-5.0.8/src”
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
#include <jemalloc/jemalloc.h>
^
编译中断。
make[1]: *** [adlist.o] 错误 1
make[1]: 离开目录“/usr/local/redis-5.0.8/src”
make: *** [all] 错误 2
image.png
错误原因:
分配器allocator, 如果有MALLOC 这个 环境变量, 会有用这个环境变量的 去建立Redis。而且libc 并不是默认的 分配器, 默认的是 jemalloc, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。
运行如下命令:
make MALLOC=libc
成功这个挺好看的
[root@localhost redis-5.0.8]# src/redis-server
9975:C 26 Nov 2021 16:25:13.396 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9975:C 26 Nov 2021 16:25:13.396 # Redis version=5.0.8, bits=64, commit=00000000, modified=0, pid=9975, just started
9975:C 26 Nov 2021 16:25:13.396 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
9975:M 26 Nov 2021 16:25:13.398 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.8 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 9975
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
9975:M 26 Nov 2021 16:25:13.402 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9975:M 26 Nov 2021 16:25:13.402 # Server initialized
9975:M 26 Nov 2021 16:25:13.402 # 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.
9975:M 26 Nov 2021 16:25:13.403 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
9975:M 26 Nov 2021 16:25:13.403 * Ready to accept connections
网友评论