linux下redis 安装
--获取redis
[redis@localhost ~]$ wget http://download.redis.io/releases/redis-2.8.7.tar.gz
--2017-05-29 09:58:56-- http://download.redis.io/releases/redis-2.8.7.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
正在连接 download.redis.io (download.redis.io)|109.74.203.151|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1064262 (1.0M) [application/x-gzip]
正在保存至: “redis-2.8.7.tar.gz”
100%[=====================================================================================================================================================>] 1,064,262 188KB/s 用时 13s
2017-05-29 09:59:10 (81.7 KB/s) - 已保存 “redis-2.8.7.tar.gz” [1064262/1064262])
--解压
[redis@localhost ~]$ tar -xzf redis-2.8.7.tar.gz
[redis@localhost ~]$ ls
redis-2.8.6 redis-2.8.6.tar.gz redis-2.8.7 redis-2.8.7.tar.gz test
[redis@localhost ~]$ cd redis-2.8.7
--编译
[redis@localhost redis-2.8.7]$ make
cd src && make all
make[1]: 进入目录“/home/redis/redis-2.8.7/src”
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: 进入目录“/home/redis/redis-2.8.7/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]: 离开目录“/home/redis/redis-2.8.7/deps”
(rm -f .make-*)
echo STD=-std=c99 -pedantic >> .make-settings
echo WARN=-Wall >> .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 -Wall -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]: 进入目录“/home/redis/redis-2.8.7/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]: 进入目录“/home/redis/redis-2.8.7/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
ar rcs libhiredis.a net.o hiredis.o sds.o async.o
make[3]: 离开目录“/home/redis/redis-2.8.7/deps/hiredis”
MAKE linenoise
cd linenoise && make
make[3]: 进入目录“/home/redis/redis-2.8.7/deps/linenoise”
cc -Wall -Os -g -c linenoise.c
make[3]: 离开目录“/home/redis/redis-2.8.7/deps/linenoise”
MAKE lua
cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI " MYLDFLAGS=""
make[3]: 进入目录“/home/redis/redis-2.8.7/deps/lua/src”
cc -O2 -Wall -DLUA_ANSI -c -o lapi.o lapi.c
cc -O2 -Wall -DLUA_ANSI -c -o lcode.o lcode.c
cc -O2 -Wall -DLUA_ANSI -c -o ldebug.o ldebug.c
cc -O2 -Wall -DLUA_ANSI -c -o ldo.o ldo.c
cc -O2 -Wall -DLUA_ANSI -c -o ldump.o ldump.c
cc -O2 -Wall -DLUA_ANSI -c -o lfunc.o lfunc.c
cc -O2 -Wall -DLUA_ANSI -c -o lgc.o lgc.c
cc -O2 -Wall -DLUA_ANSI -c -o llex.o llex.c
cc -O2 -Wall -DLUA_ANSI -c -o lmem.o lmem.c
cc -O2 -Wall -DLUA_ANSI -c -o lobject.o lobject.c
cc -O2 -Wall -DLUA_ANSI -c -o lopcodes.o lopcodes.c
cc -O2 -Wall -DLUA_ANSI -c -o lparser.o lparser.c
cc -O2 -Wall -DLUA_ANSI -c -o lstate.o lstate.c
cc -O2 -Wall -DLUA_ANSI -c -o lstring.o lstring.c
cc -O2 -Wall -DLUA_ANSI -c -o ltable.o ltable.c
cc -O2 -Wall -DLUA_ANSI -c -o ltm.o ltm.c
cc -O2 -Wall -DLUA_ANSI -c -o lundump.o lundump.c
cc -O2 -Wall -DLUA_ANSI -c -o lvm.o lvm.c
cc -O2 -Wall -DLUA_ANSI -c -o lzio.o lzio.c
cc -O2 -Wall -DLUA_ANSI -c -o strbuf.o strbuf.c
cc -O2 -Wall -DLUA_ANSI -c -o lauxlib.o lauxlib.c
cc -O2 -Wall -DLUA_ANSI -c -o lbaselib.o lbaselib.c
cc -O2 -Wall -DLUA_ANSI -c -o ldblib.o ldblib.c
cc -O2 -Wall -DLUA_ANSI -c -o liolib.o liolib.c
cc -O2 -Wall -DLUA_ANSI -c -o lmathlib.o lmathlib.c
cc -O2 -Wall -DLUA_ANSI -c -o loslib.o loslib.c
cc -O2 -Wall -DLUA_ANSI -c -o ltablib.o ltablib.c
cc -O2 -Wall -DLUA_ANSI -c -o lstrlib.o lstrlib.c
cc -O2 -Wall -DLUA_ANSI -c -o loadlib.o loadlib.c
cc -O2 -Wall -DLUA_ANSI -c -o linit.o linit.c
cc -O2 -Wall -DLUA_ANSI -c -o lua_cjson.o lua_cjson.c
cc -O2 -Wall -DLUA_ANSI -c -o lua_struct.o lua_struct.c
cc -O2 -Wall -DLUA_ANSI -c -o lua_cmsgpack.o lua_cmsgpack.c
lua_cmsgpack.c: 在函数‘table_is_an_array’中:
lua_cmsgpack.c:370:21: 警告:变量‘max’被设定但未被使用 [-Wunused-but-set-variable]
long count = 0, max = 0, idx = 0;
^
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 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 # DLL needs all object files
ranlib liblua.a
cc -O2 -Wall -DLUA_ANSI -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 -c -o luac.o luac.c
cc -O2 -Wall -DLUA_ANSI -c -o print.o print.c
cc -o luac luac.o print.o liblua.a -lm
make[3]: 离开目录“/home/redis/redis-2.8.7/deps/lua/src”
MAKE jemalloc
cd jemalloc && ./configure --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 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 __asm__ syntax is compilable... yes
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... no
checking for a BSD-compatible install... /usr/bin/install -c
checking for ranlib... ranlib
checking for ar... /usr/bin/ar
checking for ld... /usr/bin/ld
checking for autoconf... no
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 STATIC_PAGE_SHIFT... 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 _malloc_thread_cleanup... no
checking for _pthread_mutex_init_calloc_cb... no
checking for TLS... yes
checking whether a program using ffsl is compilable... yes
checking whether atomic(9) is compilable... no
checking whether Darwin OSAtomic*() is compilable... no
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 whether Darwin OSSpin*() is compilable... no
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/html.xsl
config.status: creating doc/manpages.xsl
config.status: creating doc/jemalloc.xml
config.status: creating include/jemalloc/jemalloc.h
config.status: creating include/jemalloc/internal/jemalloc_internal.h
config.status: creating test/jemalloc_test.h
config.status: creating config.stamp
config.status: creating bin/jemalloc.sh
config.status: creating include/jemalloc/jemalloc_defs.h
config.status: executing include/jemalloc/internal/size_classes.h commands
===============================================================================
jemalloc version : 3.2.0-0-g87499f6748ebe4817571e817e9f680ccb5bf54a9
library revision : 1
CC : gcc
CPPFLAGS : -D_GNU_SOURCE -D_REENTRANT
CFLAGS : -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -fvisibility=hidden
LDFLAGS :
LIBS : -lm -lpthread
RPATH_EXTRA :
XSLTPROC : /usr/bin/xsltproc
XSLROOT :
PREFIX : /usr/local
BINDIR : /usr/local/bin
INCLUDEDIR : /usr/local/include
LIBDIR : /usr/local/lib
DATADIR : /usr/local/share
MANDIR : /usr/local/share/man
srcroot :
abs_srcroot : /home/redis/redis-2.8.7/deps/jemalloc/
objroot :
abs_objroot : /home/redis/redis-2.8.7/deps/jemalloc/
JEMALLOC_PREFIX : je_
JEMALLOC_PRIVATE_NAMESPACE
:
install_suffix :
autogen : 0
experimental : 1
cc-silence : 1
debug : 0
stats : 1
prof : 0
prof-libunwind : 0
prof-libgcc : 0
prof-gcc : 0
tcache : 1
fill : 1
utrace : 0
valgrind : 0
xmalloc : 0
mremap : 0
munmap : 0
dss : 0
lazy_lock : 0
tls : 1
===============================================================================
cd jemalloc && make CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" lib/libjemalloc.a
make[3]: 进入目录“/home/redis/redis-2.8.7/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
src/jemalloc.c: 在函数‘je_realloc’中:
src/jemalloc.c:1082:9: 警告:变量‘old_rzsize’被设定但未被使用 [-Wunused-but-set-variable]
size_t old_rzsize JEMALLOC_CC_SILENCE_INIT(0);
^
src/jemalloc.c: 在函数‘je_free’中:
src/jemalloc.c:1230:10: 警告:变量‘rzsize’被设定但未被使用 [-Wunused-but-set-variable]
size_t rzsize JEMALLOC_CC_SILENCE_INIT(0);
^
src/jemalloc.c: 在函数‘je_rallocm’中:
src/jemalloc.c:1477:9: 警告:变量‘old_rzsize’被设定但未被使用 [-Wunused-but-set-variable]
size_t old_rzsize JEMALLOC_CC_SILENCE_INIT(0);
^
src/jemalloc.c: 在函数‘je_dallocm’中:
src/jemalloc.c:1622:9: 警告:变量‘rzsize’被设定但未被使用 [-Wunused-but-set-variable]
size_t rzsize JEMALLOC_CC_SILENCE_INIT(0);
^
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
src/ctl.c: 在函数‘epoch_ctl’中:
src/ctl.c:1112:11: 警告:变量‘newval’被设定但未被使用 [-Wunused-but-set-variable]
uint64_t newval;
^
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/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/prof.o src/quarantine.o src/rtree.o src/stats.o src/tcache.o src/util.o src/tsd.o
make[3]: 离开目录“/home/redis/redis-2.8.7/deps/jemalloc”
make[2]: 离开目录“/home/redis/redis-2.8.7/deps”
CC adlist.o
CC ae.o
CC anet.o
CC dict.o
CC redis.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 migrate.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
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: To run 'make test' is a good idea ;)
make[1]: 离开目录“/home/redis/redis-2.8.7/src”
--make install会将redis的命令放到系统的path下 所以可以在任何位置直接执行redis-server和redis-cli
[redis@localhost redis-2.8.7]$ make install
cd src && make install
make[1]: 进入目录“/home/redis/redis-2.8.7/src”
Hint: To run 'make test' is a good idea ;)
INSTALL install
install: 无法创建普通文件"/usr/local/bin/redis-server": 权限不够
make[1]: *** [install] 错误 1
make[1]: 离开目录“/home/redis/redis-2.8.7/src”
make: *** [install] 错误 2
[redis@localhost redis-2.8.7]$ su root
密码:
[root@localhost redis-2.8.7]# make install
cd src && make install
make[1]: 进入目录“/home/redis/redis-2.8.7/src”
Hint: To run 'make test' is a good idea ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: 离开目录“/home/redis/redis-2.8.7/src”
[root@localhost redis-2.8.7]# su redis
--将redis的配置文件拷贝到etc下(不做这一步也可以 这样只是为了使用方便 )
[redis@localhost redis-2.8.7]$ cp redis.conf /etc/redis.conf
cp: 无法创建普通文件"/etc/redis.conf": 权限不够
[redis@localhost redis-2.8.7]$ su root
密码:
[root@localhost redis-2.8.7]# cp redis.conf /etc/redis.conf
[root@localhost redis-2.8.7]# cd /etc/redis.conf
bash: cd: /etc/redis.conf: 不是目录
[root@localhost redis-2.8.7]# cd /etc/
--vi的过程打印不出来 我只是改了配置文件里的daemonize 默认是no 改为yes,这样修改之后,即使关闭了shell窗口,redis server也依然在后台运行。
[root@localhost etc]# vi redis.conf
[root@localhost etc]# su redis
--启动redis 如果不加conf参数 会是默认的conf
[redis@localhost etc]$ redis-server /etc/redis.conf
--使用客户端进行操作 测试成功
[redis@localhost etc]$ redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
--关闭redis(此处使用的是redis-cli进行的关闭操作)
127.0.0.1:6379> shutdown