SpringCloud Getting Started Series 0-Nacos installation and configuration

  • background 

    Work some years, since the early 19 completely turned java (this is another one sad story), suddenly felt abandoned for several years (not to say .net bad, but look back on my years of doing this a lot things are floating on the surface, sometimes ended up busy look, look back at his past to write the blog, is actually a lot about js, really feel a waste of time, but also to advise you in this old iron, do the back-end on a good depth do, do not divide the heart to the front too much, do not give yourself extra points, of course, except for the front end of a full-time transfer)

    (Passerby: Chedan a top two, can quickly said technology?)

    OKOK, book connected to the back, just off Ximen you want to hear this .... I chose not to say that, in fact, the most recent in-house team to reconstruct a service business, time is not so nervous, architectural structures responsible for himself, not mandatory What requirements to achieve with micro-services very honest not the end, but time and relatively abundant, so decided to wave (Lu Renyi bite the bullet: where ?? wave nonsense can be the best professional point with yellow? that figure)

    The main purpose of this series is the exchange and recording, hope the end of this series allows you to pay double (provided that you pay only 3K ah :))

    Everything is hard in the beginning, after all, there is no micro-service experience before. The beginning is a component of a component search tutorial, and then step by step integration, so the very beginning with the mainstream springcloud wave flow: consul + zuul + hystrix, surveillance SpringbootAdmin + HystrixDashboard, along with the deepening of mine (do not went wrong), found that many components have not maintained or replaced by a better, so the landlord wrong wrong step by step, and finally into the dust of the road ... I'm sorry the train station to begin immediately

  • Technical points

    The overall use of SpringCloud as a bottom support, the use of relatively more active components which involved are (here there should be a shining map, we can make up their own brain, I'm too lazy to draw :))

      Nacos- service registration, discovery and configuration center (also used during the eureka)

      SpringcloudGateway- Gateway 

      Sentinel + dashboard- blown downgrade, also known as circuit breakers, this is Ali produced sentry, many Internet companies in line with

      Zipkin- link tracking

      Elasticsearch + kibana- link tracking data persistence and query

      SpringbootAdmin- overall resource monitoring

      Quartz- regular tasks Integration

      JWT- user authentication to achieve their own set of simple jwt

      

    

    Each component version list

name version git / stomach Reference Site
SpringBoot 2.1.9    
Spring Cloud Greenwich.SR3    
Nacos(docker) 1.1.4 https://github.com/alibaba/nacos https://nacos.io/
SpringcloudGateway 2.1.3 https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-gateway  
Sentinel 2.1.1

https://github.com/alibaba/Sentinel

https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-sentinel

https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D
Zipkin-Slim(docker)  latest  https://github.com/openzipkin/zipkin  
Elasticsearch(docker) 6.8.5  https://github.com/elastic/elasticsearch  
Elasticsearch-head(node)      
kibana(docker) 6.8.5    
Quartz 2.1.9  https://github.com/quartz-scheduler/quartz  
       

    

    Follow-up article I will gradually expand the installation configuration of each component, uncle you stay tuned

    I will take nacos opening and ek installation and configuration of it as foreplay, foreplay saying do enough, behind the climax of a multi-Well (manual nugget)

  • nacos

    Nacos Ali is 18 years of open source products, the update very active part belongs springcloud-alibaba, the document will be more, do not compare compare several registry here, do not copy nacos introduction to the document, the entry may be introduced fancy table URL.

    Direct open dry:

    Since my computer configuration is not high, I chose to install on a docker remote test machine, I recommend that you do it

    A direct shuttle:

    RUN = Standalone --env the MODE Docker \ 
    -v /dockerdata/nacos/config/application.properties:/home/nacos/conf/application.properties \
    --name nacos -d -p 8848: 8848 nacos / nacos-Server: 1.1.4
   here mapped port 8848, to mount a selected configuration file, the configuration file as follows
    
# spring

server.contextPath=/nacos
server.servlet.contextPath=/nacos
server.port=8848

# nacos.cmdb.dumpTaskInterval=3600
# nacos.cmdb.eventTaskInterval=10
# nacos.cmdb.labelTaskInterval=300
# nacos.cmdb.loadDataAtStart=false


# metrics for prometheus
#management.endpoints.web.exposure.include=*

# metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

# metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true

server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
# default current work dir
server.tomcat.basedir=

## spring security config
### turn off security
#spring.security.enabled=false
#management.security=false
#security.basic.enabled=false
#nacos.security.ignore.urls=/**

nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.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.taskDispatchPeriod=200
# nacos.naming.distro.batchSyncKeyCount=1000
# nacos.naming.distro.syncRetryDelay=5000
# nacos.naming.data.warmup=true
# nacos.naming.expireInstance=true

nacos.istio.mcp.server.enabled=false

spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://xxxx:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&useAffectedRows=true
db.user=root
db.password=123456

  In fact most of the default configuration file, if you had a local test installation nacos, can be compared with the earlier default configuration is basically the same, I modified the back

  spring.datasource.platform = mysql this line, in mysql, db parameter is the beginning of the back of the mysql configuration represents data storage, and nacos official also provides a default database table structure, the address is: https://github.com /alibaba/nacos/blob/409838fe1f2dc53f7f5c63c660cd69b0fae1d49e/config/src/main/resources/META-INF/nacos-db.sql
 In your own mysql table like in construction, as for why I want to save to mysql in nature in order to prepare the back, where the first secrecy, did just fine. 
 Start after the container is installed, configured firewall port can be visited (the default user name and password are nacos, want to change, then go and change the users table just fine, password generation rules nacos source in the search for the self Tell me, three years after the publication methods in the comments .. who ?? rotten eggs littering fines fifty cents)
  

 

 

     

  

  • ES and related components Installation

    (This is not part of the service relationship with the micro, if you do not have requirements related to data, you can skip this section)

  1. Elasticsearch

    I do not explained in detail, the online installation tutorial abundance, directly on the command

    

docker run  -e xpack.security.enabled=true \
                    -e xpack.security.transport.ssl.enabled=true \
                    -e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" \
                    -d -p 9200:9200 -p 9300:9300 \
                    -v /dockerdata/es/config/master.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
                    -v /dockerdata/es/master:/usr/share/elasticsearch/data \
                    -v /dockerdata/es/config/log4j2.properties:/usr/share/elasticsearch/config/log4j2.properties \
                    --name es-master elasticsearch:6.8.5

    还是稍加解释下:映射的是9200(9300是通讯接口),挂载了配置文件master.yml,数据目录,以及日志文件,这里给出具体配置

    master.yml

    

cluster.name: elasticsearch-cluster
node.name: master
network.bind_host: 0.0.0.0
network.publish_host: xxxx
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["xxxx:9300","xxxx:9301"]
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type

  

 

 

    log4j2.properties

appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%node_name]%marker %.-10000m%n
appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size = 256MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.fileIndex = nomax
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = ${sys:es.logs.base_path}
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = ${sys:es.logs.cluster_name}-*
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize
appender.rolling.strategy.action.condition.nested_condition.exceeds = 1GB

  

      ps:这里有一个坑,log4j2的日志文件如果你复制过去可能会有空格,注意检查每一行的前后空格,否则会出意外错误

 

  1.   head插件安装教程网上也很多,这里只提一个坑,不要使用docker安装head,原因是:
      官方docker镜像没有同步git主版本,所以存在一个bug:所有接口调用都报406错误,原因是es新版更新了请求机制,需要指定content-type

      ps:由于es开启了xpack,所以head访问时要在参数上添加用户名密码才可以访问,类似这样 http://xxxx:9100/?auth_user=elastic&auth_password=123456

  1.   kibana:(注意kibana要与es的版本一致)

      

docker run -l es-master:elasticsearch -p 5601:5601 -v /dockerdata/es/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml -d kibana:6.8.5

      

      
    kibana.yml:
    
server.name: kibana
server.host: "0"
elasticsearch.url: http://xxxx:9200
xpack.monitoring.ui.container.elasticsearch.enabled: true

# Elasticsearch xpack
elasticsearch.username: "elastic"
elasticsearch.password: "123456"

  

  • 总结

   本文给出本系列涉及到的组件列表以及nacos的安装配置以及没有什么存在感的elk相关配置安装,而每一个组件的安装其实都有很多坑,不过大家可以自行查找,不属于本人原创的内容就不粘贴了

    整体来说这篇并没有什么干货(逃命中。。) 后续逐步展开各组件的使用和集成,尽快让各位老铁步入主题,覆雨翻云、高潮迭起:) 谢谢观看

    

 

    

 

Guess you like

Origin www.cnblogs.com/dzxw2371/p/12172949.html