当前位置:网站首页>Nacos service installation
Nacos service installation
2022-07-03 06:09:00 【vincentwc】
nacos
Service installation
Go to github Download the latest zip Pack and unzip https://github.com/alibaba/nacos/releases
Execute the following command in the root directory :
mvn -Prelease-nacos -DskipTests clean install -U
nacos\distribution\target Downstream required packages , decompression
Go to unzip directory
cd bin
modify startup.cmd File for standalone Pattern
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-AEBq2GMt-1620884418572)(C:\Users\admin\AppData\Roaming\Typora\typora-user-images\image-20210508103556235.png)]
- double-click startup.cmd start-up
nacos Use
/**
* 1、 How to use nacos Manage uniformly as a configuration center
* 1)、 Introduce dependencies
* <dependency>
* <groupId>com.alibaba.cloud</groupId>
* <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
* </dependency>
* 2)、 Create a bootstrap.properties, Configure the following two items
* spring.cloud.nacos.config.server-addr=127.0.0.1:8848
* spring.application.name=mall-coupon
* 3)、 You need to add a data set to the configuration center by default (Data Id)mall-coupon.properties, The default rules : Application name .properties
* 4)、 Give app name .properties Add any configuration
* 5)、 Get configuration dynamically
* @RefreshScope: Get and refresh the configuration dynamically
* @Value(""${ Name of the configuration item }): Get configuration
* If the configuration center and the configuration file of the current project are configured with the same item , Give priority to the configuration of the center
* 2、 details
* 1)、 Namespace : Configure isolation
* Default :public( Reserved space ), By default, all new configurations are in public Space
* 1.1)、 Development 、 test 、 Production uses namespaces for environmental isolation
* Be careful : stay bootstrap.properties Configuration 、 Which command namespace configuration should be used
* spring.cloud.nacos.config.namespace=1b0191f0-19f3-4784-a8b1-474c5d3d244a[ Namespace id]
* 1.2)、 Each micro service is isolated from each other , Each microservice creates its own namespace , Only load all configurations in your own namespace
* 2)、 config set : A collection of all configurations
* 3)、 config set ID: Similar file name
* DataId: Similar file name
* 4)、 Configuration group
* By default, all configuration sets belong to :DEFAULT_GROUP
* Each microservice creates its own namespace , Use configuration groups to distinguish environment configurations :test、prod、test
* 5)、 Load multiple configuration sets at the same time
* 5.1)、 Microservice any configuration information , Any configuration file can be placed in the configuration center
* 5.2)、 Only need bootstrap.properties Explain which configuration files to load
*/
Version relationship
https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E
<!-- Service registration | Find out -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
@Configuration
@EnableConfigurationProperties
@ConditionalOnNacosDiscoveryEnabled
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
// In the class AutoServiceRegistrationConfiguration,AutoServiceRegistrationAutoConfiguration And then automatically configure ,
AutoServiceRegistrationConfiguration The corresponding is
@AutoConfigureAfter({
AutoServiceRegistrationConfiguration.class,
AutoServiceRegistrationAutoConfiguration.class })
public class NacosDiscoveryAutoConfiguration {
// 1. nacos Service registration
@Bean
public NacosServiceRegistry nacosServiceRegistry(
NacosDiscoveryProperties nacosDiscoveryProperties) {
return new NacosServiceRegistry(nacosDiscoveryProperties);
}
// 2. nacos register
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration(
NacosDiscoveryProperties nacosDiscoveryProperties,
ApplicationContext context) {
return new NacosRegistration(nacosDiscoveryProperties, context);
}
// 3. nacos Automatic service registration
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosAutoServiceRegistration nacosAutoServiceRegistration(
NacosServiceRegistry registry,
AutoServiceRegistrationProperties autoServiceRegistrationProperties,
NacosRegistration registration) {
return new NacosAutoServiceRegistration(registry,
autoServiceRegistrationProperties, registration);
}
}
NacosDiscoveryProperties {
serverAddr = '127.0.0.1:8848',
endpoint = '',
namespace = '',
watchDelay = 30000,
logName = '',
service = 'mall-coupon',
weight = 1.0,
clusterName = 'DEFAULT',
namingLoadCacheAtStart = 'false',
metadata = {
preserved.register.source = SPRING_CLOUD
},
registerEnabled = true,
ip = '192.168.1.7',
networkInterface = '',
port = -1,
secure = false,
accessKey = '',
secretKey = ''
}
namingService {
namespace: "public",
endpoint: "",
serverList: "127.0.0.1:8848",
cacheDir; "C:\Users\admin/nacos/naming/public",
logName: "naming.log"
hostReactor:
beatReactor:
eventDispatcher;
serverProxy: {
serverPort: 8848,
namespaceId: "public",
endpoint: "",
nacosDomain: "127.0.0.1:8848",
serverList: [
"127.0.0.1:8848"
],
serversFromEndpoint: [],
lastSrvRefTime: 0,
vipSrvRefInterMillis: 30000,
properties: {
}
}
}
instance How does the instance come from ?
com.alibaba.cloud.nacos.registry.NacosServiceRegistry#register
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
Instance instance = getNacosInstanceFromRegistration(registration);
@PostConstruct public void init() { Map<String, String> metadata = nacosDiscoveryProperties.getMetadata(); Environment env = context.getEnvironment(); String endpointBasePath = env.getProperty(MANAGEMENT_ENDPOINT_BASE_PATH); if (!StringUtils.isEmpty(endpointBasePath)) { metadata.put(MANAGEMENT_ENDPOINT_BASE_PATH, endpointBasePath); } Integer managementPort = ManagementServerPortUtils.getPort(context); if (null != managementPort) { metadata.put(MANAGEMENT_PORT, managementPort.toString()); String contextPath = env .getProperty("management.server.servlet.context-path"); String address = env.getProperty("management.server.address"); if (!StringUtils.isEmpty(contextPath)) { metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath); } if (!StringUtils.isEmpty(address)) { metadata.put(MANAGEMENT_ADDRESS, address); } } if (null != nacosDiscoveryProperties.getHeartBeatInterval()) { metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL, nacosDiscoveryProperties.getHeartBeatInterval().toString()); } if (null != nacosDiscoveryProperties.getHeartBeatTimeout()) { metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, nacosDiscoveryProperties.getHeartBeatTimeout().toString()); } if (null != nacosDiscoveryProperties.getIpDeleteTimeout()) { metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, nacosDiscoveryProperties.getIpDeleteTimeout().toString()); } }
边栏推荐
- Synthetic keyword and NBAC mechanism
- Advanced technology management - do you know the whole picture of growth?
- .NET程序配置文件操作(ini,cfg,config)
- Kubernetes notes (IV) kubernetes network
- Kubernetes notes (I) kubernetes cluster architecture
- 深入解析kubernetes controller-runtime
- QT read write excel -- qxlsx insert chart 5
- 【系统设计】邻近服务
- 理解 YOLOV1 第一篇 预测阶段
- ThreadLocal的简单理解
猜你喜欢
Phpstudy setting items can be accessed by other computers on the LAN
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
Apt update and apt upgrade commands - what is the difference?
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
[teacher Zhao Yuqiang] kubernetes' probe
[teacher Zhao Yuqiang] Cassandra foundation of NoSQL database
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
[teacher Zhao Yuqiang] use the catalog database of Oracle
QT read write excel -- qxlsx insert chart 5
项目总结--01(接口的增删改查;多线程的使用)
随机推荐
【系统设计】邻近服务
Zhiniu stock project -- 05
Characteristics and isolation level of database
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
[teacher Zhao Yuqiang] use the catalog database of Oracle
从 Amazon Aurora 迁移数据到 TiDB
Maximum likelihood estimation, divergence, cross entropy
Project summary --01 (addition, deletion, modification and query of interfaces; use of multithreading)
JS implements the problem of closing the current child window and refreshing the parent window
Virtual memory technology sharing
Apt update and apt upgrade commands - what is the difference?
The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
About the difference between count (1), count (*), and count (column name)
Leetcode solution - 02 Add Two Numbers
Oauth2.0 - user defined mode authorization - SMS verification code login
Kubernetes notes (VIII) kubernetes security
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
[teacher Zhao Yuqiang] index in mongodb (Part 1)
Mysql database table export and import with binary
[video of Teacher Zhao Yuqiang's speech on wot] redis high performance cache and persistence