Redis编译安装
文档说明
本文作者:SwBack
创作时间:2024/3/26 17:19:19
知乎:https://www.zhihu.com/people/back-88-87
CSDN:https://blog.csdn.net/qq_30817059
百度搜索: SwBack
系统: Ubuntu
redis: 2.8.17
下载redis源代码,并进行解压
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
tar -zxvf redis-2.8.17.tar.gz
cd redis-2.8.17
make
make安装
make未安装时会出现如下情况
root@ubuntu:~/redis-2.8.17# make
Command 'make' not found, but can be installed with:
apt install make
apt install make-guile
按照指示进行安装make.
apt install make
gcc安装
gcc 未安装时会出现如下情况
root@ubuntu:~/redis-2.8.17# make
cd src && make all
make[1]: Entering directory '/root/redis-2.8.17/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
....
....
...
gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
make[3]: gcc: Command not found
Makefile:118: recipe for target 'net.o' failed
make[3]: *** [net.o] Error 127
make[3]: Leaving directory '/root/redis-2.8.17/deps/hiredis'
Makefile:45: recipe for target 'hiredis' failed
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory '/root/redis-2.8.17/deps'
Makefile:142: recipe for target 'persist-settings' failed
make[1]: [persist-settings] Error 2 (ignored)
CC adlist.o
/bin/sh: 1: cc: not found
Makefile:197: recipe for target 'adlist.o' failed
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory '/root/redis-2.8.17/src'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
apt-get install gcc
安装之后执行make
.仍然出现如下问题,原因时因为在之前gcc
未安装的时候执行make
编译失败之后存在残留的文件,需要清理一下再进行重新编译。
root@ubuntu:~/redis-2.8.17# make
cd src && make all
make[1]: Entering directory '/root/redis-2.8.17/src'
CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:10: fatal error: jemalloc/jemalloc.h: No such file or directory
#include <jemalloc/jemalloc.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:197: recipe for target 'adlist.o' failed
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory '/root/redis-2.8.17/src'
Makefile:6: recipe for target 'all' failed
make: *** [all] Error 2
make distclean && make
编译成功
指定安装目录
参数:后面跟 PREFIX=/usr/local/redis 指定redis的安装路径
make install PREFIX=/usr/local/redis
移动配置文件
cp ~/redis-2.8.17/{redis.conf,sentinel.conf} ./conf/
关闭守护进程
编辑redis.conf文件 将如下内容修改为yes
daemonize yes
配置自启动
vim /etc/systemd/system/redis.service
添加如下内容
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
# ExecStart需要按照实际情况修改成自己的地址
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
验证-生效
systemctl的一些其他命令
systemctl enable redis # 开机自启redis服务
systemctl disable redis # 取消开机自启
systemctl start redis.service # 启动redis服务
systemctl stop redis.service # 停止服务
systemctl restart redis.service # 重新启动服务
systemctl status redis.service # 查看服务当前状态
systemctl list-units --type=service # 查看所有已启动的服务
systemctl daemon-reload # 加载服务配置文件
原创申明
本文由SwBack
原创文章, 如有问题,欢迎指正。
如果转载,请标明来源!