当前位置:网站首页>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 -Unacos\distribution\target Downstream required packages , decompression
Go to unzip directory
cd binmodify 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()); } }
边栏推荐
- Virtual memory technology sharing
- Kubesphere - Multi tenant management
- Sorry, this user does not exist!
- How to create and configure ZABBIX
- 智牛股项目--04
- 最大似然估计,散度,交叉熵
- Kubernetes notes (II) pod usage notes
- The programmer shell with a monthly salary of more than 10000 becomes a grammar skill for secondary school. Do you often use it!!!
- How to create your own repository for software packages on Debian
- 1. Somme des deux nombres
猜你喜欢

Understand one-way hash function

深度学习,从一维特性输入到多维特征输入引发的思考

Cesium 点击获取模型表面经纬度高程坐标(三维坐标)

.NET程序配置文件操作(ini,cfg,config)

有意思的鼠标指针交互探究

伯努利分布,二项分布和泊松分布以及最大似然之间的关系(未完成)

Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide

pytorch DataLoader实现miniBatch(未完成)

智牛股项目--05

Interesting research on mouse pointer interaction
随机推荐
Why should there be a firewall? This time xiaowai has something to say!!!
[teacher Zhao Yuqiang] Cassandra foundation of NoSQL database
Installation of CAD plug-ins and automatic loading of DLL and ARX
Understand the first prediction stage of yolov1
Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
Simple handwritten ORM framework
Oauth2.0 - user defined mode authorization - SMS verification code login
Es remote cluster configuration and cross cluster search
有意思的鼠标指针交互探究
项目总结--04
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Kubernetes notes (IV) kubernetes network
Detailed explanation of contextclassloader
Use abp Zero builds a third-party login module (I): Principles
Mysql database table export and import with binary
Txt document download save as solution
Tabbar settings
Solve the 1251 client does not support authentication protocol error of Navicat for MySQL connection MySQL 8.0.11
Kubernetes notes (VIII) kubernetes security
Sorry, this user does not exist!