docker-compose安装nacos集群

 官网说明

操作步骤

  • Clone 项目

    git clone https://github.com/nacos-group/nacos-docker.git
    cd nacos-docker
  • 单机模式 Derby

    docker-compose -f example/standalone-derby.yaml up
  • 单机模式 Mysql

    docker-compose -f example/standalone-mysql.yaml up
  • 集群模式

    docker-compose -f example/cluster-hostname.yaml up 
    

      

  • 服务注册

    curl -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
  • 服务发现

    curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instances?serviceName=nacos.naming.serviceName'
  • 发布配置

    curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=helloWorld
  • 获取配置

      curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
  • Nacos 控制台

    link:http://127.0.0.1:8848/nacos/

通用配置

name description option
MODE cluster模式/standalone模式 cluster/standalone default cluster
NACOS_SERVERS nacos cluster地址 eg. ip1,ip2,ip3
PREFER_HOST_MODE 是否支持hostname hostname/ip default ip
NACOS_SERVER_PORT nacos服务器端口 default 8848
NACOS_SERVER_IP 多网卡下的自定义nacos服务器IP  
SPRING_DATASOURCE_PLATFORM standalone 支持 mysql mysql / empty default empty
MYSQL_MASTER_SERVICE_HOST mysql 主节点host  
MYSQL_MASTER_SERVICE_PORT mysql 主节点端口 default : 3306
MYSQL_MASTER_SERVICE_DB_NAME mysql 主节点数据库  
MYSQL_MASTER_SERVICE_USER 数据库用户名  
MYSQL_MASTER_SERVICE_PASSWORD 数据库密码  
MYSQL_SLAVE_SERVICE_HOST mysql从节点host  
MYSQL_SLAVE_SERVICE_PORT mysql从节点端口 default :3306
MYSQL_DATABASE_NUM 数据库数量 default :2
JVM_XMS -Xms default :2g
JVM_XMX -Xmx default :2g
JVM_XMN -Xmn default :1g
JVM_MS -XX:MetaspaceSize default :128m
JVM_MMS -XX:MaxMetaspaceSize default :320m
NACOS_DEBUG 开启远程调试 y/n default :n
TOMCAT_ACCESSLOG_ENABLED server.tomcat.accesslog.enabled default :false

 安装示例如下:

