Redis的基本安装

redis基本安装

Remode Dlctionary Server(远程字典服务器)
使用C语言编写的,遵守BSD的开源软件
是一款高性能的(Key/Values)分布式内存数据库
并支持数据持久化的NoSQL数据库服务软件
中文网站www.redis.cn

特点
支持数据持久化,可写入硬盘

安装
安装源码包
确认gcc gcc-c++已经安装
[root@51 redis-4.0.8]# rpm -q gcc gcc-c++
gcc-4.8.5-16.el7.x86_64
gcc-c++-4.8.5-16.el7.x86_64

直接编译,已配置好
[root@51 redis-4.0.8]# make
cd src && make all
make[1]: 进入目录“/root/soft/redis/redis-4.0.8/src”
CC Makefile.dep
make[1]: 离开目录“/root/soft/redis/redis-4.0.8/src”
make[1]: 进入目录“/root/soft/redis/redis-4.0.8/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]: 进入目录“/root/soft/redis/redis-4.0.8/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
(rm -f .make-*)
make[2]: 离开目录“/root/soft/redis/redis-4.0.8/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]: 进入目录“/root/soft/redis/redis-4.0.8/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
(rm -f .make-*)
(echo “” > .make-cflags)
(echo “” > .make-ldflags)
MAKE hiredis
cd hiredis && make static
make[3]: 进入目录“/root/soft/redis/redis-4.0.8/deps/hiredis”
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb hiredis.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb sds.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb async.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb read.c
ar rcs libhiredis.a net.o hiredis.o sds.o async.o read.o
make[3]: 离开目录“/root/soft/redis/redis-4.0.8/deps/hiredis”
MAKE linenoise
cd linenoise && make
make[3]: 进入目录“/root/soft/redis/redis-4.0.8/deps/linenoise”
cc -Wall -Os -g -c linenoise.c
make[3]: 离开目录“/root/soft/redis/redis-4.0.8/deps/linenoise”
MAKE lua
cd lua/src && make all CFLAGS=”-O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” ” MYLDFLAGS=”” AR=”ar rcu”
make[3]: 进入目录“/root/soft/redis/redis-4.0.8/deps/lua/src”
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lapi.o lapi.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lcode.o lcode.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ldebug.o ldebug.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ldo.o ldo.c
ldo.c: 在函数‘f_parser’中:
ldo.c:496:7: 警告:未使用的变量‘c’ [-Wunused-variable]
int c = luaZ_lookahead(p->z);
^
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ldump.o ldump.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lfunc.o lfunc.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lgc.o lgc.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o llex.o llex.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lmem.o lmem.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lobject.o lobject.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lopcodes.o lopcodes.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lparser.o lparser.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lstate.o lstate.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lstring.o lstring.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ltable.o ltable.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ltm.o ltm.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lundump.o lundump.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lvm.o lvm.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lzio.o lzio.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o strbuf.o strbuf.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o fpconv.o fpconv.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lauxlib.o lauxlib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lbaselib.o lbaselib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ldblib.o ldblib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o liolib.o liolib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lmathlib.o lmathlib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o loslib.o loslib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o ltablib.o ltablib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lstrlib.o lstrlib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o loadlib.o loadlib.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o linit.o linit.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lua_cjson.o lua_cjson.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lua_struct.o lua_struct.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o lua_cmsgpack.o lua_cmsgpack.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -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 -DREDIS_STATIC=” -c -o lua.o lua.c
cc -o lua lua.o liblua.a -lm
liblua.a(loslib.o):在函数‘os_tmpname’中:
loslib.c:(.text+0x28c): 警告:the use of `tmpnam’ is dangerous, better use `mkstemp’
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o luac.o luac.c
cc -O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC=” -c -o print.o print.c
cc -o luac luac.o print.o liblua.a -lm
make[3]: 离开目录“/root/soft/redis/redis-4.0.8/deps/lua/src”
MAKE jemalloc
cd jemalloc && ./configure –with-lg-quantum=3 –with-jemalloc-prefix=je_ –enable-cc-silence CFLAGS=”-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops ” LDFLAGS=””
checking for xsltproc… /usr/bin/xsltproc
checking for gcc… gcc
checking whether the C compiler works… yes
checking for C compiler default output file name… a.out
checking for suffix of executables…
checking whether we are cross compiling… no
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ISO C89… none needed
checking how to run the C preprocessor… gcc -E
checking for grep that handles long lines and -e… /usr/bin/grep
checking for egrep… /usr/bin/grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking whether byte ordering is bigendian… no
checking size of void *… 8
checking size of int… 4
checking size of long… 8
checking size of intmax_t… 8
checking build system type… x86_64-unknown-linux-gnu
checking host system type… x86_64-unknown-linux-gnu
checking whether pause instruction is compilable… yes
checking for ar… ar
checking malloc.h usability… yes
checking malloc.h presence… yes
checking for malloc.h… yes
checking whether malloc_usable_size definition can use const argument… no
checking whether __attribute__ syntax is compilable… yes
checking whether compiler supports -fvisibility=hidden… yes
checking whether compiler supports -Werror… yes
checking whether tls_model attribute is compilable… yes
checking whether compiler supports -Werror… yes
checking whether alloc_size attribute is compilable… yes
checking whether compiler supports -Werror… yes
checking whether format(gnu_printf, …) attribute is compilable… yes
checking whether compiler supports -Werror… yes
checking whether format(printf, …) attribute is compilable… yes
checking for a BSD-compatible install… /usr/bin/install -c
checking for ranlib… ranlib
checking for ld… /usr/bin/ld
checking for autoconf… false
checking for memalign… yes
checking for valloc… yes
checking configured backtracing method… N/A
checking for sbrk… yes
checking whether utrace(2) is compilable… no
checking whether valgrind is compilable… no
checking whether a program using __builtin_ffsl is compilable… yes
checking LG_PAGE… 12
checking pthread.h usability… yes
checking pthread.h presence… yes
checking for pthread.h… yes
checking for pthread_create in -lpthread… yes
checking for library containing clock_gettime… none required
checking for secure_getenv… yes
checking for issetugid… no
checking for _malloc_thread_cleanup… no
checking for _pthread_mutex_init_calloc_cb… no
checking for TLS… yes
checking whether C11 atomics is compilable… no
checking whether atomic(9) is compilable… no
checking whether Darwin OSAtomic*() is compilable… no
checking whether madvise(2) is compilable… yes
checking whether to force 32-bit __sync_{add,sub}_and_fetch()… no
checking whether to force 64-bit __sync_{add,sub}_and_fetch()… no
checking for __builtin_clz… yes
checking whether Darwin OSSpin*() is compilable… no
checking whether glibc malloc hook is compilable… yes
checking whether glibc memalign hook is compilable… yes
checking whether pthreads adaptive mutexes is compilable… yes
checking for stdbool.h that conforms to C99… yes
checking for _Bool… yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating jemalloc.pc
config.status: creating doc/html.xsl
config.status: creating doc/manpages.xsl
config.status: creating doc/jemalloc.xml
config.status: creating include/jemalloc/jemalloc_macros.h
config.status: creating include/jemalloc/jemalloc_protos.h
config.status: creating include/jemalloc/jemalloc_typedefs.h
config.status: creating include/jemalloc/internal/jemalloc_internal.h
config.status: creating test/test.sh
config.status: creating test/include/test/jemalloc_test.h
config.status: creating config.stamp
config.status: creating bin/jemalloc-config
config.status: creating bin/jemalloc.sh
config.status: creating bin/jeprof
config.status: creating include/jemalloc/jemalloc_defs.h
config.status: creating include/jemalloc/internal/jemalloc_internal_defs.h
config.status: creating test/include/test/jemalloc_test_defs.h
config.status: executing include/jemalloc/internal/private_namespace.h commands
config.status: executing include/jemalloc/internal/private_unnamespace.h commands
config.status: executing include/jemalloc/internal/public_symbols.txt commands
config.status: executing include/jemalloc/internal/public_namespace.h commands
config.status: executing include/jemalloc/internal/public_unnamespace.h commands
config.status: executing include/jemalloc/internal/size_classes.h commands
config.status: executing include/jemalloc/jemalloc_protos_jet.h commands
config.status: executing include/jemalloc/jemalloc_rename.h commands
config.status: executing include/jemalloc/jemalloc_mangle.h commands
config.status: executing include/jemalloc/jemalloc_mangle_jet.h commands
config.status: executing include/jemalloc/jemalloc.h commands
===============================================================================
jemalloc version : 4.0.3-0-ge9192eacf8935e29fc62fddc2701f7942b1cc02c
library revision : 2

