zoukankan      html  css  js  c++  java
  • Centos6.5安装Redis3.0备忘记录

    Centos6.5安装Redis3.0

    1. 安装C编译环境

    首先需要安装编译Redis的C环境,在命令行执行以下命令:

    [root@itzhouq32 tools] yum install gcc-c++
    

    2. 将redis3.0上传到Linux上

    3. 解压redis,我这里解压到/usr/local下

    [root@itzhouq32 tools]# tar -xvf redis-3.0.0.tar.gz -C /usr/local
    

    4.编译

    进入解压的目录,使用make编译

    [root@itzhouq32 tools]# cd /usr/local/
    [root@itzhouq32 local]# ls
    bin  games    jdk1.8.0_201  lib64    redis-3.0.0  share  src
    etc  include  lib           libexec  sbin         soft   tomcat
    [root@itzhouq32 local]# cd redis-3.0.0/
    [root@itzhouq32 redis-3.0.0]# ls
    00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
    BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
    CONTRIBUTING     INSTALL  README     runtest-cluster  src
    [root@itzhouq32 redis-3.0.0]# make
    

    5. 安装

    在原来的目录下安装,当前目录为/usr/local/redis

    [root@itzhouq32 redis-3.0.0]# make PREFIX=/usr/local/redis install
    

    6. 修改配置文件

    进入redis-3.0.0的目录,找到redis.conf配置文件,将其拷贝到redis/bin目录下

    [root@itzhouq32 local]# ls
    bin  games    jdk1.8.0_201  lib64    redis        sbin   soft  tomcat
    etc  include  lib           libexec  redis-3.0.0  share  src
    [root@itzhouq32 local]# cd redis-3.0.0/
    [root@itzhouq32 redis-3.0.0]# ls
    00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-sentinel  tests
    BUGS             deps     MANIFESTO  runtest          sentinel.conf     utils
    CONTRIBUTING     INSTALL  README     runtest-cluster  src
    [root@itzhouq32 redis-3.0.0]# cp redis.conf ../redis/bin/
    

    返回redis/bin目录,修改redis.conf配置文件

    [root@itzhouq32 redis-3.0.0]# cd ../redis/bin/
    [root@itzhouq32 bin]# ls
    dump.rdb         redis-check-aof   redis-cli   redis-sentinel
    redis-benchmark  redis-check-dump  redis.conf  redis-server
    [root@itzhouq32 bin]# vi redis.conf
    

    将redis.conf文件中的daemonize从false修改成true表示后台启动

    7. 后台启动测试

    [root@itzhouq32 bin]# ./redis-server redis.conf
    [root@itzhouq32 bin]# ps -ef | grep redis
    root       4653   4628  0 16:56 pts/1    00:00:00 ./redis-cli
    root       4702      1  0 17:11 ?        00:00:02 ./redis-server *:6379    
    root       4782   1631  0 17:37 pts/0    00:00:00 grep redis
    [root@itzhouq32 bin]#
    

    进程中有redis,说明后台启动成功。

    8. 客户端登录及测试

    [root@itzhouq32 bin]# ./redis-cli 
    127.0.0.1:6379> set username zhangsan
    OK
    127.0.0.1:6379> get username
    "zhangsan"
    127.0.0.1:6379> exit
    [root@itzhouq32 bin]#
    

    9. 远程访问配置

    如果需要远程访问redis,需要在Linux防火墙中开放6379端口,并将规则保存到防火墙中。

    [root@itzhouq32 bin]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT
    [root@itzhouq32 bin]# /etc/rc.d/init.d/iptables save
    iptables:将防火墙规则保存到 /etc/sysconfig/iptables:     [确定]
    [root@itzhouq32 bin]#
    

    10. Java连接测试

    在Eclipse中导入jar包,编写一个测试类。

    package com.itzhouq.jedis;
    
    import org.junit.Test;
    
    import redis.clients.jedis.Jedis;
    
    public class JedisTest {
        @Test
        public void test01() {
            //1. 获得连接对象
            Jedis jedis = new Jedis("192.168.146.132", 6379);
            
            //2. 获得数据
            String username = jedis.get("username");
            System.out.println(username);//zhangsan
            
            //3. 存储
            jedis.set("addr", "上海");
            System.out.println(jedis.get("addr"));//上海
        }
    }
    
  • 相关阅读:
    安装wamp的方法及过程
    js原生获取className&多选一
    构造函数
    轮播图
    NaN
    ++与--运算练习
    if语句的练习
    switch语句的练习
    九九乘法表
    mac下git提交github代码
  • 原文地址:https://www.cnblogs.com/itzhouq/p/redis.html
Copyright © 2011-2022 走看看