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之後,自動顯示的提示信息)

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