Redis安装与启动    ​

Redis【REmote DIctionary Server】作为当前比较流行的NoSql数据库,以其高性能,高可用的的特点,应用越来越广泛,深得各大企业和开发人员的青睐,本文主要简述Redis的下载,安装,启动,关闭的整个流程,仅供学习分享使用,如有不足之处,还请指正。

 概述

Redis【REmote DIctionary Server】作为当前比较流行的NoSql数据库,以其高性能,高可用的的特点,应用越来越广泛,深得各大企业和开发人员的青睐,本文主要简述Redis的下载,安装,启动,关闭的整个流程,仅供学习分享使用,如有不足之处,还请指正。

什么是Redis?

Redis 是完全开源的,遵守 BSD 协议,是一个高性能的 key-value 数据库。

Redis 与其他 key - value 缓存产品有以下三个特点:

  1. Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。
  2. Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
  3. Redis支持数据的备份,即master-slave模式的数据备份。

Redis 优势

  • 性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s 。
  • 丰富的数据类型 – Redis支持二进制案例的 Strings, Lists, Hashes, Sets 及 Ordered Sets 数据类型操作。
  • 原子 – Redis的所有操作都是原子性的,意思就是要么成功执行要么失败完全不执行。单个操作是原子性的。多个操作也支持事务,即原子性,通过MULTI和EXEC指令包起来。
  • 丰富的特性 – Redis还支持 publish/subscribe, 通知, key 过期等等特性。

Redis安装环境

  • 操作系统:Linux CentOS 7.0 64位操作系统
  • Redis版本:稳定版 redis6.0.9

Redis下载安装包

Redis的安装包,可以到​​Redis官网​​进行下载最新稳定版本,目前的稳定版本为redis6.0.9,如下所示:

Redis安装与启动_Redis

Redis安装

1. 下载安装包【redis-6.0.9.tar.gz】以后,通过Xftp工具,上传到Linux系统中 HOME/DownLoad中。然后切换到home/DownLoad 并通过 【tar -zxvf redis-6.0.9.tar.gz 】进行解压到当前目录。如下所示:

Redis安装与启动_Redis_02

2. 通过过cp -r redis-6.0.9 /usr/local/src/redis 命令,将复制解压后的目录到/usr/local/src目录下,并修改文件夹名称为redis。如下所示:

Redis安装与启动_Redis_03

3. 通过gcc -v命令检测gcc是否安装。如下所示:

Redis安装与启动_Redis_04

 4. 如果没有安装,则通过yum install gcc-c++命令进行安装,如下所示:

Redis安装与启动_Redis_05

5. gcc安装成功后,进入到/usr/local/src/redis/deps目录下,对hiredis lua jemalloc linenoise 四个进行预编译,命令为【 make hiredis lua jemalloc linenoise 】编译过程无error出现,则表示预编译成功。如下所示:

Redis安装与启动_Redis_06Redis安装与启动_Redis_07

