Redis 一windows 安装 以及 linux 安装 redis和 后台启动

windows 安装

安装包:https://github.com/MicrosoftArchive/redis/releases 下载 .msi 文件,下载后,点击下一步下一步,就完成。
redis.conf 简单配置(liunx 和 windows 通用):
主要3 个地方 :

1、后台启动 :
		 daemonized  yes  //默认是 no
2、所有有IP可以访问:
        bind  127.0.0.1   //默认只允许本地访问,注解掉后,所有ip 都可以访问了。
3、设置密码:
       requirepass yourpassword  //此处注意,行前不能有空格

如果启动一闪而过,就是要cmd 来启动:可能是需要制定 redis.conf,可以将redis.windows-service.conf
修改为redis.conf 随意 可以不用改。

redis-server.exe ./redis.conf

redis-cli 使用方式:
本地连接:auth 后输入密码,密码就是requirepass 上面设置的

127.0.0.1:6379> auth "你在redis.conf  中设置的requirepass 密码"

远程连接
redis-cli -h host -p port -a password

E:\Program Files\Redis>redis-cli -h 192.168.200.33 -p 6379 -a 123qwe,.

在window 下安装自启动:

redis-server --service-install redis.windows-service.conf 

linux 安装

常用命令
pwd 查看当前位置
ls 查看子目录
ll 查看子目录 (详情版)
cp 文件位置 目标位置 拷贝文件。
make 编译
make install 安装 (make xxxx install 带指定安装位置的安装命令)

安装:

yum install gcc-c++
//遇到 [y/n]: 输入 ‘y’ 回车
$ wget http://download.redis.io/releases/redis-3.2.6.tar.gz   //下载redis
$ tar xzf redis-3.2.6.tar.gz   //解压文件
$ cd redis-3.2.6					//进入解压后的文件夹
$ make								//编译,如果没有安装 gcc-c++就会报错
$ make install PREFIX =/usr/local/redis     //安装到指定目录

如果出现 Hint: It’s a good idea to run 'make test’
那么你可能是遇到问题了 用 make test 来测试一下。

$make test   //有点慢 请耐心等待。

如果出现 You need tcl 8.5 or newer in order to run the Redis

$ yum install tcl    //安装一下最新的 tcl 安装的时候注意看一下 版本号是不是 大于等于 8.5 
$ make test      //完毕后再 test一下

最后 test 完毕后如果 出现 \o/ All tests passed without errors!

说明可以安装了:

make install PREFIX=/usr/local/redis   #注意 PREFIX 一定要大写 不然安装不了

恭喜你,安装成功了
成功后 输入 whereis redis 就可以看到安装目录了

配置redis

首先 copy redis.cof文件到安装目录 方便管理:

$ cd /root/redis-3.2.6                //回到解压目录
$ cp redis.conf /usr/local/redis      //copy文件到 安装目录
$ vim redis.conf

进入 vim 点击 i 进去 vim 编辑模式

配置redis在后台运行
按 esc : set nu 查看行号。
第 136 行所有 就是 daemonized no 设置。
输入 / daemonize 回车 就可以定位到 daemonize 位置

 daemonized no  改成 yes   //告诉redis 后台启动。

设置 安全ip (部分版本需要):
当外网访问时。有些版本只允许 固定访问:
69行:

bind  127.0.0.1  
bind  111.23.36.11   //你自己的ip
如果想所有人访问,注解掉所有ip

设置密码

 # requirepass foobared
requirepass yourpassword  //此处注意,行前不能有空格

点击 ESC 输入 ‘:wq’ 保存退出

启动 redis

进入到 redis目录:
$ ./bin/redis-server ./redis.conf     //使用该配置启动服务

关闭 redis

$ ps -ef | grep -i redis  //查看是否启动 和进程编号
$ kill -9 pid  //关闭服务  pid 就是 进程编号

简单的使用

$ ./bin/redis-cli   //      连接本地 redis 客户端   
$ ./redis-cli -h 118.22.33.44  -p 6379  //连接远程的方式

如果 有密码 需要 输入 
127.0.0.1:6379> auth myPassword

$ ping              //ping 一下 回复 PONG 说明正常
$ set name zll      //保存 名字name 值为 zll
$ get name           //获取name 值
$ keys *            //查看 所有key
$ del name          //删除 name
$exit                     //退出
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值