欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Redis环境搭建和可视化工具Redis Desktop Manager安装

程序员文章站 2022-05-17 21:46:36
...

安装环境:

操作系统 Centos 7.4

redis版本:redis-4.0.11

一.安装Redis

  1. 使用wget下载redis安装包:wget http://download.redis.io/releases/redis-4.0.11.tar.gz
  2. 解压压缩包:tar -zxvf redis-4.0.11.tar.gz
  3. yum 安装gcc依赖:yum install gcc,一路y到底。
  4. 进入解压目录:cd redis-4.0.11
  5. 编译安装:make MALLOC=libc
  6. 安装:cd source && make install 执行结果如下,即表示成功:
    CC Makefile.dep
 
Hint: It's a good idea to run 'make test' ;)
 
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

二.启动redis

    1.前台启动

       先切换到redis的src目录下,直接启动redis:./redis-server  执行结果如下表示安装成功:

18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started
18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                 
           _.-``__ ''-._                                            
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18685
  `-._    `-._  `-./  _.-'    _.-'                                  
 |`-._`-._    `-.__.-'    _.-'_.-'|                                 
 |    `-._`-._        _.-'_.-'    |           http://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                  
 |`-._`-._    `-.__.-'    _.-'_.-'|                                 
 |    `-._`-._        _.-'_.-'    |                                 
  `-._    `-._`-.__.-'_.-'    _.-'                                  
      `-._    `-.__.-'    _.-'                                      
          `-._        _.-'                                          
              `-.__.-'                                              
 
18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18685:M 13 Dec 12:56:12.508 # Server initialized
18685:M 13 Dec 12:56:12.508 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
18685:M 13 Dec 12:56:12.508 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
18685:M 13 Dec 12:56:12.508 * Ready to accept connections  

上图中,redis虽然启动成功了,但是这种启动方式需要一直开着该窗口,不能进行其他操作,很不方便。

执行 ctrl + c命令可以关闭窗口,但是redis服务也随之关闭。

2.后台进程方式启动redis

    1.修改redis.conf文件将

daemonize no

    修改为

daemonize yes

    2.指定redis.conf文件的方式启动:

./redis-server /usr/local/redis-4.0.11/redis.conf

    启动成功的结果如下图所示:

18713:C 13 Dec 13:07:41.109 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18713:C 13 Dec 13:07:41.109 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=18713, just started
18713:C 13 Dec 13:07:41.109 # Configuration loaded

     3.后台启动的话应该如何关闭redis进程呢,使用如下方式:

     首先,执行

ps -aux | grep redis

     查看redis的进程:

[aaa@qq.com_0_26_centos ~]# ps -aux | grep redis
root     26541  0.0  0.1 141832  2032 ?        Ssl  18:38   0:04 ./redis-server *:6379
root     31124  0.0  0.0 112704   976 pts/0    R+   20:23   0:00 grep --color=auto redis

    然后使用kill命令杀死进程:

kill -9 26541

3.设置redis开机自启动

    1.在/etc目录下新建redis目录 mkdir redis

    2.将/usr/local/redis-4.0.11/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf  

cp /usr/local/redis-4.0.11/redis.conf /etc/redis/6379.conf

     3.将redis的启动脚本复制一份放到/etc/init.d目录下

cp /usr/local/redis-4.0.11/utils/redis_init_script /etc/init.d/redisd

     4.使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

      注释的含义表示,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database

   4.设置redis开机自启动

   先切换到/etc/init.d目录下,然后执行自启命令成功

chkconfig redisd on

    现在可以直接已服务的形式启动和关闭redis了。启动:service redisd start  

Starting Redis server...

2288:C 13 Dec 13:51:38.087 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo

2288:C 13 Dec 13:51:38.087 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=2288, just started

2288:C 13 Dec 13:51:38.087 # Configuration loaded

  关闭:service redisd stop

4.使用redis-desktop-manager链接redis

    redis-desktop-manager下载地址:https://pan.baidu.com/s/1-Lhbxc5X2BDTkYuZKaz8dQ

  1.修改redis.conf配置文件:

  • 找到bind 127.0.0.1,把这行前面加个#注释掉。
  • 再查找protected-mode yes 把yes修改为no。
  • 设置远程登录的密码:取消requirepass前面的#注释,并设置密码123456
requirepass 123456

  2.使用redis-desktop-manager进行远程连接。

Redis环境搭建和可视化工具Redis Desktop Manager安装

相关标签: redis安装