centos7 安装redis及遇到的问题

此处仅仅是为了保存处理错误的过程。html

[root@leekwen ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"



[root@leekwen ~]# wget http://download.redis.io/releases/redis-3.0.0.tar.gz

[root@leekwen ~]# tar zxvf redis-3.0.0.tar.gz

[root@leekwen ~]# cd redis-3.0.0

[root@leekwen redis-3.0.0]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
CONTRIBUTING     INSTALL  README     runtest-cluster  src
[root@leekwen redis-3.0.0]# make
cd src && make all
make[1]: Entering directory `/usr/local/nodeclub/redis-3.0.0/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 <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/nodeclub/redis-3.0.0/src'
make: *** [all] Error 2

在README 有这个一段话。
Allocator 
--------- 

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


[root@leekwen redis-3.0.0]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/usr/local/nodeclub/redis-3.0.0/src'
    CC adlist.o
    CC ae.o
    CC anet.o
    CC dict.o
    CC redis.o
    CC sds.o
	.........
    CC latency.o
    CC sparkline.o
    LINK redis-server
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/nodeclub/redis-3.0.0/src'
make: *** [all] Error 2
[root@leekwen redis-3.0.0]# cd deps/
[root@leekwen deps]# make lua
MAKE lua
cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL " MYLD                                                                                        FLAGS="" AR="ar rcu"
make[1]: Entering directory `/usr/local/nodeclub/redis-3.0.0/deps/lua/src'
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lgc.o lgc.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o llex.o llex.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lmem.o lmem.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lobject.o lobject.c
........
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lua_cmsgpack.o lua_cmsgpack.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lua_bit.o lua_bit.c
ar rcu liblua.a lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o strbuf.o fpconv.o lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o loadlib.o linit.o lua_cjson.o lua_struct.o lua_cmsgpack.o lua_bit.o # DLL needs all object files
ranlib liblua.a
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o lua.o lua.c
cc -o lua  lua.o liblua.a -lm
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o luac.o luac.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL    -c -o print.o print.c
cc -o luac  luac.o print.o liblua.a -lm
make[1]: Leaving directory `/usr/local/nodeclub/redis-3.0.0/deps/lua/src'
[root@leekwen deps]# cd ..
[root@leekwen redis-3.0.0]# make MALLOC=libc
cd src && make all
make[1]: Entering directory `/usr/local/nodeclub/redis-3.0.0/src'
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    CC redis-check-dump.o
    LINK redis-check-dump
    CC redis-check-aof.o
    LINK redis-check-aof

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

make[1]: Leaving directory `/usr/local/nodeclub/redis-3.0.0/src'
[root@leekwen redis-3.0.0]# make install
[root@leekwen redis-3.0.0]# vim redis.conf 
[root@leekwen redis-3.0.0]# cat redis.conf |grep -v "#" |grep -v "^$"
daemonize yes
pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@leekwen redis-3.0.0]# cd
[root@leekwen ~]#  vi /etc/sysctl.conf
+ vm.overcommit_memory=1
[root@leekwen ~]# sysctl vm.overcommit_memory=1
[root@leekwen ~]# vim /etc/init.d/redis
[root@leekwen ~]# cat /etc/init.d/redis
#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 90 10
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis-3.0.0/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ]
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [ -x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac

查看是否存在对应的文件:

[root@leekwen ~]# ls /usr/local/redis-3.0.0/redis.conf
[root@leekwen ~]# ls -l /usr/local/bin/redis-server
[root@leekwen ~]# ls -l /usr/local/bin/redis-cli

为脚本增长可执行权限:
[root@leekwen ~]# chmod 755 /etc/init.d/redis
启动服务:
[root@leekwen ~]# /etc/init.d/redis start

其它redis配置问题,能够自行百度,或参阅推荐的博客地址。node

推荐博客地址:http://keenwon.com/1335.htmlredis