1 [root@bogon deps]# ls  2 hiredis  jemalloc  linenoise  lua  Makefile  README.md  update-jemalloc.sh  3 [root@bogon deps]# make hiredis lua jemalloc linenoise  4 MAKE hiredis  5 cd hiredis && make static 
6 make[1]: Entering directory `/usr/local/src/redis/deps/hiredis' 7 make[1]: Nothing to be done for `static'. 8 make[1]: Leaving directory `/usr/local/src/redis/deps/hiredis' 9 MAKE lua 10 cd lua/src && make all CFLAGS="-O2 -Wall -DLUA_ANSI -DENABLE_CJSON_GLOBAL -DREDIS_STATIC='' " MYLDFLAGS="" AR="ar rcu" 11 make[1]: Entering directory `/usr/local/src/redis/deps/lua/src' 12 make[1]: Nothing to be done for `all'. 13 make[1]: Leaving directory `/usr/local/src/redis/deps/lua/src' 14 MAKE jemalloc 15 cd jemalloc && ./configure --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" 16 configure: WARNING: unrecognized options: --enable-cc-silence 17 checking for xsltproc... /usr/bin/xsltproc 18 checking for gcc... gcc 19 checking whether the C compiler works... yes 20 checking for C compiler default output file name... a.out 21 checking for suffix of executables...
22 checking whether we are cross compiling... no 23 checking for suffix of object files... o 24 checking whether we are using the GNU C compiler... yes 25 checking whether gcc accepts -g... yes 26 checking for gcc option to accept ISO C89... none needed 27 checking whether compiler is cray... no 28 checking whether compiler supports -std=gnu11... yes 29 checking whether compiler supports -Wall... yes 30 checking whether compiler supports -Wshorten-64-to-32... no 31 checking whether compiler supports -Wsign-compare... yes 32 checking whether compiler supports -Wundef... yes 33 checking whether compiler supports -Wno-format-zero-length... yes 34 checking whether compiler supports -pipe... yes 35 checking whether compiler supports -g3... yes 36 checking how to run the C preprocessor... gcc -E 37 checking for g++... g++ 38 checking whether we are using the GNU C++ compiler... yes 39 checking whether g++ accepts -g... yes 40 checking whether g++ supports C++14 features by default... no 41 checking whether g++ supports C++14 features with -std=c++14... no 42 checking whether g++ supports C++14 features with -std=c++0x... no 43 checking whether g++ supports C++14 features with +std=c++14... no 44 checking whether g++ supports C++14 features with -h std=c++14... no 45 configure: No compiler with C++14 support was found 46 checking for grep that handles long lines and -e... /usr/bin/grep 47 checking for egrep... /usr/bin/grep -E 48 checking for ANSI C header files... yes 49 checking for sys/types.h... yes 50 checking for sys/stat.h... yes 51 checking for stdlib.h... yes 52 checking for string.h... yes 53 checking for memory.h... yes 54 checking for strings.h... yes 55 checking for inttypes.h... yes 56 checking for stdint.h... yes 57 checking for unistd.h... yes 58 checking whether byte ordering is bigendian... no 59 checking size of void *... 8 60 checking size of int... 4 61 checking size of long... 8 62 checking size of long long... 8 63 checking size of intmax_t... 8 64 checking build system type... x86_64-pc-linux-gnu 65 checking host system type... x86_64-pc-linux-gnu 66 checking whether pause instruction is compilable... yes 67 checking number of significant virtual address bits... 48 68 checking for ar... ar 69 checking for nm... nm 70 checking for gawk... gawk 71 checking malloc.h usability... yes 72 checking malloc.h presence... yes 73 checking for malloc.h... yes 74 checking whether malloc_usable_size definition can use const argument... no 75 checking for library containing log... -lm 76 checking whether __attribute__ syntax is compilable... yes 77 checking whether compiler supports -fvisibility=hidden... yes 78 checking whether compiler supports -fvisibility=hidden... yes 79 checking whether compiler supports -Werror... yes 80 checking whether compiler supports -herror_on_warning... no 81 checking whether tls_model attribute is compilable... yes 82 checking whether compiler supports -Werror... yes 83 checking whether compiler supports -herror_on_warning... no 84 checking whether alloc_size attribute is compilable... yes 85 checking whether compiler supports -Werror... yes 86 checking whether compiler supports -herror_on_warning... no 87 checking whether format(gnu_printf, ...) attribute is compilable... yes 88 checking whether compiler supports -Werror... yes 89 checking whether compiler supports -herror_on_warning... no 90 checking whether format(printf, ...) attribute is compilable... yes 91 checking for a BSD-compatible install... /usr/bin/install -c 92 checking for ranlib... ranlib 93 checking for ld... /usr/bin/ld 94 checking for autoconf... false 95 checking for memalign... yes 96 checking for valloc... yes 97 checking whether compiler supports -O3... yes 98 checking whether compiler supports -O3... yes 99 checking whether compiler supports -funroll-loops... yes100 checking configured backtracing method... N/A101 checking for sbrk... yes102 checking whether utrace(2) is compilable... no103 checking whether a program using __builtin_unreachable is compilable... yes104 checking whether a program using __builtin_ffsl is compilable... yes105 checking LG_PAGE... 12106 checking pthread.h usability... yes107 checking pthread.h presence... yes108 checking for pthread.h... yes109 checking for pthread_create in -lpthread... yes110 checking dlfcn.h usability... yes111 checking dlfcn.h presence... yes112 checking for dlfcn.h... yes113 checking for dlsym... no114 checking for dlsym in -ldl... yes115 checking whether pthread_atfork(3) is compilable... yes116 checking whether pthread_setname_np(3) is compilable... yes117 checking for library containing clock_gettime... none required118 checking whether clock_gettime(CLOCK_MONOTONIC_COARSE, ...) is compilable... yes119 checking whether clock_gettime(CLOCK_MONOTONIC, ...) is compilable... yes120 checking whether mach_absolute_time() is compilable... no121 checking whether compiler supports -Werror... yes122 checking whether syscall(2) is compilable... yes123 checking for secure_getenv... yes124 checking for sched_getcpu... yes125 checking for sched_setaffinity... yes126 checking for issetugid... no127 checking for _malloc_thread_cleanup... no128 checking for _pthread_mutex_init_calloc_cb... no129 checking for TLS... yes130 checking whether C11 atomics is compilable... no131 checking whether GCC __atomic atomics is compilable... yes132 checking whether GCC __sync atomics is compilable... yes133 checking whether Darwin OSAtomic*() is compilable... no134 checking whether madvise(2) is compilable... yes135 checking whether madvise(..., MADV_FREE) is compilable... no136 checking whether madvise(..., MADV_DONTNEED) is compilable... yes137 checking whether madvise(..., MADV_DO[NT]DUMP) is compilable... yes138 checking whether madvise(..., MADV_[NO]HUGEPAGE) is compilable... yes139 checking whether to force 32-bit __sync_{add,sub}_and_fetch()... no140 checking whether to force 64-bit __sync_{add,sub}_and_fetch()... no141 checking for __builtin_clz... yes142 checking whether Darwin os_unfair_lock_*() is compilable... no143 checking whether Darwin OSSpin*() is compilable... no144 checking whether glibc malloc hook is compilable... yes145 checking whether glibc memalign hook is compilable... yes146 checking whether pthreads adaptive mutexes is compilable... yes147 checking whether compiler supports -D_GNU_SOURCE... yes148 checking whether compiler supports -Werror... yes149 checking whether compiler supports -herror_on_warning... no150 checking whether strerror_r returns char with gnu source is compilable... yes151 checking for stdbool.h that conforms to C99... yes152 checking for _Bool... yes153 configure: creating ./config.status154 config.status: creating Makefile155 config.status: creating jemalloc.pc156 config.status: creating doc/html.xsl157 config.status: creating doc/manpages.xsl158 config.status: creating doc/jemalloc.xml159 config.status: creating include/jemalloc/jemalloc_macros.h160 config.status: creating include/jemalloc/jemalloc_protos.h161 config.status: creating include/jemalloc/jemalloc_typedefs.h162 config.status: creating include/jemalloc/internal/jemalloc_preamble.h163 config.status: creating test/test.sh164 config.status: creating test/include/test/jemalloc_test.h165 config.status: creating config.stamp166 config.status: creating bin/jemalloc-config167 config.status: creating bin/jemalloc.sh168 config.status: creating bin/jeprof169 config.status: creating include/jemalloc/jemalloc_defs.h170 config.status: include/jemalloc/jemalloc_defs.h is unchanged171 config.status: creating include/jemalloc/internal/jemalloc_internal_defs.h172 config.status: include/jemalloc/internal/jemalloc_internal_defs.h is unchanged173 config.status: creating test/include/test/jemalloc_test_defs.h174 config.status: test/include/test/jemalloc_test_defs.h is unchanged175 config.status: executing include/jemalloc/internal/public_symbols.txt commands176 config.status: executing include/jemalloc/internal/private_symbols.awk commands177 config.status: executing include/jemalloc/internal/private_symbols_jet.awk commands178 config.status: executing include/jemalloc/internal/public_namespace.h commands179 config.status: executing include/jemalloc/internal/public_unnamespace.h commands180 config.status: executing include/jemalloc/internal/size_classes.h commands181 config.status: executing include/jemalloc/jemalloc_protos_jet.h commands182 config.status: executing include/jemalloc/jemalloc_rename.h commands183 config.status: executing include/jemalloc/jemalloc_mangle.h commands184 config.status: executing include/jemalloc/jemalloc_mangle_jet.h commands185 config.status: executing include/jemalloc/jemalloc.h commands186 configure: WARNING: unrecognized options: --enable-cc-silence187 ===============================================================================188 jemalloc version : 5.1.0-0-g0189 library revision : 2190 191 CONFIG : --with-version=5.1.0-0-g0 --with-lg-quantum=3 --with-jemalloc-prefix=je_ --enable-cc-silence 'CFLAGS=-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops ' LDFLAGS=192 CC : gcc193 CONFIGURE_CFLAGS : -std=gnu11 -Wall -Wsign-compare -Wundef -Wno-format-zero-length -pipe -g3 -fvisibility=hidden -O3 -funroll-loops194 SPECIFIED_CFLAGS : -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops
195 EXTRA_CFLAGS :
196 CPPFLAGS : -D_GNU_SOURCE -D_REENTRANT197 CXX : g++198 CONFIGURE_CXXFLAGS : -fvisibility=hidden -O3199 SPECIFIED_CXXFLAGS :
200 EXTRA_CXXFLAGS :
201 LDFLAGS :
202 EXTRA_LDFLAGS :
203 DSO_LDFLAGS : -shared -Wl,-soname,$(@F)204 LIBS : -lm -lpthread -ldl205 RPATH_EXTRA :
206 207 XSLTPROC : /usr/bin/xsltproc208 XSLROOT :
209 210 PREFIX : /usr/local211 BINDIR : /usr/local/bin212 DATADIR : /usr/local/share213 INCLUDEDIR : /usr/local/include214 LIBDIR : /usr/local/lib215 MANDIR : /usr/local/share/man216 217 srcroot :
218 abs_srcroot : /usr/local/src/redis/deps/jemalloc/219 objroot :
220 abs_objroot : /usr/local/src/redis/deps/jemalloc/221 222 JEMALLOC_PREFIX : je_223 JEMALLOC_PRIVATE_NAMESPACE224 : je_225 install_suffix :
226 malloc_conf :
227 autogen : 0228 debug : 0229 stats : 1230 prof : 0231 prof-libunwind : 0232 prof-libgcc : 0233 prof-gcc : 0234 fill : 1235 utrace : 0236 xmalloc : 0237 log : 0238 lazy_lock : 0239 cache-oblivious : 1240 cxx : 0241 ===============================================================================242 cd jemalloc && make CFLAGS="-std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops " LDFLAGS="" lib/libjemalloc.a243 make[1]: Entering directory `/usr/local/src/redis/deps/jemalloc'244 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/jemalloc.sym.o src/jemalloc.c245 nm -a src/jemalloc.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/jemalloc.sym246 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/arena.sym.o src/arena.c247 nm -a src/arena.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/arena.sym248 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/background_thread.sym.o src/background_thread.c249 nm -a src/background_thread.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/background_thread.sym250 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/base.sym.o src/base.c251 nm -a src/base.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/base.sym252 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/bin.sym.o src/bin.c253 nm -a src/bin.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/bin.sym254 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/bitmap.sym.o src/bitmap.c255 nm -a src/bitmap.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/bitmap.sym256 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/ckh.sym.o src/ckh.c257 nm -a src/ckh.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/ckh.sym258 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/ctl.sym.o src/ctl.c259 nm -a src/ctl.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/ctl.sym260 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/div.sym.o src/div.c261 nm -a src/div.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/div.sym262 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/extent.sym.o src/extent.c263 nm -a src/extent.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/extent.sym264 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/extent_dss.sym.o src/extent_dss.c265 nm -a src/extent_dss.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/extent_dss.sym266 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/extent_mmap.sym.o src/extent_mmap.c267 nm -a src/extent_mmap.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/extent_mmap.sym268 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/hash.sym.o src/hash.c269 nm -a src/hash.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/hash.sym270 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/hooks.sym.o src/hooks.c271 nm -a src/hooks.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/hooks.sym272 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/large.sym.o src/large.c273 nm -a src/large.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/large.sym274 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/log.sym.o src/log.c275 nm -a src/log.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/log.sym276 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/malloc_io.sym.o src/malloc_io.c277 nm -a src/malloc_io.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/malloc_io.sym278 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/mutex.sym.o src/mutex.c279 nm -a src/mutex.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/mutex.sym280 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/mutex_pool.sym.o src/mutex_pool.c281 nm -a src/mutex_pool.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/mutex_pool.sym282 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/nstime.sym.o src/nstime.c283 nm -a src/nstime.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/nstime.sym284 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/pages.sym.o src/pages.c285 nm -a src/pages.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/pages.sym286 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/prng.sym.o src/prng.c287 nm -a src/prng.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/prng.sym288 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/prof.sym.o src/prof.c289 nm -a src/prof.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/prof.sym290 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/rtree.sym.o src/rtree.c291 nm -a src/rtree.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/rtree.sym292 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/stats.sym.o src/stats.c293 nm -a src/stats.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/stats.sym294 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/sz.sym.o src/sz.c295 nm -a src/sz.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/sz.sym296 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/tcache.sym.o src/tcache.c297 nm -a src/tcache.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/tcache.sym298 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/ticker.sym.o src/ticker.c299 nm -a src/ticker.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/ticker.sym300 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/tsd.sym.o src/tsd.c301 nm -a src/tsd.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/tsd.sym302 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -DJEMALLOC_NO_PRIVATE_NAMESPACE -o src/witness.sym.o src/witness.c303 nm -a src/witness.sym.o | gawk -f include/jemalloc/internal/private_symbols.awk > src/witness.sym304 /bin/sh include/jemalloc/internal/private_namespace.sh src/jemalloc.sym src/arena.sym src/background_thread.sym src/base.sym src/bin.sym src/bitmap.sym src/ckh.sym src/ctl.sym src/div.sym src/extent.sym src/extent_dss.sym src/extent_mmap.sym src/hash.sym src/hooks.sym src/large.sym src/log.sym src/malloc_io.sym src/mutex.sym src/mutex_pool.sym src/nstime.sym src/pages.sym src/prng.sym src/prof.sym src/rtree.sym src/stats.sym src/sz.sym src/tcache.sym src/ticker.sym src/tsd.sym src/witness.sym > include/jemalloc/internal/private_namespace.gen.h305 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/jemalloc.o src/jemalloc.c306 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/arena.o src/arena.c307 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/background_thread.o src/background_thread.c308 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/base.o src/base.c309 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/bin.o src/bin.c310 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/bitmap.o src/bitmap.c311 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ckh.o src/ckh.c312 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ctl.o src/ctl.c313 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/div.o src/div.c314 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/extent.o src/extent.c315 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/extent_dss.o src/extent_dss.c316 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/extent_mmap.o src/extent_mmap.c317 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/hash.o src/hash.c318 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/hooks.o src/hooks.c319 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/large.o src/large.c320 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/log.o src/log.c321 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/malloc_io.o src/malloc_io.c322 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mutex.o src/mutex.c323 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/mutex_pool.o src/mutex_pool.c324 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/nstime.o src/nstime.c325 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/pages.o src/pages.c326 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/prng.o src/prng.c327 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/prof.o src/prof.c328 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/rtree.o src/rtree.c329 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/stats.o src/stats.c330 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/sz.o src/sz.c331 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tcache.o src/tcache.c332 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/ticker.o src/ticker.c333 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/tsd.o src/tsd.c334 gcc -std=gnu99 -Wall -pipe -g3 -O3 -funroll-loops -c -D_GNU_SOURCE -D_REENTRANT -Iinclude -Iinclude -o src/witness.o src/witness.c335 ar crus lib/libjemalloc.a src/jemalloc.o src/arena.o src/background_thread.o src/base.o src/bin.o src/bitmap.o src/ckh.o src/ctl.o src/div.o src/extent.o src/extent_dss.o src/extent_mmap.o src/hash.o src/hooks.o src/large.o src/log.o src/malloc_io.o src/mutex.o src/mutex_pool.o src/nstime.o src/pages.o src/prng.o src/prof.o src/rtree.o src/stats.o src/sz.o src/tcache.o src/ticker.o src/tsd.o src/witness.o336 make[1]: Leaving directory `/usr/local/src/redis/deps/jemalloc'337 MAKE linenoise338 cd linenoise && make339 make[1]: Entering directory `/usr/local/src/redis/deps/linenoise'340 make[1]: `linenoise.o' is up to date.341 make[1]: Leaving directory `/usr/local/src/redis/deps/linenoise'342 [root@bogon deps]#