CONFIG : –with-lg-quantum=3 –with-jemalloc-prefix=je_ –enable-cc-silence ‘CFLAGS=-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops ‘ LDFLAGS=
CC : gcc
CFLAGS : -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -fvisibility=hidden
CPPFLAGS : -D_GNU_SOURCE -D_REENTRANT
LDFLAGS :
EXTRA_LDFLAGS :
LIBS : -lpthread
TESTLIBS :
RPATH_EXTRA :

XSLTPROC : /usr/bin/xsltproc
XSLROOT :

PREFIX : /usr/local
BINDIR : /usr/local/bin
DATADIR : /usr/local/share
INCLUDEDIR : /usr/local/include
LIBDIR : /usr/local/lib
MANDIR : /usr/local/share/man

srcroot :
abs_srcroot : /root/soft/redis/redis-4.0.8/deps/jemalloc/
objroot :
abs_objroot : /root/soft/redis/redis-4.0.8/deps/jemalloc/

JEMALLOC_PREFIX : je_
JEMALLOC_PRIVATE_NAMESPACE
: je_
install_suffix :
autogen : 0
cc-silence : 1
debug : 0
code-coverage : 0
stats : 1
prof : 0
prof-libunwind : 0
prof-libgcc : 0
prof-gcc : 0
tcache : 1
fill : 1
utrace : 0
valgrind : 0
xmalloc : 0
munmap : 0
lazy_lock : 0
tls : 1
cache-oblivious : 1
===============================================================================
cd jemalloc && make CFLAGS=”-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops ” LDFLAGS=”” lib/libjemalloc.a
make[3]: 进入目录“/root/soft/redis/redis-4.0.8/deps/jemalloc”
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/jemalloc.o src/jemalloc.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/arena.o src/arena.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/atomic.o src/atomic.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/base.o src/base.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/bitmap.o src/bitmap.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk.o src/chunk.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk_dss.o src/chunk_dss.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/chunk_mmap.o src/chunk_mmap.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ckh.o src/ckh.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ctl.o src/ctl.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/extent.o src/extent.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/hash.o src/hash.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/huge.o src/huge.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mb.o src/mb.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mutex.o src/mutex.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/pages.o src/pages.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/prof.o src/prof.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/quarantine.o src/quarantine.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/rtree.o src/rtree.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/stats.o src/stats.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tcache.o src/tcache.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/util.o src/util.c
gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tsd.o src/tsd.c
ar crus lib/libjemalloc.a src/jemalloc.o src/arena.o src/atomic.o src/base.o src/bitmap.o src/chunk.o src/chunk_dss.o src/chunk_mmap.o src/ckh.o src/ctl.o src/extent.o src/hash.o src/huge.o src/mb.o src/mutex.o src/pages.o src/prof.o src/quarantine.o src/rtree.o src/stats.o src/tcache.o src/util.o src/tsd.o
make[3]: 离开目录“/root/soft/redis/redis-4.0.8/deps/jemalloc”
make[2]: 离开目录“/root/soft/redis/redis-4.0.8/deps”
CC adlist.o
CC quicklist.o
CC ae.o
CC anet.o
CC dict.o
CC server.o
CC sds.o
CC zmalloc.o
CC lzf_c.o
CC lzf_d.o
CC pqsort.o
CC zipmap.o
CC sha1.o
CC ziplist.o
CC release.o
CC networking.o
CC util.o
CC object.o
CC db.o
CC replication.o
CC rdb.o
CC t_string.o
CC t_list.o
CC t_set.o
CC t_zset.o
CC t_hash.o
CC config.o
CC aof.o
CC pubsub.o
CC multi.o
CC debug.o
CC sort.o
CC intset.o
CC syncio.o
CC cluster.o
CC crc16.o
CC endianconv.o
CC slowlog.o
CC scripting.o
CC bio.o
CC rio.o
CC rand.o
CC memtest.o
CC crc64.o
CC bitops.o
CC sentinel.o
CC notify.o
CC setproctitle.o
CC blocked.o
CC hyperloglog.o
CC latency.o
CC sparkline.o
CC redis-check-rdb.o
CC redis-check-aof.o
CC geo.o
CC lazyfree.o
CC module.o
CC evict.o
CC expire.o
CC geohash.o
CC geohash_helper.o
CC childinfo.o
CC defrag.o
CC siphash.o
CC rax.o
LINK redis-server
INSTALL redis-sentinel
CC redis-cli.o
LINK redis-cli
CC redis-benchmark.o
LINK redis-benchmark
INSTALL redis-check-rdb
INSTALL redis-check-aof

