关注分享主机优惠活动
国内外VPS云服务器

Docker环境下Nacos2 MySQL8的具体操作

本文介绍了如何在docker环境下安装运行Nacos2,并在docker环境下使用MySQL 8存储数据。

1拉镜像

1.1创建目录在硬盘上创建nacos的相关目录:

mkdir -p/users/yygnb/docker me/nacos/conf/users/yygnb/docker me/nacos/logs/users/yygnb/docker me/nacos/data/users/yygnb/docker me/nacos/init . d向此目录添加权限:

chown 200 -R/Users/yygnb/docker me/nacos

1.2拉动镜子搜索镜子:

Docker搜索nacos搜索结果:

Docker环境下Nacos2 MySQL8的具体操作-主机频道

2配置文件

2.1 nacos-logback.xml在conf目录中创建配置文件nacos-logback.xml:

& lt?XML version = " 1.0 " encoding = " ut F-8 "?& gt& lt配置scan="true" scanPeriod="10秒" >& ltspring property scope = " context " name = " log path " source = " nacos . logs . path " default value = " $ { nacos . home }/logs "/& gt;& ltproperty name = " LOG _ HOME " value = " $ { LOG path } "/& gt;& ltappender name = " CMDB -main " class = " ch . QoS . log back . core . rolling . rolling file appender " & gt;& lt文件& gt${ nacos . home }/logs/CMDB -main . log & lt;/file & gt;& lt追加& gttrue & lt/append & gt;& ltrolling policy class = " ch . QoS . log back . core . rolling . sizeandtimebasedrollingpolicy " & gt;& lt文件名模式& gt${ nacos . home }/logs/CMDB -main . log . % d { yyyy -MM-DD }。% i & lt/filename pattern & gt;& ltmaxFileSize & gt2GB & lt/max filesize & gt;& ltmaxHistory & gt7 & lt/max history & gt;& lttotalSizeCap & gt7GB & lt/totalSizeCap & gt;& ltcleanHistoryOnStart & gttrue & lt/cleanHistoryOnStart & gt;& lt/rolling policy & gt;& lt编码器& gt& lt模式& gt% date % level % msg % n % n & lt/Pattern & gt;& ltcharset & gtut F-8 & lt;/charset & gt;& lt/encoder & gt;& lt/appender & gt;& ltappender name = " root file " class = " ch . QoS . log back . core . rolling . rolling file appender " & gt;& lt文件& gt$ { LOG _ HOME }/nacos . LOG & lt;/file & gt;& lt追加& gttrue & lt/append & gt;& ltrolling policy class = " ch . QoS . log back . core . rolling . sizeandtimebasedrollingpolicy " & gt;& lt文件名模式& gt$ { LOG _ HOME }/nacos . LOG . % d { yyyy -MM-DD }。% i & lt/filename pattern & gt;& ltmaxFileSize & gt50MB & lt/max filesize & gt;& ltmaxHistory & gt7 & lt/max history & gt;& lttotalSizeCap & gt512MB & lt/totalSizeCap & gt;& ltcleanHistoryOnStart & gttrue & lt/cleanHistoryOnStart & gt;& lt/rolling policy & gt;& lt编码器& gt& lt模式& gt% date % level % msg % n % n & lt/Pattern & gt;& ltcharset & gtut F-8 & lt;/charset & gt;& lt/encoder & gt;& lt/appender & gt;& ltappender name = " CONSOLE " class = " ch . QoS . log back . core . CONSOLE appender " & gt;& lt编码器& gt& lt模式& gt% date % level % msg % n % n & lt/Pattern & gt;& ltcharset & gtut F-8 & lt;/charset & gt;& lt/encoder & gt;& lt/appender & gt;& ltappender name = " naming -server " class = " ch . QoS . log back . core . rolling . rolling file appender " & gt;& lt文件& gt$ { LOG _ HOME }/naming -server . LOG & lt;/file & gt;& lt追加& gttrue & lt/append & gt;& ltrolling policy class = " ch . QoS . log back . core . rolling . sizeandtimebasedrollingpolicy " & gt;& lt文件名模式& gt$ { LOG _ HOME }/naming -server . LOG . % d { yyyy -MM-DD }。% i & lt/filename pattern & gt;& ltmaxFileSize & gt1GB & lt/max filesize & gt;& ltmaxHistory & gt7 & lt/max history & gt;& lttotalSizeCap & gt7GB & lt/totalSizeCap & gt;& ltcleanHistoryOnStart & gttrue & lt/cleanHistoryOnStart & gt;& lt/rolling policy & gt;& lt编码器& gt& lt模式& gt% date % level % msg % n % n & lt/Pattern & gt;& ltcharset & gtut F-8 & lt;/charset & gt;& lt/encoder & gt;& lt/appender & gt;& ltspringProfile name="standalone " >& ltlogger name = " org . spring framework " & gt;& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " INFO "/& gt;& lt/logger & gt;& ltlogger name = " org . Apache . catalina . startup . digester factory " & gt;& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " INFO "/& gt;& lt/logger & gt;& ltlogger name = " org . Apache . catalina . util . life cycle base " & gt;& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " ERROR "/& gt;& lt/logger & gt;& ltlogger name = " org . Apache . coyote . http 11 . http 11 nio protocol " >& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " WARN "/& gt;& lt/logger & gt;& ltlogger name = " org . Apache . Tomcat . util . net . nioselectorpool " & gt;& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " WARN "/& gt;& lt/logger & gt;& lt/spring profile & gt;& ltlogger name = " com . Alibaba . nacos . core . listener . startingapplicationlistener " & gt;& ltappender -ref ref = " CONSOLE "/& gt;& ltlevel value = " INFO "/& gt;& lt/logger & gt;& ltroot & gt& ltlevel value = " INFO "/& gt;& ltappender -ref ref = " root file "/& gt;& lt/root & gt;& lt/configuration & gt;

