基于Docker-Compose 安装Nacos
Common property configuration
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 |
Mysql 模式
Mysql模式会将配置文件保存在mysql数据库中,避免因为nacos容器被删除而导致配置文件的丢失。
将以下脚本保存在docker-compose.yaml文件中,执行docker-compose -f docker-compose.yaml up -d命令。注意必须和数据库一起安装
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql-test
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: nacos
ports:
- 3306:3306
volumes:
- /mydata/mysql/data/db:/var/lib/mysql
- /mydata/mysql/data/conf:/etc/mysql/conf.d
- /mydata/mysql/log:/var/log/mysql
privileged: true
nacos-registry:
image: nacos/nacos-server:1.4.0
container_name: nacos-registry-test
volumes:
- /mydata/nacos/logs:/home/nacos/logs
environment:
- MODE=standalone
- SPRING_DATASOURCE_PLATFORM=mysql
- MYSQL_SERVICE_HOST=mysql-test
- MYSQL_SERVICE_DB_NAME=nacos
- MYSQL_SERVICE_PORT=3306
- MYSQL_SERVICE_USER=root
- MYSQL_SERVICE_PASSWORD=root
- management.endpoints.web.exposure.include=*
ports:
- 8848:8848
privileged: true
单机模式 Derby
Derby自带数据库,信息保存在nacos项目中集成的数据库中,不保存在mysql数据库。缺点是删除nacos容器后,配置文件数据会被删除。
将以下脚本保存在docker-compose.yaml文件中,执行docker-compose -f docker-compose.yaml up -d命令
version: '3'
services:
mysql:
image: mysql:5.7
container_name: mysql
command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: root #设置root帐号密码
ports:
- 3306:3306
volumes:
- /mydata/mysql/data/db:/var/lib/mysql #数据文件挂载
- /mydata/mysql/data/conf:/etc/mysql/conf.d #配置文件挂载
- /mydata/mysql/log:/var/log/mysql #日志文件挂载
privileged: true
redis:
image: redis:5
container_name: redis
command: redis-server --appendonly yes
volumes:
- /mydata/redis/data:/data #数据文件挂载
ports:
- 6379:6379
nginx:
image: nginx:1.10
container_name: nginx
volumes:
- /mydata/nginx/nginx.conf:/etc/nginx/nginx.conf #配置文件挂载
- /mydata/nginx/html:/usr/share/nginx/html #静态资源根目录挂载
- /mydata/nginx/log:/var/log/nginx #日志文件挂载
ports:
- 80:80
rabbitmq:
image: rabbitmq:3.7.15-management
container_name: rabbitmq
volumes:
- /mydata/rabbitmq/data:/var/lib/rabbitmq #数据文件挂载
- /mydata/rabbitmq/log:/var/log/rabbitmq #日志文件挂载
ports:
- 5672:5672
- 15672:15672
privileged: true
elasticsearch:
image: elasticsearch:7.6.2
container_name: elasticsearch
user: root
environment:
- "cluster.name=elasticsearch" #设置集群名称为elasticsearch
- "discovery.type=single-node" #以单一节点模式启动
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #设置使用jvm内存大小
volumes:
- /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins #插件文件挂载
- /mydata/elasticsearch/data:/usr/share/elasticsearch/data #数据文件挂载
ports:
- 9200:9200
- 9300:9300
privileged: true
logstash:
image: logstash:7.6.2
container_name: logstash
environment:
- TZ=Asia/Shanghai
volumes:
- /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf #挂载logstash的配置文件
depends_on:
- elasticsearch #kibana在elasticsearch启动之后再启动
links:
- elasticsearch:es #可以用es这个域名访问elasticsearch服务
ports:
- 4560:4560
- 4561:4561
- 4562:4562
- 4563:4563
kibana:
image: kibana:7.6.2
container_name: kibana
links:
- elasticsearch:es #可以用es这个域名访问elasticsearch服务
depends_on:
- elasticsearch #kibana在elasticsearch启动之后再启动
environment:
- "elasticsearch.hosts=http://es:9200" #设置访问elasticsearch的地址
ports:
- 5601:5601
privileged: true
mongo:
image: mongo:4.2.5
container_name: mongo
volumes:
- /mydata/mongo/db:/data/db #数据文件挂载
ports:
- 27017:27017
privileged: true
nacos-registry:
image: nacos/nacos-server:1.4.0
container_name: nacos-registry
environment:
- MODE=standalone
ports:
- 8848:8848
privileged: true