See the 中文文档 for Chinese readme.
Based on Nacos(official site:http://nacos.io )The additional web server is designed for addressing the addresses of server and client,
reducing changes (server and client projects) and facilitating dynamic expansion and management。
It is suitable for single machine or cluster management of self built Nacos,
阿里云的MSE微服务引擎托管 It doesn't need to be considered. The government has dealt with it。
When the company needed to use the configuration center last year, through research and selection,
Nacos was finally used as the configuration center and registration center。In the process of using,
we Some problems were also found in the client project (spring cloud) and other clients (springboot, go, Node.js , python... Etc.)
When we configure the server address spring.cloud.nacos.config.serverAddr=127.0.0.1:8848,127.0.0.2:8848,127.0.0.3:8848
,
If we have 100 + clients and the address changes, do we need to change all 100 clients? This is not flexible。
The official documents and blogs don't explain it in detail. Basically, it's only to configure 'serveraddr'. In the server cluster mode,
new server machines are offline or online,We need to be incluster.conf
Address changes, there will be similar scenarios,
so go to the source code and research, resulting in this project。
It adapts to the client and server, providing usage and deployment documents, unified API management of address lists with different storage methods, and support for docker. At the same time, we are also welcome to use, suggest and contribute. If it is helpful or helpful in the future, welcome to star。
-[x] redis (single machine + cluster)
-[x] cache (standalone)
-[x] File (standalone)
-[x] docker support
- nacos-address system parameters(environment)
Parameter name | meaning | Optional value | Default value |
---|---|---|---|
APP_MODE | application mode | cluster/standalone | true |
ACCOUNT_USERNAME | Operation API username | NULL | nacos |
ACCOUNT_PASSWORD | Operation API password | NULL | nacos |
REDIS_HOST | redis address | NULL | "" |
REDIS_PASSWORD | redis password | NULL | "" |
REDIS_DB | redis select index | NULL | 0 |
-
nacos-address Data source parameters
-
By default, the 'application. Conf' file will prevail
-
The priority of system parameters is higher than that of file configuration, which is read from configuration file by default
-
- standalone (environment or (yaml)app.model=standalone) default
- set redis: redis store data
- no set redis:
cluster.conf
file exists :Read from file (real time read at two second intervals)cluster.conf
file not exists :Cache stores data (after the lifecycle of data ends in the current process)
- cluster(environment or (yaml)app.model=cluster)must set redis
- The data is stored in redis
- No matter whether it runs in stand-alone or cluster mode, redis is equivalent to a cluster. Cluster mode only makes a mandatory verification, and must be connected to redis
In the 'releases' page, select the corresponding operating system compressed package, unzip and configure it to run.
-
Search for and install nacos-address in dockerhub
-
Docker-compose mode can also be used
server {
# Listening port, which corresponds to the connection point port specified by the client and server to initiate the request.
The default value is 8080, which does not need to be changed
listen 8080;
# The custom domain name value corresponds to the domain name configured by the client and server
server_name nacos-address.aliyun.com;
location / {
# nacos vip server ip:port,You can also use the upstream proxy here
proxy_pass http://127.0.0.1:8849/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Access-Control-Allow-Origin *;
}
}
- Stand alone
- start-up
sh startup.sh -m standalone
- start-up
- cluster
- start-up
sh startup.sh
- configure
- The latest version provides a way to configure the cluster list
- change cluster.conf
- application.properties nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
- AddressServer vip mode (Recommended)
- Configuration for mode 3
- Read from environment variable
- windows Computer > right click Properties > Advanced System Settings > environment variables > new environment variable name: Address_ server_ Domain variable value: custom domain name value (for example: Nacos- vip.aliyun.com (corresponding to the server of nginx proxy_ name))
- linux In the same way
- Read from Nacos system parameters (recommended)
- Note: (external / built-in) please refer to Nacos(官方网站:http://nacos.io)
- Server code address:AddressServerMemberLookup.initAddressSys()
# Initialization addressing mode needs to be changed nacos.core.member.lookup.type=address-server # The server corresponding to nginx proxy needs to be changed (the domain name can be set by yourself)_ name address.server.domain=nacos-address.aliyun.com # There is no need to change the port of Nacos' get address request. The default port is 8080 # address.server.port=8080 # To change the access address of Nacos, the link of the request is /nacos/serverlist. However, the protocol of getting list between the client and the server is not compatible, so we need to open a new interface to be compatible with the server address.server.url=/nacos/server/serverlist
- Read from environment variable
- If we start normally, we can operate the service list of Nacos by using the following open API method, and the server can discover it normally (it is recommended to initialize the service list data through the 'open API' operation after the Nacos VIP service is started)
- The latest version provides a way to configure the cluster list
- start-up
-
to configure(spring cloud)
spring: cloud: nacos: config: file-extension: yaml prefix: ${spring.application.name} # Connect to the connection point specified by Nacos server. We put the domain name on the corresponding endpoint. endpoint: nacos-address.aliyun.com discovery: endpoint: nacos-address.aliyun.com
-
How domain names specify addresses
- Local hosts configuration
127.0.0.1 nacos-address.aliyun.com
- Using DNS to resolve domain name in LAN
- Load SLB of alicloud intranet (free. When clients deploy to alicloud servers, there is no need to specify a domain name. The only drawback is that the quota may be insufficient in the region at some time.)
- Local hosts configuration
-
Similar to other clients(SpringBoot,Go,Node.js,Python...Etc.)The way of access is the same
-
For the client, whether the server is a single machine or a cluster, we can use this method to facilitate future expansion. Once configured for permanent use (unless the domain name is changed), there is no need to worry about the need to update all services for the expansion of the registration center and service center.
Nacos-address console link: http://127.0.0.1:8849/index Follow the prompts on the page
- Request example
curl http://127.0.0.1:8849/login \
-X POST \
-H "Content-Type:application/json" \
-d '{"username":"nacos","password":"nacos"}'
- Return to example
{
"code": 200,
"message": "success",
"data": "token value"
}
- Request example
curl http://127.0.0.1:8849/nacos/serverlist
- Return to example
127.0.0.1
127.0.0.2
127.0.0.3
- Request example
curl http://127.0.0.1:8849/nacos/server/serverlist
- Return to example
{
"code": 200,
"message": null,
"data": "127.0.0.1\n127.0.0.2\n127.0.0.3\n"
}
- Request example
curl http://127.0.0.1:8849/nacos/serverlist \
-X POST \
-H "Content-Type:application/json" \
-H "Authorization:Bearer token-value" \
-d '{"clusterIps": ["127.0.0.1","127.0.0.2","127.0.0.3"]}' -v
- Return to example
{
"code": 200,
"message": null,
"data": null
}
- Request example
curl http://127.0.0.1:8849/nacos/serverlist \
-X DELETE \
-H "Content-Type:application/json" \
-H "Authorization:Bearer token-value" \
-d '{"clusterIps": ["127.0.0.1"]}' -v
- Return to example
{
"code": 200,
"message": null,
"data": null
}
- Request example
curl http://127.0.0.1:8849/nacos/serverlist/all \
-X DELETE \
-H "Content-Type:application/json" \
-H "Authorization:Bearer token-value" -v
- Return to example
{
"code": 200,
"message": null,
"data": null
}