Hint: It’s a good idea to run ‘make test’ 😉

make[1]: 离开目录“/root/soft/redis/redis-4.0.8/src”

安装
[root@51 redis-4.0.8]# make install
cd src && make install
make[1]: 进入目录“/root/soft/redis/redis-4.0.8/src”
CC Makefile.dep
make[1]: 离开目录“/root/soft/redis/redis-4.0.8/src”
make[1]: 进入目录“/root/soft/redis/redis-4.0.8/src”

Hint: It’s a good idea to run ‘make test 😉

INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 离开目录“/root/soft/redis/redis-4.0.8/src”

*重要*初始化配置
[root@51 redis-4.0.8]# ./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
选择端口,默认6379
Please select the redis port for this instance: [6379]
Selecting default: 6379
选择配置文件名称和位置,默认
Please select the redis config file name [/etc/redis/6379.conf]
Selected default – /etc/redis/6379.conf
选择日志名称和位置,选择默认
Please select the redis log file name [/var/log/redis_6379.log]
Selected default – /var/log/redis_6379.log
选择数据库名称和位置,选择默认
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default – /var/lib/redis/6379
选择程序输出位置,选择默认
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service…
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server…
Installation successful!

确认服务已启动
[root@51 redis-4.0.8]# netstat -antuo | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN off (0.00/0/0)

