redis教程redis的安装(二)

redis的安装过程

windows下的安装

  • 下载地址:https://github.com/MSOpenTech/redis/releases。
  • Redis 支持 32 位和 64 位。这个需要根据你系统平台的实际情况选择,这里我们下载 Redis-x64-xxx.zip压缩包到 D(这里可以随便进行解压,按照自己的习惯进行解压就ok了) 盘,解压后,将文件夹重新命名为 redis。
  • redis的版本一直在更新,选择自己喜欢的版本,这里选择的版本是3.0的
    在这里插入图片描述
  • 解压后的文件夹入下图所示:
    在这里插入图片描述
  • 打开一个 cmd 窗口 使用 cd 命令切换目录到 D:\software\redis(自己的解压目录下) 运行
	redis-server.exe redis.windows.conf
 如果想方便的话,可以把 redis 的路径加到系统的环境变量里,这样就省得再输路径了,后面的那个 redis.windows.conf 可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:

在这里插入图片描述

  • 这时候另启一个 cmd 窗口,原来的不要关闭,不然就无法访问服务端了。
    切换到 redis 目录下运行:
redis-cli.exe -h 127.0.0.1 -p 6379
	如果设置了环境变量,那么可以直接运行redis-cli.exe 

在这里插入图片描述

	以上就是在windows下安装redis的步骤,我们测试的时候可以用windows来做开发

linux下的安装教程

因为redis是用c语言写的,随着项目的变大,在windows下的效率是非常低下的,所以在生产环境,我们都是用linux开发环境
前提

1.安装了linux虚拟机(如果有linux环境,可以不用安装)
2.如果安装开了虚拟机,请确保能和主机进行通信(上传安装包到linux虚拟机)

  • 下载linux版本的redis
    下载地址:http://redis.io/download,这里按redis-3.0版本

    安装完虚拟机后,我们配置好虚拟机!可以用一些工具软件对虚拟机进行操作
    这里我们使用SecureCRT,也可以使用其他的例如winscp软件等
    
  • 环境安装

      redis是C语言开发,建议在linux上运行,本教程使用Centos6.4作为安装环境。
      安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
    
需要执行 yum install gcc-c++
执行这个语句可能会添加其他的依赖,一起安装就OK(一定要联网)

在这里插入图片描述
注意:出现is this Ok[y/N]: 输入Y就好了,等待安装完成就好了

  • 上传redis源码并编译
1.切换目录:[root@pratice ~]# cd /usr/local/ 
2.创建redis文件夹:[root@pratice local]# mkdir redis
3.切换到redis目录:[root@pratice local]# cd redis
4.将redis源码上传到目录下:
5.上传上来因为要执行,所以没有可执行权限,所以执行命令
        [root@pratice redis]# Chmod -x 777 redis-3.0.7.tar.gz 
6.解压文件到该目录[root@pratice redis]# tar -zxvf redis-3.0.7.tar.gz 
7.解压完成后[root@pratice redis]# ls  会看到源文件和解压的文件目录
8.进入解压的目录:[root@pratice redis]# cd redis-3.0.7
9.使用make命令进行编译:[root@pratice redis-3.0.7]# make
  等待编译完成(需要一会时间)
10.安装到指定目录:[root@pratice redis-3.0.7]# make PREFIX=/usr/local/redis install
11.到安装目录下查看:[root@pratice redis-3.0.7]# cd ..
12.[root@pratice redis]# ll
		总用量 1352
		drwxr-xr-x. 2 root root    4096 725 21:18 bin
		drwxrwxr-x. 6 root root    4096 125 2016 redis-3.0.7
		-rwxr-xr-x. 1 root root 1375200 725 21:07 redis-3.0.7.tar.gz
13.切换到bin目录下:[root@pratice redis]# cd  bin
14.[root@pratice  bin]# ll
	总用量 13872
	-rwxr-xr-x. 1 root root 4169851 725 21:18 redis-benchmark
	-rwxr-xr-x. 1 root root   16467 725 21:18 redis-check-aof
	-rwxr-xr-x. 1 root root   37703 725 21:18 redis-check-dump
	-rwxr-xr-x. 1 root root 4262289 725 21:18 redis-cli
	lrwxrwxrwx. 1 root root      12 725 21:18 redis-sentinel -> redis-server
	-rwxr-xr-x. 1 root root 5704743 725 21:18 redis-server
以上文件:一般会用 redis-server 和 redis-cli

-前端模式 启动redis服务器

1.[root@zhangjh-pratice bin]# ./redis-server  

在这里插入图片描述
出现以上的效果证明安装并且启动成功

  • 启动客户端

      启动客户端的时候,不能关闭服务端(第二种方法可以关闭,稍后再说)
    
[root@pratice ~]# cd /usr/local/
[root@pratice local]# ls
bin  etc  games  include  lib  libexec  redis  sbin  share  src
[root@pratice local]# cd redis
[root@pratice redis]# ls
bin  redis-3.0.7  redis-3.0.7.tar.gz
[root@pratice redis]# cd bin
[root@pratice bin]# ls
redis-benchmark  redis-check-aof  redis-check-dump  redis-cli  redis-sentinel  redis-server
[root@pratice bin]# ./redis-cli
127.0.0.1:6379> set gzh 222
OK
127.0.0.1:6379> get gzh
"222"
127.0.0.1:6379>  
  • 后端模式启动服务端
前端模式启动的缺点是ssh命令窗口关闭则redis-server程序结束,不推荐使用此方法
1.将源码中的redis.conf 拷贝到安装目录中:[root@pratice redis-3.0.7]# cp redis.conf /usr/local/redis/bin
2.切换到安装目录中:[root@pratice redis-3.0.7]# cd /usr/local/redis/bin/
3.修改redis.conf配置文件, daemonize yes 以后端模式启动。

在这里插入图片描述
按esc,:wq保存退出

[root@zhangjh-pratice bin]# ./redis-server ./redis.conf 
[root@pratice bin]# ps -aux|grep redis
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root     27143  0.0  0.1  35560  1992 pts/0    Tl   21:44   0:00 ./redis-server *:6379
root     27152  0.0  0.0  10812  1036 pts/1    T    21:45   0:00 ./redis-cli
root     27209  0.0  0.0  10812   992 pts/1    T    21:57   0:00 ./redis-cli
root     27210  0.0  0.0  10812  1004 pts/1    T    21:57   0:00 ./redis-cli
root     27214  0.0  0.0   5980   728 pts/0    S+   21:58   0:00 grep redis
[root@zhangjh-pratice bin]# 

后端模式已启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值