redis服务器安装流程

avatar
作者
猴君
阅读量:0

redis官方github,Releases · tporadowski/redis · GitHub

所有版本都有,不止windows,tar.gz就是源码版本。我下载了redis-5.0.9.tar.gz

安装步骤如下:

在Linux服务器上安装Redis,可以通过以下步骤进行:

  1. 更新包管理器索引。

  2. 安装Redis。

  3. 启动Redis服务。

  4. 设置Redis为开机自启。

以下是基于Ubuntu系统的安装步骤:

# 更新包管理器索引
sudo apt-get update
 
# 安装Redis
sudo apt-get install redis-server
 
# 启动Redis服务
sudo systemctl start redis-server
 
# 设置Redis为开机自启
sudo systemctl enable redis-server
 
# 检查Redis服务状态
sudo systemctl status redis-server

对于其他Linux发行版(如CentOS、Fedora等),可能需要使用不同的包管理器命令(如yumdnf),或者从源代码编译安装。

如果需要安装特定版本或最新的Redis,可以从Redis官网下载源码并编译安装:

# 下载Redis源码
wget http://download.redis.io/releases/redis-x.y.z.tar.gz
 
# 解压源码
tar xzf redis-x.y.z.tar.gz
 
# 进入Redis目录
cd redis-x.y.z
 
# 编译安装
make
 
# 运行安装脚本
sudo make install
 
# 启动Redis
redis-server

详细步骤:

tar xzf redis-5.0.9.tar.gz

然后进入redis509的目录,然后make,结果报错一堆,我擦,别人都是成功,

make 

【注意,只有一个命令make,下面的都是报错信息】

cd src && make all

make[1]: Entering directory '/data/xul/redis-5.0.9/src'

rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark

(cd ../deps && make distclean)

make[2]: Entering directory '/data/g/redis-5.0.9/deps'

(cd hiredis && make clean) > /dev/null || true

(cd linenoise && make clean) > /dev/null || true

(cd lua && make clean) > /dev/null || true