可以手动启动和停止
[root@51 redis-4.0.8]# /etc/init.d/
netconsole network redis_6379 rhnsd
[root@51 redis-4.0.8]# /etc/init.d/
netconsole network redis_6379 rhnsd
[root@51 redis-4.0.8]# /etc/init.d/redis_6379 status
Redis is running (4762)
[root@51 redis-4.0.8]# /etc/init.d/redis_6379 stop
Stopping …
Redis stopped
[root@51 redis-4.0.8]# /etc/init.d/redis_6379 status
cat: /var/run/redis_6379.pid: 没有那个文件或目录
Redis is running ()
[root@51 redis-4.0.8]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@51 redis-4.0.8]# /etc/init.d/redis_6379 status
Redis is running (4831)
[root@51 redis-4.0.8]# netstat -antuo | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN off (0.00/0/0)
tcp 0 0 127.0.0.1:6379 127.0.0.1:47670 TIME_WAIT timewait (40.09/0/0)

查看配置文件
[root@51 redis-4.0.8]# vim /etc/redis/6379.conf

查看数据库目录
[root@51 redis-4.0.8]# ll /var/lib/redis/6379/
总用量 4
-rw-r–r–. 1 root root 92 6月 7 09:34 dump.rdb

redis命令

[root@51 redis-4.0.8]# redis-cli
127.0.0.1:6379> ping
PONG

插入值
插入格式:
127.0.0.1:6379[15]> set key valuse [EX seconds] [PX milliseconds] [NX|XX]
例如
127.0.0.1:6379> select 15
OK
127.0.0.1:6379[15]> keys *
(empty list or set)
127.0.0.1:6379[15]> set key jim
OK
127.0.0.1:6379[15]> get key
“jim”

插入多个值
127.0.0.1:6379[15]> select 0
OK
127.0.0.1:6379> set v1 9
OK
127.0.0.1:6379> set v2 10
OK
127.0.0.1:6379> set v3 100
OK
127.0.0.1:6379> keys v?
1) “v3”
2) “v2”
3) “v1”

查看变量类型,默认都是字符类型string
127.0.0.1:6379> type v1
string

查看变量生存期(即什么时候从内存清除),默认用不过期
127.0.0.1:6379> ttl v1
(integer) -1

