Redis(一) redis安装、启停

Redis是开源的内存数据存储,常被用作为内存数据库、缓存、全局队列、计数器等等。

Redis安装

Redis分为多种模式:单机模式、高可用模式、集群模式。这篇中主要简介单机版的安装方式。

源码构建式
1.安装

首先下载redis源码,目前redis官网http://redis.io提供两种版本稳定版和非稳定版。这里我们使用稳定版3.2版本,下载地址:http://redis.io/download

也可以在命令行中以命令的形式下载:

$ wget http://download.redis.io/releases/redis-3.2.3.tar.gz

安装redis,执行以下命令编译安装:
$ tar xzf redis-3.2.3.tar.gz
cd redis-3.2.3
$ make

2.启动

在命令行中执行:

$ redis-server

63318:C 13 Aug 15:38:19.401 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
63318:M 13 Aug 15:38:19.402 * Increased maximum number of open files to 10032 (it was originally set to 2560).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 63318
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

63318:M 13 Aug 15:38:19.405 # Server started, Redis version 3.2.4
63318:M 13 Aug 15:38:19.406 * DB loaded from disk: 0.001 seconds
63318:M 13 Aug 15:38:19.406 * The server is now ready to accept connections on port 6379

然后出现如图,表示启动成功,默认监听端口6379。以上的方式以默认方式启动,未指定启动的配置文件,在需要指定按照特定配置启动时,可以:

redis-server /path/conf/redis.conf
3.停止

查询redis进程id:

ps -ef | grep redis

结果如下:

501 63336 63065   0  3:42下午 ttys000    0:00.02 redis-server *:6379

kill掉redis进程:

kill -9 63336
Docker方式安装

以上的方式安装比较繁琐,对于运维来说可操作性不友好。如果对于熟练docker的道友,可以选择使用docker方式安装使用Redis。这里假设读者们都已经熟练docker。

从镜像仓库搜索redis的各个tag版本:

docker search redis

从仓库拉取redis镜像,可以拉取指定版本:

docker pull redis
或
docker pull redis:{version}

直接运行镜像,docker会创建对应的容器:

docker run -d --name redis redis:{version}

然后进入容器,使用redis-cli可以连接至redis:

docker exec -it {container} /bin/bash

如:

xxxxx:~ lixinyou$ docker exec -it  e12d6cd0cacc /bin/bash
root@e12d6cd0cacc:/data# 
root@e12d6cd0cacc:/data# 
root@e12d6cd0cacc:/data# redis-cli 
127.0.0.1:6379> 
127.0.0.1:6379> 
127.0.0.1:6379> set k v
OK
127.0.0.1:6379> 

转载于:https://www.cnblogs.com/lxyit/p/9828642.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值