Centos安装Redis

下载Redis

wget https://github.com/redis/redis/archive/7.0.10.tar.gz

解压

tar -zxf 7.0.10.tar.gz -C /usr/local/
cd /usr/local/redis-7.0.10
mv /usr/local/redis-7.0.10/ /usr/local/redis
cd /usr/local/redis/

安装一些依赖

yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake

编译,执行make时报错了

In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
 #include <jemalloc/jemalloc.h>

原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。
解决办法是:make时添加 MALLOC=libc参数。

继续编译

make MALLOC=libc

编译成功

按照提示运行make test,则需安装 tcl8.5 以上

http://mirror.centos.org/centos/7/os/x86_64/Packages/tcl-8.5.13-8.el7.x86_64.rpm
rpm -ivh tcl-8.5.13-8.el7.x86_64.rpm 
rm -rf tcl-8.5.13-8.el7.x86_64.rpm

运行maketest过程可能需要几分钟,可以不运行

make test

编译安装

make install

可能INSTALL后面会没有具体提示安装了什么,但是实际在/usr/local/bin/目录下多了redis-benchmark、redis-cli、redis-server这3个文件。

启动

前台启动:直接启动会占用一个链接窗口,一般是使用后台启动

redis-server

后台启动

sed -i 's/daemonize no/daemonize yes/' /usr/local/redis/redis.conf
redis-server /usr/local/redis/redis.conf 
netstat -tunlp | grep 6379

进入redis

# redis-cli 
127.0.0.1:6379>

远程连接,修改配置文件

# vim redis.conf
bind 0.0.0.0 -::1
protected-mode no

重启redis 

设置systemctl启动

# vim /etc/systemd/system/redis.service
[Unit]
Description=redis.server
After=network.target

[Service]
Type=forking
PIDFILE=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecRepload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

posted @ 2023-04-17 17:17  Maniana  阅读(57)  评论(0编辑  收藏  举报