云原生之使用Docker部署Redis数据库
Posted 江湖有缘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了云原生之使用Docker部署Redis数据库相关的知识,希望对你有一定的参考价值。
云原生之使用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>
以上是关于云原生之使用Docker部署Redis数据库的主要内容,如果未能解决你的问题,请参考以下文章