Linux Ubuntn环境下---Redis缓存的安装和启动

一、环境

       主机:win10 64位

       虚拟机:Ubuntu 16.04

二、安装

  1. $ cd /usr/local
  2. $ mkdir redis
  3. $ wget http://download.redis.io/releases/redis-5.0.0.tar.gz
  4. $ tar -zxvf redis-5.0.0.tar.gz
  5. $ cd redis-5.0.0
  6. $ make

     编译完成后,创建bin目录,建立我们需要使用的文件

  • $ make PREFIX=/usr/local/redis install
  • $ cd ..
  • $ ll

    此时我们可以看到创建的bin目录

  • $ cd bin
  • $ ll

   接下来介绍第一种Redis 的启动方式---前端启动

  • $ ./redis-server

    结果如下:

32422:C 06 Nov 2018 16:28:41.594 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
32422:C 06 Nov 2018 16:28:41.594 # Redis version=5.0.0, bits=32, commit=00000000, modified=0, pid=32422, just started
32422:C 06 Nov 2018 16:28:41.594 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
32422:M 06 Nov 2018 16:28:41.595 * Increased maximum number of open files to 10032 (it was originally set to 1024).
32422:M 06 Nov 2018 16:28:41.596 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.0 (00000000/0) 32 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 32422
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

32422:M 06 Nov 2018 16:28:41.597 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
32422:M 06 Nov 2018 16:28:41.597 # Server initialized
32422:M 06 Nov 2018 16:28:41.597 # 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.
32422:M 06 Nov 2018 16:28:41.597 # 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.
32422:M 06 Nov 2018 16:28:41.597 * Ready to accept connections

   服务端启动,我们在启动客户端,进行数据交互:

  • $ ./redis-cli
  • 127.0.0.1:6379>set QQ WeChat
  • ok
  • 127.0.0.1:6379>get QQ
  • "WeChat"

   接下来介绍第二种Redis 的启动方式:

  • $ cd redis-5.0.0
  • $ vim redis.conf

 修改成如下数据:

     136  daemonize yes

  • $ cp redis.conf /usr/local/redis/bin
  • $ cd ..
  • $ cd bin
  • $ ./redis-server redis.conf

此时redis 已经在后台启动,我们可以通过 ps -aux|grep redis 查看是否启动,运行结果如下图:

从上图结果中可以看出来,redis-server 已经在后台启动了

 

启动多个redis进程

方法1:

启动时指定端口可在一台服务器启动多个redis进程。

cd /usr/local/redis/bin

./redis-server ./redis.conf --port 6380

 

方法2(推荐此方法)

创建多个redis目录,以端口号命名,比如:创建6379、6380两个目录,将redis的安装文件bin和conf拷贝至这两个目录。

修改6379目录下的redis.conf设置端口号为6379

修改6380目录下的redis.conf设置端口号为6380

启动6379和6380目录下的redis-server程序:

cd 6379

./redis-server . /redis.conf

cd 6380

./redis-server . /redis.conf

查询当前redis的进程:

 

redis停止

强行终止Redis进程可能会导致redis持久化数据丢失。正确停止Redis的方式应该是向Redis发送SHUTDOWN命令,方法为:

 

cd /usr/local/redis

./bin/redis-cli shutdown

至此  Redis 的倆zhog种启动方式都介绍完了
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值