当前位置:网站首页>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
- Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
- Apple submitted the new MAC model to the regulatory database before the spring conference
- 项目总结--04
- Kubesphere - build MySQL master-slave replication structure
- Cesium 点击获三维坐标(经纬度高程)
- Understand expectations (mean / estimate) and variances
- Advanced technology management - do you know the whole picture of growth?
- Code generator - single table query crud - generator
- Oauth2.0 - use database to store client information and authorization code
猜你喜欢
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
pytorch 多分类中的损失函数
Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow
Zhiniu stock -- 03
Phpstudy setting items can be accessed by other computers on the LAN
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Es remote cluster configuration and cross cluster search
Core principles and source code analysis of disruptor
Advanced technology management - do you know the whole picture of growth?
Kubesphere - build MySQL master-slave replication structure
随机推荐
BeanDefinitionRegistryPostProcessor
Detailed explanation of iptables (1): iptables concept
从 Amazon Aurora 迁移数据到 TiDB
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
Kubernetes cluster environment construction & Deployment dashboard
[video of Teacher Zhao Yuqiang's speech on wot] redis high performance cache and persistence
Pytorch dataloader implements minibatch (incomplete)
项目总结--2(Jsoup的基本使用)
Oauth2.0 - user defined mode authorization - SMS verification code login
1. 兩數之和
Solve the problem of automatic disconnection of SecureCRT timeout connection
深入解析kubernetes controller-runtime
QT read write excel -- qxlsx insert chart 5
pytorch 搭建神经网络最简版
Synthetic keyword and NBAC mechanism
[teacher Zhao Yuqiang] use the catalog database of Oracle
Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)
[teacher Zhao Yuqiang] RDB persistence of redis
Installation of CAD plug-ins and automatic loading of DLL and ARX
GPS坐标转百度地图坐标的方法