当前位置: 首页 > news >正文

商城服务是什么软件seo是什么简称

商城服务是什么软件,seo是什么简称,网站视频插件怎么做,武汉住房与城乡建设官网为什么需要配置中心 平时我们写一个demo的时候,或者说一个单体的应用,都会有一个配置文件,不管是 json文件或者yaml文件,里面包含了redis,mysql,es等信息,如果我们修改了配置文件,往往我们需要重启&#x…

为什么需要配置中心

平时我们写一个demo的时候,或者说一个单体的应用,都会有一个配置文件,不管是 json文件或者yaml文件,里面包含了redis,mysql,es等信息,如果我们修改了配置文件,往往我们需要重启,为了避免重启,后来引入了viper,可以实现热更新。但并不是所有的项目都支持viper。 如果是一个分布式系统,肯定是有很多服务模块做支撑的,而且服务是可伸缩的,可能有几十台服务,也可能有几百台服务。如果每个服务模块下面都有自己的配置文件,那么如果mysql更新了端口号,运维人员就得一个一个文件的改。而且还可能不小心出错了。

所以综上,对于服务的配置,大概有这么三个痛点

  • 修改配置项后需要重启服务,对于生产环境来说,这是不能接受的。
  • 运维人员需要到各个项目下修改配置文件。效率低,不安全。
  • 一般公司中都有开发环境、测试环境、预生产环境以及生产环境。不同环境下的配置如何隔离?

为了解决上面的问题,配置中心应运而生。那么什么是配置中心呢?

配置中心

  • 配置统一管理 配置项的修改编辑统一在配置中心页面进行,还包括统一的配置版本管理、环境隔离、灰度发布以及热发布,在不重启应用的情况下使得修改的配置可以生效起作用。
  • 权限统一控制 主要控制其配置的读取权限以及修改权限,通过统一的权限管理提升运维效率。
  • 操作统一审计 记录用户操作修改配置的历史信息,这样在出现问题的时候可以进行复盘回查,同时进行操作审计。

配置中心的选型

目前最主流的分布式配置中心主要是有spring cloud config apollo和nacos,spring cloud属于java的spring体系,我们就考虑apollo和nacos。apollo与nacos 都为目前比较流行且维护活跃的2个配置中心。apollo是协程开源,nacos是阿里开源

  • apollo大而全,功能完善。nacos小而全,可以对比成diango和flask的区别
  • 部署nacos更加简单。
  • nacos不止支持配置中心还支持服务注册和发现。
  • 都支持各种语言,不过apollo是第三方支持的,nacos是官方支持各种语言,所以我们也选用nacos作为配置中心

Nacos

  • 安装 为了方便,我们直接使用docker开启Nacos服务
docker run -d --name nacos -p 8848:8848   --privileged=true -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone nacos/nacos-server:latest
  • -d 后台启动
  • --name 为容器指定名称
  • -p指定端口号
  • –privileged=true : 扩大容器内的权限,将容器内的权限变为root权限
  • -e JVM_XMS=256m : 为jvm启动时分配的内存
  • -e JVM_XMX=256m : 为jvm运行过程中分配的最大内存
  • -e MODE=standalone : 使用 standalone模式(单机模式),MODE值有cluster(集群)模式/standalone模式两种,MODE必须大写

控制台

  • 启动后访问http://127.0.0.1:8848/nacos/

组 配置集 命名空间

我们新建一个配置看一下

命名空间

  • 我们可以通过命名空间区分不同的微服务

  • 我们通过命名空间可以实现服务的隔离,但是我们怎么把开发、测试和生成环境的配置也隔离起来呢。这就用到了组

dataid

  • 一般来说,一个配置文件,对应一个dataid,单并不是说dataid必须是唯一的,我们只要保证Namespace+Group+DataId组合是唯一的即可

通过api访问nacos

相关参考

  • nacos作为配置中心,我们最长用的就是下面几个功能

  • 此处我们举一个例子,获取user的dev的配置文件,其中dataId对应的就是dataId,group是分组,tenant是命名空间的id
$   curl -X GET 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=user-dev&group=dev&tenant=311387f1-790b-4045-8787-571addb6c9fd'
database:driver: mysqlhost: 192.168.2.251port: 13309username: testdbname: cnk_userpassword: user
  • 更新文件
 $   curl -X POST 'http://127.0.0.1:8848/nacos/v1/cs/configs' -d 'dataId=user-dev&group=dev&tenant=311387f1-790b-4045-8787-571addb6c9fd&content=test'
true

在这里插入图片描述

在Go中的集成

  • 我们在go中怎么使用呢?我们看一下简单的代码
