云原生之使用Docker部署Redis数据库

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介: 云原生之使用Docker部署Redis数据库

一、检查系统版本

[root@node ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

二、检查docker状态

[root@node ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-11-03 15:34:06 CST; 28min ago
     Docs: https://docs.docker.com
 Main PID: 112383 (dockerd)
    Tasks: 48
   Memory: 124.7M
   CGroup: /system.slice/docker.service
           ├─112383 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─112738 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8100 -container-ip 172.17.0.2 -container-port 8100
           ├─112744 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8100 -container-ip 172.17.0.2 -container-port 8100
           ├─112757 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3541 -container-ip 172.17.0.3 -container-port 3306
           ├─112762 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3541 -container-ip 172.17.0.3 -container-port 3306
           ├─113542 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8680 -container-ip 172.17.0.4 -container-port 80
           └─113547 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8680 -container-ip 172.17.0.4 -container-port 80

Nov 03 15:34:05 node dockerd[112383]: time="2022-11-03T15:34:05.956013742+08:00" level=info msg="ccResolverWrapper: sending update to cc...ule=grpc
Nov 03 15:34:05 node dockerd[112383]: time="2022-11-03T15:34:05.956019563+08:00" level=info msg="ClientConn switching balancer to \"pick...ule=grpc
Nov 03 15:34:05 node dockerd[112383]: time="2022-11-03T15:34:05.960312657+08:00" level=info msg="[graphdriver] using prior storage drive...verlay2"
Nov 03 15:34:05 node dockerd[112383]: time="2022-11-03T15:34:05.981619343+08:00" level=info msg="Loading containers: start."
Nov 03 15:34:06 node dockerd[112383]: time="2022-11-03T15:34:06.194025623+08:00" level=info msg="Default bridge (docker0) is assigned wi...address"
Nov 03 15:34:06 node dockerd[112383]: time="2022-11-03T15:34:06.562242635+08:00" level=info msg="Loading containers: done."
Nov 03 15:34:06 node dockerd[112383]: time="2022-11-03T15:34:06.591059825+08:00" level=info msg="Docker daemon" commit=a89b842 graphdriv...20.10.17
Nov 03 15:34:06 node dockerd[112383]: time="2022-11-03T15:34:06.591120629+08:00" level=info msg="Daemon has completed initialization"
Nov 03 15:34:06 node systemd[1]: Started Docker Application Container Engine.
Nov 03 15:34:06 node dockerd[112383]: time="2022-11-03T15:34:06.657656055+08:00" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.

三、检查docker版本

[root@node ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:05:12 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:03:33 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

四、搜索redis镜像

[root@node ~]# docker search redis
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
bitnami/redis                      Bitnami Redis Docker Image                      234                  [OK]
redislabs/redisinsight             RedisInsight - The GUI for Redis                68                   
redislabs/redisearch               Redis With the RedisSearch module pre-loaded…   54                   
redislabs/rejson                   RedisJSON - Enhanced JSON data type processi…   48                   
redislabs/redis                    Clustered in-memory database engine compatib…   35                   
redislabs/redismod                 An automated build of redismod - latest Redi…   27                   [OK]
redislabs/redisgraph               A graph database module for Redis               24                   [OK]
redis/redis-stack                  redis-stack installs a Redis server with add…   24                   
redislabs/rebloom                  A probablistic datatypes module for Redis       21                   [OK]
circleci/redis                     CircleCI images for Redis                       14                   [OK]
redislabs/redistimeseries          A time series database module for Redis         12                   
redis/redis-stack-server           redis-stack-server installs a Redis server w…   11                   
redislabs/operator                                                                 7                    
redislabs/redis-py                                                                 5                    
redislabs/redisai                                                                  4                    
redislabs/redisgears               An automated build of RedisGears                4                    
redislabs/redisml                  A Redis module that implements several machi…   2                    [OK]
redislabs/k8s-controller                                                           2                    
redislabs/redis-webcli             A tiny Flask app to provide access to Redis …   2                    [OK]
redislabs/rcp-kubectl              Container for running kubectl commands (plus…   1                    
redislabs/ng-redis-raft            Redis with redis raft module                    0                    
redislabs/gesher                   K8s Admission control proxy                     0                    
redislabs/redis-connect-postgres   Redis Connect PostgreSQL Connector for Conti…   0                    
redislabs/memtier_benchmark        Docker image to run memtier_benchmark           0                    
redis                              Redis is an open source key-value store that…   0         [OK]     

五、下载redis镜像

[root@node ~]# docker pull redis:6.0
6.0: Pulling from library/redis
a2abf6c4d29d: Already exists 
c7a4e4382001: Already exists 
4044b9ba67c9: Already exists 
2b1fc7c1d01d: Pull complete 
956e458715d7: Pull complete 
cd2a61b616a9: Pull complete 
Digest: sha256:20756751c3382cf4867bef796eeda760e93022ec3decdd9803dea7a4f33f3b4b
Status: Downloaded newer image for redis:6.0
docker.io/library/redis:6.0

六、创建redis容器

1.创建数据目录

[root@node ~]# mkdir /data/redis
[root@node ~]# cd /data/redis/
[root@node redis]# 

2.运行redis容器

[root@node redis]# docker run  -d  --name redis --restart always    -v /data/redis/:/data    -p 6379:6379 redis:6.0 --save 60 1
7977af803f55b623520e6780dc4670c072d6a54c750916a5e5b6c0c62804bf8e

3.检查redis容器状态

[root@node redis]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
7977af803f55   redis:6.0           "docker-entrypoint.s…"   12 seconds ago   Up 12 seconds   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp              redis

4.查看redis容器运行日志

[root@node redis]# docker logs redis
1:C 03 Nov 2022 10:22:34.663 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 03 Nov 2022 10:22:34.663 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 03 Nov 2022 10:22:34.663 # Configuration loaded
1:M 03 Nov 2022 10:22:34.664 * Running mode=standalone, port=6379.
1:M 03 Nov 2022 10:22:34.664 # 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:M 03 Nov 2022 10:22:34.664 # Server initialized
1:M 03 Nov 2022 10:22:34.664 # 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:M 03 Nov 2022 10:22:34.664 # 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 madvise > /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 (set to 'madvise' or 'never').
1:M 03 Nov 2022 10:22:34.664 * Ready to accept connections

七、连接redis数据库

1.进入redis容器

[root@node redis]# docker exec -it redis /bin/bash

2.进入redis数据库

root@7977af803f55:/data# redis-cli
127.0.0.1:6379> 

3.查看redis信息

root@7977af803f55:/data# redis-cli
127.0.0.1:6379> info
# Server
redis_version:6.0.16
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:281f24c34ac9a20
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:10.2.1
process_id:1
run_id:83e681088344957da260effb9150f8cf4a36c581
tcp_port:6379
uptime_in_seconds:165
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:6526735
executable:/data/redis-server
config_file:
io_threads_active:0

# Clients
connected_clients:1
client_recent_max_input_buffer:8
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0

# Memory
used_memory:866656
used_memory_human:846.34K
used_memory_rss:4710400
used_memory_rss_human:4.49M
used_memory_peak:923360
used_memory_peak_human:901.72K
used_memory_peak_perc:93.86%
used_memory_overhead:823680
used_memory_startup:803184
used_memory_dataset:42976
used_memory_dataset_perc:67.71%
allocator_allocated:1005576
allocator_active:1228800
allocator_resident:3592192
total_system_memory:8182054912
total_system_memory_human:7.62G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.22
allocator_frag_bytes:223224
allocator_rss_ratio:2.92
allocator_rss_bytes:2363392
rss_overhead_ratio:1.31
rss_overhead_bytes:1118208
mem_fragmentation_ratio:5.72
mem_fragmentation_bytes:3886256
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:20496
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1667470954
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:18601
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:3
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_reads_processed:2
total_writes_processed:1
io_threaded_reads_processed:0
io_threaded_writes_processed:0

# Replication
role:master
connected_slaves:0
master_replid:c0790d4b3b3e47000ff63bc7f04f46c7c391c61a
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.143155
used_cpu_user:0.123634
used_cpu_sys_children:0.001258
used_cpu_user_children:0.000942

# Modules

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6379> 
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
2月前
|
Kubernetes Cloud Native Docker
云原生时代的容器化实践:Docker和Kubernetes入门
【10月更文挑战第37天】在数字化转型的浪潮中,云原生技术成为企业提升敏捷性和效率的关键。本篇文章将引导读者了解如何利用Docker进行容器化打包及部署,以及Kubernetes集群管理的基础操作,帮助初学者快速入门云原生的世界。通过实际案例分析,我们将深入探讨这些技术在现代IT架构中的应用与影响。
111 2
|
2月前
|
运维 Cloud Native 虚拟化
一文吃透云原生 Docker 容器,建议收藏!
本文深入解析云原生Docker容器技术,涵盖容器与Docker的概念、优势、架构设计及应用场景等,建议收藏。关注【mikechen的互联网架构】,10年+BAT架构经验倾囊相授。
一文吃透云原生 Docker 容器,建议收藏!
|
3天前
|
NoSQL 关系型数据库 Redis
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
《docker高级篇(大厂进阶):1.Docker复杂安装详说》包括:安装mysql主从复制、安装redis集群
38 14
|
16天前
|
NoSQL 算法 Redis
docker高级篇(大厂进阶):安装redis集群
docker高级篇(大厂进阶):安装redis集群
77 24
|
23天前
|
人工智能 缓存 异构计算
云原生AI加速生成式人工智能应用的部署构建
本文探讨了云原生技术背景下,尤其是Kubernetes和容器技术的发展,对模型推理服务带来的挑战与优化策略。文中详细介绍了Knative的弹性扩展机制,包括HPA和CronHPA,以及针对传统弹性扩展“滞后”问题提出的AHPA(高级弹性预测)。此外,文章重点介绍了Fluid项目,它通过分布式缓存优化了模型加载的I/O操作,显著缩短了推理服务的冷启动时间,特别是在处理大规模并发请求时表现出色。通过实际案例,展示了Fluid在vLLM和Qwen模型推理中的应用效果,证明了其在提高模型推理效率和响应速度方面的优势。
云原生AI加速生成式人工智能应用的部署构建
|
24天前
|
SQL 弹性计算 安全
在云上轻松部署达梦数据库
达梦数据库(DM Database)是达梦数据库有限公司开发的关系型数据库管理系统,广泛应用于政府、金融、能源等行业。它具备高性能、高安全、兼容性强、易管理等特点,支持多种操作系统,适用于关键业务系统、政务系统及大数据处理等场景。在阿里云上,可通过一键部署快速使用达梦数据库DM8。
|
2月前
|
Kubernetes Cloud Native 微服务
云原生入门与实践:Kubernetes的简易部署
云原生技术正改变着现代应用的开发和部署方式。本文将引导你了解云原生的基础概念,并重点介绍如何使用Kubernetes进行容器编排。我们将通过一个简易的示例来展示如何快速启动一个Kubernetes集群,并在其上运行一个简单的应用。无论你是云原生新手还是希望扩展现有知识,本文都将为你提供实用的信息和启发性的见解。
|
2月前
|
敏捷开发 Kubernetes Cloud Native
阿里云云原生技术为企业提供了一套高效、灵活的解决方案,支持跨云部署与管理
在多云环境中,阿里云云原生技术为企业提供了一套高效、灵活的解决方案,支持跨云部署与管理。通过容器化、服务网格等技术,实现了应用的一致性与可移植性,简化了多云环境下的资源管理和服务治理,帮助企业应对复杂的云环境挑战,加速数字化转型。
49 5
|
2月前
|
运维 Cloud Native 云计算
云原生之旅:Docker容器化实战
本文将带你走进云原生的世界,深入理解Docker技术如何改变应用部署与运维。我们将通过实际案例,展示如何利用Docker简化开发流程,提升应用的可移植性和伸缩性。文章不仅介绍基础概念,还提供操作指南和最佳实践,帮助你快速上手Docker,开启云原生的第一步。
|
2月前
|
运维 Kubernetes Cloud Native
云原生技术入门:Kubernetes和Docker的协同工作
【10月更文挑战第43天】在云计算时代,云原生技术成为推动现代软件部署和运行的关键力量。本篇文章将带你了解云原生的基本概念,重点探讨Kubernetes和Docker如何协同工作以支持容器化应用的生命周期管理。通过实际代码示例,我们将展示如何在Kubernetes集群中部署和管理Docker容器,从而为初学者提供一条清晰的学习路径。