Redis容器化部署教程
一、准备工作
(1)安装Docker环境
文章推荐:Docker安装部署教程
(2)获取Redis镜像
[root@10-27-0-224 ~]# docker pull redis:5.0.0 [root@10-27-0-224 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis 5.0.0 1babb1dde7e1 2 years ago 94.9MB
(3)创建Redis数据持久化卷
[root@10-27-0-224 ~]# docker volume create redis [root@10-27-0-224 ~]# docker volume ls DRIVER VOLUME NAME local redis [root@10-27-0-224 ~]# docker volume inspect redis [ { "CreatedAt": "2021-10-08T21:31:27-05:00", "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/redis/_data", "Name": "redis", "Options": {}, "Scope": "local" } ]
推荐文章:Docker应用程序数据管理与持久化
二、运行Redis容器
(1)启动容器
[root@10-27-0-224 ~]# docker run --name my-redis -p 6379:6379 --restart=always --mount source=redis,destination=/var/lib/redis -v /etc/localtime:/etc/localtime -d redis:5.0.0 redis-server --appendonly yes [root@10-27-0-224 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a4685fcbaefb redis:5.0.0 "docker-entrypoint.s…" 9 seconds ago Up 8 seconds 0.0.0.0:6379->6379/tcp redis
(2)参数解读
--name my-redis # 启动后容器名为 my-redis
-p 6379:6379 # 将容器的 6379 端口映射到主机的 6379 端口
--mount source=redis,destination=/var/lib/redis # 将主机 redis卷 挂载到容器的/var/lib/redis
redis-server --appendonly yes # 在容器执行redis-server启动命令,并打开redis持久化配置
(3)连接redis实例
[root@ansible ~]# redis-cli -h 107.155.48.73 -p 6379 # 默认没有密码,可以直接连接 107.155.48.73:6379> config set requirepass ucloud.cn # 给Redis设置密码 OK 107.155.48.73:6379> info # 未验证 NOAUTH Authentication required. (0.82s) 107.155.48.73:6379> auth ucloud.cn # 验证密码 OK 107.155.48.73:6379> info # 查看Redis配置 # Server redis_version:5.0.0 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:9a5fa86bdce33ad2 redis_mode:standalone os:Linux 3.10.0-957.1.3.el7.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll atomicvar_api:atomic-builtin gcc_version:6.3.0 process_id:1 run_id:eff44afa9d624282d66dc7859eaf6631151eb004 tcp_port:6379 uptime_in_seconds:2925 uptime_in_days:0 hz:10 configured_hz:10 lru_clock:6360676 executable:/data/redis-server config_file: # Clients connected_clients:1 client_recent_max_input_buffer:2 client_recent_max_output_buffer:0 blocked_clients:0 # Memory used_memory:854608 used_memory_human:834.58K used_memory_rss:3448832 used_memory_rss_human:3.29M used_memory_peak:875528 used_memory_peak_human:855.01K used_memory_peak_perc:97.61% used_memory_overhead:840726 used_memory_startup:790848 used_memory_dataset:13882 used_memory_dataset_perc:21.77% allocator_allocated:1173536 allocator_active:1474560 allocator_resident:5033984 total_system_memory:3988504576 total_system_memory_human:3.71G 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.26 allocator_frag_bytes:301024 allocator_rss_ratio:3.41 allocator_rss_bytes:3559424 rss_overhead_ratio:0.69 rss_overhead_bytes:18446744073707966464 mem_fragmentation_ratio:4.24 mem_fragmentation_bytes:2636216 mem_not_counted_for_evict:0 mem_replication_backlog:0 mem_clients_slaves:0 mem_clients_normal:49686 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:94 rdb_bgsave_in_progress:0 rdb_last_save_time:1633747787 rdb_last_bgsave_status:ok rdb_last_bgsave_time_sec:-1 rdb_current_bgsave_time_sec:-1 rdb_last_cow_size:0 aof_enabled:1 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 aof_current_size:5934 aof_base_size:0 aof_pending_rewrite:0 aof_buffer_length:0 aof_rewrite_buffer_length:0 aof_pending_bio_fsync:0 aof_delayed_fsync:0 # Stats total_connections_received:15 total_commands_processed:163 instantaneous_ops_per_sec:0 total_net_input_bytes:9729 total_net_output_bytes:101513 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 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 # Replication role:master connected_slaves:0 master_replid:01e58420ba0d348ce42ed52619bd46758b56de72 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:2.190291 used_cpu_user:2.175793 used_cpu_sys_children:0.004203 used_cpu_user_children:0.000000 # Cluster cluster_enabled:0 # Keyspace db0:keys=4,expires=0,avg_ttl=0
作者:UStarGao
链接:https://www.starcto.com/redis/250.html
来源:STARCTO
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
UCloud云平台推荐
随便看看
- 2021-01-28Docker安装部署教程
- 2021-04-23Linux进程带宽占用查看—NetHogs工具
- 2021-07-17开源EyouCms博客安装教程
- 2021-06-28Nginx文件下载服务器搭建
- 2021-11-03Redis持久化解决方案实操