查看变量是否存在(存在为1,不存在为0)
127.0.0.1:6379> Exists k1
(integer) 0
127.0.0.1:6379> Exists v1
(integer) 1
127.0.0.1:6379>

将值移动到其它库,例如2
127.0.0.1:6379> move v2 1
(integer) 1
127.0.0.1:6379> keys * //0库里面已经没了
1) “v3”
2) “v1”
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> keys * //在1库里面了
1) “v2”
127.0.0.1:6379[1]>

redis支持持久化,使用save命令
127.0.0.1:6379[1]> save
OK

redis清空内存
127.0.0.1:6379[1]> keys *
1) “v2″
127.0.0.1:6379[1]> flushall
OK
127.0.0.1:6379[1]> keys *
(empty list or set)

修改配置文件
[root@51 ~]# vim /etc/redis/6379.conf
在70行添加IP
70 bind 127.0.0.1 192.168.4.51

重启服务
[root@51 ~]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@51 ~]# /etc/init.d/redis_6379 status
Redis is running (5967)

确认配置文件起效,可以看到,已经在监听192.168.4.51
[root@51 ~]# netstat -antup | grep redis
tcp 0 0 192.168.4.51:6379 0.0.0.0:* LISTEN 5967/redis-server 1
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 5967/redis-server 1

也可以更改一个端口
93 port 8888
[root@51 ~]# vim /etc/redis/6379.conf
[root@51 ~]# /etc/init.d/redis_6379 stop
Stopping …
Waiting for Redis to shutdown …
^[[ARedis stopped
[root@51 ~]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@51 ~]# /etc/init.d/redis_6379 status
Redis is running (6028)
[root@51 ~]# netstat -antup | grep redis
tcp 0 0 192.168.4.51:8888 0.0.0.0:* LISTEN 6028/redis-server 1
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 6028/redis-server 1

注意,此时访问时需要指定端口
原端口已经无法使用
[root@51 ~]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit
使用新端口
[root@51 ~]# redis-cli -p 8888
127.0.0.1:8888> exit

在另外一台机器51上验证
[root@56 ~]# redis-cli -h 192.168.4.51 -p 8888
192.168.4.51:8888> select 0
OK
192.168.4.51:8888> keys *
(empty list or set)
192.168.4.51:8888>

可以限制TCP链接数量
redis使用的是TCP连接,可以限制TCP总和,超过的就排队
102 tcp-backlog 511

设置连接永不超时
114 timeout 0

设置连接保活时间(每隔300S检查一下链接状态)
131 tcp-keepalive 300

是否常驻内存守护进程
137 daemonize yes

数据库个数(默认0-15号库)
187 databases 16

日志文件位置,之前已经配置好了
172 logfile /var/log/redis_6379.log

redis链接的并发链接数
533 # maxclients 10000

设置redis数据库目录,前面也设置过了
264 dir /var/lib/redis/6379

设置开辟多少内存空间给数据库,注意在配置文件的开头已经注释好了单位(只能是字节)
560 # maxmemory <bytes>

12 # 1k => 1000 bytes
13 # 1kb => 1024 bytes
14 # 1m => 1000000 bytes
15 # 1mb => 1024*1024 bytes
16 # 1g => 1000000000 bytes
17 # 1gb => 1024*1024*1024 bytes

内存的清除策略
最近最少使用
565 # volatile-lru -> Evict using approximated LRU among the keys with an expire set.
删除最少使用的key
566 # allkeys-lru -> Evict any key using approximated LRU.

567 # volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
568 # allkeys-lfu -> Evict any key using approximated LFU.
在设置了过期的key里随机移除
569 # volatile-random -> Remove a random key among the ones with an expire set.
随机移除key
570 # allkeys-random -> Remove a random key, any key.
移除最近过期的key
571 # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
默认不清除,存满时报错,生产环境不使用
572 # noeviction -> Don’t evict anything, just return an error on write operations.
在591行已经说明了默认的清除策略是不清楚

设置最大模板数量
602 # maxmemory-samples 5

/etc/init.d/下面为脚本
[root@51 ~]# cd /etc/init.d/
[root@51 init.d]# ll
总用量 48
-rw-r–r–. 1 root root 17500 5月 3 2017 functions
-rwxr-xr-x. 1 root root 4334 5月 3 2017 netconsole
-rwxr-xr-x. 1 root root 7293 5月 3 2017 network
-rw-r–r–. 1 root root 1160 6月 27 2017 README
-rwxr-xr-x. 1 root root 1702 6月 7 09:28 redis_6379
-rwxr-xr-x. 1 root root 2443 3月 6 2017 rhnsd

[root@51 init.d]# netstat -antup | grep 2636
tcp 0 0 192.168.4.51:6379 0.0.0.0:* LISTEN 2636/redis-server 1
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 2636/redis-server 1

设置需要密码
501 requirepass 123456

[root@51 init.d]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@51 init.d]# /etc/init.d/redis_6379 status
Redis is running (2636)
[root@51 init.d]# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> exit