2.2 custom.properties在init.d目录下创建一个custom.properties文件,用MySQL数据库的信息进行配置。MySQL 8在Docker中的安装在之前的文章中已经介绍过了。

server . context path =/nacos server . servlet . context path =/nacos server . port = 8848 spring . data source . platform = mysqldb . num = 1db . URL . 0 = JDBC:MySQL://127 . 0 . 0 . 1/nacos?字符编码= utf8 & ampconnectTimeout = 1000 & ampsocketTimeout = 3000 & ampautore connect = true db . user = rootdb . password = MySQL . 123 nacos . CMDB . dump task interval = 3600 nacos . CMDB . event task interval = 10 nacos . CMDB . labeltaskinterval = 300 nacos . CMDB . loaddataatstart = false management . metrics . export . elastic . enabled = false management . metrics . export . influre . enabled = false server . Tomcat . access log . enabled = true server . Tomcat . access log . pattern = % h % l % u % t“% rcss,/**/*。js,/**/*。html,/**/*。地图,/**/*。svg,/**/*。png,/**/*。ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/* * nacos . naming . distro . taskdispatchthreadcount = 1 nacos . naming . distro . taskdispatchperiod = 200 nacos . naming . distro . batchsyncckeycount = 1000 nacos . naming . distro in Itratio

3准备数据库

