转自:http://blog.fens.me/linux-redis-install/

1. Redis在Windows中安装

在Windows系统上安装Redis数据库是件非常简单的事情,下载可执行安装文件(exe),双击安装即可。下载地址:https://github.com/rgl/redis/downloads

  • Redis服务器运行命令:Redis安装目录/redis-server.exe
  • Redis客户端运行命令:Redis安装目录/redis-cli.exe

2. Redis在Linux Ubuntu中安装

本文使用的Linux是Ubuntu 12.04.2 LTS 64bit的系统,安装Redis数据库软件包可以通过apt-get实现。

在Linux Ubuntu中安装Redis数据库


#安装Redis服务器端
~ sudo apt-get install redis-server

安装完成后,Redis服务器会自动启动,我们检查Redis服务器程序


# 检查Redis服务器系统进程
~ ps -aux|grep redis
redis 4162 0.1 0.0 10676 1420 ? Ss 23:24 0:00 /usr/bin/redis-server /etc/redis/redis.conf
conan 4172 0.0 0.0 11064 924 pts/0 S+ 23:26 0:00 grep --color=auto redis # 通过启动命令检查Redis服务器状态
~ netstat -nlt|grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN # 通过启动命令检查Redis服务器状态
~ sudo /etc/init.d/redis-server status
redis-server is running

3. 通过命令行客户端访问Redis

安装Redis服务器,会自动地一起安装Redis命令行客户端程序。

在本机输入redis-cli命令就可以启动,客户端程序访问Redis服务器。


~ redis-cli
redis 127.0.0.1:6379> # 命令行的帮助
redis 127.0.0.1:6379> help
redis-cli 2.2.12
Type: "help @" to get a list of commands in
"help " for help on
"help " to get a list of possible help topics
"quit" to exit # 查看所有的key列表
redis 127.0.0.1:6379> keys *
(empty list or set)

基本的Redis客户端命令操作

增加一条字符串记录key1


# 增加一条记录key1
redis 127.0.0.1:6379> set key1 "hello"
OK # 打印记录
redis 127.0.0.1:6379> get key1
"hello"

增加一条数字记录key2


# 增加一条数字记录key2
set key2 1
OK # 让数字自增
redis 127.0.0.1:6379> INCR key2
(integer) 2
redis 127.0.0.1:6379> INCR key2
(integer) 3 # 打印记录
redis 127.0.0.1:6379> get key2
"3"

增加一条列表记录key3


# 增加一个列表记录key3
redis 127.0.0.1:6379> LPUSH key3 a
(integer) 1 # 从左边插入列表
redis 127.0.0.1:6379> LPUSH key3 b
(integer) 2 # 从右边插入列表
redis 127.0.0.1:6379> RPUSH key3 c
(integer) 3 # 打印列表记录,按从左到右的顺序
redis 127.0.0.1:6379> LRANGE key3 0 3
1) "b"
2) "a"
3) "c"

增加一条哈希表记录key4


# 增加一个哈希记表录key4
redis 127.0.0.1:6379> HSET key4 name "John Smith"
(integer) 1 # 在哈希表中插入,email的Key和Value的值
redis 127.0.0.1:6379> HSET key4 email "abc@gmail.com"
(integer) 1 # 打印哈希表中,name为key的值
redis 127.0.0.1:6379> HGET key4 name
"John Smith" # 打印整个哈希表
redis 127.0.0.1:6379> HGETALL key4
1) "name"
2) "John Smith"
3) "email"
4) "abc@gmail.com"

增加一条哈希表记录key5


# 增加一条哈希表记录key5,一次插入多个Key和value的值
redis 127.0.0.1:6379> HMSET key5 username antirez password P1pp0 age 3
OK # 打印哈希表中,username和age为key的值
redis 127.0.0.1:6379> HMGET key5 username age
1) "antirez"
2) "3" # 打印完整的哈希表记录
redis 127.0.0.1:6379> HGETALL key5
1) "username"
2) "antirez"
3) "password"
4) "P1pp0"
5) "age"
6) "3"

删除记录


# 查看所有的key列表
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"
4) "key5"
5) "key1" # 删除key1,key5
redis 127.0.0.1:6379> del key1
(integer) 1
redis 127.0.0.1:6379> del key5
(integer) 1 # 查看所有的key列表
redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"

4. 修改Redis的配置

4.1 使用Redis的访问账号

默认情况下,访问Redis服务器是不需要密码的,为了增加安全性我们需要设置Redis服务器的访问密码。设置访问密码为redisredis。

用vi打开Redis服务器的配置文件redis.conf


~ sudo vi /etc/redis/redis.conf #取消注释requirepass
requirepass redisredis

4.2 让Redis服务器被远程访问

默认情况下,Redis服务器不允许远程访问,只允许本机访问,所以我们需要设置打开远程访问的功能。

用vi打开Redis服务器的配置文件redis.conf


~ sudo vi /etc/redis/redis.conf #注释bind
#bind 127.0.0.1

修改后,重启Redis服务器。


~ sudo /etc/init.d/redis-server restart
Stopping redis-server: redis-server.
Starting redis-server: redis-server.

未使用密码登陆Redis服务器