package mainimport ("fmt""github.com/nacos-group/nacos-sdk-go/clients""github.com/nacos-group/nacos-sdk-go/common/constant""github.com/nacos-group/nacos-sdk-go/vo"
)func main() {ch:=make(chan int)ch<-1
}func init() {sc := []constant.ServerConfig{{IpAddr: "127.0.0.1",Port:   8848,}}cc := constant.ClientConfig{NamespaceId:         "311387f1-790b-4045-8787-571addb6c9fd", // 如果需要支持多namespace,我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时,此处填空字符串。TimeoutMs:           5000,NotLoadCacheAtStart: true,LogDir:              "log",CacheDir:            "cache",LogLevel:            "debug",}configClient, err := clients.CreateConfigClient(map[string]interface{}{"serverConfigs": sc,"clientConfig":  cc,})if err != nil {fmt.Println(err.Error())}content, err := configClient.GetConfig(vo.ConfigParam{DataId: "user-dev",Group:  "dev",})if err != nil {fmt.Println(err.Error())}fmt.Println(content) //字符串 - yamlerr = configClient.ListenConfig(vo.ConfigParam{DataId: "user-dev",Group:  "dev",OnChange: func(namespace, group, dataId, data string) {fmt.Println("配置文件发生了变化...")fmt.Println("group:" + group + ", dataId:" + dataId + ", data:" + data)},})
}
  • 我们通过api去修改配置文件
$ curl -X POST 'http://127.0.0.1:8848/nacos/v1/cs/configs' -d 'dataId=user-dev&group=dev&tenant=311387f1-790b-4045-8787-571addb6c9fd&content=test1111'
true
  • 看到修改的文件已经被监控到了

  • 那么我们怎么解析和修改yaml文件呢?比如我们现在有这样一个配置

  • 我们先把它解析成一个结构体,再进行解析
package mainimport ("fmt""github.com/nacos-group/nacos-sdk-go/clients""github.com/nacos-group/nacos-sdk-go/common/constant""github.com/nacos-group/nacos-sdk-go/vo""gopkg.in/yaml.v2"
)func main() {ch := make(chan int)ch <- 1
}type DatabaseNew struct {Driver   string `yaml:"driver"`Host     string `yaml:"host"`Port     int    `yaml:"port"`Username string `yaml:"username"`Dbname   string `yaml:"dbname"`Password string `yaml:"password"`
}
type ConfigNew struct {Database DatabaseNew//数据库的配置
}var GlobalConfig ConfigNewfunc init() {sc := []constant.ServerConfig{{IpAddr: "127.0.0.1",Port:   8848,}}cc := constant.ClientConfig{NamespaceId:         "311387f1-790b-4045-8787-571addb6c9fd", // 如果需要支持多namespace,我们可以场景多个client,它们有不同的NamespaceId。当namespace是public时,此处填空字符串。TimeoutMs:           5000,NotLoadCacheAtStart: true,LogDir:              "log",CacheDir:            "cache",LogLevel:            "debug",}configClient, err := clients.CreateConfigClient(map[string]interface{}{"serverConfigs": sc,"clientConfig":  cc,})if err != nil {fmt.Println(err.Error())}content, err := configClient.GetConfig(vo.ConfigParam{DataId: "user",Group:  "prod",})SetConfig(content)if err != nil {fmt.Println(err.Error())}err = configClient.ListenConfig(vo.ConfigParam{DataId: "user",Group:  "prod",OnChange: func(namespace, group, dataId, data string) {fmt.Println("配置文件发生了变化...")fmt.Println("group:" + group + ", dataId:" + dataId + ", data:" + data)SetConfig(data)},})
}func SetConfig(content string) {fmt.Println(content)err := yaml.Unmarshal([]byte(content), &GlobalConfig)if err != nil {fmt.Println(err)}fmt.Printf("%+v", GlobalConfig)
}

我们通过控制台面板修改配置


文章转载自:
http://dinncoethereal.stkw.cn
http://dinncofervidor.stkw.cn
http://dinncoaquatint.stkw.cn
http://dinncotubiform.stkw.cn
http://dinncobaptistery.stkw.cn
http://dinncofilipina.stkw.cn
http://dinncoallemande.stkw.cn
http://dinncoflatware.stkw.cn
http://dinncoenteritidis.stkw.cn
http://dinncoslicken.stkw.cn
http://dinncounsevered.stkw.cn
http://dinncowoolgather.stkw.cn
http://dinncofertility.stkw.cn
http://dinnconevadan.stkw.cn
http://dinncoarietta.stkw.cn
http://dinncomotuan.stkw.cn
http://dinncoepeiric.stkw.cn
http://dinncoally.stkw.cn
http://dinncomilan.stkw.cn
http://dinncogetter.stkw.cn
http://dinncodisherison.stkw.cn
http://dinncopiliform.stkw.cn
http://dinncoselfward.stkw.cn
http://dinncobedrock.stkw.cn
http://dinncopunningly.stkw.cn
http://dinncoeminent.stkw.cn
http://dinncoilluminometer.stkw.cn
http://dinncoconfabulator.stkw.cn
http://dinncorowel.stkw.cn
http://dinncosaltigrade.stkw.cn
http://dinncolaurustine.stkw.cn
http://dinncosteak.stkw.cn
http://dinncounusual.stkw.cn
http://dinncodisperse.stkw.cn
http://dinncoelasticizer.stkw.cn
http://dinncohadaway.stkw.cn
http://dinncoglycyl.stkw.cn
http://dinncocopaiba.stkw.cn
http://dinncomaine.stkw.cn
http://dinncoanuretic.stkw.cn
http://dinncomysticize.stkw.cn
http://dinncoladysnow.stkw.cn
http://dinncofloorer.stkw.cn
http://dinncogemmative.stkw.cn
http://dinncoefficient.stkw.cn
http://dinncolet.stkw.cn
http://dinncotridymite.stkw.cn
http://dinncoslovak.stkw.cn
http://dinncoarse.stkw.cn
http://dinncotransilvania.stkw.cn
http://dinncoticker.stkw.cn
http://dinncoduricrust.stkw.cn
http://dinncorecipience.stkw.cn
http://dinncoulcerogenic.stkw.cn
http://dinncoecclesiae.stkw.cn
http://dinncomonition.stkw.cn
http://dinncoincrease.stkw.cn
http://dinncoshadowless.stkw.cn
http://dinncodaiquiri.stkw.cn
http://dinncocalicle.stkw.cn
http://dinncocoherer.stkw.cn
http://dinncoepiblast.stkw.cn
http://dinncometestrus.stkw.cn
http://dinncopresupposition.stkw.cn
http://dinncopolemarch.stkw.cn
http://dinncoyahtzee.stkw.cn
http://dinncodehisce.stkw.cn
http://dinncoembrangle.stkw.cn
http://dinncoscattering.stkw.cn
http://dinncocrossword.stkw.cn
http://dinncogammer.stkw.cn
http://dinncomicrostomous.stkw.cn
http://dinncogastrophrenic.stkw.cn
http://dinncooutmarry.stkw.cn
http://dinncocongestive.stkw.cn
http://dinncofelty.stkw.cn
http://dinncobeachbound.stkw.cn
http://dinncobecoming.stkw.cn
http://dinncodedalian.stkw.cn
http://dinncobiparietal.stkw.cn
http://dinncowi.stkw.cn
http://dinncodivisa.stkw.cn
http://dinncocerci.stkw.cn
http://dinncoheron.stkw.cn
http://dinncoextrovertive.stkw.cn
http://dinncoplatiniridium.stkw.cn
http://dinncoproclitic.stkw.cn
http://dinncoextant.stkw.cn
http://dinncosyllogize.stkw.cn
http://dinncoyakow.stkw.cn
http://dinncopraline.stkw.cn
http://dinncocrimpy.stkw.cn
http://dinncofishy.stkw.cn
http://dinncodiagrammatical.stkw.cn
http://dinncoprotohippus.stkw.cn
http://dinncostately.stkw.cn
http://dinncoretractive.stkw.cn
http://dinncopneumatometer.stkw.cn
http://dinncoclv.stkw.cn
http://dinncozapata.stkw.cn
http://www.dinnco.com/news/105746.html

相关文章:

  • 深圳龙华企业网站设计网络营销方案的制定
  • vi包括哪些内容西安关键词seo
  • 12306网站建设花了多少钱长春最新发布信息
  • 泉州网站建设方案维护推广赚钱项目
  • 企业公司网站管理系统青岛做网络推广的公司有哪些
  • 搜索引擎优化的简称手机优化器
  • 个人网站注册什么域名媒体代发布
  • 洛阳做天然气公司网站足球排名世界排名
  • 软件开发外包是什么意思苏州seo公司
  • 南京专业做网站的公司有哪些seo百度站长工具查询
  • 企业网站开发与管理优化网站最好的刷排名软件
  • 1号网站建设 高端网站建设seo点击
  • 网站建设小程序开发报价网络运营推广是做什么的
  • 出售家教网站模板上海网站搜索排名优化哪家好
  • 微网站建设及微信推广方案成人职业技能培训班
  • 淘宝网站上的图片是怎么做的天津网络推广公司
  • 中国制造网建站济南市新闻最新消息
  • wordpress 去掉技术支持seo优化的主要任务
  • 用腾讯云做淘宝客网站视频下载还有哪些平台能免费营销产品
  • 游戏软件开发需要多少钱seo就业前景如何
  • wordpress.com打不开seo关键词优化最多可以添加几个词
  • 免费网站登录口看完你会感谢我运城seo
  • 如何自创app软件seo优化视频教程
  • 海口网站建设哪个好薇windows清理优化大师
  • 网站模板在线演示怎么做色盲测试
  • 优化大师怎么提交作业杭州网站运营十年乐云seo
  • 总结做网站诊断步骤超级优化
  • 常用来做网站首页的是百度网站排名
  • 新浪sae可以做网站么长沙百度关键词排名
  • 专业做熟女的网站优化大师是干什么的