View Code

6. 预编译成功后,则返回上级目录进一步对redis进行编译。命令为【make】,编译过程如下所示:

Redis安装与启动_Redis_07Redis安装与启动_Redis_06

1 [root@bogon redis]# make 2 cd src && make all 3 make[1]: Entering directory `/usr/local/src/redis/src' 4     CC Makefile.dep 5 make[1]: Leaving directory `/usr/local/src/redis/src' 6 make[1]: Entering directory `/usr/local/src/redis/src' 7     CC server.o 8     CC sds.o 9     CC zmalloc.o10     CC lzf_c.o11     CC lzf_d.o12     CC pqsort.o13     CC zipmap.o14     CC sha1.o15     CC ziplist.o16     CC release.o17     CC networking.o18     CC util.o19     CC object.o20     CC db.o21     CC replication.o22     CC rdb.o23     CC t_string.o24     CC t_list.o25     CC t_set.o26     CC t_zset.o27     CC t_hash.o28     CC config.o29     CC aof.o30     CC pubsub.o31     CC multi.o32     CC debug.o33     CC sort.o34     CC intset.o35     CC syncio.o36     CC cluster.o37     CC crc16.o38     CC endianconv.o39     CC slowlog.o40     CC scripting.o41     CC bio.o42     CC rio.o43     CC rand.o44     CC memtest.o45     CC crcspeed.o46     CC crc64.o47     CC bitops.o48     CC sentinel.o49     CC notify.o50     CC setproctitle.o51     CC blocked.o52     CC hyperloglog.o53     CC latency.o54     CC sparkline.o55     CC redis-check-rdb.o56     CC redis-check-aof.o57     CC geo.o58     CC lazyfree.o59     CC module.o60     CC evict.o61     CC expire.o62     CC geohash.o63     CC geohash_helper.o64     CC childinfo.o65     CC defrag.o66     CC siphash.o67     CC rax.o68     CC t_stream.o69     CC listpack.o70     CC localtime.o71     CC lolwut.o72     CC lolwut5.o73     CC lolwut6.o74     CC acl.o75     CC gopher.o76     CC tracking.o77     CC connection.o78     CC tls.o79     CC sha256.o80     CC timeout.o81     CC setcpuaffinity.o82     LINK redis-server83     INSTALL redis-sentinel84     CC redis-cli.o85     LINK redis-cli86     CC redis-benchmark.o87     LINK redis-benchmark88     INSTALL redis-check-rdb89     INSTALL redis-check-aof90 91 Hint: It's a good idea to run 'make test' ;)92 93 make[1]: Leaving directory `/usr/local/src/redis/src'