注意,如果更改了端口号,密码,IP等等,则调用脚本时,需要在脚本里面也更改相应的信息
例如,如果有密码,直接用脚本停是停不了的
[root@51 init.d]# /etc/init.d/redis_6379 stop
Stopping …
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
^C

此时需修改脚本
[root@51 init.d]# vim /etc/init.d/redis_6379
43 $CLIEXEC -p $REDISPORT -a 123456 shutdown

再用脚本停止服务时一切正常
[root@51 init.d]# /etc/init.d/redis_6379 stop
Stopping …
Waiting for Redis to shutdown …
Redis stopped

同理在修改IP,端口号等,脚本也要做相应的调整

换另一台机器验证IP
[root@56 ~]# redis-cli -h 192.168.4.51 -a 123456
192.168.4.51:6379> ping
PONG
192.168.4.51:6379>

再修改端口试一试,把6379改成8888
[root@51 init.d]# vim /etc/redis/6379.conf
93 port 8888
[root@51 init.d]# /etc/init.d/redis_6379 stop
Stopping …
Redis stopped
[root@51 init.d]#
[root@51 init.d]# /etc/init.d/redis_6379 start
Starting Redis server…
[root@51 init.d]# netstat -antup | grep 8888
tcp 0 0 192.168.4.51:8888 0.0.0.0:* LISTEN 3198/redis-server 1
tcp 0 0 127.0.0.1:8888 0.0.0.0:* LISTEN 3198/redis-server 1
验证关闭,可以看到,关不了了
[root@51 init.d]# /etc/init.d/redis_6379 stop
Stopping …
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
^C

把端口改一下,再运行一次,就对了
[root@51 init.d]# vim /etc/init.d/redis_6379
8 REDISPORT=”8888″
[root@51 init.d]# /etc/init.d/redis_6379 stop
Stopping …
Redis stopped
[root@51 init.d]#

以上总之,改了什么值,脚本也要做相应的修改,否则就运行 redis-cli 命令加上参数

LNMP配置
1部署LNMP平台
(1)源码安装NGINX
[root@51 nginx-1.12.2]# yum install -y gcc gcc-c++ pcre-devel zlib-devel php-common
[root@51 nginx-1.12.2]# ./configure –prefix=/usr/local/nginx
make & make install
[root@51 lnmp]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
[root@51 lnmp]# nginx
[root@51 lnmp]# netstat -antup | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8627/nginx: master

配置nginx配置文件
[root@51 nginx]# vim conf/nginx.conf

65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
71 }
72
73 # deny access to .htaccess files, if Apache’s document root
74 # concurs with nginx’s one
75 #
76 location ~ /\.ht {
77 deny all;
78 }

(2)部署MYSQL
已经安装了,省略

(3)部署PHP
[root@51 lnmp]# rpm -ivh php-fpm-5.4.16-42.el7.x86_64.rpm
警告:php-fpm-5.4.16-42.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中… ################################# [100%]
正在升级/安装…
1:php-fpm-5.4.16-42.el7 ################################# [100%]
[root@51 lnmp]# systemctl restart php-fpm
[root@51 lnmp]# systemctl enable php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@51 lnmp]# netstat -antup | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 9038/php-fpm: maste

写一个默认主页
[root@51 lnmp]# echo 123 > /usr/local/nginx/html/index.html

找一台机器试一下能不能访问
[root@56 ~]# curl 192.168.4.51
123

