-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add nacos basic startup content
- Loading branch information
Showing
2 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--- | ||
layout: doc | ||
--- | ||
|
||
# 基本概念和安装启动 | ||
|
||
## 概念 | ||
|
||
Nacos(官方网站:[nacos.io](https://nacos.io/))是一个易于使用的平台,专为动态服务发现、配置和服务管理而设计。它帮助您轻松构建云原生应用程序和微服务平台。 | ||
|
||
Nacos提供四个主要功能: | ||
|
||
- 服务发现和服务健康检查 | ||
|
||
- 动态配置管理 | ||
- 动态 DNS 服务 | ||
- 服务和元数据管理 | ||
|
||
## 启动Nacos | ||
|
||
:::tip | ||
- 启动nacos有`单机模式运行`和`集群模式`,今天只使用`单机模式` | ||
::: | ||
|
||
我们使用`Docker`来搭建`Nacos`服务,服务目录如下: | ||
|
||
```shell | ||
. | ||
├── .env | ||
├── env | ||
│ ├── mysql.env | ||
│ └── nacos-standlone-mysql.env | ||
├── image | ||
│ └── mysql8 | ||
│ └── Dockerfile | ||
└── standalone-mysql-8.yaml | ||
``` | ||
|
||
> `.env` | ||
:::warning | ||
- `Mac Apple`内核的机器要使用`v2.3.1-slim`版本的镜像,不然会报错,其他的内核应该用`v2.3.1`就行 | ||
::: | ||
|
||
```yaml | ||
NACOS_VERSION=v2.3.1-slim | ||
``` | ||
|
||
> `env/mysql.env` | ||
```yaml | ||
MYSQL_ROOT_PASSWORD=root # root用户密码 | ||
MYSQL_DATABASE=nacos_devtest # 启动nacos后,创建的数据库名称 | ||
MYSQL_USER=nacos # 创建的用户名称 | ||
MYSQL_PASSWORD=nacos # 创建的nacos用户密码 | ||
LANG=C.UTF-8 | ||
``` | ||
|
||
> `env/nacos-standlone-mysql.env` | ||
```yaml | ||
PREFER_HOST_MODE=hostname # 优先主机模式 | ||
MODE=standalone # 当前模式 | ||
SPRING_DATASOURCE_PLATFORM=mysql | ||
MYSQL_SERVICE_HOST=mysql | ||
MYSQL_SERVICE_DB_NAME=nacos_devtest # mysql 数据库名称 | ||
MYSQL_SERVICE_PORT=3306 # 数据库端口 | ||
MYSQL_SERVICE_USER=nacos # 数据库用户名 | ||
MYSQL_SERVICE_PASSWORD=nacos # 数据库密码 | ||
MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true | ||
NACOS_AUTH_IDENTITY_KEY=2222 | ||
NACOS_AUTH_IDENTITY_VALUE=2xxx | ||
NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789 | ||
``` | ||
|
||
> `image/mysql8/Dockerfile` | ||
```yaml | ||
FROM mysql:latest | ||
# 将 https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql | ||
# 这个远程文件下载并添加到镜像中的 /docker-entrypoint-initdb.d/ 目录下,并将其命名为 nacos-mysql.sql | ||
ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql | ||
# 将 /docker-entrypoint-initdb.d/nacos-mysql.sql 文件的所有者和所属组更改为 mysql 用户和 mysql 组 | ||
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql | ||
# 对外暴露 3306端口 | ||
EXPOSE 3306 | ||
# 启动 MySQL 服务器,并设置字符集为 utf8mb4 和排序规则为 utf8mb4_unicode_ci | ||
CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"] | ||
``` | ||
|
||
> `standalone-mysql-8.yaml` | ||
```yaml | ||
version: "2.6" | ||
services: | ||
mysql: | ||
container_name: MYSQL_NACOS | ||
restart: always | ||
build: | ||
context: . | ||
dockerfile: ./image/mysql8/Dockerfile | ||
env_file: | ||
- ./env/mysql.env | ||
volumes: | ||
- ./mysql:/var/lib/mysql | ||
ports: | ||
- "1004:3306" | ||
# 通过命令检查容器是否健康运行 | ||
healthcheck: | ||
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ] | ||
interval: 5s | ||
timeout: 10s | ||
retries: 10 | ||
nacos: | ||
image: nacos/nacos-server:${NACOS_VERSION} | ||
container_name: NACOS_STANDALONE_MYSQL | ||
restart: always | ||
env_file: | ||
- ./env/nacos-standlone-mysql.env | ||
volumes: | ||
- ./standalone-logs/:/home/nacos/logs | ||
ports: | ||
- "8848:8848" | ||
- "9848:9848" | ||
depends_on: | ||
mysql: | ||
condition: service_healthy | ||
``` | ||
启动`nacos` | ||
|
||
```shell | ||
docker-compose -f standalone-mysql-8.yaml up -d | ||
``` | ||
|
||
然后访问[http://localhost:8848/nacos](http://localhost:8848/nacos)就可以看到主界面 | ||
|