View Code

当出现如下所示,则表示编译成功,如下所示:

Redis安装与启动_Redis_10

 6. 编译成功后,则显示如下所示:

Redis安装与启动_Redis_11

7. 通过mkdir /usr/local/redis 命令在/usr/local目录下,创建redis文件夹。然后通过make install PREFIX=/usr/local/redis 命令进行安装redis。

Redis安装与启动_Redis_12

 8. 安装成功后,切换到/usr/local/redis/bin目录下进行查看,存在如下所示文件则表示安装成功。

Redis安装与启动_Redis_13

 9. 在root目录下,创建myredis文件夹,并将/usr/local/src/redis/redis.conf 文件复制到myredis文件夹下。【目的:方便后续修改】

复制命令为【cp redis.conf /root/myredis】执行过程如下所示:

Redis安装与启动_Redis_07Redis安装与启动_Redis_06

1 [root@bogon bin]# mkdir /root/myredis 2 [root@bogon bin]# cd ../../ 3 [root@bogon local]# cd src 4 [root@bogon src]# ls 5 redis 6 [root@bogon src]# cd redis 7 [root@bogon redis]# ll 8 total 292 9 -rw-r--r--.  1 root root 108806 Jan  1 20:50 00-RELEASENOTES10 -rw-r--r--.  1 root root     51 Jan  1 20:50 BUGS11 -rw-r--r--.  1 root root   2499 Jan  1 20:50 CONTRIBUTING12 -rw-r--r--.  1 root root   1487 Jan  1 20:50 COPYING13 drwxr-xr-x.  6 root root    192 Jan  1 21:00 deps14 -rw-r--r--.  1 root root     11 Jan  1 20:50 INSTALL15 -rw-r--r--.  1 root root    151 Jan  1 20:50 Makefile16 -rw-r--r--.  1 root root   6888 Jan  1 20:50 MANIFESTO17 -rw-r--r--.  1 root root  21099 Jan  1 20:50 README.md18 -rw-r--r--.  1 root root  84841 Jan  1 20:50 redis.conf19 -rwxr-xr-x.  1 root root    275 Jan  1 20:50 runtest20 -rwxr-xr-x.  1 root root    280 Jan  1 20:50 runtest-cluster21 -rwxr-xr-x.  1 root root    795 Jan  1 20:50 runtest-moduleapi22 -rwxr-xr-x.  1 root root    281 Jan  1 20:50 runtest-sentinel23 -rw-r--r--.  1 root root  10744 Jan  1 20:50 sentinel.conf24 drwxr-xr-x.  3 root root   8192 Jan  1 21:11 src25 drwxr-xr-x. 11 root root    182 Jan  1 20:50 tests26 -rw-r--r--.  1 root root   3055 Jan  1 20:50 TLS.md27 drwxr-xr-x.  9 root root   4096 Jan  1 20:50 utils28 [root@bogon redis]# cp redis.conf /root/myredis

