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

Redis介绍——Linux环境Redis安装全过程和遇到的问题及解决方案

2017-06-17 10:58 761 查看
一:redis的入门介绍:

1.是什么

--REmote DIctionary Server(远程字典服务器)

--完全开源免费,用c语言编写的,遵守BSD协议

--高性能(key/value)分布式内存数据库,基于内存运行。并支持持久化的NoSql数据库。

--Redis于其他key-value产品的三个特点

(1)可以持久化,到磁盘

(2)数据类型多,list,set,zset,hash的数据结构的存储

(3)支持数据备份,即master-slave模式

2.能干嘛

--内存的存储和持久化

--发布,订阅消息系统

--定时器、计算器

3.去哪里下载

--官网 www.redis.cn

4.怎么玩

--数据类型的基本操作

--持久化和复制

--事务的控制 - 部分成,不保证事务

--......

二:Redis安装全过程和遇到问题解决方案

1.下载redis安装包,然后使用解压命令进行解压

tar -zxvf redis.tar.gz

2.解压完成,进入解压的目录,使用make命令

[root@localhost redis-3.0.4]# make

然后遇到错误了!如下所示:老长一串了!大概看看就行!

cd src && make all
make[1]: Entering directory `/root/dufy/redis/redis-3.0.4/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 `/root/dufy/redis/redis-3.0.4/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 `/root/dufy/redis/redis-3.0.4/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 `/root/dufy/redis/redis-3.0.4/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-ldflags)
(echo "" > .make-cflags)
MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/root/dufy/redis/redis-3.0.4/deps/hiredis'
gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 错误 127
make[3]: Leaving directory `/root/dufy/redis/redis-3.0.4/deps/hiredis'
make[2]: *** [hiredis] 错误 2
make[2]: Leaving directory `/root/dufy/redis/redis-3.0.4/deps'
make[1]: [persist-settings] 错误 2 (忽略)
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] 错误 127
make[1]: Leaving directory `/root/dufy/redis/redis-3.0.4/src'
make: *** [all] 错误 2

怎么解决呢,安装进行不下去了,仔细看错误,发现make[3]: gcc:命令未找到 ,是gcc的问题啊!

解决方案在这里:使用yum进行安装gcc

备注:如果你的虚拟机可以直接上网,那么请直接使用下面命令:

yum -y install gcc

否则请先搭建本地yum源,使用光盘搭建,然后在使用下面命令:

yum -y install gcc

3.在此使用make命令

[root@localhost redis-3.0.4]# make

然后发现又有问题出现了?出错信息如下:

cd src && make all
make[1]: Entering directory `/root/dufy/redis/redis-3.0.4/src'
CC adlist.o
在包含自 adlist.c:34 的文件中:
zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
make[1]: *** [adlist.o] 错误 1
make[1]: Leaving directory `/root/dufy/redis/redis-3.0.4/src'
make: *** [all] 错误 2

备注:没有文件或者目录 ,这个是残存文件需要处理,使用命令make distclean

[root@localhost redis-3.0.4]# make distclean
cd src && make distclean
make[1]: Entering directory `/root/dufy/redis/redis-3.0.4/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 `/root/dufy/redis/redis-3.0.4/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 `/root/dufy/redis/redis-3.0.4/deps'
(rm -f .make-*)
make[1]: Leaving directory `/root/dufy/redis/redis-3.0.4/src'

在此执行make命令,一切ok了!

4.备份redis.conf,启动redis服务

注:安装了软件之后需要更改配置文件最好将原始的文件备份一份出来。

(1)进入到redis的目录:

cp redis.conf redis.conf.bak  #备份redis.conf

修改redis.conf

daemonize yes
#其他的配置暂时使用默认
#默认的端口是port 6379

(2)启动redis服务

redis的启动命令放在:


/usr/local/bin


启动命令:

#redis-server 目录名称/配置文件
#redis-server /root/dufy/redis/redis-3.0.4/redis.conf

[root@localhost redis-3.0.4]# cd /usr/local/bin/
[root@localhost bin]# ll
总用量 13848
-rwxr-xr-x. 1 root root 4165407 6月  17 06:19 redis-benchmark
-rwxr-xr-x. 1 root root   16467 6月  17 06:19 redis-check-aof
-rwxr-xr-x. 1 root root   37703 6月  17 06:19 redis-check-dump
-rwxr-xr-x. 1 root root 4254645 6月  17 06:19 redis-cli
lrwxrwxrwx. 1 root root      12 6月  17 06:19 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 5695533 6月  17 06:19 redis-server
[root@localhost bin]# redis-server /root/dufy/redis/redis-3.0.4/redis.conf

注:#加上
&
号使redis以后台程序方式运行,为什么要后台运行:使程序在Linux后台运行

例如:

redis-server /root/dufy/redis/redis-3.0.4/redis.conf &

5.验证redis服务是否正常

[root@localhost bin]# redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set key helloworld
OK
127.0.0.1:6379> get key
"helloworld"
127.0.0.1:6379>

[root@localhost bin]# ps -ef|grep redis
root     28047     1  0 06:39 ?        00:00:00 redis-server *:6379
root     28058 24868  0 06:40 pts/1    00:00:00 grep redis

redis安装结束,谢谢!

欢迎访问我的csdn博客,我们一同成长!

"不管做什么,只要坚持下去就会看到不一样!在路上,不卑不亢!"

博客首页:http://blog.csdn.net/u010648555
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: