先更新一下系统。
[janl@svr1 ~]$ sudo yum update [sudo] password for janl: Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn No packages marked for update
没有wget,先安装wget.
[janl@svr1 ~]$ sudo yum install wget
下载Redis 3.0.5 源码压缩包。
[janl@svr1 ~]$ wget http://download.redis.io/releases/redis-3.0.5.tar.gz --2015-11-17 23:01:06-- http://download.redis.io/releases/redis-3.0.5.tar.gz Resolving download.redis.io (download.redis.io)... 109.74.203.151 Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1366160 (1.3M) [application/x-gzip] Saving to: ‘redis-3.0.5.tar.gz’ 100%[======================================================================================================>] 1,366,160 14.2KB/s in 55s 2015-11-17 23:02:04 (24.3 KB/s) - ‘redis-3.0.5.tar.gz’ saved [1366160/1366160] [janl@svr1 ~]$ ls redis-3.0.5.tar.gz
解压源码包。
[janl@svr1 ~]$ tar xvzf redis-3.0.5.tar.gz
编译
[janl@svr1 ~]$ ll total 1340 drwxrwxr-x. 6 janl janl 4096 Oct 15 09:44 redis-3.0.5 -rw-rw-r--. 1 janl janl 1366160 Oct 15 09:48 redis-3.0.5.tar.gz [janl@svr1 ~]$ cd redis-3.0.5 [janl@svr1 redis-3.0.5]$ ls 00-RELEASENOTES CONTRIBUTING deps Makefile README runtest runtest-sentinel src utils BUGS COPYING INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests [janl@svr1 redis-3.0.5]$ make
排错,没有gcc,安装gcc-c++
cd src && make all make[1]: Entering directory `/home/janl/redis-3.0.5/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]: Entering directory `/home/janl/redis-3.0.5/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]: Leaving directory `/home/janl/redis-3.0.5/deps' (rm -f .make-*) echo STD=-std=c99 -pedantic >> .make-settings echo WARN=-Wall -W >> .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 -W -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]: Entering directory `/home/janl/redis-3.0.5/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]: Entering directory `/home/janl/redis-3.0.5/deps/hiredis' gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c make[3]: gcc: Command not found make[3]: *** [net.o] Error 127 make[3]: Leaving directory `/home/janl/redis-3.0.5/deps/hiredis' make[2]: *** [hiredis] Error 2 make[2]: Leaving directory `/home/janl/redis-3.0.5/deps' make[1]: [persist-settings] Error 2 (ignored) CC adlist.o /bin/sh: cc: command not found make[1]: *** [adlist.o] Error 127 make[1]: Leaving directory `/home/janl/redis-3.0.5/src' make: *** [all] Error 2
[janl@svr1 redis-3.0.5]$ sudo yum install gcc-c++ ...... Installed: gcc-c++.x86_64 0:4.8.3-9.el7 Dependency Installed: cpp.x86_64 0:4.8.3-9.el7 gcc.x86_64 0:4.8.3-9.el7 glibc-devel.x86_64 0:2.17-78.el7 glibc-headers.x86_64 0:2.17-78.el7 kernel-headers.x86_64 0:3.10.0-229.20.1.el7 libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.3-9.el7 mpfr.x86_64 0:3.1.1-4.el7 Complete!
排错,清理编译临时文件。
[janl@svr1 redis-3.0.5]$ make test cd src && make test make[1]: Entering directory `/home/janl/redis-3.0.5/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 `/home/janl/redis-3.0.5/src' make: *** [test] Error 2
[janl@svr1 redis-3.0.5]$ make distclean cd src && make distclean make[1]: Entering directory `/home/janl/redis-3.0.5/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]: Entering directory `/home/janl/redis-3.0.5/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]: Leaving directory `/home/janl/redis-3.0.5/deps' (rm -f .make-*) make[1]: Leaving directory `/home/janl/redis-3.0.5/src'
排错,安装tcl
[janl@svr1 src]$ make test ...... You need tcl 8.5 or newer in order to run the Redis test make: *** [test] Error 1
[janl@svr1 src]$ sudo yum install tcl [sudo] password for janl: Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirror.bit.edu.cn * updates: mirror.bit.edu.cn Resolving Dependencies --> Running transaction check ---> Package tcl.x86_64 1:8.5.13-4.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================================ Installing: tcl x86_64 1:8.5.13-4.el7 base 1.9 M Transaction Summary ================================================================================================================================================ Install 1 Package Total download size: 1.9 M Installed size: 4.4 M Is this ok [y/d/N]: y Downloading packages: tcl-8.5.13-4.el7.x86_64.rpm | 1.9 MB 00:00:03 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:tcl-8.5.13-4.el7.x86_64 1/1 Verifying : 1:tcl-8.5.13-4.el7.x86_64 1/1 Installed: tcl.x86_64 1:8.5.13-4.el7 Complete!
[janl@svr1 src]$ make distclean 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[1]: Entering directory `/home/janl/redis-3.0.5/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[1]: Leaving directory `/home/janl/redis-3.0.5/deps' (rm -f .make-*) [janl@svr1 src]$ make ...... 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' ;)
复制编译好的文件
[janl@svr1 src]$ sudo cp redis-benchmark /usr/local/bin/ [sudo] password for janl: [janl@svr1 src]$ sudo cp redis-check-dump /usr/local/bin/ [janl@svr1 src]$ sudo cp redis-sentinel /usr/local/bin/ [janl@svr1 src]$ sudo cp redis-trib.rb /usr/local/bin/ [janl@svr1 src]$ sudo cp redis-check-aof /usr/local/bin/ [janl@svr1 src]$ sudo cp redis-cli /usr/local/bin/ [janl@svr1 src]$ sudo cp redis-server /usr/local/bin/
创建工作目录
[janl@svr1 src]$ sudo mkdir /etc/redis [sudo] password for janl: [janl@svr1 src]$ sudo mkdir /var/redis [janl@svr1 src]$ sudo mkdir /var/redis/log [janl@svr1 src]$ sudo mkdir /var/redis/run [janl@svr1 src]$ sudo mkdir /var/redis/6379
复制修改配置文件
[janl@svr1 redis-3.0.5]$ sudo cp redis.conf /etc/redis/6379.conf [sudo] password for janl: [janl@svr1 redis-3.0.5]$ sudo vim /etc/redis/6379.conf
daemonize yes 介个是设置服务在后台运行 pidfile /var/redis/run/redis_6379.pid logfile /var/redis/log/redis_6379.log dir /var/redis/6379
运行redis-server
[janl@svr1 ~]$ sudo /usr/local/bin/redis-server /etc/redis/6379.conf
添加防火墙端口
[janl@svr1 bin]$ sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent [sudo] password for janl: success [janl@svr1 bin]$ firewall-cmd --reload Authorization failed. Make sure polkit agent is running or run the application as superuser. [janl@svr1 bin]$ sudo firewall-cmd --reload success
如果一切顺利,此时redis数据库已经可以正常工作了。