centos7下安装Redis5.0.2

1、下载redis 地址 http://download.redis.io/releases/redis-5.0.2.tar.gz

2、解压tar -zxf redis-5.0.2.tar.gz

3、make编译

3.1 如果缺少gcc环境需要

      yum install gcc

3.2 报错:

[root@lang redis-5.0.2]#

make

make all

make[1]: Entering directory `/usr/local/redis-4.0.10/src'

CC adlist.o

In file included from adlist.c:34:

zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory

zmalloc.h:55:2: error: #error "Newer version of jemalloc required"

make[1]: *** [adlist.o] Error 1

make[1]: Leaving directory `/usr/local/redis-4.0.10/src'

make: *** [all] Error 2

redis解压目录下有个README.md文件中有如下一段话:

Selecting a non-default memory allocator when building Redis is done by setting the `MALLOC` environment variable. Redis is compiled and linked against libc malloc by default, with the exception of jemalloc being the default on Linux systems. This default was picked because jemalloc has proven to have fewer fragmentation problems than libc malloc.

To force compiling against libc malloc, use:

% make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:

% make MALLOC=jemalloc

4、编译加上MALLOC=libc 即可

make MALLOC=libc

5、运行redis

80eda7725ca08d43c4fb1292a1e98d6a.png

修改配置文件 redis.conf

daemonize no 改为 yes 后台运行:

protected-mode yes 改为no 可以不用输入密码登陆

bind 127.0.0.1  表示只可以本机访问,要是远程访问需要注释掉(前面加#号)

#requirepass foobared,去除前面的#号注释,将foobared修改成要设置的密码串

6、带配置文件后台启动

[root@lang redis-5.0.2]# src/redis-server redis.conf

7897:C 06 Dec 2018 06:25:57.484 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

7897:C 06 Dec 2018 06:25:57.484 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=7897, just started

7897:C 06 Dec 2018 06:25:57.484 # Configuration loaded

[root@lang redis-5.0.2]# ps -ef | grep redis

root       7898      1  4 06:25 ?        00:00:00 src/redis-server *:6379

root       7903   2880  0 06:25 pts/1    00:00:00 grep redis

7.设置  redis 为系统服务并开机自启

根据本机实际路径,可以确定开启和关闭redis的命令分别为

/home/redis-5.0.2/src/redis-server redis.conf  和  /home/redis-5.0.2/src/redis-cli -p 6379 shutdown

要实现开机自启,要在redis.conf中将daemonize设置为no

创建服务文件创建文件/lib/systemd/system/redis.service,设置执行权限为644,文件内容为:

复制代码
[Unit]
Description=Redis Service
After=network.target

[Service]
Type=simple
ExecStart=/home/redis-5.0.2/src/redis-server /home/redis-5.0.2/redis.conf
Execstop=/home/redis-5.0.2/src/redis-cli -p 6379 shutdown
User=root
Group=root

[Install]
WantedBy=multi-user.target
复制代码

设置服务为开机自启:

systemctl enable redis.service

手动启用服务:

systemctl start redis.service

查看redis进程:

ps -ef | grep redis

查看服务执行日志:

systemctl status redis.service -l

 

posted on   空明流光  阅读(206)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-05-06 Cent OS vsftp 配置

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示