注册 X
提交 注:点击提交后系统会发送邮件到邮箱验证!(仅支持中国大陆邮箱)
我已阅读并同意 服务条款
首页 > IT技术笔记 > 查看笔记

linux安装redis

附件:

tcl8.6.1-src.tar.gz

一、安装gcc 
1、Redis在linux上的安装首先必须先安装gcc,这个是用来编译redis的源文件的。首先需要先切换的到root用户:

[cheny@localhost ~]$ su

Password:

[root@localhost cheny]#

2、然后开始安装gcc:

[root@localhost /]# yum install gcc-c++

//这个命令是在线安装的,所以在这之前你的VM必须能够上网,需要在   VM中把网卡设置成NAT模式 ,因为我使用的是centos,在网络设置中需要把网卡开启,反正我在装完系统之后它是默认关闭的

3、之后便会出现下载文件界面:

20170730135437107.png

4、会出现2次确认界面,输入y即可 

20170730135916432.png

5、之后会进行更新检查,进行更新验证等等操作,等他自动完成即可。 
6、出现如下代码即是安装成功:

20190429140629.png

二、解压redis的源文件


[root@localhost cheny]# wget http://download.redis.io/releases/redis-4.0.1.tar.gz

[root@localhost Desktop]# ls

redis-4.0.1.tar.gz

[root@localhost Desktop]# tar zxvf redis-4.0.1.tar.gz 

redis-4.0.1/

redis-4.0.1/.gitignore

redis-4.0.1/00-RELEASENOTES

redis-4.0.1/BUGS

redis-4.0.1/CONTRIBUTING

.......等等

三、进入redis的解压目录

[root@localhost Desktop]# ls

redis-4.0.1  redis-4.0.1.tar.gz[root@localhost Desktop]# cd redis-4.0.1/

四、使用make命令编译


[root@localhost redis-4.0.1]# make

//出现以下信息即是编译成功

    CC notify.o

    CC setproctitle.o

    CC blocked.o

    CC hyperloglog.o

    CC latency.o

    CC sparkline.o

    CC redis-check-rdb.o

    CC redis-check-aof.o

    CC geo.o

    CC lazyfree.o

    CC module.o

    CC evict.o

    CC expire.o

    CC geohash.o

    CC geohash_helper.o

    CC childinfo.o

    CC defrag.o

    CC siphash.o

    CC rax.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

    INSTALL redis-check-aof

五、进入解压的src目录下

[root@localhost redis-4.0.1]# cd src


六、 

1、运行make test测试是否可以安装

[root@localhost src]# make test

You need tcl 8.5 or newer in order to run the Redis test

make: *** [test] Error 1

2、在这里发现有错误 
TCL(Tool Command Language)工具脚本语言,是Linux内的一种语言包。,这里需要先安装tcl。


1、先去这里下载(官网):http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz

百度网盘下载:https://pan.baidu.com/s/1t9DgT6VQxfyEBoIbO0Wybw          提取码: 637s 

备用地址: tcl8.6.1-src.tar.gz

文件

2、然后将其拷贝至虚拟机

3、然后解压对于.tar.gz的后缀文件可以使用tar zxvf 。。。.tar.gz解压

tar zxvf tcl8.6.1-src.tar.gz

4、安装 Tcl

为编译 Tcl 做准备:

cd 到tcl文件夹里

[root@localhost Desktop]# cd tcl8.6.1/

cd unix

[root@localhost tcl8.6.1]# cd unix/

./configure

[root@localhost unix]# ./configure

编译软件包:

[root@localhost unix]# make

安装软件包:

[root@localhost unix]# make install

这个时候在命令行就可以输入tclsh进入tcl解释器(经测试不输入tclsh也可以继续下一步)

tcl就可以使用了。

继续我们的redis安装

3、再次测试make test 
这里反正检查的一大堆,都是绿色的ok。这就可以了

20170730153316680.png



make teset的时候也有可能出现下面警告信息,不需要处理,不影响下一步操作。

!!! WARNING The following tests failed:

*** [err]: Active defrag big keys in tests/unit/memefficiency.tcl Expected condition ‘$max_latency <= 120’ to be true (130 <= 120)

4、安装 
[root@localhost src]# make PREFIX=/usr/local/redis install

20170730153838246.png

安装成功!

七、把解压的redis路径下的redis.conf文件拷贝到安装路径下面


[root@localhost Desktop]# cd redis-4.0.1/

[root@localhost redis-4.0.1]# ls

00-RELEASENOTES  INSTALL     runtest           tests

BUGS             Makefile    runtest-cluster   utils

CONTRIBUTING     MANIFESTO   runtest-sentinel

COPYING          README.md   sentinel.conf

deps             redis.conf  src

[root@localhost redis-4.0.1]# cp redis.conf /usr/local/redis

[root@localhost redis-4.0.1]# cd /usr/local/redis

[root@localhost redis]# ls

bin  redis.conf

到这里redis已经安装成功了。

八、启动redis 
第一种方法:进入安装路径下的bin

[root@localhost redis]# cd bin

[root@localhost bin]# ./redis-server

20170730154741696.png


这样其实已经启动成功了,但是这属于前端启动,启动redis之后,我们的控制台就不能进行任何操作了。只能ctrl+c停止启动。

第二种方法: 
后端启动 
1、首先编辑redis.conf

[root@localhost redis]# vim redis.conf

2、找到daemonize no将其改为yes(在vim中插入数据按键盘上的i或者insert)

TIM截图20190429141845.png


3、按esc退出insert模式,再按:,并且输入wq。代表保存并且退出

4、再次启动


[root@localhost redis]# ls

bin  redis.conf

[root@localhost redis]# ./bin/redis-server ./redis.conf

//这里加载配置文件


80167:C 30 Jul 16:01:58.145 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

80167:C 30 Jul 16:01:58.145 # Redis version=4.0.1, bits=64, commit=00000000, modified=0, pid=80167, just started

80167:C 30 Jul 16:01:58.145 # Configuration loaded

这样redis就启动了

可以通过
ps -ef | grep -i redis
来查看是否启动


5、关闭redis

[root@localhost redis]# ./bin/redis-cli shutdown

九、简单的使用


//首先链接客户端

[root@localhost redis]# ./bin/redis-cli

//检查网络是否可以

127.0.0.1:6379> ping

PONG

//设置一个键值对

127.0.0.1:6379> set name cheny

OK

//获取刚刚设置的键值对

127.0.0.1:6379> get name

"cheny"

//查看所有的键

127.0.0.1:6379> keys *

1) "name"

//删除name这个键

127.0.0.1:6379> del name

(integer) 1

127.0.0.1:6379> keys *

(empty list or set)

127.0.0.1:6379> 


	        
			
	      

 打赏        分享



评论

邮箱: 昵称:
\n