redis安装和配置

前言

咱们经过和数据库的交互获取数据,可是某些数据加载会严重影响性能,由于查询数据库是一个比较耗时的事情。咱们能不能提升查询数据的效率?javascript

这个时候咱们就须要使用 redis了。(固然提高查询效率不仅有redis)java

若是图片连接失效能够直接在github上看,并且更新更及时,也更加有条理。在项目模块有相关文章github.com/leosanqing/…c++

目前已经有将近300个stargit

安装和配置

下载

到官网下载redis redis.io/downloadgithub

而后经过filezilla上传至相应的虚拟机 我上传至/opt文件夹下redis

安装

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

配置

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

  2. 找到以下参数,并修改vim

    # 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 rediside

设置自启动

  1. vim /etc/init.d/redis_init_script 添加以下内容性能

    #chkconfig: 22345 10 90
    #description: Start and Stop redis
    复制代码

验证

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

相关文章
相关标签/搜索