Nacos single node, which is the standalone mode, the configuration of our most started using the default database data is stored in the embedded derby in.
If we are to build a cluster, then certainly not with embedded databases, or data can not be shared. Cluster Setup when we need to Nacos docking Mysql for data storage.
We usually cluster model with capacity expansion is the same, can be forwarded via Nginx to multiple nodes, linked to a domain name to the front, as shown below:
Usually if we just talk directly to the experience of the local start three instances on it, no need to engage in really three servers, here we have a way to build the local cluster.
The decompression of the packet replication Nacos divided into three parts, namely:
- nacos
- nacos1
- nacos2
Nacos enter the conf directory, edit application.properties file, add the database configuration
# 指定数据源为Mysql
spring.datasource.platform=mysql
# 数据库实例数量
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=123456
复制代码
The same steps and enter nacos1 nacos2 operation again, the only modification required is application.properties file server.port, default nacos of server.port = 8848, we launched three instances locally, then the port will certainly be conflict, so other port 2 instance we need to be modified, such as nacos1 modified to 8847, nacos2 modified to 8846.
After the database configuration information is good, we need the corresponding database tables and initialize the database scripts nacos-mysql.sql the conf directory, you can execute.
The last step you need to configure a cluster node information, configuration files cluster.conf.example file in the conf directory, we rename into cluster.conf.
Cluster.conf then edit the file, add three nodes of information, in the format of IP: PORT, three directories are consistent can be.
127.0.0.1:8848
127.0.0.1:8847
127.0.0.1:8846
复制代码
Start, then directly to the bin directory, execute ./startup.sh on it, the default is the cluster model, does not require any arguments.
About Nginx installation and configuration, this article is not to explain, and can not own to try next, core configuration is as follows:
upstream nacos {
server 127.0.0.1:8848;
server 127.0.0.1:8847;
server 127.0.0.1:8846;
}
复制代码
Overall, nacos way to build clusters was quite simple, nothing special to note, the best way is through the domain name to access the other databases if this production environment, high availability issues also need to consider, at least, You have to have a master-slave.
Guess you want to see:
Ali Nacos- Configuration - Multiple Environments
Nacos do frequently asked questions Configuration Center