阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu下用Docker安装Redis镜像和使用Redis容器分享

432次阅读
没有评论

共计 4680 个字符,预计需要花费 12 分钟才能阅读完成。

1. 安装 Ubuntu
2. 用 Putty 登录 Ubuntu
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-40-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Wed Dec 31 06:41:16 UTC 2014

  System load:  0.01              Processes:              228
  Usage of /:  6.0% of 28.80GB  Users logged in:        0
  Memory usage: 11%              IP address for eth0:    10.205.178.22
  Swap usage:  0%                IP address for docker0: 172.17.42.1

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

3. 拉取 redis 镜像
root@jumping:~# sudo docker pull redis:latest
redis:latest: The image you are pulling has been verified
eee46bd361c1: Pull complete
ff8650f588b2: Pull complete
130985f77ca0: Pull complete
4d81fff38a25: Pull complete
e6d98faa32e2: Pull complete
95d3849978c3: Pull complete
263f96794544: Pull complete
1ed9b7611cf5: Pull complete
451742990a7f: Pull complete
511136ea3c5a: Already exists
f10807909bc5: Already exists
f6fab3b798be: Already exists
1e6ac0ffed3b: Already exists
62ff5003ac9a: Already exists
e49d349e8a75: Already exists
61213f5a1710: Already exists
9feca322d1c7: Already exists
1aa8ce669b93: Already exists
Status: Downloaded newer image for redis:latest
root@jumping:~# sudo docker images
REPOSITORY                TAG                IMAGE ID            CREATED            VIRTUAL SIZE
redis                    latest              451742990a7f        11 days ago        111.2 MB