View Code

10. 复制成功后,到/root/myredis进行查看,如下所示:

Redis安装与启动_Redis_16

 Redis启动

切换到usr/local/redis/bin目录,通过命令【./redis-server /root/myredis/redis.conf】进行启动,启动成功后,如下所示:

Redis安装与启动_Redis_17

redis默认的窗口是前台显示,不可以关闭的,需要重新打开一个窗口,通过redis客户端【/usr/local/redis/bin/redis-cli】进行访问。如下所示:

Redis安装与启动_Redis_18

通过按Ctrl+C,可以关闭redis打开的服务端窗口,返回命令窗口,如下所示:

Redis安装与启动_Redis_19

修改Redis为后台运行

redis默认为窗口运行,一旦关闭,则停止,可以通过修改配置文件/root/myredis/redis.conf,使redis后台运行,如下所示:

Redis安装与启动_Redis_20

关于Linux下如何修改文件,可参考上一篇博文。

重新启动redis,则以守护进程运行,如下所示:

Redis安装与启动_Redis_21

查看Redis进程

通过命令【ps -ef|grep redis】查看redis相关进程,如下所示:

Redis安装与启动_Redis_22

 Redis关闭服务

通过命令【./redis-cli shutdown】关闭redis服务,如下所示:

Redis安装与启动_Redis_23

 以上就是Redis的下载,安装,启动,关闭的整个流程。

