docker部署单节点nacos
一、准备数据库
1) 新建数据库nacos
2) 导入nacos-mysql.sql
/* * Copyright 1999-2018 Alibaba Group Holding Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//******************************************//* 数据库全名 = nacos_config *//* 表名称 = config_info *//******************************************/CREATETABLE `config_info` ( `id` bigint(20)NOTNULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255)NOTNULL COMMENT 'data_id', `group_id` varchar(255) DEFAULT NULL, `content` longtextNOTNULL COMMENT 'content', `md5` varchar(32) DEFAULT NULL COMMENT 'md5', `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text COMMENT 'source user', `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', `app_name` varchar(128) DEFAULT NULL, `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', `c_desc` varchar(256) DEFAULT NULL, `c_use` varchar(64) DEFAULT NULL, `effect` varchar(64) DEFAULT NULL, `type` varchar(64) DEFAULT NULL, `c_schema` text, `encrypted_data_key` textNOTNULL COMMENT '秘钥', PRIMARY KEY (`id`), UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = config_info_aggr *//******************************************/CREATETABLE `config_info_aggr` ( `id` bigint(20)NOTNULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255)NOTNULL COMMENT 'data_id', `group_id` varchar(255)NOTNULL COMMENT 'group_id', `datum_id` varchar(255)NOTNULL COMMENT 'datum_id', `content` longtextNOTNULL COMMENT '内容', `gmt_modified` datetimeNOTNULL COMMENT '修改时间', `app_name` varchar(128) DEFAULT NULL, `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', PRIMARY KEY (`id`), UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = config_info_beta *//******************************************/CREATETABLE `config_info_beta` ( `id` bigint(20)NOTNULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255)NOTNULL COMMENT 'data_id', `group_id` varchar(128)NOTNULL COMMENT 'group_id', `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', `content` longtextNOTNULL COMMENT 'content', `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps', `md5` varchar(32) DEFAULT NULL COMMENT 'md5', `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text COMMENT 'source user', `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', `encrypted_data_key` textNOTNULL COMMENT '秘钥', PRIMARY KEY (`id`), UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = config_info_tag *//******************************************/CREATETABLE `config_info_tag` ( `id` bigint(20)NOTNULL AUTO_INCREMENT COMMENT 'id', `data_id` varchar(255)NOTNULL COMMENT 'data_id', `group_id` varchar(128)NOTNULL COMMENT 'group_id', `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id', `tag_id` varchar(128)NOTNULL COMMENT 'tag_id', `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', `content` longtextNOTNULL COMMENT 'content', `md5` varchar(32) DEFAULT NULL COMMENT 'md5', `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', `src_user` text COMMENT 'source user', `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip', PRIMARY KEY (`id`), UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = config_tags_relation *//******************************************/CREATETABLE `config_tags_relation` ( `id` bigint(20)NOTNULL COMMENT 'id', `tag_name` varchar(128)NOTNULL COMMENT 'tag_name', `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type', `data_id` varchar(255)NOTNULL COMMENT 'data_id', `group_id` varchar(128)NOTNULL COMMENT 'group_id', `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id', `nid` bigint(20)NOTNULL AUTO_INCREMENT, PRIMARY KEY (`nid`), UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`), KEY `idx_tenant_id` (`tenant_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = group_capacity *//******************************************/CREATETABLE `group_capacity` ( `id` bigint(20)unsignedNOTNULL AUTO_INCREMENT COMMENT '主键ID', `group_id` varchar(128)NOTNULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群', `quota` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '配额,0表示使用默认值', `usage` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '使用量', `max_size` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', `max_aggr_count` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值', `max_aggr_size` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', `max_history_count` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '最大变更历史数量', `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_group_id` (`group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = his_config_info *//******************************************/CREATETABLE `his_config_info` ( `id` bigint(20)unsignedNOTNULL, `nid` bigint(20)unsignedNOTNULL AUTO_INCREMENT, `data_id` varchar(255)NOTNULL, `group_id` varchar(128)NOTNULL, `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name', `content` longtextNOTNULL, `md5` varchar(32) DEFAULT NULL, `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP, `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP, `src_user` text, `src_ip` varchar(50) DEFAULT NULL, `op_type` char(10) DEFAULT NULL, `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段', `encrypted_data_key` textNOTNULL COMMENT '秘钥', PRIMARY KEY (`nid`), KEY `idx_gmt_create` (`gmt_create`), KEY `idx_gmt_modified` (`gmt_modified`), KEY `idx_did` (`data_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';/******************************************//* 数据库全名 = nacos_config *//* 表名称 = tenant_capacity *//******************************************/CREATETABLE `tenant_capacity` ( `id` bigint(20)unsignedNOTNULL AUTO_INCREMENT COMMENT '主键ID', `tenant_id` varchar(128)NOTNULL DEFAULT '' COMMENT 'Tenant ID', `quota` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '配额,0表示使用默认值', `usage` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '使用量', `max_size` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值', `max_aggr_count` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '聚合子配置最大个数', `max_aggr_size` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值', `max_history_count` int(10)unsignedNOTNULL DEFAULT '0' COMMENT '最大变更历史数量', `gmt_create` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `gmt_modified` datetimeNOTNULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_tenant_id` (`tenant_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';CREATETABLE `tenant_info` ( `id` bigint(20)NOTNULL AUTO_INCREMENT COMMENT 'id', `kp` varchar(128)NOTNULL COMMENT 'kp', `tenant_id` varchar(128) default '' COMMENT 'tenant_id', `tenant_name` varchar(128) default '' COMMENT 'tenant_name', `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc', `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source', `gmt_create` bigint(20)NOTNULL COMMENT '创建时间', `gmt_modified` bigint(20)NOTNULL COMMENT '修改时间', PRIMARY KEY (`id`), UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`), KEY `idx_tenant_id` (`tenant_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';CREATETABLE `users` ( `username` varchar(50)NOTNULL PRIMARY KEY, `password` varchar(500)NOTNULL, `enabled` booleanNOTNULL);CREATETABLE `roles` ( `username` varchar(50)NOTNULL, `role` varchar(50)NOTNULL, UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE );CREATETABLE `permissions` ( `role` varchar(50)NOTNULL, `resource` varchar(255)NOTNULL, `action` varchar(8)NOTNULL, UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE );INSERTINTO users (username, password, enabled)VALUES('nacos','$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu',TRUE);INSERTINTO roles (username, role)VALUES('nacos','ROLE_ADMIN');
二 、拉取镜像
docker pull nacos/nacos-server
三、配置
mkdir-p /server/nacos/conf
新增配置文件:
重点关注以下配置:
spring.datasource.platform=mysql
db.url.0=
db.user=root
db.password=123456
application.properties
#springserver.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos} server.contextPath=/nacosserver.port=${NACOS_APPLICATION_PORT:8848} server.tomcat.accesslog.max-days=30server.tomcat.accesslog.pattern=%h%l%u%t"%r"%s%b%D%{User-Agent}i%{Request-Source}ispring.datasource.platform=mysqlnacos.cmdb.dumpTaskInterval=3600nacos.cmdb.eventTaskInterval=10nacos.cmdb.labelTaskInterval=300nacos.cmdb.loadDataAtStart=falsedb.num=${MYSQL_DATABASE_NUM:1} db.url.0=jdbc:mysql://<ip>:<port>/<db>?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false#db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}db.user=rootdb.password=123456###Theauthsystemtouse, currentlyonly'nacos'and'ldap'issupported: nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos} ###workedwhennacos.core.auth.system.type=nacos###Thetokenexpirationinseconds: nacos.core.auth.plugin.nacos.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000} ###Thedefaulttoken: nacos.core.auth.plugin.nacos.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789} ###Turnon/offcachingofauthinformation. Byturningonthisswitch, theupdateofauthinformationwouldhavea15secondsdelay. nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false} nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false} nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity} nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security} server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false} #defaultcurrentworkdirserver.tomcat.basedir=file:. ##springsecurityconfig###turnoffsecuritynacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}# metrics for elastic searchmanagement.metrics.export.elastic.enabled=falsemanagement.metrics.export.influx.enabled=falsenacos.naming.distro.taskDispatchThreadCount=10nacos.naming.distro.taskDispatchPeriod=200nacos.naming.distro.batchSyncKeyCount=1000nacos.naming.distro.initDataRatio=0.9nacos.naming.distro.syncRetryDelay=5000nacos.naming.data.warmup=true
四、启动
dockerrun-d-v/server/nacos/conf/application.properties:/home/nacos/conf/application.properties--privileged=true--namenacos-p8848:8848-ePREFER_HOST_MODE=hostname-eMODE=standalonenacos/nacos-server
五、访问
http://:8848/nacos
六、测试
在nacos中新建test.yml
在服务器输入命令:
curl-XGET"http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=test.yml&group=DEFAULT_GROUP"
得到结果:
证明部署成功!:)