`
hai0378
  • 浏览: 515092 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ubuntu 12.04 安装 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中的系统安装完成

分享到:
评论

相关推荐

    Ubuntu12.04 安装 redis-3.2.1集群

    NULL 博文链接:https://greatwqs.iteye.com/blog/2311578

    redis-source-code:为Ubuntu 12.04安装Redis-ubuntu source code

    Redis源代码

    chef-redis:Redis 的厨师食谱

    Ubuntu 12.04+ Debian 6+ 食谱 (建议,不需要) 食谱 redis - 默认配方。 使用 ppa 详细信息设置 apt。 redis::server - 安装 Redis 服务器。 redis::client - 安装 Redis 客户端。 用法 如果 Redis 组件不...

    webqq3.0协议的实现pywebqq.zip

    首先安装依赖(以Ubuntu12.04为例) 安装显示通知的插件和用于存储联系人资料的redisapt-get install python-notify redis-server 安装pywebqq以来的python库pip install redis requests colorama gevent readline ...

    php-vagrant-ansible:从 .deb 包构建带有 PHP 5.6.0 的 Ubuntu 12.04

    Ubuntu 12.04.4 所有 .deb 包都在那里: : 安装下载并安装和 克隆这个仓库git clone https://github.com/urakozz/php-vagrant-ansible.git 移动到它的目录cd php-vagrant-ansible 你可以修改Vagrantfile ip/hostname...

    oc-redis:用于建立 redis 或 redis 实例的内部食谱

    Ubuntu 12.04食谱: apt - 用于apt_repository资源以选择性地添加 PPA。 runit - 在redis_instance资源中用于为每个实例创建一个runit_service 。属性node['redis']['service_state'] - service[redis-server]资源...

    simplecfs:简单编码文件系统

    Ubuntu 12.04+ 用 安装 git clone http://github.com/hustlijian/simplecfs.git cd simplecfs # change directory to simplecfs sudo apt-get install -y automake libtool autoconf python-dev python-pip sudo ...

    rwbox:Ruby 和 ROR 开发人员的 Vagrant 图像

    带有已编译 Ruby 2.0.0-p645、2.1.6、2.2.2 的 RVM MySQL、PostgreSQL、Redis 和 Memcached 用于 pg、mysql2、rmagick、curb 和其他 gem 的开发库如何安装安装 安装接下来只需在终端命令中执行:Ubuntu 14.04 $ ...

    ethercalc:多用户SocialCalc的Node.js端口

    给Redis 2.2用户的注意事项(例如在Ubuntu 12.04上):请禁用/etc/redis.conf的timeout 300设置,或者如果可能的/etc/redis.conf ,升级到Redis /etc/redis.conf 。 有关更多详细信息,请参见 。 经过测试的浏览器...

    phpstack:通过 Chef 的 PHP 堆栈

    phpstack支持的平台CentOS 6.5 Ubuntu 12.04 Ubuntu 14.04要求食谱apache2 application application_...食谱默认它能做什么没有什么切换没有什么阿帕奇它能做什么创建来自node['phpstack']['apache']['sites']数组node...

    selena-agent:塞莱娜(Selena)的经纪人

    安装要求Selena代理需要Python 2.7,该Python 2.7已包含在最新的Ubuntu Server 12.04 LTS系统中: $ sudo apt-get install python-dev python-virtualenv依存关系: $ sudo apt-get install libcurl3 libcurl4-...

    vagrant-php5.4:基于https的LAMP PHP 5.4

    vagrant-php5.4 基于LAMP PHP 5.4在板上Ubuntu 12.04 阿帕奇-2.2.22 PHP-5.4.44 MySQL-5.5.24 PostgreSQL-9.1 豆茎-1.4.6 Redis-2.2.12 内存缓存-1.4.13要求VirtualBox-免费的虚拟化软件 Vagrant 1.3+ -用于处理...

    bitrix_vagrant:Bitrix 流浪者

    Bitrix / 流浪者8888 - 阿帕奇8889 - MySQL 5433 - PostgreSQL管理员虚拟机操作系统 - Ubuntu 12.04 阿帕奇 - 2.4.6 PHP - 5.5.4 MySQL - 5.5.32 PostgreSQL - 9.1 Beanstalkd - 1.4.6 Redis - 2.2.12 Memcached - ...

    chef-thumbor:食谱拇指的开发存储库

    Ubuntu (>= 12.04) 食谱: apt - 配置 apt 和 apt 服务和 LWRP 以管理 apt 存储库和首选项 python - 安装 Python、pip 和 virtualenv。 nginx - 安装和配置 nginx monit-ng - 安装和配置 monit redisio - 安装/...

    pythonstack:Pythonstack 通过厨师

    Ubuntu 12.04 Centos 6.5 要求 食谱 apache2 application application_python apt chef-sugar database git memcached mongodb mysql-multi mysql newrelic openssl pg-multi platformstack python ...

    docker-gitlab-ci-runner-python:用于 Python 测试的 Dockerized Gitlab CI 运行器

    从 12.04 切换到 Ubuntu 14.04 来自 Ubuntu 14.04 的 Ruby 2.0 Python 2.6、2.7、3.3 和 3.4(来自 Dead Snakes 的 2.6 和 3.3) pip 和 virtualenv 安装 安装 此映像可用作 。 像这样导入构建: docker pull ...

Global site tag (gtag.js) - Google Analytics