编译异常处理

如果在编译redis的过程中,出现如下错误,则表示gcc版本太低,需要升级。错误如下所示:

Redis安装与启动_Redis_24

如果以上错误,需要执行三个命令进行升级,如下所示:

yum -y install centos-release-scl

yum -y install devtoolset-9-gcc devtoolset-g-gcc-c++ devtoolset-9-binutils

scl enable devtoolset-9 bash

执行过程,如下所示:

Redis安装与启动_Redis_07Redis安装与启动_Redis_06

1 [root@bogon redis]# yum -y install centos-release-scl  2 Loaded plugins: fastestmirror, langpacks  3 Loading mirror speeds from cached hostfile  4  * base: mirrors.163.com  5  * extras: mirrors.aliyun.com  6  * updates: mirrors.aliyun.com  7 Resolving Dependencies  8 --> Running transaction check  9 ---> Package centos-release-scl.noarch 0:2-3.el7.centos will be installed 10 --> Processing Dependency: centos-release-scl-rh for package: centos-release-scl-2-3.el7.centos.noarch 11 --> Running transaction check 12 ---> Package centos-release-scl-rh.noarch 0:2-3.el7.centos will be installed 13 --> Finished Dependency Resolution 14  15 Dependencies Resolved 16  17 =========================================================================================================== 18  Package                           Arch               Version                     Repository          Size 19 =========================================================================================================== 20 Installing: 21  centos-release-scl                noarch             2-3.el7.centos              extras              12 k 22 Installing for dependencies: 23  centos-release-scl-rh             noarch             2-3.el7.centos              extras              12 k 24  25 Transaction Summary 26 =========================================================================================================== 27 Install  1 Package (+1 Dependent package) 28  29 Total download size: 24 k 30 Installed size: 39 k 31 Downloading packages: 32 (1/2): centos-release-scl-2-3.el7.centos.noarch.rpm                                 |  12 kB  00:00:02     
33 (2/2): centos-release-scl-rh-2-3.el7.centos.noarch.rpm | 12 kB 00:00:02
34 ----------------------------------------------------------------------------------------------------------- 35 Total 8.8 kB/s | 24 kB 00:00:02
36 Running transaction check 37 Running transaction test 38 Transaction test succeeded 39 Running transaction 40 Installing : centos-release-scl-rh-2-3.el7.centos.noarch 1/2
41 Installing : centos-release-scl-2-3.el7.centos.noarch 2/2
42 Verifying : centos-release-scl-2-3.el7.centos.noarch 1/2
43 Verifying : centos-release-scl-rh-2-3.el7.centos.noarch 2/2
44 45 Installed: 46 centos-release-scl.noarch 0:2-3.el7.centos
47 48 Dependency Installed: 49 centos-release-scl-rh.noarch 0:2-3.el7.centos
50 51 Complete! 52 [root@bogon redis]# yum -y install devtoolset-9-gcc devtoolset-g-gcc-c++ devtoolset-9-binutils 53 Loaded plugins: fastestmirror, langpacks 54 Loading mirror speeds from cached hostfile 55 * base: mirrors.163.com 56 * centos-sclo-rh: mirrors.163.com 57 * centos-sclo-sclo: mirrors.163.com 58 * extras: mirrors.aliyun.com 59 * updates: mirrors.aliyun.com 60 No package devtoolset-g-gcc-c++ available. 61 Resolving Dependencies 62 --> Running transaction check 63 ---> Package devtoolset-9-binutils.x86_64 0:2.32-16.el7 will be installed 64 --> Processing Dependency: devtoolset-9-runtime for package: devtoolset-9-binutils-2.32-16.el7.x86_64 65 ---> Package devtoolset-9-gcc.x86_64 0:9.3.1-2.el7 will be installed 66 --> Running transaction check 67 ---> Package devtoolset-9-runtime.x86_64 0:9.1-0.el7 will be installed 68 --> Finished Dependency Resolution 69 70 Dependencies Resolved 71 72 =========================================================================================================== 73 Package Arch Version Repository Size 74 =========================================================================================================== 75 Installing: 76 devtoolset-9-binutils x86_64 2.32-16.el7 centos-sclo-rh 5.9 M 77 devtoolset-9-gcc x86_64 9.3.1-2.el7 centos-sclo-rh 32 M 78 Installing for dependencies: 79 devtoolset-9-runtime x86_64 9.1-0.el7 centos-sclo-rh 20 k 80 81 Transaction Summary 82 =========================================================================================================== 83 Install 2 Packages (+1 Dependent package) 84 85 Total download size: 38 M 86 Installed size: 100 M 87 Downloading packages: 88 warning: /var/cache/yum/x86_64/7/centos-sclo-rh/packages/devtoolset-9-runtime-9.1-0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f2ee9d55: NOKEY 89 Public key for devtoolset-9-runtime-9.1-0.el7.x86_64.rpm is not installed 90 (1/3): devtoolset-9-runtime-9.1-0.el7.x86_64.rpm | 20 kB 00:00:02
91 (2/3): devtoolset-9-binutils-2.32-16.el7.x86_64.rpm | 5.9 MB 00:00:34
92 (3/3): devtoolset-9-gcc-9.3.1-2.el7.x86_64.rpm | 32 MB 00:01:57
93 ----------------------------------------------------------------------------------------------------------- 94 Total 328 kB/s | 38 MB 00:01:57
95 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo 96 Importing GPG key 0xF2EE9D55: 97 Userid : "CentOS SoftwareCollections SIG (https://wiki.centos.org/SpecialInterestGroup/SCLo)" 98 Fingerprint: c4db d535 b1fb ba14 f8ba 64a8 4eb8 4e71 f2ee 9d55 99 Package : centos-release-scl-rh-2-3.el7.centos.noarch (@extras)100 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo101 Running transaction check102 Running transaction test103 Transaction test succeeded104 Running transaction105 Installing : devtoolset-9-runtime-9.1-0.el7.x86_64 1/3
106 Installing : devtoolset-9-binutils-2.32-16.el7.x86_64 2/3
107 Installing : devtoolset-9-gcc-9.3.1-2.el7.x86_64 3/3
108 Verifying : devtoolset-9-gcc-9.3.1-2.el7.x86_64 1/3
109 Verifying : devtoolset-9-binutils-2.32-16.el7.x86_64 2/3
110 Verifying : devtoolset-9-runtime-9.1-0.el7.x86_64 3/3
111 112 Installed:113 devtoolset-9-binutils.x86_64 0:2.32-16.el7 devtoolset-9-gcc.x86_64 0:9.3.1-2.el7
114 115 Dependency Installed:116 devtoolset-9-runtime.x86_64 0:9.1-0.el7
117 118 Complete!119 [root@bogon redis]# scl enable devtoolset-9 bash

View Code

备注

冬夜读书示子聿(yù)

陆游 〔宋代〕

古人学问无遗力,少壮工夫老始成。

纸上得来终觉浅,绝知此事要躬行。