4. 启动 redis 容器
root@jumping:~# sudo docker run -t -i redis:latest
[1] 31 Dec 02:56:57.870 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
          _.-“__ ”-._
      _.-“    `.  `_.  ”-._          Redis 2.8.19 (00000000/0) 64 bit
  .-“ .-“`.  “`\/    _.,_ ”-._
 (‘      ,      .-`  | `,)    Running in stand alone mode
 |`-._`-…-` __…-.“-._|’` _.-‘|    Port: 6379
 |    `-._  `._    /    _.-‘    |    PID: 1
  `-._    `-._  `-./  _.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |          http://redis.io
  `-._    `-._`-.__.-‘_.-‘    _.-‘
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|
 |    `-._`-._        _.-‘_.-‘    |
  `-._    `-._`-.__.-‘_.-‘    _.-‘
      `-._    `-.__.-‘    _.-‘
          `-._        _.-‘
              `-.__.-‘

[1] 31 Dec 02:56:57.890 # Server started, Redis version 2.8.19
[1] 31 Dec 02:56:57.890 # 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.
[1] 31 Dec 02:56:57.891 # 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.
[1] 31 Dec 02:56:57.891 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
[1] 31 Dec 02:56:57.891 * The server is now ready to accept connections on port 6379

5.Redis 容器启动了,那接下来怎么办?
办法:把 putty 关了,然后从新进来 putty

6. 怎么进入容器呢?
先安装 NSenter:

cd /tmp; curl http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/utils/util-linux/v2.25/util-linux-2.25.tar.gz | tar -zxf-; cd util-linux-2.25;
sudo apt-get install build-essential
sudo apt-get make
./configure –without-ncurses
make nsenter && sudo cp nsenter /usr/local/bin

方法一:

PID=$(docker inspect –format “{{ .State.Pid}}” <container>)

nsenter –target $PID –mount –uts –ipc –net –pid

方法二:

安装脚本(脚本参照:https://github.com/jpetazzo/nsenter/blob/master/docker-enter)

wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;

echo “[-f ~/.bashrc_docker] && . ~/.bashrc_docker” >> ~/.bashrc; source ~/.bashrc

最后,调用 docker-enter 进入容器:

root@jumping:/tmp# docker-enter b430d6f4ff00 ls
dirname: invalid option — ‘s’
Try ‘dirname –help’ for more information.
bin  boot  data  dev  entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
root@b430d6f4ff00:~#

注:这里大家看到有错误,是因为脚本中用到 $(dirname “$0″”),大家可以直接 echo “$0″,我这边显示的是 -su

7. 测试 redis 命令
进入容器后可以用 redis-cli ping 测试可以连接上本机刚才启动的 redis-server 不,返回 PONG 说明连接成功。

直接按 redis-cli 进入 redis 命令测试下可以用不:

root@816ebd247014:~# redis-cli ping
PONG
root@816ebd247014:~# redis-cli
127.0.0.1:6379> set myname jumping
OK
127.0.0.1:6379> get myname
“jumping”
127.0.0.1:6379>

8. 这样就简单的把 redis 启动起来了,要用起来大家还要把端口影射到宿主机器上,然后可以通过客户端来调用 Redis:http://redis.io/clients

Ubuntu 14.04 下 Redis 安装及简单测试 http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis 集群明细文档 http://www.linuxidc.com/Linux/2013-09/90118.htm

Ubuntu 12.10 下安装 Redis(图文详解)+ Jedis 连接 Redis http://www.linuxidc.com/Linux/2013-06/85816.htm

Redis 系列 - 安装部署维护篇 http://www.linuxidc.com/Linux/2012-12/75627.htm

CentOS 6.3 安装 Redis http://www.linuxidc.com/Linux/2012-12/75314.htm

Redis 安装部署学习笔记 http://www.linuxidc.com/Linux/2014-07/104306.htm

Redis 配置文件 redis.conf 详解 http://www.linuxidc.com/Linux/2013-11/92524.htm

Redis 的详细介绍:请点这里
Redis 的下载地址:请点这里

更多 Ubuntu 相关信息见Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计4680字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19348
评论数
4
阅读量
7822493
文章搜索
热门文章
开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南

开发者必备神器:阿里云 Qoder CLI 全面解析与上手指南 大家好,我是星哥。之前介绍了腾讯云的 Code...
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板1Panel:小白轻松构建Web服务与面板加固指南

云服务器部署服务器面板 1Panel:小白轻松构建 Web 服务与面板加固指南 哈喽,我是星哥,经常有人问我不...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS-1:安装飞牛NAS

星哥带你玩飞牛NAS-1:安装飞牛NAS

星哥带你玩飞牛 NAS-1:安装飞牛 NAS 前言 在家庭和小型工作室场景中,NAS(Network Atta...
2025年11月28日-Cloudflare史诗级事故:一次配置失误,引爆全球宕机

2025年11月28日-Cloudflare史诗级事故:一次配置失误,引爆全球宕机

2025 年 11 月 28 日 -Cloudflare 史诗级事故: 一次配置失误,引爆全球宕机 前言 继今...
亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示

亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示

亚马逊云崩完,微软云崩!当全球第二大云“摔了一跤”:Azure 宕机背后的配置风险与警示 首先来回顾一下 10...
星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

星哥带你玩飞牛NAS-16:不再错过公众号更新,飞牛NAS搭建RSS

  星哥带你玩飞牛 NAS-16:不再错过公众号更新,飞牛 NAS 搭建 RSS 对于经常关注多个微...
开发者福利:免费 .frii.site 子域名,一分钟申请即用

开发者福利:免费 .frii.site 子域名,一分钟申请即用

  开发者福利:免费 .frii.site 子域名,一分钟申请即用 前言 在学习 Web 开发、部署...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个AI智能体—跟创业大佬对话

自己手撸一个 AI 智能体 — 跟创业大佬对话 前言 智能体(Agent)已经成为创业者和技术人绕...
如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的Nano Banana Pro?附赠邪修的用法

如何免费使用强大的 Nano Banana Pro?附赠邪修的用法 前言 大家好,我是星哥,今天来介绍谷歌的 ...
一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸

一句话生成拓扑图!AI+Draw.io 封神开源组合,工具让你的效率爆炸 前言 作为天天跟架构图、拓扑图死磕的...
你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你

你的云服务器到底有多强?宝塔跑分告诉你 为什么要用宝塔跑分? 宝塔跑分其实就是对 CPU、内存、磁盘、IO 做...
每年0.99刀,拿下你的第一个顶级域名,详细注册使用

每年0.99刀,拿下你的第一个顶级域名,详细注册使用

每年 0.99 刀,拿下你的第一个顶级域名,详细注册使用 前言 作为长期折腾云服务、域名建站的老玩家,星哥一直...