3.1创建数据库` nacos '默认字符集ut F8 MB 4 collate ut F8 MB 4 _ general _ ci;

3.2创建表格结构,可以去Nacos官方github下载:

https://github . com/Alibaba/nacos/blob/master/distribution/conf/nacos -Mysql . SQL如果网络不工作,可以复制以下SQL语句来执行:

CREATE TABLE ` config _ info `( ` id ` bigint(20)NOT NULL AUTO _ INCREMENT COMMENT ' id ',` data _ id ` varchar(255)NOT NULL COMMENT ' data _ id ',` group _ id ` varchar(255)DEFAULT NULL,' content ` long text NOT NULL COMMENT ' content ',` MD5 ` varchar(32)DEFAULT NULL COMMENT ' MD5 ',` GMT _ CREATE ` datetime NOT NULL DEFAULT current _ timestamp COMMENT '创建时间',` gmt _ modified` datetime not null缺省当前时间戳注释'修改时间 ` tenant _ id ` varchar(128)DEFAULT ' ' COMMENT ' tenant field ',` c _ desc` varchar (256) default null,` effect` varchar (64) default null,` type` varchar (64) default null,` c _ schema` text,` encrypted _ data _ KEY ` text not null COMMENT ' secret KEY,主键(` id `),唯一键` uk _ configinfo _ datagroup tenant `( ` data _ id `, ` group _ id ` /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos _ config *//* Table name = config _ info _ agg创建表` config _ info _ aggr `( ` id ` bigint(20)NOT NULL AUTO _ INCREMENT注释' id ',` data_id` varchar(255) NOT NULL注释' data_id ', ` group _ id ` varchar(255)NOT NULL COMMENT ' group _ id ',` Datum _ id ` varchar(255)NOT NULL COMMENT ' Datum _ id ',` content ` long text NOT NULL COMMENT ' content ',` GMT _ modified ` datetime NOT NULL COMMENT ' modified time ',` app _ name ` varchar(128)default NULL,` Tenant _ id ` varchar(128)default ' ' COMMENT ' Tenant Field ',主键(` id `),唯一键` uk _ configinfoaggr _ datagroup Tenant `(` data /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos _ config *//* Table name = config _ info _ beta创建表` config _ info _ beta `( ` id ` bigint(20)NOT NULL AUTO _ INCREMENT注释' id ',` data_id` varchar(255) NOT NULL注释' data_id ', ` group_id` varchar(128) NOT NULL注释' group_id ',` app_name` varchar(128)默认NULL注释' app_name ',` content` longtext NOT NULL注释' content ',` beta_ips` varchar(1024)默认NULL注释' betaIps ',` md5` varchar (32)默认NULL注释' md5 ',` gmt _ create` datetime not null默认current _ timestamp注释'创建时间',` gmt _ modified` datetime not null默认current _ timestamp注释'已修改 ` tenant _ id ` varchar(128)DEFAULT ' ' COMMENT ' tenant field ',` encrypted _ data _ key ` text not null COMMENT ' secret key,primary key (`id `),unique key ` uk _ configinfo beta _ datagroup tenant `(` data _ id `,` tenant _ id `))ENGINE = InnoDB DEFAULT CHARSET = utf8 COLLATE = utf8 _ bin COMMENT = ' config _ info _ beta '; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos _ config *//* Table name = config _ info _ tag创建表` config _ info _ tag `( ` id ` bigint(20)NOT NULL AUTO _ INCREMENT注释' id ',` data_id` varchar(255) NOT NULL注释' data_id ', ` group _ id ` varchar(128)NOT NULL COMMENT ' group _ id ',` tenant _ id ` varchar(128)DEFAULT ' ' COMMENT ' tenant _ id ',` tag _ id ` varchar(128)NOT NULL COMMENT ' tag _ id ',` app _ name ` varchar(128)DEFAULT NULL COMMENT ' app _ name ',` content ` longtext NOT NULL COMMENT ' content ',` MD5 ` varchar(32)DEFAULT NULL COMMENT ' MD5 ',` GMT _ create ` datetime NOT NULL DEFAULT current _ timestamp COMMENT /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos _ config *//* TABLE name = config _ tags _ * * */CREATE TABLE ` config _ tags _ relation `( ` id ` bigint(20)NOT NULL注释' id ',` tag_name` varchar(128) NOT NULL注释' tag_name ',` tag_type` varchar(64)默认NULL注释' tag_type ', ` data _ id ` varchar(255)NOT NULL COMMENT ' data _ id ',` group _ id ` varchar(128)NOT NULL COMMENT ' group _ id ',` tenant _ id ` varchar(128)DEFAULT ' ' COMMENT ' tenant _ id ',` nid ` bigint(20)NOT NULL AUTO _ INCREMENT,主键(` NID `),唯一键` uk _ configtag relation _ configidtag `( ` id `,` tag_name`,`tag_type `),键` idx_tenant_id ` /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos_config *//*表名= group _ capacity * create ` group _ capacity `(` id ` bigint(20)unsigned not null auto _ increment注释'主键ID ', ` group _ id ` varchar(128)not null default ' ' comment '组id,空字符表示整个群集',` quota ` int(10)unsigned not null default ' 0 ' comment ' quota,0表示使用默认值',` usage ` int(10)unsigned not null default ' 0 ' comment ' usage ',` max _ size ` int(10)unsigned not null default ' 0 ' comment '单个配置大小的上限,以字节为单位,0表示使用默认值', ` max _ aggr _ count ` int(10)unsigned not null default ' 0 ' comment '聚合子配置的最大数量,0表示使用默认值',` max _ aggr _ size ` int(10)unsigned not null default ' 0 ' comment '单个聚合数据的子配置大小的上限,以字节为单位,0表示默认值',` max _ history _ count ` int(10)unsigned not null default ' 0 ' comment '最大更改历史数量', ` GMT _ create ` datetime not null default current _ timestamp comment '创建时间',` GMT _ modified ` datetime not null default current _ timestamp comment '修改时间',主键(` id `),唯一键` uk _ Group _ id `(` Group _ id `))engine = innodb default charset = ut F8 collete = utf8 _ bin comment = '集群和组的容量信息表'; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos _ config *//* Table name = His _ config _ info创建表` His _ config _ info `( ` id ` bigint(20)unsigned NOT NULL,` NID ` bigint(20)unsigned NOT NULL AUTO _ INCREMENT,` data_id` varchar(255) NOT NULL, ` group_id` varchar(128) NOT NULL,` app_name` varchar(128)默认NULL注释' app_name ',` content` longtext NOT NULL,` md5` varchar(32)默认NULL,` gmt_create` datetime NOT NULL默认CURRENT_TIMESTAMP,` gmt_modified` datetime NOT NULL默认CURRENT_TIMESTAMP,` src_user` text,` src_ip` varchar(50)默认NULL,` op_type` char(10)默认NULL,` tenant _ id` varchar (128)默认'' key ` idx _ did `(` data _ id `))engine = innodb default charset = ut F8 collete = ut F8 _ bin comment/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *数据库全名= nacos_config *//*表名= tenant _ capacity * create ` tenant _ capacity `( ` id ` bigint(20) unsigned not null auto _ increment注释'主键ID ',` tenant _ ID ` varchar(128)not null default ' '注释' tenantid ',` quota ` int(10)unsigned not null default ' 0 '注释'配额,0表示使用默认值',` Usage ` int(10)unsigned not null default ' 0 '注释' usage ',` max _ size ` int(10)unsigned not null default ' 0 '注释'单个配置大小的上限,以字节为单位,0表示使用默认值', ` max _ aggr _ count ` int(10)unsigned not null default ' 0 ' comment '聚合子配置的最大数量',` max _ aggr _ size ` int(10)unsigned not null default ' 0 ' comment '单个聚合数据的子配置大小的上限,以字节为单位,0表示默认值',` max _ history _ count ` int(10)unsigned not null default ' 0 ' comment '最大更改历史数量', ` GMT _ create ` datetime not null default current _ timestamp comment '创建时间',` GMT _ modified ` datetime not null default current _ timestamp comment '修改时间,主键(` id `),唯一键` uk _ tenant _ id `(` tenant _ id `))engine = innodb default charset = ut F8 collete = utf8 _ bin comment = '租户容量信息表'; CREATE TABLE ` tenant _ info `( ` id ` bigint(20)NOT NULL AUTO _ INCREMENT COMMENT ' id ',` KP ` varchar(128)NOT NULL COMMENT ' KP ',` tenant _ id ` varchar(128)DEFAULT ' ' COMMENT ' tenant _ id ',` tenant _ name ` DEFAULT ' ' COMMENT ' tenant _ name ',` tenant _ desc ` varchar(256)DEFAULT NULL COMMENT ' tenant _ desc ',` CREATE _ source ` varchar(32)DEFAULT NULL COMMENT ' CREATE创建表` users `( ` username ` varchar(50)NOT NULL主键,` password` varchar(500) NOT NULL,` enabled ` boolean NOT NULL);使用BTREE创建表` roles `( ` username ` varchar(50)NOT NULL,` role` varchar(50) NOT NULL,唯一索引` idx_user_role` (`username` ASC,` role ` ASC));使用BTREE创建表` permissions `( ` role ` varchar(50)NOT NULL,` resource` varchar(255) NOT NULL,` action` varchar(8) NOT NULL,唯一索引` uk_role_permission` (`role `,` resource `,` action `));INSERT INTO users (username,password,enabled)值(' nacos ',' $ 2a $ 10 $ euwpzhzz 32 djn 7 jexm 34 moeyirddfazm 2 kuwj 7 veojhhzkdrxfvuu ',TRUE);插入到角色(用户名,角色)值(' nacos ',' ROLE _ ADMIN ');

4启动容器并执行以下命令:

docker run -D-p 8848:8848 \ -e MODE = standalone \ -v/Users/yygnb/docker me/nacos/conf:/home/nacos/conf \ -v/Users/yygnb/docker me/nacos/logs:/home/nacos/logs \ -v/Users/yyygnb/docker me/nacos/data:/home/nacos/data \ -v/Users/yyygnb/docker me/nacos/init。

docker ps | grep nacosDocker环境下Nacos2 MySQL8的具体操作-主机频道

检查Nacos操作日志:

docker日志-f nacosDocker环境下Nacos2 MySQL8的具体操作-主机频道

5访问Nacos在浏览器中访问Nacos:

Http://localhost:8848/默认用户名和密码都是nacos。

Docker环境下Nacos2 MySQL8的具体操作-主机频道

关于Docker环境Nacos2 MySQL8的这篇文章到此为止。关于Docker环境Nacos2的更多信息,请搜索主机频道zhujipindao之前的文章。或者继续浏览下面的相关文章。希望大家支持主机频道zhujipindao。以后多来com!

未经允许不得转载:主机频道 » Docker环境下Nacos2 MySQL8的具体操作

评论 抢沙发

评论前必须登录!