zoukankan      html  css  js  c++  java
  • Linux下安装Redis

    什么是Redis?如果对Redis不了解可以看下这篇Redis简单入门:Redis学习


    1、 开始安装

    1.1 首先肯定得下载安装包

    进入官网,看一下当前的最新稳定版本:https://redis.io/

    然后进入下载页面,这里官网给安排的明明白白的,直接对着操作就完了 

    Download, extract and compile Redis with:

    $ wget http://download.redis.io/releases/redis-6.0.7.tar.gz
    $ tar xzf redis-6.0.7.tar.gz
    $ cd redis-6.0.7
    $ make

    The binaries that are now compiled are available in the src directory. Run Redis with:

    $ src/redis-server

    You can interact with Redis using the built-in client:

    $ src/redis-cli
    redis> set foo bar
    OK
    redis> get foo
    "bar"

    1.2  实操一遍安装

    1.2.1  下载

    打开Linux,随便进入一个目录输入第一条命令开始下载,个人一般在/opt目录下下载

    cd /opt
    wget http://download.redis.io/releases/redis-6.0.7.tar.gz

    (网真慢2m大小的文件,愣是下了快10分钟,这里嫌慢的可以先下载好,再传到linux中,下载网址就是上面的网址)

    1.2.2  解压编译

    下载好后压缩包就在当前目录下

    ll    #查看
    tar xzf redis-6.0.7.tar.gz   #解压

    完成后会得到文件夹redis-6.0.7,进入目录中,编译

    cd redis-6.0.7
    make

    嗯?出现了错误:

     莫慌,百度一下,有条解决方案:https://jingyan.baidu.com/article/15622f2435355dfdfcbea595.html

     上边那条解决方案有错,gcc版本太低,不能编译redis6.x的版本,用这条方案:http://siguoyi.com/?content/read-199.html

     

    2、 运行Redis

    2.1  基本运行

    Redis编译完成后,客户端与服务端在安装目录下的src文件夹下,分别为redis-server、redis-cli,配置文件在安装目录下,为redis.conf

    运行服务端:

    src/redis.server   
    src/redis.server redis.conf #指定配置文件,可以根据需要指定其他的配置文件

    再开一个窗口运行客户端

    src/redis.cli
    src/redis-cli -h 127.0.0.1 -p 6379 #指定连接的服务端ip和端口

    2.2  后台运行

    简单运行很容易操作,直接启动redis服务端程序即可,但是这样做会使程序占用我们的控制台窗口,要连接客户端程序或执行其他命令就得重新开启一个窗口。

    可以设置让redis在后台运行:

    创建一个新的文件夹,复制一份redis.conf配置文件,在复制的文件中修改配置,daemonize no 改为yes,然后加载配置文件运行。

    mkdir redisconf && cp redis.conf redisconf/ && cd redisconf
    vim redis.conf
    daemonize no -> daemonize yes
    :wq #保存

    src/redis-server redisconf/redis.conf #注意目录结构

    查看进程:

    ps -ef | grep redis

    连接客户端测试

    3、 退出关闭

    3.1  退出客户端

    exit quit,不会影响服务端

    3.2  关闭服务端

    shutdown

     执行后服务端程序退出,查看进程该进程已经结束。

  • 相关阅读:
    HDU 1069 Monkey and Banana
    HDU 1029 Ignatius and the Princess IV
    HDU 1024 Max Sum Plus Plus
    Gym100923H Por Costel and the Match
    Codeforces 682C Alyona and the Tree
    Codeforces 449B Jzzhu and Cities
    Codeforces (ccpc-wannafly camp day2) L. Por Costel and the Semipalindromes
    Codeforces 598D (ccpc-wannafly camp day1) Igor In the Museum
    Codeforces 1167c(ccpc wannafly camp day1) News Distribution 并查集模板
    快乐数问题
  • 原文地址:https://www.cnblogs.com/liuyiyuan/p/13604890.html
Copyright © 2011-2022 走看看