~ redis-cli redis 127.0.0.1:6379> keys *
(error) ERR operation not permitted

发现可以登陆,但无法执行命令了。

登陆Redis服务器,输入密码


~ redis-cli -a redisredis redis 127.0.0.1:6379> keys *
1) "key2"
2) "key3"
3) "key4"

登陆后,一切正常。

我们检查Redis的网络监听端口


检查Redis服务器占用端口
~ netstat -nlt|grep 6379
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN

我们看到从之间的网络监听从 127.0.0.1:3306 变成 0 0.0.0.0:3306,表示Redis已经允许远程登陆访问。

我们在远程的另一台Linux访问Redis服务器


~ redis-cli -a redisredis -h 192.168.1.199 redis 192.168.1.199:6379> keys *
1) "key2"
2) "key3"
3) "key4"

远程访问正常。通过上面的操作,我们就把Redis数据库服务器,在Linux Ubuntu中的系统安装完成。

Ubuntu的Redis安装的更多相关文章

  1. Ubuntu 18 + Redis安装

    Ubuntu 18 + Redis安装 1.安装命令: opengis@gisserver20:~$ sudo apt-get install redis-server 2.查看tcp 连接 open ...

  2. Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)

    Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...

  3. Redis安装及配置

    Redis缓存数据库 借鉴出处 http://www.runoob.com/redis/redis-install.html http://www.runoob.com/redis/redis-con ...

  4. Redis安装配置及在Python上的应用

    最近在使用Kazoo(开源电话系统) API时,一次请求的处理需要调用几次API,只为了得到一个name和id的对应关系,耗时非常大,开始想使用一种简单的实现,直接将对应关系保存到静态类的静态变量中, ...

  5. ubuntu 下redis的安装简介

    Linux公社:https://www.linuxidc.com/topicnews.aspx?page=2&tid=2 简单介绍下ubuntu下redis的安装方式: 第一种: 1:进入re ...

  6. Ubuntu下redis数据库的安装和配置详细过程

    Redis 安装 当前redis最新稳定版本是4.0.9 当前ubuntu虚拟机中已经安装好了redis,以下步骤可以跳过 最新稳定版本下载链接:http://download.redis.io/re ...

  7. Ubuntu 16.04 安装和配置 Redis

    因为发现之前手动安装的 redis 与现有的教程不一样,所以总结统一一下安装的标准步骤. 安装依赖项 为了获取最新版本的 Redis,我们将从源代码进行编译和安装.下载源代码之前,需要先安装一些编译所 ...

  8. redis Linux 、Windows ubuntu 下的安装

    Redis 安装 2018-07-05 Window 下安装 下载地址:https://github.com/MSOpenTech/redis/releases. Redis 支持 32 位和 64 ...

  9. Ubuntu系统的Redis安装配置

    Ubuntu系统的Redis安装配置 一.      安装Redis: 在Ubuntu系统下安装Redis数据库有两种方式: 方式一:下载最新的Redis版本(tar.gz格式),解压安装.操作如下: ...

随机推荐

  1. The magic behind configure, make, make install

    原文:https://robots.thoughtbot.com/the-magic-behind-configure-make-make-install#where-do-these-scripts ...

  2. spring @Autowired或@Resource 的区别

    1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认按类型装配(这个注解是属于spring的),默认情况下必 ...

  3. MSG 结构

    MSG 消息结构 在 Windows 程序中,消息是由 MSG 结构体来表示的. 结构原型: typedef struct tagMSG { HWND   hwnd; UINT   message; ...

  4. selenium2(WebDriver) API

    selenium2(WebDriver) API 作者:Glen.He出处:http://www.cnblogs.com/puresoul/  1.1  下载selenium2.0的包 官方downl ...

  5. Gym 100917L Liesbeth and the String 规律&&胡搞

    题目: Description standard input/outputStatements Little Liesbeth likes to play with strings. Initiall ...

  6. apache php 配置 CI 框架

    声明:配置域名需要用到  httpd.conf  httpd_vhosts.conf  (apache) 中两个文件 和   hosts (C:\Windows\System32\drivers\et ...

  7. HttpURLConnection请求网络数据的GET请求

    //清单文件中添加权限 <uses-permission android:name="android.permission.INTERNET"/> new Thread ...

  8. 将所需要的图标排成一列组成一张图片,方便管理。li的妙用

    我在做一个网站的header 但是视频教学里面将电话图标,微信图标,以及每一个英文字母右边的小点拼成一副图. (图片的名字是top_ioc.png)拼成的整个图片作为li的背景.通过移动就可以分别将每 ...

  9. POJ 2186 Popular Cows tarjan缩点算法

    题意:给出一个有向图代表牛和牛喜欢的关系,且喜欢关系具有传递性,求出能被所有牛喜欢的牛的总数(除了它自己以外的牛,或者它很自恋). 思路:这个的难处在于这是一个有环的图,对此我们可以使用tarjan算 ...

  10. CDN(转载)

    CDN是什么? 谈到CDN的作用,可以用8年买火车票的经历来形象比喻: 8年前,还没有火车票代售点一说,12306.cn更是无从说起.那时候火车票还只能在火车站的售票大厅购买,而我所住的小县城并不通火 ...