(*)重要安装 php-redis
安装依赖1
[root@51 redis]# yum install -y autoconf automake
已安装:
autoconf.noarch 0:2.69-11.el7 automake.noarch 0:1.13.4-3.el7
作为依赖被安装:
m4.x86_64 0:1.4.16-10.el7
完毕!

安装依赖2
[root@51 redis]# yum install php-devel-5.4.16-42.el7.x86_64.rpm
已安装:
php-devel.x86_64 0:5.4.16-42.el7
作为依赖被安装:
php-cli.x86_64 0:5.4.16-42.el7
完毕!

确认依赖安装好(即安装好了PHP配置文件命令)
[root@51 phpredis-2.2.4]# ll /usr/bin/php*
-rwxr-xr-x. 1 root root 4617936 8月 5 2016 /usr/bin/php
-rwxr-xr-x. 1 root root 4596800 8月 5 2016 /usr/bin/php-cgi
-rwxr-xr-x. 1 root root 4524 11月 6 2016 /usr/bin/php-config
-rwxr-xr-x. 1 root root 4760 8月 5 2016 /usr/bin/phpize

解压安装包php-redis
[root@51 redis]# tar -xf php-redis-2.2.4.tar.gz
[root@51 redis]# cd phpredis-2.2.4/
[root@51 phpredis-2.2.4]# ll
总用量 504
-rw-rw-r–. 1 root root 8156 9月 2 2013 arrays.markdown
-rw-rw-r–. 1 root root 5747 9月 2 2013 common.h
-rw-rw-r–. 1 root root 1966 9月 2 2013 config.h
-rwxrwxr-x. 1 root root 3344 9月 2 2013 config.m4
-rw-rw-r–. 1 root root 462 9月 2 2013 config.w32
-rw-rw-r–. 1 root root 3218 9月 2 2013 COPYING
-rw-rw-r–. 1 root root 160 9月 2 2013 CREDITS
drwxrwxr-x. 2 root root 112 9月 2 2013 debian
-rw-rw-r–. 1 root root 309 9月 2 2013 debian.control
-rw-rw-r–. 1 root root 49143 9月 2 2013 library.c
-rw-rw-r–. 1 root root 5246 9月 2 2013 library.h
-rwxrwxr-x. 1 root root 636 9月 2 2013 mkdeb-apache2.sh
-rwxrwxr-x. 1 root root 471 9月 2 2013 mkdeb.sh
-rw-rw-r–. 1 root root 2703 9月 2 2013 package.xml
-rw-rw-r–. 1 root root 8357 9月 2 2013 php_redis.h
-rw-rw-r–. 1 root root 86482 9月 2 2013 README.markdown
-rw-rw-r–. 1 root root 36092 9月 2 2013 redis_array.c
-rw-rw-r–. 1 root root 1513 9月 2 2013 redis_array.h
-rw-rw-r–. 1 root root 35592 9月 2 2013 redis_array_impl.c
-rw-rw-r–. 1 root root 1528 9月 2 2013 redis_array_impl.h
-rw-rw-r–. 1 root root 200437 9月 2 2013 redis.c
-rw-rw-r–. 1 root root 12241 9月 2 2013 redis_session.c
-rw-rw-r–. 1 root root 251 9月 2 2013 redis_session.h
drwxrwxr-x. 2 root root 45 9月 2 2013 rpm
-rw-rw-r–. 1 root root 424 9月 2 2013 serialize.list
drwxrwxr-x. 2 root root 101 9月 2 2013 tests

先配置安装

linux系统中,php安装成功后,在bin目录下会生成一个名叫phpize的可执行脚本,这个脚本的用途是动态安装php扩展模块。
使用phpize脚本安装php扩展模块的好处:在安装php时没有安装的扩展,可以在以后随时安装上,且不需要重新安装PHP。
安装步骤:
1、切换到扩展模块目录
在php源码包被解压后的目录中有个ext子目录,这里有近70多个主流的php扩展模块安装包。
如现在要安装imap扩展,则切换到imap目录:
cd /software/php-5.5.3/ext/imap
2、在imap目录中执行phpize脚本
/usr/local/php/bin/phpize
执行成功会返回几行数据:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
3、开始编译(注意–with-php-config参数)
./configure –with-php-config=/usr/local/php/bin/php-config –with-kerberos –with-imap-ssl
4、make
5、make install’