[root@iZbp143t3oxhfc3ar7jey0Z ~]# git clone https://github.com/nacos-group/nacos-docker.git /software/nacos-docker
Cloning into '/software/nacos-docker'...
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (38/38), done.
remote: Total 407 (delta 21), reused 44 (delta 15), pack-reused 351
Receiving objects: 100% (407/407), 2.20 MiB | 96.00 KiB/s, done.
Resolving deltas: 100% (157/157), done.
[root@iZbp143t3oxhfc3ar7jey0Z ~]# ll
total 4
-rw-r--r-- 1 root root 59 Apr 15 14:30 11.sh
[root@iZbp143t3oxhfc3ar7jey0Z ~]# cd /software/nacos-docker
[root@iZbp143t3oxhfc3ar7jey0Z nacos-docker]# ll
total 32
drwxr-xr-x 5 root root 4096 Apr 25 11:16 build
-rw-r--r-- 1 root root   79 Apr 25 11:16 changlog
drwxr-xr-x 2 root root 4096 Apr 25 11:16 env
drwxr-xr-x 5 root root 4096 Apr 25 11:16 example
-rw-r--r-- 1 root root 6018 Apr 25 11:16 README.md
-rw-r--r-- 1 root root 6507 Apr 25 11:16 README_ZH.md
[root@iZbp143t3oxhfc3ar7jey0Z bin]# docker-compose --version
docker-compose version 1.24.1, build 4667896b
[root@iZbp143t3oxhfc3ar7jey0Z bin]# cd /software/nacos-docker
[root@iZbp143t3oxhfc3ar7jey0Z nacos-docker]# ll
total 32
drwxr-xr-x 5 root root 4096 Apr 25 11:16 build
-rw-r--r-- 1 root root   79 Apr 25 11:16 changlog
drwxr-xr-x 2 root root 4096 Apr 25 11:16 env
drwxr-xr-x 5 root root 4096 Apr 25 11:16 example
-rw-r--r-- 1 root root 6018 Apr 25 11:16 README.md
-rw-r--r-- 1 root root 6507 Apr 25 11:16 README_ZH.md
[root@iZbp143t3oxhfc3ar7jey0Z nacos-docker]# cd example/
[root@iZbp143t3oxhfc3ar7jey0Z example]# ll
total 32
-rw-r--r-- 1 root root 1295 Apr 25 11:16 cluster-hostname.yaml
-rw-r--r-- 1 root root 1391 Apr 25 11:16 cluster-ip.yaml
drwxr-xr-x 2 root root 4096 Apr 25 11:16 init.d
drwxr-xr-x 3 root root 4096 Apr 25 11:16 plugins
drwxr-xr-x 2 root root 4096 Apr 25 11:16 prometheus
-rw-r--r-- 1 root root  712 Apr 25 11:16 standalone-derby.yaml
-rw-r--r-- 1 root root  966 Apr 25 11:16 standalone-mysql-5.7.yaml
-rw-r--r-- 1 root root  640 Apr 25 11:16 standalone-mysql-8.yaml
[root@iZbp143t3oxhfc3ar7jey0Z example]# docker-compose -f cluster-hostname.yaml up
Creating network "example_default" with the default driver
Pulling mysql (nacos/nacos-mysql:5.7)...
Trying to pull repository docker.io/nacos/nacos-mysql ...
5.7: Pulling from docker.io/nacos/nacos-mysql
0a4690c5d889: Pull complete
98aa2fc6cbeb: Pull complete
0777e6eb0e6f: Pull complete
2464189c041c: Pull complete
b45df9dc827d: Pull complete
b42b00086160: Pull complete
bb93567627c7: Pull complete
48acc32b4863: Pull complete
6257d2da4815: Pull complete
1cd5ed3b2653: Pull complete
f4ba7ff24ae9: Pull complete
b9052e968393: Pull complete
df2aaf502f09: Pull complete
Digest: sha256:2f60778f69febed2dd65d52d4c5aa789751d1fd8e172be2eb162879fb6f59a39
Status: Downloaded newer image for docker.io/nacos/nacos-mysql:5.7
Pulling nacos3 (nacos/nacos-server:latest)...
Trying to pull repository docker.io/nacos/nacos-server ...
latest: Pulling from docker.io/nacos/nacos-server
5ad559c5ae16: Pull complete
be7fcb81503b: Pull complete
184628106033: Pull complete
659182d1bc33: Pull complete
f50076ce88c1: Pull complete
7409127fbcf2: Pull complete
110ead5a3247: Pull complete
2a4cb2f6d49b: Pull complete
Digest: sha256:ab9a49756f23ba89c389e855a5ec0ae8d81adf6875c43817e8f7091b5b56d401
Status: Downloaded newer image for docker.io/nacos/nacos-server:latest
Creating mysql ... done
Creating nacos1 ... done
Creating nacos2 ... done
Creating nacos3 ... done
Attaching to mysql, nacos2, nacos3, nacos1
mysql     | Initializing database
mysql     | 2020-04-25T05:00:47.806960Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql     | 2020-04-25T05:00:48.837324Z 0 [Warning] InnoDB: New log files created, LSN=45790
mysql     | 2020-04-25T05:00:48.989159Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysql     | 2020-04-25T05:00:49.068966Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: bade5bb6-86b1-11ea-9831-0242ac130002.
mysql     | 2020-04-25T05:00:49.071862Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysql     | 2020-04-25T05:00:49.072442Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

查看:

[root@iZbp143t3oxhfc3ar7jey0Z example]# docker-compose -f cluster-hostname.yaml ps
 Name              Command             State                       Ports
---------------------------------------------------------------------------------------------
mysql    docker-entrypoint.sh mysqld   Up      0.0.0.0:3306->3306/tcp, 33060/tcp
nacos1   bin/docker-startup.sh         Up      0.0.0.0:8848->8848/tcp, 0.0.0.0:9555->9555/tcp
nacos2   bin/docker-startup.sh         Up      0.0.0.0:8849->8848/tcp
nacos3   bin/docker-startup.sh         Up      0.0.0.0:8850->8848/tcp
[root@iZbp143t3oxhfc3ar7jey0Z example]#

docker-compose安装nacos集群_第1张图片

配置文件:

spring:
  application:
    name: xxxx
  cloud:
    nacos:
      config:
        server‐addr: 127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850

 

你可能感兴趣的:(docker-compose安装nacos集群)