IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Redis + RHEL 7.1:编译安装 与 简单的使用

    Adamhuan发表于 2017-05-16 06:47:27
    love 0

    如题所示,本文在RHEL7.1上面编译安装Redis。

    首先,要去官网获取REDIS的最新版本安装包。

    你可以从以下几个地址获取最新版的REDIS:
    1. http://download.redis.io/
    2. https://redis.io/download

    在Linux上下载:

    [root@oracle-cluster-4 redis]# cat /etc/redhat-release 
    Red Hat Enterprise Linux Server release 7.1 (Maipo)
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 ~]# ping baidu.com -c 3
    PING baidu.com (111.13.101.208) 56(84) bytes of data.
    64 bytes from 111.13.101.208: icmp_seq=1 ttl=50 time=27.5 ms
    64 bytes from 111.13.101.208: icmp_seq=2 ttl=50 time=27.7 ms
    64 bytes from 111.13.101.208: icmp_seq=3 ttl=50 time=26.7 ms
    
    --- baidu.com ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2002ms
    rtt min/avg/max/mdev = 26.777/27.380/27.786/0.434 ms
    [root@oracle-cluster-4 ~]# 
    [root@oracle-cluster-4 ~]# mkdir /software
    [root@oracle-cluster-4 ~]# cd /software
    [root@oracle-cluster-4 software]# ls
    [root@oracle-cluster-4 software]# mkdir redis
    [root@oracle-cluster-4 software]# cd redis/
    [root@oracle-cluster-4 redis]# ls
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# wget http://download.redis.io/redis-stable.tar.gz
    --2017-05-16 10:34:09--  http://download.redis.io/redis-stable.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: 1575076 (1.5M) [application/x-gzip]
    Saving to: ‘redis-stable.tar.gz’
    
    100%[=======================================================================================================================================>] 1,575,076   97.5KB/s   in 47s    
    
    2017-05-16 10:34:58 (32.8 KB/s) - ‘redis-stable.tar.gz’ saved [1575076/1575076]
    
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# pwd
    /software/redis
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# ls -ltr *
    -rw-r--r--. 1 root root 1575076 Feb 12 23:15 redis-stable.tar.gz
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# du -sh *
    1.6M    redis-stable.tar.gz
    [root@oracle-cluster-4 redis]#

    解压:

    [root@oracle-cluster-4 redis]# tar -xzf redis-stable.tar.gz 
    [root@oracle-cluster-4 redis]# ls -ltr *
    -rw-r--r--. 1 root     root     1575076 Feb 12 23:15 redis-stable.tar.gz
    
    redis-stable:
    total 204
    drwxr-xr-x.  7 adamhuan adamhuan  4096 Feb 12 23:14 utils
    drwxr-xr-x. 10 adamhuan adamhuan  4096 Feb 12 23:14 tests
    drwxr-xr-x.  2 adamhuan adamhuan  4096 Feb 12 23:14 src
    -rw-r--r--.  1 adamhuan adamhuan  7606 Feb 12 23:14 sentinel.conf
    -rwxr-xr-x.  1 adamhuan adamhuan   281 Feb 12 23:14 runtest-sentinel
    -rwxr-xr-x.  1 adamhuan adamhuan   280 Feb 12 23:14 runtest-cluster
    -rwxr-xr-x.  1 adamhuan adamhuan   271 Feb 12 23:14 runtest
    -rw-r--r--.  1 adamhuan adamhuan 46695 Feb 12 23:14 redis.conf
    -rw-r--r--.  1 adamhuan adamhuan  6834 Feb 12 23:14 README.md
    -rw-r--r--.  1 adamhuan adamhuan  4223 Feb 12 23:14 MANIFESTO
    -rw-r--r--.  1 adamhuan adamhuan   151 Feb 12 23:14 Makefile
    -rw-r--r--.  1 adamhuan adamhuan    11 Feb 12 23:14 INSTALL
    drwxr-xr-x.  7 adamhuan adamhuan  4096 Feb 12 23:14 deps
    -rw-r--r--.  1 adamhuan adamhuan  1487 Feb 12 23:14 COPYING
    -rw-r--r--.  1 adamhuan adamhuan  1805 Feb 12 23:14 CONTRIBUTING
    -rw-r--r--.  1 adamhuan adamhuan    53 Feb 12 23:14 BUGS
    -rw-r--r--.  1 adamhuan adamhuan 85775 Feb 12 23:14 00-RELEASENOTES
    [root@oracle-cluster-4 redis]#

    编译:

    [root@oracle-cluster-4 redis]# ls -ltr
    total 1544
    drwxr-xr-x. 6 adamhuan adamhuan    4096 Feb 12 23:14 redis-stable
    -rw-r--r--. 1 root     root     1575076 Feb 12 23:15 redis-stable.tar.gz
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# cd redis-stable/
    [root@oracle-cluster-4 redis-stable]# 
    
    [root@oracle-cluster-4 redis-stable]# make
    cd src && make all
    make[1]: Entering directory `/software/redis/redis-stable/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
    (cd ../deps && make distclean)
    make[2]: Entering directory `/software/redis/redis-stable/deps'
    (cd hiredis && make clean) > /dev/null || true
    (cd linenoise && make clean) > /dev/null || true
    (cd lua && make clean) > /dev/null || true
    (cd geohash-int && make clean) > /dev/null || true
    (cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
    (rm -f .make-*)
    make[2]: Leaving directory `/software/redis/redis-stable/deps'
    (rm -f .make-*)
    echo STD=-std=c99 -pedantic -DREDIS_STATIC='' >> .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 -DREDIS_STATIC='' -Wall -W -O2 -g -ggdb   -I../deps/geohash-int -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 geohash-int jemalloc)
    make[2]: Entering directory `/software/redis/redis-stable/deps'
    (cd hiredis && make clean) > /dev/null || true
    (cd linenoise && make clean) > /dev/null || true
    (cd lua && make clean) > /dev/null || true
    (cd geohash-int && 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 `/software/redis/redis-stable/deps/hiredis'
    cc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.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]: Leaving directory `/software/redis/redis-stable/deps/jemalloc'
    make[2]: Leaving directory `/software/redis/redis-stable/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 geo.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
        CC redis-check-aof.o
        LINK redis-check-aof
    
    Hint: It's a good idea to run 'make test' ;)
    
    make[1]: Leaving directory `/software/redis/redis-stable/src'
    [root@oracle-cluster-4 redis-stable]#

    【make install】:

    [root@oracle-cluster-4 redis-stable]# make install
    cd src && make install
    make[1]: Entering directory `/software/redis/redis-stable/src'
    
    Hint: It's a good idea to run 'make test' ;)
    
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
    make[1]: Leaving directory `/software/redis/redis-stable/src'
    [root@oracle-cluster-4 redis-stable]#

    这样就安装完成了。

    查看下版本信息:

    [root@oracle-cluster-4 redis-stable]# redis-cli --version
    redis-cli 3.2.8
    [root@oracle-cluster-4 redis-stable]#

    启动Redis:

    一、直接启动redis
    启动前:

    [root@oracle-cluster-4 redis-stable]# ps -ef | grep redis
    root      6448  3017  0 10:53 pts/0    00:00:00 grep --color=auto redis
    [root@oracle-cluster-4 redis-stable]#

    启动:

    [root@oracle-cluster-4 redis-stable]# redis-server 
    6490:C 16 May 10:54:15.515 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
    6490:M 16 May 10:54:15.516 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 3.2.8 (00000000/0) 64 bit
      .-`` .-```.  ```\/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 6490
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    6490:M 16 May 10:54:16.041 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    6490:M 16 May 10:54:16.041 # Server started, Redis version 3.2.8
    6490:M 16 May 10:54:16.041 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
    6490:M 16 May 10:54:16.041 * The server is now ready to accept connections on port 6379

    查看系统进程状态:

    [root@oracle-cluster-4 ~]# ps -ef | grep redis
    root      6490  3017  1 10:54 pts/0    00:00:00 redis-server *:6379
    root      6494  6449  0 10:54 pts/1    00:00:00 grep --color=auto redis
    [root@oracle-cluster-4 ~]# 
    [root@oracle-cluster-4 ~]# netstat -tupln | grep redis
    tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      6490/redis-server * 
    tcp6       0      0 :::6379                 :::*                    LISTEN      6490/redis-server * 
    [root@oracle-cluster-4 ~]#

    默认,redis启动在端口【6379】上,… 也可以自定义端口:redis-server –port xxx

    Redis的命令行窗口:

    [root@oracle-cluster-4 redis]# ifconfig | grep inet
            inet 10.158.1.178  netmask 255.255.254.0  broadcast 10.158.1.255
            inet6 fe80::250:56ff:fe84:f8a  prefixlen 64  scopeid 0x20
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# redis-cli ping
    PONG
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# redis-cli echo "Hello world"
    "Hello world"
    [root@oracle-cluster-4 redis]#

    停止Redis:

    [root@oracle-cluster-4 redis]# ps -ef | grep redis
    root      9415  9373  0 14:20 pts/1    00:00:00 redis-server *:6379
    root      9435  9052  0 14:22 pts/0    00:00:00 grep --color=auto redis
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# redis-cli shutdown
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]# ps -ef | grep redis
    root      9447  9052  0 14:22 pts/0    00:00:00 grep --color=auto redis
    [root@oracle-cluster-4 redis]# 
    [root@oracle-cluster-4 redis]#

    停止过程中,产生的日志:

    9415:M 16 May 14:22:15.582 # User requested shutdown...
    9415:M 16 May 14:22:15.582 * Saving the final RDB snapshot before exiting.
    9415:M 16 May 14:22:15.633 * DB saved on disk
    9415:M 16 May 14:22:15.633 # Redis is now ready to exit, bye bye...

    ————————————————————
    Done。



沪ICP备19023445号-2号
友情链接