Red Hat系统安装Redis

环境

RHLinux-6.4-64-EN, 红帽6.4 64位,英文正式公布版

安装

安装非常easy,先下载redis的压缩包,下载地址见这里。然后复制到你的linux机器。接着运行以下的命令。

1
2
3
$ tar xzf redis-2.6.14.tar.gz
$ cd redis-2.6.14
$ make

启动

编译完后添加了src文件夹。运行src以下的redis-server脚本就可以启动redis服务。

1
$ src/redis-server

调试

运行src文件夹下的redis-cli脚本,这个是redis的client。

1
2
3
4
5
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

java调用

  1. Redis比較出名的javaclient是jedis,先下载jedis的jar包,能够去maven库搜下jedis就能够下载到。源代码是放在github上:https://github.com/xetorthio/jedis
  2. 简单写个main方法就能够调用。
1
2
3
4
5
6
    public static void main(String[] args) {
        Jedis jedis = new Jedis("10.20.8.39"); //redisserver的ip,端口默认6379
        jedis.set("foo", "bar");
        String value = jedis.get("foo");
        System.out.println(value);
    }

后台进程

之前的启动方式不是后台进程方式的,终端关了服务也就停了,能够使用以下的命令将Redis作为后台进程启动。并加入到系统启动命名中。

1
2
$ cd redis-2.6.14/utils
$./install_server

运行命令后,会提示你回答几个问题,能够一路回车过去。选择默认设置。

1
2
3
4
5
6
7
8
9
10
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
...

兴许能够通过以下的方式启停服务。


1. /etc/init.d/redis_6379 start —启动
2. /etc/init.d/redis_6379 stop —服务
当然也可在/usr/local/bin文件夹下使用redis-server来启动。

PS: 我在运行install_server脚本后,发现服务启动不起来。查看/etc/init.d/redis_6379这个文件发现里面的换行符号被替换成了/n符号。手动将这些符号替换成换行就能够了。

很多其它资料

很多其它资料能够看这里:http://redis.io/

posted @ 2017-04-25 16:25  wzzkaifa  阅读(696)  评论(0编辑  收藏  举报