1、前言

Redis是常用基于内存的Key-Value数据库,比Memcache更先进,支持多种数据结构,高效,快速。用Redis可以很轻松解决高并发的数据访问问题;做为时时监控信号处理也非常不错。


2、安装

//在终端中安装Redis服务器端
sudo apt-get install redis-server

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

//在终端中检查Redis服务器系统进程
ps -aux|grep 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客户端命令操作

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

   2 . 增加一条数字记录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"

   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"

   4.增加一条哈希表记录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"

   5.增加一条哈希表记录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"

   6.删除记录

# 查看所有的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的配置

1、 使用Redis的访问账号

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

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

~ sudo vi /etc/redis/redis.conf

#取消注释requirepass
requirepass redis

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 redis

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:6379 变成 0 0.0.0.0:6379,表示Redis已经允许远程登陆访问。

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

~ redis-cli -a redis -h 192.168.1.199

redis 192.168.1.199:6379> keys *
1) "key2"
2) "key3"
3) "key4"

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

Ubuntu14.04安装redis和简单配置的更多相关文章

  1. ubuntu14.04 安装redis 2.8.9

    ubuntu14.04安装前准备工作,为了保证安装顺利,请先执行apt-get update 然后安装make 和gcc(已安装的可忽略) apt-get install make apt-get i ...

  2. Ubuntu14.04安装之后的一些配置

    不多说,直接上干货! 主要分为 一.root用户的开启和vim编辑器的安装 二.ssh的安装 三.静态ip的设置 四.中英切换文环境切换 一.root用户的开启和vim编辑器的安装 Ubuntu在默认 ...

  3. Ubuntu14.04安装配置web/ftp/tftp/dns服务器

    目录: 1.安装ftp服务器vsftpd --基于tcp,需要帐号密码 2.安装tftp服务器tftpd-hpa,tftp-hpa --udp 3.web服务器--使用Apache2+Mysql+PH ...

  4. Ubuntu14.04安装配置ndnSIM

    Ubuntu14.04安装配置ndnSIM 预环境 Ubuntu14.04官方系统 请先使用sudo apt-get update更新一下源列表 安装步骤 安装boost-lib sudo apt-g ...

  5. Ubuntu16.04安装Redis并配置

    Ubuntu16.04安装Redis并配置 2018年05月22日 10:40:35 Hello_刘 阅读数:29146   Ubuntu16.04安装Redis并配置 1):安装: 1:终端命令下载 ...

  6. Ubuntu14.04(nginx+php+mysql+vsftp)配置安装流程

    Ubuntu14.04(nginx+php+mysql+vsftp)配置安装流程 1.先切换到root用户 sudo  su 2.更新软件源 apt update apt-get upgrade 3. ...

  7. Ubuntu14.04 安装配置Opencv3.0和Python2.7

    http://blog.csdn.NET/u010381648/article/details/49452023 Install OpenCV 3.0 and Python 2.7+ on Ubunt ...

  8. ubuntu14.04安装cuda

    1 装系统时候注意,另外14.04要好于12.04,自带了无线驱动 ubuntu14.04安装完不要update 2 安装cuda和cudnn http://blog.csdn.net/l297969 ...

  9. Ubuntu14.04安装中文输入法以及解决Gedit中文乱码问题

    1 设置中文显示环境 1. 打开System Settings 2. 打开Personal-> Language Support. 会弹出如下对话框,提示你“语言支持没安装完整”. 点击“Rem ...

随机推荐

  1. 【微信开发】 新浪SAE开发平台 注意事项

    1. 微信开发 新浪SAE开发平台 验证Token 一直失败? 这个问题困扰了一个又一个的微信学习者,现在百度到的答案有:在echo $echoStr;之前添加header('content-type ...

  2. Summary of Mac Versions

    1.在 submit 的过程被 cancel 掉,可能会出现某些文件被 lock 住导致没办法再重新 update and commit. 解决方法: a) Memu."Action&quo ...

  3. 小试牛刀3之JavaScript基础题

    JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...

  4. iOS 1-2年经验面试参考题

    Model层: 数据持久化存储方案有哪些? 沙盒的目录结构是怎样的?各自一般用于什么场合? SQL语句问题:inner join.left join.right join的区别是什么? SQLite的 ...

  5. ios - 纯代码创建collectionView

    开始考虑好一点点时间,因为一般的都是用xib,或者storyboard来写的.这次用纯代码...废话较多请看 首先把storyboard干掉,工程里面的main干掉 由于干掉了storyboard则启 ...

  6. Communication 交流

    1:请不要立马抗拒别人的观点,先沉默下来思考,在做出回应. 2:在与别人交流的时候,请尽量先让别人同意你的观点,找到共同点,让别人回答 "是";

  7. 关于spring-servlet.xml cannot be opened because it does not exist的解决

    右键项目---->properties--->Java Build Path--->source--->Add Folder --->选择conf文件夹

  8. asp检测数字类型函数

    '**************************************************'函数ID:0014[检测ID是否为数字类型]'函数名:JCID'作 用:检测ID是否为数字类型' ...

  9. 夺命雷公狗-----React---7--组建的状态props和state

    props:组建初始要渲染的数据,他是不可以改变的 state:组建状态发生改变,调用render重新渲染数据 我们来写一个例子: <!DOCTYPE html> <html lan ...

  10. Head中的标签

    Head中的其它一些用法 1.scheme (方案) 说明:scheme can be used when name is used to specify how the value of conte ...