redis配置和使用

1 篇文章 0 订阅

前言

我们通过和数据库的交互获取数据,但是某些数据加载会严重影响性能,因为查询数据库是一个比较耗时的事情。我们能不能提高查询数据的效率?

这个时候我们就需要使用 redis了。(当然提升查询效率不只有redis)

如果图片链接失效可以直接在github上看,而且更新更及时,也更加有条理。在项目模块有相关文章https://github.com/leosanqing/Java-Notes

目前已经有将近300个star

其他redis相关 (待更新)

  1. 设置主从复制
  2. Redis 为啥会这么快
  3. Redis常用的命令和数据结构

安装和配置

下载

到官网下载redis https://redis.io/download

然后通过filezilla上传至相应的虚拟机 我上传至/opt文件夹下

安装

  1. 使用 解压缩命令解压文件tar -zxvf <压缩包名>
  2. 进入文件夹后 会发现有一个 Makefile文件,使用 make && make install
  3. 安装的时候可能报错,缺少gcc依赖。使用 yum install gcc-c++安装一下就行

配置

  1. 进入redis目录下,打开 redis.conf 文件 vim redis.conf

  2. 找到如下参数,并修改

    # The working directory.
    #
    # The DB will be written inside this directory, with the filename specified
    # above using the 'dbfilename' configuration directive.
    #
    # The Append Only File will also be created inside this directory.
    #
    # Note that you must specify a directory here, not a file name.
    #工作目录,持久化 aof rdb都会存放在这个目录下,如果修改了 需要创建相应的目录
    dir /opt/redis5/working
    
    # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
    # JUST COMMENT THE FOLLOWING LINE.
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # 将127.0.0.1 改成 0.0.0.0 所有ip都能访问
    bind 0.0.0.0
    
    # 保护模式关闭
    protected-mode no
    
    # By default Redis does not run as a daemon. Use 'yes' if you need it.
    # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
    # 是否后台运行,设置成yes
    daemonize yes
    
    # 还有其他一下参数,比如 密码什么的,因为是在虚拟机上运行,所以不需要设置
    

启动

  1. 将redis目录下的 /utils/ 的 redis_init_script文件复制到 /etc/init.d/下 。 cp redis_init_script /etc/init.d/
  2. 进入目录cd /etc/init.d,修改相应文件 vim redis_init_script 将其配置文件路径改成 我们的配置文件存放的路径CONF="/opt/redis5/redis.conf"
  3. 赋予权限 chmod 777 redis_init_script
  4. 启动 ./redis_init_script start

查看是否启动成功

查看进程号 ps -ef|grep redis

设置自启动

  1. vim /etc/init.d/redis_init_script 添加如下内容

    #chkconfig: 22345 10 90
    #description: Start and Stop redis
    

验证

重启虚拟机 reboot。再查看进程号是否存在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值