您的位置:首页 > 数据库 > Redis

【redis的搭建】centos6.4下搭建redis

2017-08-21 17:56 267 查看
说明:本文内容参考自一些资料,如有雷同,还请见谅。

部分参考:
http://blog.csdn.net/su377486/article/details/51803616 http://blog.csdn.net/wzygis/article/details/51705559
1.下载redis

[root@zhangmeng ~]#  wget http://download.redis.io/releases/redis-3.2.10.tar.gz --2017-08-18 18:14:39--  http://download.redis.io/releases/redis-3.2.10.tar.gz Resolving download.redis.io... 109.74.203.151
Connecting to download.redis.io|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1550261 (1.5M) [application/x-gzip]
Saving to: ?.edis-3.2.10.tar.gz?

100%[=======================================================================================>] 1,550,261    510K/s   in 3.0s

2017-08-18 18:14:42 (510 KB/s) - ?.edis-3.2.10.tar.gz?.saved [1550261/1550261]

[root@zhangmeng ~]# ll
total 1194064
-rw-------. 1 root root        959 Jun 22 11:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1221135418 Aug 18 17:29 cp_cmpyun_test.sql
-rw-r--r--. 1 root root       8785 Jun 22 11:24 install.log
-rw-r--r--. 1 root root       3161 Jun 22 11:24 install.log.syslog
-rw-r--r--. 1 root root       5824 Nov 12  2015 mysql-community-release-el6-5.noarch.rpm
-rw-r--r--. 1 root root    1550261 Jul 29 00:00 redis-3.2.10.tar.gz


2.解压文件

[root@zhangmeng ~]# tar xf redis-3.2.10.tar.gz
[root@zhangmeng ~]#
[root@zhangmeng ~]# ll
total 1194068
-rw-------. 1 root root        959 Jun 22 11:24 anaconda-ks.cfg
-rw-r--r--. 1 root root 1221135418 Aug 18 17:29 cp_cmpyun_test.sql
-rw-r--r--. 1 root root       8785 Jun 22 11:24 install.log
-rw-r--r--. 1 root root       3161 Jun 22 11:24 install.log.syslog
-rw-r--r--. 1 root root       5824 Nov 12  2015 mysql-community-release-el6-5.noarch.rpm
drwxrwxr-x. 6 root root       4096 Jul 28 23:59 redis-3.2.10
-rw-r--r--. 1 root root    1550261 Jul 29 00:00 redis-3.2.10.tar.gz


3.编译及安装

[root@zhangmeng ~]# cd redis-3.2.10
[root@zhangmeng redis-3.2.10]# make && make install
cd src && make all
make[1]: Entering directory `/root/redis-3.2.10/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 `/root/redis-3.2.10/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 `/root/redis-3.2.10/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 `/root/redis-3.2.10/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-ldflags)
(echo "" > .make-cflags)
MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/root/redis-3.2.10/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 `/root/redis-3.2.10/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/root/redis-3.2.10/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 `/root/redis-3.2.10/src'
make: *** [all] Error 2
[root@zhangmeng redis-3.2.10]#


4.上面报错:

make[3]: gcc: Command not found

/bin/sh: cc: command not found

是由于系统没有安装gcc

安装gcc:yum -y install gcc

Dependencies Resolved

==========================================================================================
Package                Arch           Version                      Repository       Size
==========================================================================================
Installing:
gcc                    x86_64         4.4.7-18.el6                 base             10 M
Installing for dependencies:
cloog-ppl              x86_64         0.15.7-1.2.el6               base             93 k
cpp                    x86_64         4.4.7-18.el6                 base            3.7 M
glibc-devel            x86_64         2.12-1.209.el6_9.2           updates         991 k
glibc-headers          x86_64         2.12-1.209.el6_9.2           updates         620 k
kernel-headers         x86_64         2.6.32-696.6.3.el6           updates         4.5 M
libgomp                x86_64         4.4.7-18.el6                 base            134 k
mpfr                   x86_64         2.4.1-6.el6                  base            157 k
ppl                    x86_64         0.10.2-11.el6                base            1.3 M
Updating for dependencies:
glibc                  x86_64         2.12-1.209.el6_9.2           updates         3.8 M
glibc-common           x86_64         2.12-1.209.el6_9.2           updates          14 M
libgcc                 x86_64         4.4.7-18.el6                 base            103 k
tzdata                 noarch         2017b-1.el6                  updates         455 k

Transaction Summary


5.重新编译安装,还是报错

[root@zhangmeng redis-3.2.10]# make && make install
cd src && make all
make[1]: Entering directory `/root/redis-3.2.10/src'
CC adlist.o
In file included from adlist.c:34:
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/root/redis-3.2.10/src'
make: *** [all] Error 2


6.上网查了一下,将make改为make MALLOC=libc,推测是因为编译库的问题。

[root@zhangmeng redis-3.2.10]# make MALLOC=libc
  ......
   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 `/root/redis-3.2.10/src'
