Linux(Centos)搭建Redis

  1. 到官网下载安装包
    https://redis.io/download
  2. 将安装包放置到/usr/local/src下
[root@localhost src]# ls
jdk-8u144-linux-x64.tar.gz  redis-5.0.3.tar.gz
  1. 解压缩
[root@localhost src]# tar zxvf redis-5.0.3.tar.gz
  1. 编译
[root@localhost src]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make
  1. 报错1,需要安装gcc
make[3]: Entering directory `/usr/local/src/redis-5.0.3/deps/hiredis'
gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/usr/local/src/redis-5.0.3/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/usr/local/src/redis-5.0.3/deps'
make[1]: [persist-settings] Error 2 (ignored)
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/usr/local/src/redis-5.0.3/src'
make: *** [all] Error 2

解决方案

[root@localhost redis-5.0.3]# yum install gcc

报错2

make[1]: Entering directory `/usr/local/src/redis-5.0.3/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/src/redis-5.0.3/src'
make[1]: Entering directory `/usr/local/src/redis-5.0.3/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include 
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/src/redis-5.0.3/src'
make: *** [all] Error 2

解决方案

原因是jemalloc重载了Linux下的ANSI C的malloc和free函数。解决办法:make时添加参数。
[root@localhost redis-5.0.3]# make MALLOC=libc
  1. 安装
[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis
cd src && make install
make[1]: Entering directory `/usr/local/src/redis-5.0.3/src'
    CC Makefile.dep
make[1]: Leaving directory `/usr/local/src/redis-5.0.3/src'
make[1]: Entering directory `/usr/local/src/redis-5.0.3/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/local/src/redis-5.0.3/src'
  1. 编辑配置文件
# 绑定地址去除回环地址,添加物理地址
#bind 127.0.0.1
bind 172.16.1.20
# 指定以守护进程方式启动
daemonize yes
# 指定日志文件夹
logfile "/usr/local/redis/logs/redis.log"
# 指定数据文件夹
dir /usr/local/redis/datas
  1. 创建logs文件夹和datas文件夹
[root@localhost redis]# mkdir /usr/local/redis/logs
[root@localhost redis]# mkdir /usr/local/redis/datas
  1. 启动服务
[root@localhost bin]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 
[root@localhost bin]# ps -ef | grep 6379
root       5728      1  0 08:52 ?        00:00:00 /usr/local/redis/bin/redis-server 172.16.1.20:6379
root       5733   2642  0 08:52 pts/0    00:00:00 grep --color=auto 6379
  1. 登陆
[root@localhost ~]# /usr/local/redis/bin/redis-cli -h 172.16.1.20 -p 6379
  1. 操作
172.16.1.20:6379> set name aa
OK
172.16.1.20:6379> get name
"aa"
172.16.1.20:6379> set name ff
OK
172.16.1.20:6379> get name
"ff"
  1. 关闭redis服务
[root@localhost ~]# ps aux | grep redis
root       5728  0.1  0.1 144084  2192 ?        Ssl  08:52   0:00 /usr/local/redis/bin/redis-server 172.16.1.20:6379
root       5737  0.0  0.0 112680   736 pts/0    R+   08:59   0:00 grep --color=auto redis
[root@localhost ~]# /usr/local/redis/bin/redis-cli -h 172.16.1.20 shutdown
[root@localhost ~]# ps aux | grep redis
root       5740  0.0  0.0 112680   732 pts/0    R+   09:00   0:00 grep --color=auto redis

你可能感兴趣的:(Linux(Centos)搭建Redis)