执行phpize命令,该命令用于动态加载PHP模块
[root@51 phpredis-2.2.4]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525

指定配置文件的安装位置
[root@51 phpredis-2.2.4]# ./configure –with-php-config=/usr/bin/php-config

执行make
[root@51 phpredis-2.2.4]# make
/bin/sh /root/soft/redis/phpredis-2.2.4/libtool –mode=compile cc -I. -I/root/soft/redis/phpredis-2.2.4 -DPHP_ATOM_INC -I/root/soft/redis/phpredis-2.2.4/include -I/root/soft/redis/phpredis-2.2.4/main -I/root/soft/redis/phpredis-2.2.4 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/soft/redis/phpredis-2.2.4/redis.c -o redis.lo

*************************

执行make install
[root@51 phpredis-2.2.4]# make install
Installing shared extensions: /usr/lib64/php/modules/

安装完成后,加载redis模块
先确定有没有redis模块
[root@51 phpredis-2.2.4]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
ereg
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
json
libxml
mhash
openssl
pcntl
pcre
Phar
readline
Reflection
session
shmop
SimpleXML
sockets
SPL
standard
tokenizer
xml
zip
zlib

[Zend Modules]

[root@51 phpredis-2.2.4]# php -m | grep -i redis
(可以发现什么也没有,说明没有redis模块)

修改php程序配置文件php.ini,模块在哪里?
通过刚才的安装信息
[root@51 phpredis-2.2.4]# make install
Installing shared extensions: /usr/lib64/php/modules/
可以发现 ‘/usr/lib64/php/modules/’这个关键词

查看一下这个目录
[root@51 phpredis-2.2.4]# ll /usr/lib64/php/modules/
总用量 4116
-rwxr-xr-x. 1 root root 74648 8月 5 2016 curl.so
-rwxr-xr-x. 1 root root 2713352 8月 5 2016 fileinfo.so
-rwxr-xr-x. 1 root root 44680 8月 5 2016 json.so
-rwxr-xr-x. 1 root root 272000 8月 5 2016 phar.so
-rwxr-xr-x. 1 root root 1038392 6月 7 16:50 redis.so
-rwxr-xr-x. 1 root root 58376 8月 5 2016 zip.so

可以发现redis.so 这个模块已经装了,只是没有启用,因此配置模块
注意文件夹路径要写对
854 extension_dir=”/usr/lib64/php/modules/”
855 extension=”redis.so”
配置这里的时候,配置文件已经给出了提示:
726 ; Directory in which the loadable extensions (modules) reside.
727 ; http://php.net/extension-dir
728 ; extension_dir = “./”
729 ; On windows:
730 ; extension_dir = “ext”
********************************************
842 ; If you wish to have an extension loaded automatically, use the following
843 ; syntax:
844 ;
845 ; extension=modulename.extension
846 ;
847 ; For example, on Windows:
848 ;
849 ; extension=msql.dll
850 ;
851 ; … or under UNIX:
852 ;
853 ; extension=msql.so
854 extension_dir=”./”
855 extension=”redis.so”
856 ;
857 ; … or with a path:
858 ;
859 ; extension=/path/to/extension/msql.so

访问页面检查http://192.168.4.51/test.php
搜索redis
redis
Redis Support enabled
Redis Version 2.2.4
或者本地确认
[root@51 phpredis-2.2.4]# php -m | grep -i redis
redis

编写页面,链接测试
(我已经在56上面装好了redis)
[root@51 phpredis-2.2.4]# cat /usr/local/nginx/html/redis.php
<?php
$redis = new redis();
$redis->connect(‘192.168.4.56’,6379);
$redis->set(‘redistest’,’666666′);
echo $redis->get(‘redistest’);
?>

访问页面http://192.168.4.51/redis.php,测试成功
[root@room9pc01 ~]# curl http://192.168.4.51/redis.php
666666
再次验证,直接远程登陆redis,可以发现有值了
[root@51 phpredis-2.2.4]# redis-cli -h 192.168.4.56
192.168.4.56:6379> keys *
1) “redistest”
192.168.4.56:6379> get redistest
“666666”
192.168.4.56:6379>

此条目发表在reids分类目录,贴了标签。将固定链接加入收藏夹。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注