(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true

/bin/sh: 1: cd: can't cd to jemalloc

(rm -f .make-*)

make[2]: Leaving directory '/data/xu/redis-5.0.9/deps'

(rm -f .make-*)

echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .make-settings

echo WARN=-Wall -W -Wno-missing-field-initializers >> .make-settings

echo OPT=-O2 >> .make-settings

echo MALLOC=jemalloc >> .make-settings

echo CFLAGS= >> .make-settings

echo LDFLAGS= >> .make-settings

echo REDIS_CFLAGS= >> .make-settings

echo REDIS_LDFLAGS= >> .make-settings

echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -DREDIS_STATIC='' -Wall -W -Wno-missing-field-initializers -O2 -g -ggdb   -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings

echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings

(cd ../deps && make hiredis linenoise lua jemalloc)

make[2]: Entering directory '/data/x/redis-5.0.9/deps'

(cd hiredis && make clean) > /dev/null || true

(cd linenoise && make clean) > /dev/null || true

(cd lua && make clean) > /dev/null || true

(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true

/bin/sh: 1: cd: can't cd to jemalloc

(rm -f .make-*)

(echo "" > .make-cflags)

(echo "" > .make-ldflags)

MAKE hiredis

cd hiredis && make static

make[3]: Entering directory '/data/x/redis-5.0.9/deps/hiredis'

cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c

In file included from hiredis.h:36,

                 from net.h:38,

                 from net.c:60:

read.h:78:50: error: unknown type name ‘PORT_LONGLONG’

   78 |     void *(*createInteger)(const redisReadTask*, PORT_LONGLONG);

      |                                                  ^~~~~~~~~~~~~

In file included from hiredis.h:45,

                 from net.h:38,

                 from net.c:60:

sds.h:295:21: error: unknown type name ‘PORT_LONGLONG’

  295 | sds sdsfromlonglong(PORT_LONGLONG value);

      |                     ^~~~~~~~~~~~~

In file included from net.h:38,

                 from net.c:60:

hiredis.h:119:5: error: unknown type name ‘PORT_LONGLONG’

  119 |     PORT_LONGLONG integer; /* The integer when type is REDIS_REPLY_INTEGER */

      |     ^~~~~~~~~~~~~

net.c:212:53: error: unknown type name ‘PORT_LONG’

  212 | static int redisContextTimeoutMsec(redisContext *c, PORT_LONG *result)

      |                                                     ^~~~~~~~~

net.c:235:51: error: unknown type name ‘PORT_LONG’

  235 | static int redisContextWaitReady(redisContext *c, PORT_LONG msec) {

      |                                                   ^~~~~~~~~

net.c: In function ‘_redisContextConnectTcp’:

net.c:337:2: error: unknown type name ‘PORT_LONG’

  337 |  PORT_LONG timeout_msec = -1;

      |  ^~~~~~~~~

net.c:352:4: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]

  352 |    free(c->tcp.host);

      |    ^~~~

net.c:352:4: warning: incompatible implicit declaration of built-in function ‘free’

net.c:61:1: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’

   60 | #include "net.h"

  +++ |+#include <stdlib.h>

   61 | #include "sds.h"

net.c:360:18: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]

  360 |     c->timeout = malloc(sizeof(struct timeval));

      |                  ^~~~~~

net.c:360:18: warning: incompatible implicit declaration of built-in function ‘malloc’

net.c:360:18: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’

net.c:367:4: warning: incompatible implicit declaration of built-in function ‘free’

  367 |    free(c->timeout);

      |    ^~~~

net.c:367:4: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’

net.c:371:6: warning: implicit declaration of function ‘redisContextTimeoutMsec’; did you mean ‘redisContextSetTimeout’? [-Wimplicit-function-declaration]

  371 |  if (redisContextTimeoutMsec(c, &timeout_msec) != REDIS_OK) {

      |      ^~~~~~~~~~~~~~~~~~~~~~~

      |      redisContextSetTimeout

net.c:377:3: warning: incompatible implicit declaration of built-in function ‘free’

  377 |   free(c->tcp.source_addr);

      |   ^~~~

net.c:377:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’

net.c:381:3: warning: incompatible implicit declaration of built-in function ‘free’

  381 |   free(c->tcp.source_addr);

      |   ^~~~

net.c:381:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’

net.c:460:9: warning: implicit declaration of function ‘redisContextWaitReady’; did you mean ‘redisContextCloseF’? [-Wimplicit-function-declaration]

  460 |     if (redisContextWaitReady(c, timeout_msec) != REDIS_OK)

      |         ^~~~~~~~~~~~~~~~~~~~~

      |         redisContextCloseFd

net.c: In function ‘redisContextConnectUnix’:

net.c:510:2: error: unknown type name ‘PORT_LONG’

  510 |  PORT_LONG timeout_msec = -1;

      |  ^~~~~~~~~

net.c:524:18: warning: incompatible implicit declaration of built-in function ‘malloc’

  524 |     c->timeout = malloc(sizeof(struct timeval));

      |                  ^~~~~~

net.c:524:18: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’

net.c:531:4: warning: incompatible implicit declaration of built-in function ‘free’

  531 |    free(c->timeout);

      |    ^~~~

net.c:531:4: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’

make[3]: *** [Makefile:118: net.o] Error 1

make[3]: Leaving directory '/data/xu/redis-5.0.9/deps/hiredis'

make[2]: *** [Makefile:46: hiredis] Error 2

make[2]: Leaving directory '/data/x/redis-5.0.9/deps'

make[1]: [Makefile:200: persist-settings] Error 2 (ignored)

    CC adlist.o

In file included from adlist.c:36:

adlist.h:56:5: error: unknown type name ‘PORT_ULONG’

   56 |     PORT_ULONG len;

      |     ^~~~~~~~~~

adlist.h:88:33: error: unknown type name ‘PORT_LONG’

   88 | listNode *listIndex(list *list, PORT_LONG index);

      |                                 ^~~~~~~~~

In file included from adlist.c:37:

zmalloc.h:55:10: fatal error: jemalloc/jemalloc.h: No such file or directory

   55 | #include <jemalloc/jemalloc.h>

      |          ^~~~~~~~~~~~~~~~~~~~~

compilation terminated.

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

make[1]: Leaving directory '/data//redis-5.0.9/src'

make: *** [Makefile:6: all] Error 2

后来发现我是Ubuntu的系统,直接按照第一个方法即可安装成功。

● redis-server.service - Advanced key-value store

     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)

     Active: active (running) since Thu 2024-08-29 10:31:09 CST; 31s ago

       Docs: http://redis.io/documentation,

             man:redis-server(1)

   Main PID: 1396096 (redis-server)

     Status: "Ready to accept connections"

      Tasks: 5 (limit: 151631)

     Memory: 13.2M

        CPU: 36ms

     CGroup: /system.slice/redis-server.service

             └─1396096 /usr/bin/redis-server 127.0.0.1:6379

Aug 29 10:31:09 bigdata-offline-flask-service-node02-75-72 systemd[1]: Starting Advanced key-value store...

Aug 29 10:31:09 bigdata-offline-flask-service-node02-75-72 systemd[1]: Started Advanced key-value store.

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!