[root@zhangmeng redis-3.2.10]#


7.make完成之后,进行install,默认安装路径为/usr/local/bin下,这里我们把他安装目录放到/usr/local/redis下,使用PREFIX指定目录

[root@zhangmeng redis-3.2.10]# mkdir /usr/local/redis
[root@zhangmeng redis-3.2.10]# make PREFIX=/usr/local/redis install
cd src && make install
make[1]: Entering directory `/root/redis-3.2.10/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 `/root/redis-3.2.10/src'
[root@zhangmeng redis-3.2.10]#


8.将redis可执行目录添加到环境变量中,编辑~/.bash_profile添加redis环境变量

[root@zhangmeng redis-3.2.10]# vi ~/.bash_profile
[root@zhangmeng redis-3.2.10]#
[root@zhangmeng redis-3.2.10]# cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=/usr/local/redis/bin:$PATH:$HOME/bin

export PATH
[root@zhangmeng redis-3.2.10]#


9.拷贝redis.conf文件到/etc下

[root@zhangmeng redis-3.2.10]# cp redis.conf /etc/


10.查看redis参数

[root@zhangmeng redis-3.2.10]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options]
./redis-server - (read config from stdin)
./redis-server -v or --version
./redis-server -h or --help
./redis-server --test-memory <megabytes>

Examples:
./redis-server (run the server with default conf)
./redis-server /etc/redis/6379.conf
./redis-server --port 7777
./redis-server --port 7777 --slaveof 127.0.0.1 8888
./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
./redis-server /etc/sentinel.conf --sentinel
[root@zhangmeng redis-3.2.10]#


11.版本查看

[root@zhangmeng redis-3.2.10]# redis-server -v
Redis server v=3.2.10 sha=00000000:0 malloc=libc bits=64 build=a60a764624df1665


12.启动redis服务

[root@zhangmeng redis-3.2.10]# redis-server /etc/redis.conf
3268:M 21 Aug 15:10:51.251 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-``    `.  `_.  ''-._           Redis 3.2.10 (00000000/0) 64 bit
.-`` .-```.  ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 3268
`-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |           http://redis.io `-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |
`-._    `-._`-.__.-'_.-'    _.-'
`-._    `-.__.-'    _.-'
`-._        _.-'
`-.__.-'

3268:M 21 Aug 15:10:51.355 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3268:M 21 Aug 15:10:51.355 # Server started, Redis version 3.2.10
3268:M 21 Aug 15:10:51.356 # 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.
3268:M 21 Aug 15:10:51.357 # 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.
3268:M 21 Aug 15:10:51.357 * The server is now ready to accept connections on port 6379


13.测试启动 redis-cli ping 返回PONG,启动成功。

[root@zhangmeng ~]# redis-cli ping
PONG
[root@zhangmeng ~]#
[root@zhangmeng ~]# netstat -tulnp |grep 6379
tcp        0      0 127.0.0.1:6379              0.0.0.0:*                   LISTEN      3268/redis-server 1


14.关闭redis服务(备注:可指定端口:redis-cli -p <port> shutdown)

[root@zhangmeng ~]# redis-cli shutdown
[root@zhangmeng ~]#
[root@zhangmeng ~]# netstat -tulnp |grep 6379
[root@zhangmeng ~]#
[root@zhangmeng ~]# redis-cli ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused
[root@zhangmeng ~]#

.......
_._
_.-``__ ''-._
_.-``    `.  `_.  ''-._           Redis 3.2.10 (00000000/0) 64 bit
.-`` .-```.  ```\/    _.,_ ''-._
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 3268
`-._    `-._  `-./  _.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |           http://redis.io `-._    `-._`-.__.-'_.-'    _.-'
|`-._`-._    `-.__.-'    _.-'_.-'|
|    `-._`-._        _.-'_.-'    |
`-._    `-._`-.__.-'_.-'    _.-'
`-._    `-.__.-'    _.-'
`-._        _.-'
`-.__.-'

3268:M 21 Aug 15:10:51.355 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
3268:M 21 Aug 15:10:51.355 # Server started, Redis version 3.2.10
3268:M 21 Aug 15:10:51.356 # 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.
3268:M 21 Aug 15:10:51.357 # 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.
3268:M 21 Aug 15:10:51.357 * The server is now ready to accept connections on port 6379
3268:M 21 Aug 15:19:09.124 # User requested shutdown...
3268:M 21 Aug 15:19:09.124 * Saving the final RDB snapshot before exiting.
3268:M 21 Aug 15:19:09.185 * DB saved on disk
3268:M 21 Aug 15:19:09.185 * Removing the pid file.
3268:M 21 Aug 15:19:09.185 # Redis is now ready to exit, bye bye...


15.连接redis,下面的提示是因为刚才我们把redis关了(连接redis的两种方法见http://www.cnblogs.com/xphdbky/p/7405825.html

[root@zhangmeng ~]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: