nacos分布式程序开发实例

news/2024/7/8 1:11:51

1.通过windows docker desktop 完成 nacos 的安装/启动/配置

(1)先安装docker desktop

docker-toolbox-windows-docker-for-windows-stable安装包下载_开源镜像站-阿里云

(2)配置docker 国内镜像源

Docker 镜像加速 | 菜鸟教程

阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台

(3)拉取nacos的image,部署到本地docker

PS C:\Users\admin> docker pull nacos/nacos-server
Using default tag: latest
latest: Pulling from nacos/nacos-server
5ad559c5ae16: Pull complete
5746ca7cf180: Pull complete
d709fe221c89: Pull complete
e88fdcf257b1: Pull complete
eb573b28173c: Pull complete
a71625257ced: Pull complete
26e7e7836838: Pull complete
30f7d6851c4a: Pull complete
d565cd94c625: Pull complete
Digest: sha256:87a3d8b78ec24c253a4db7c093097a7b256327eb5117cd9498e289b896918153
Status: Downloaded newer image for nacos/nacos-server:latest
docker.io/nacos/nacos-server:latest

What's Next?
  View summary of image vulnerabilities and recommendations → docker scout quickview nacos/nacos-server
PS C:\Users\admin> docker run --name nacos -e MODE=standalone -p 8848:8848 -d nacos/nacos-server
8d17121aac278dc1353e342020183c412a8a4400a7a8fea293e5f5836b876f64

docker run --name nacos后,nacos即启动成功,在docker desktop界面上可以看到运行情况

(4)将现网nacos的yaml配置导出,并导入本地nacos中

导出的yaml文件会以zip压缩包形式下载到本地

将zip包导入本地nacos中即可(本地nacos登录地址http://127.0.0.1:8848/nacos)

至此,nacos安装启动配置完毕。

2.在windows docker desktop中,现在最新的redis镜像(image),并用下载的镜像创建容器(container)

(1)下载redis镜像

PS C:\Users\admin> docker pull redis
Using default tag: latest
latest: Pulling from library/redis
a2abf6c4d29d: Pull complete
c7a4e4382001: Pull complete
4044b9ba67c9: Pull complete
c8388a79482f: Pull complete
413c8bb60be2: Pull complete
1abfd3011519: Pull complete
Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest

What's Next?
  View summary of image vulnerabilities and recommendations → docker scout quickview redis

(2)查看本地镜像

PS C:\Users\admin> docker image ls
REPOSITORY                                             TAG          IMAGE ID       CREATED         SIZE
frappe/erpnext                                         v15.10.1     a3b490c6e849   2 months ago    1.71GB
postgres                                               15           d366292ba654   3 months ago    419MB
odoo                                                   latest       a5e2a8d99256   3 months ago    1.81GB
redis                                                  6.2-alpine   0e8d64a9df81   4 months ago    30.3MB
mariadb                                                10.6         d1d924d97091   4 months ago    396MB
mysql                                                  8.0          96bc8cf3633b   5 months ago    582MB
redis                                                  <none>       7c4b517da47d   7 months ago    153MB
mysql                                                  5.7          a5b7ceed4074   8 months ago    581MB
traefik                                                v2.6         22c6901de2be   22 months ago   102MB
redis                                                  latest       7614ae9453d1   2 years ago     113MB
nacos/nacos-server                                     latest       bdf60dc2ada3   2 years ago     1.05GB
rohitbasu77/oracle11g                                  latest       06b948774586   4 years ago     5.35GB
elasticsearch                                          6.8.3        1d0fd79266e6   4 years ago     800MB
mobz/elasticsearch-head                                5            b19a5c98e43b   7 years ago     824MB
registry.cn-hangzhou.aliyuncs.com/helowin/oracle_11g   latest       3fa112fd3642   8 years ago     6.85GB
jaspeen/oracle-11g                                     latest       0c8711fe4f0f   8 years ago     281MB

(3)创建容器(命令行)

PS C:\Users\admin> docker run -p 6379:6379 --name redis-gzw -v D:\code\wx\conf\redis.conf:/etc/redis/redis.conf -v D:\code\wx\dockerdata:/data -d redis:aliyunlast redis-server --appendonly yes
a9dfa639b1be5ece6178709016350124999db9467f6f73b8aa05b0bad41a46fc

------------------------------------------------------------------------------------------
第一次创建时,下面的报错是因为有redis容器正在运行,6379端口被占用,提示启动失败,但容器创建成功

docker: Error response from daemon: driver failed programming external connectivity on endpoint redis-gzw (231f0fb67ea730a060682083c7662e114189acad547729d002ee5457184d12d9): Bind for 0.0.0.0:6379 failed: port is already allocated.
PS C:\Users\admin> docker run -p 6379:6379 --name redis-gzw -v D:\code\wx\conf\redis.conf:/etc/redis/redis.conf -v D:\code\wx\dockerdata:/data -d redis:aliyunlast redis-server --appendonly yes

------------------------------------------------------------------------------------------
第二次创建时,下面的报错是因为容器名redis-gzw的容器已存在,不可重复创建。

docker: Error response from daemon: Conflict. The container name "/redis-gzw" is already in use by container "a9dfa639b1be5ece6178709016350124999db9467f6f73b8aa05b0bad41a46fc". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.

-p 6379:6379 端口映射:前表示主机部分,:后表示容器部分。
–name redis-gzw 指定该容器名称,查看和进行操作都比较方便。


-v 挂载目录,规则与端口映射相同。

-v D:\code\wx\conf\redis.conf:/etc/redis/redis.conf D:\code\wx\conf\redis.conf 挂载配置文件实体机和虚拟机映射

表示实体机路径(本例使用的是windows主机),冒号后面的/etc/redis/redis.conf表示容器中的路径,可以理解为虚拟机路径

-v D:\code\wx\dockerdata:/data 挂载持久化存储目录的实体机和虚拟机映射


-d 是docker run命令的一个选项,它用于在后台(detached mode)运行容器。

redis:aliyunlast 表示使用指定的redis:aliyunlast镜像创建容器,是docker基本语法:

docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]


redis-server 是Redis数据库的服务器进程(也是命令),当您运行Redis容器时,需要指定要运行的命令。redis-server命令用于启动Redis服务器。通过在docker run命令中指定redis-server作为容器的命令,您可以在Redis容器中启动Redis服务器进程。


--appendonly yes 是redis-server命令的参数,标识开启redis 持久化

windows|nacos 安装Redis_nacos配置redis-CSDN博客

gpt详细的解释:

https://poe.com/s/3jY7OrWD973byObFPGv5

创建后容器自动启动,如果没有启动成功,可以手动启动

(4)修改镜像的标签(tag)

PS C:\Users\admin> docker tag 7614ae9453d1d87e740a2056257a6de7135c84037c367e1fffa92ae922784631 redis:aliyunlast

docker tag IMAGEID(镜像id) REPOSITORY:TAG(仓库:标签)

(5)测试验证(redisinsight)

redisinsight:

Download | Redis


http://lihuaxi.xjx100.cn/news/2154556.html

相关文章

上传应用程序到苹果应用商店的工具和要

引言 在今天的移动应用市场中&#xff0c;将应用程序上传到苹果应用商店&#xff08;App Store&#xff09;是许多开发者的首要任务之一。然而&#xff0c;不同操作系统下的开发者可能需要使用不同的工具和遵循不同的要求来完成这一任务。本文将介绍在 macOS、Windows 和 Linu…

服务网关-微服务小白入门(3)

基本概念 Spring Cloud Gateway Spring Cloud Gateway是基于Spring生态系统之上构建的API网关&#xff0c;包括&#xff1a;Spring 5.x&#xff0c;Spring Boot 2.x和Project Reactor。Spring Cloud Gateway旨在提供一种简单而有效的方法来路由到API&#xff0c;并为它们提供…

CSS常见样式

字体相关的样式 <style>div{/* 斜体 */font-style: italic;/* 加粗 100-900*/font-weight: 900;/* 字体大小 */font-size: 20px;/* 声明字体格式 */font-family: "微软雅黑";}</style> div内部文字垂直居中 只需要将行高设为其height的大小即可。 div{…

高频SQL 有趣的电影

题目信息 表&#xff1a;cinema -------------------------- | Column Name | Type | -------------------------- | id | int | | movie | varchar | | description | varchar | | rating | float | --------------------…

【JavaWeb】Day33.MySQL概述

什么是数据库 数据库&#xff1a;英文为 DataBase&#xff0c;简称DB&#xff0c;它是存储和管理数据的仓库。 像我们日常访问的电商网站京东&#xff0c;企业内部的管理系统OA、ERP、CRM这类的系统&#xff0c;以及大家每天都会刷的头条、抖音类的app&#xff0c;那这些大家所…

纯小白蓝桥杯备赛笔记--DAY10(字符串)

文章目录 KMP字符串哈希算法简介&#xff1a;斤斤计较的小z--2047字符串hash Manacher回文串的性质算法简介最长回文子串 字典树基础朴素字符串查找步骤前缀判定--1204 01tire算法简介&#xff1a;例题1&#xff1a;例题2&#xff1a; KMP字符串哈希 算法简介&#xff1a; 真前…

数字图像处理项目——基于BCNN和迁移学习的鸟类图像细粒度分类(论文/代码)

完整的论文代码见文章末尾 以下为核心内容 摘要 本文采用了ResNet50、VGG19、InceptionV3和Xception等四种不同的深度神经网络模型&#xff0c;并应用于鸟类图像的细粒度分类问题中&#xff0c;以探究其在该任务上的性能表现。 其中&#xff0c;本文使用了BCNN&#xff08;B…

C++中的inline用法

1. 引入inline关键字的原因 在c/c中&#xff0c;为了解决一些频繁调用的小函数大量消耗栈空间&#xff08;栈内存&#xff09;的问题&#xff0c;特别的引入了inline修饰符&#xff0c;表示为内联函数。 栈空间就是指放置程序的局部数据&#xff08;也就是函数内数据&#xf…