工具推荐-使用RedisInsight工具对Redis集群CURD操作及数据可视化和性能监控


关注「WeiyiGeek」公众号

设为「特别关注」每天带你玩转网络安全运维、应用开发、物联网IOT学习!

希望各位看友【关注、点赞、评论、收藏、投币】,助力每一个梦想。


本章目录

目录
  • https://redis.io/docs/tools/ ],当然你也可以可以选择客户端桌面管理工具(例如,AnotherRedisDesktopManage [ https://github.com/qishibo/AnotherRedisDesktopManager ] )


    0x01 安装部署

    描述:redis-insight 与现在大多数软件一样,有多种安装方式其中用得比较多的就是二进制、源码编译以及容器化部署的方式。

    二进制方式

    描述:我们需要在Redis官方进行下载 redis-insight 二进制包然后进行安装部署,有可能国内下载比较缓慢,此时我已将其打包下来,方便大家下载。

    Redis GUI redis-insight 工具 下载:

    • https://share.weiyigeek.top/d/36158960-51461225-1d5ee1?p=2088 (访问密码: 2088)
    • https://url60.ctfile.com/d/36158960-51461225-1d5ee1?p=2088 (访问密码: 2088)

    环境依赖

    Requirement Ubuntu MacOS Windows
    Operating System Ubuntu 18.04 LTS or later MacOS 10.13 or later Windows 10
    Memory (RAM) 8GB 8GB 8GB
    Processor 64 bit 64 bit 32 bit or 64 bit

    安装环境

    $ lsb_release  -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 20.04.3 LTS
    Release:        20.04
    Codename:       focal
    
    $ lscpu  | grep "CPU(s)"
    CPU(s):                          4
    On-line CPU(s) list:             0-3
    
    $ lsmem  | grep "Total online memory"
    Total online memory:       8G
    

    安装流程

    步骤 01.官网下载 RedisInsight 上传到 /usr/local/bin 目录 并打开 shell 终端赋予其下载权限。

    cd /usr/local/bin
    mv redisinsight-linux64-1.13.0 redisinsight-linux64
    chmod +x redisinsight-linux64
    

    步骤 02.设置Redisinsight启动所需的环境变量:

    mkdir ~/.redisinsight
    echo "export RIHOST=0.0.0.0" > ~/.bash_profile
    echo "export RIPORT=8081" >> ~/.bash_profile
    echo "export RIHOMEDIR=~/.redisinsight" >> ~/.bash_profile
    echo "export RILOGDIR=~/.redisinsight" >> ~/.bash_profile
    source ~/.bash_profile
    

    温馨提示:如果使用了REDISINSIGHT_HOST, REDISINSIGHT_PORT, REDISINSIGHT_HOME_DIR and LOG_DIR等环境变量便会出现如下提示。

    WARNING 2022-09-20 05:56:33,461 redisinsight_startup REDISINSIGHT_HOST, REDISINSIGHT_PORT, REDISINSIGHT_HOME_DIR and LOG_DIR environment variables will be deprecated in the version v1.9.
    Please use RIHOST, RIPORT, RIHOMEDIR and RILOGDIR environment variables for setting host, port, db directory and log directory respectively.
    

    步骤 03.启动Redisinsight并后台运行它

    #  后台运行
    nohup /usr/local/bin/redisinsight-linux64 > ~/.redisinsight/console.log 2>&1 &
    

    步骤 04.查看 redisinsight 进程运行情况

    root@weiyigeek:~# ps aux | grep "redisinsight"
    root        6592  8.0  0.0   3220  2212 pts/0    S    13:59   0:00 /usr/local/bin/redisinsight-linux64
    root        6593  8.9  0.9 602080 74616 pts/0    Sl   13:59   0:00 /usr/local/bin/redisinsight-linux64
    root        6602  0.0  0.0   6432   724 pts/0    S+   13:59   0:00 grep redisinsight
    root@weiyigeek:~# netstat -ano | grep ":8081"
    tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      off (0.00/0/0)
    

    步骤 05.访问部署的redisinsight站点 http://10.20.172.201:8081/ 进行下一步配置,继续配置你的 Redis 数据库,此处我已经搭建好了一个redis数据库如需搭建请参考此篇文章【https://blog.weiyigeek.top/2022/4-24-653.html】,点击连接到 Redis 数据库进入到下一步。

    步骤 06.进行配置Redis数据库信息,此处我是单节点进行演示,输入主机、端口、名称、以及redis密码。

    至此安装配置完成,使用将在后续实践!


    容器化方式

    描述:当下大多数企业的应用都是在容器环境中运行,所以redis官方也提供了相应容器镜像以及在kubernetes中部署的资源清单,下述将演示在 Kubernetes 上安装 RedisInsight,安装高可用的K8S可以参照此篇文章 【 https://blog.weiyigeek.top/2022/6-7-664.html 】

    镜像主页:https://hub.docker.com/r/redislabs/redisinsight/tags
    镜像名称:docker pull redislabs/redisinsight:1.13.0

    部署方式

    步骤 01.在 k8s 集群中创建一个 RedisInsight 部署和服务 YAML 文件资源清单,注意此处我使用了动态存储卷,如果有需要的部署nfs动态存储卷可参考此篇文章( https://blog.weiyigeek.top/2022/6-7-664.html )

    tee redisinsight-1.13.0.yaml <<'EOF'
    # RedisInsight service with name 'redisinsight-service'
    apiVersion: v1
    kind: Service
    metadata:
      name: redisinsight-service
      namespace: dev
    spec:
      type: LoadBalancer
      ports:
        - port: 8001
          targetPort: 8001
      selector:
        app: redisinsight
    ---
    # RedisInsight persistant storage 
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: redisinsight-pv-claim
      namespace: dev
      labels:
        app: redisinsight
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 2Gi
      storageClassName: managed-nfs-storage
    ---
    # RedisInsight deployment with name 'redisinsight'
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: redisinsight   # deployment name
      namespace: dev
      labels:
        app: redisinsight  # deployment label
    spec:
      replicas: 1          # a single replica pod
      strategy:
        type: Recreate
      selector:
        matchLabels:
          app: redisinsight # which pods is the deployment managing, as defined by the pod template
      template:             # pod template
        metadata:
          labels:
            app: redisinsight # label for pod/s
        spec:
          volumes:
            - name: db
              persistentVolumeClaim:
                claimName: redisinsight-pv-claim
          initContainers:
            - name: init
              image: busybox
              command:
                - /bin/sh
                - '-c'
                - |
                                chown -R 1001 /db
              resources: {}
              volumeMounts:
                - name: db
                  mountPath: /db
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
          containers:
            - name:  redisinsight                  # Container name (DNS_LABEL, unique)
              image: redislabs/redisinsight:1.13.0 # Hub Image
              imagePullPolicy: IfNotPresent        # Pull Policy
              env: 
              - name: RIHOST
                value: "0.0.0.0"
              - name: RIPORT
                value: "8001"
              volumeMounts:
              - name: db 
                mountPath: /db
              ports:
              - containerPort: 8001        # exposed container port and protocol
                protocol: TCP
              livenessProbe:
                httpGet:
                  path : /healthcheck/     # exposed RI endpoint for healthcheck
                  port: 8001               # exposed container port
                initialDelaySeconds: 5      # number of seconds to wait after the container starts to perform liveness probe
                periodSeconds: 5            # period in seconds after which liveness probe is performed
                failureThreshold: 1         # number of liveness probe failures after which container restarts
    EOF
    

    步骤02.在k8s集群中部署 redisinsight v1.13.0 应用、服务以及持久化卷,查看其部署状态。

    $ kubectl create namespace dev
    namespace/dev created
    
    $ kubectl apply -f redisinsight-1.13.0.yaml
    service/redisinsight-service created
    persistentvolumeclaim/redisinsight-pv-claim created
    deployment.apps/redisinsight created
    
    $ kubectl get pod,svc -n dev -o wide
    NAME                               READY   STATUS    RESTARTS   AGE     IP              NODE       NOMINATED NODE   READINESS GATES
    pod/redisinsight-55d44b5bb-xzggg   1/1     Running   0          3m22s   10.66.182.217   weiyigeek-226              
    
    NAME                           TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE     SELECTOR
    service/redisinsight-service   LoadBalancer   10.108.198.8        80:31793/TCP   3m22s   app=redisinsight
    
    $ curl -I 10.66.182.217:8001
    HTTP/1.1 200 OK
    Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
    
    # 端口转发
    $ kubectl -n dev port-forward deployment/redisinsight --address 0.0.0.0 30081:8001
    Forwarding from 0.0.0.0:30081 -> 8001
    Handling connection for 30081
    Handling connection for 30081
    

    步骤 03.成功应用并完成部署和服务,我们可通过浏览器访问 192.168.1.107:31793 便可看到如下图所示界面。

    至此,在k8s集群中部署完毕


    0x02 实践应用

    1.配置连接的Redis数据库

    描述:在使用任何工具处理数据库之前,必须先添加数据库(Add Database),以便 RedisInsight 可以连接到该数据库,添加独立的 Redis 数据库 这是只有一台 Redis 服务器的 Redis 数据库最简单的设置,当然也支持独立 Redis 集群 Redis Sentinel 或者 具有TLS认证的Redis数据库。
    注意:目前 RedisInsight 支持 Redis 版本 4 及更高版本。

    2.查看Redis数据库实时统计信息

    描述:点击配置好的Redis数据目标,即可看到如下overview页面

    3.操作Redis数据库中的数据

    描述: 可以通过使用 Browser(图形) 或者 cli(命令行)进行Redis数据库的CURD,如下图所示

    4.操作Redis数据库中的流Streams数据

    描述: 可以通过使用 Streams 选项进行 Redis 流操作。

    5.性能内存、慢查询分析

    描述:RedisInsight 提供了强大的分析功能,支持内存使用分析、分析器(在Redis中执行的命令过程摘要分析)以及慢日志查询。

    6.可视化配置redis数据库

    描述:在Database选项卡中我们可以直接配置Redis数据库,包括其网络配置、通用配置以及快照、配置等等。

    当然对应devops来说使用最多的还是CURD以及性能分析以及优化,此工具还是非常方便的,如需解更多其它功能需的朋友,可参考 redisinsight 用户使用文档:https://docs.redis.com/latest/ri/using-redisinsight/


    0x03 入坑出坑

    问题1.运行 RedisInsight-v2-linux-x86_64 时出现不存在libatk-1.0.so.0/libatk-bridge-2.0.so.0/libcups.so.2/libgtk-3.so.0等错误

    • 错误信息
    root@weiyigeek:/usr/local/bin# wget https://download.redisinsight.redis.com/latest/RedisInsight-v2-linux-x86_64.AppImage
    root@weiyigeek:/usr/local/bin# mv RedisInsight-v2-linux-x86_64.AppImage RedisInsight
    root@weiyigeek:/usr/local/bin# chmod +x RedisInsight
    root@weiyigeek:/usr/local/bin# ./RedisInsight
    /tmp/.mount_RedisIuCY68M/redisinsight: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory
    /tmp/.mount_RedisIbwUuBs/redisinsight: error while loading shared libraries: libatk-bridge-2.0.so.0: cannot open shared object file: No such file or directory
    /tmp/.mount_RedisIb3qNiD/redisinsight: error while loading shared libraries: libcups.so.2: cannot open shared object file: No such file or directory
    /tmp/.mount_RedisI9GZsHC/redisinsight: error while loading shared libraries: libgtk-3.so.0: cannot open shared object file: No such file or directory
    
    • 解决办法:由于我的测试系统是Ubuntu的则使用apt命令安装错误提示中的依赖包。
    apt install libatk1.0-dev
    apt install libatk-bridge2.0-dev
    apt install libcups2-dev
    apt install libgtk-3-dev
    

    问题2.运行 RedisInsight-v2-linux-x86_64 时出现 root without --no-sandbox is not supported 错误提示:

    错误信息:[0920/133850.852943:FATAL:electron_main_delegate.cc(292)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
    解决办法:在低权限用户中执行./RedisInsight启动RedisInsight服务即可。


    0x0n 参考来源

    官网地址:https://redis.com/redis-enterprise/redis-insight/
    项目源码:https://github.com/RedisInsight/RedisInsight
    项目文档:https://docs.redis.com/latest/ri
    下载地址:https://redis.com/redis-enterprise/redis-insight/#insight-form

    原文地址: https://blog.weiyigeek.top/2022/9-20-686.html

    本文至此完毕,更多技术文章,尽情期待下一章节!


    WeiyiGeek Blog 个人博客 - 为了能到远方,脚下的每一步都不能少 】

    欢迎各位志同道合的朋友一起学习交流【点击加入交流群】,如文章有误请在下方留下您宝贵的经验知识!

    作者主页: 【 https://weiyigeek.top】
    博客地址: 【 https://blog.weiyigeek.top 】

    专栏书写不易,如果您觉得这个专栏还不错的,请给这篇专栏 【点个赞、投个币、收个藏、关个注,转个发,留个言】(人间六大情),这将对我的肯定,谢谢!。

    • echo "【点个赞】,动动你那粗壮的拇指或者芊芊玉手,亲!"

    • printf("%s", "【投个币】,万水千山总是情,投个硬币行不行,亲!")

    • fmt.Printf("【收个藏】,阅后即焚不吃灰,亲!")

    • console.info("【转个发】,让更多的志同道合的朋友一起学习交流,亲!")

    • System.out.println("【关个注】,后续浏览查看不迷路哟,亲!")

    • cout << "【留个言】,文章写得好不好、有没有错误,一定要留言哟,亲! " << endl;

    更多网络安全、系统运维、应用开发、物联网实践、网络工程、全栈文章,尽在 https://blog.weiyigeek.top 之中,谢谢各位看又支持!