Centos7安装Redis

下载源码:Wget http://download.redis.io/releases/redis-3.2.7.tar.gz

解压:tar xzf redis-3.2.7.tar.gz

cd redis-3.2.7

[root@devmaster redis-3.2.7]# make
cd src && make all
make[1]: Entering directory `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/opt/redis-3.2.7/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 `/opt/redis-3.2.7/src'
make: *** [all] Error 2

安装gcc:

yum install gcc

 

验证gcc安装位置:

[root@devmaster opt]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz

 

查看gcc版本:

[root@devmaster opt]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

清空之前安装的错误编译信息:make distclean

 

重新编译:Make

重新安装:

[root@devmaster redis-3.2.7]# make
cd src && make all
make[1]: Entering directory `/opt/redis-3.2.7/src'
……
    LINK redis-check-aof
 
Hint: It's a good idea to run 'make test' ;)
 
make[1]: Leaving directory `/opt/redis-3.2.7/src'

 运行redis:

[root@devmaster redis-3.2.7]# src/redis-server
5705:C 06 Feb 17:38:06.390 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
5705:M 06 Feb 17:38:06.391 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 5705
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

5705:M 06 Feb 17:38:06.398 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
5705:M 06 Feb 17:38:06.398 # Server started, Redis version 3.2.7
5705:M 06 Feb 17:38:06.398 # 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.
5705:M 06 Feb 17:38:06.398 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
5705:M 06 Feb 17:38:06.398 * The server is now ready to accept connections on port 6379

看到最后的俩行,表示安装成功。



第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

意思是:TCP  backlog设置值,511没有成功,因为 /proc/sys/net/core/somaxconn这个设置的是更小的128.

临时解决方法:(即下次启动还需要修改此值)

echo 511 > /proc/sys/net/core/somaxconn

永久解决方法:(即以后启动还需要修改此值)

将其写入/etc/rc.local文件中。

baklog参数实际控制的是已经3次握手成功的还在accept queue的大小。

参考linux里的backlog详解

第二个警告: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 andthen reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

意思是:overcommit_memory参数设置为0!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。

临时解决方法:echo "vm.overcommit_memory=1" > /etc/sysctl.conf

永久解决方法:将其写入/etc/sysctl.conf文件中。

参考:有关linux下redis overcommit_memory的问题

第三个警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain thesetting after a reboot. Redis must be restarted after THP is disabled.

意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。

临时解决方法:

echo never > /sys/kernel/mm/transparent_hugepage/enabled。

永久解决方法:

将其写入/etc/rc.local文件中。

参考透明大页介绍


测试:

[root@devmaster src]# cd src
[root@devmaster src]# ./redis-cli    
redis-cli -h 10.168.85.25 -p 6379


127.0.0.1:6379> ping 
PONG
127.0.0.1:6379> set foor tesetvalue
OK
127.0.0.1:6379> get foor
"tesetvalue"
127.0.0.1:6379> incr mycounter
(integer) 1
127.0.0.1:6379> incr mycounter
(integer) 2

127.0.0.1:6379> set key value [EX seconds] [PX milliseconds] [NX|XX]

很有意思的是,命令行中也有命令提示(可以看最后一行浅灰色的,就是输入一个set之后,自动显示的提示信息)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章