Several nouns in Nacos
Nacos is the abbreviation of Dynamic Naming and Configuration Service. A dynamic service discovery, configuration management and service management center that is easier to build cloud native applications.
For Nacos configuration management, you can locate a configuration set through Namespace, Group and Data ID
Configuration set Data ID
In the system, a configuration file is usually a configuration set. A configuration set can contain various configuration information of the system. For example, a configuration set may contain configuration items such as database. Each configuration set can define a meaningful name
Configuration items: configuration items are the configuration contents contained in the configuration set. It represents a specific configurable parameter and its value range, usually in the form of key=value. For example, we often configure the log output level of the system (logLevel=INFO|WARN|ERROR) as a configuration item.
Configure group
Configuration grouping is the grouping of configuration sets, which is identified by a meaningful string. Different configuration groups can have the same configuration set. The default name of the configuration group is DEFAULT_GROUP
Namespace
Namespace can be used for configuration isolation of different environments. Such as isolating development, testing and production environments. Configuration groups or configuration sets (data IDS) with the same name can exist in different namespaces
Nacos installation
Nacos stand alone environment
Download the source code from GitHub
git clone https://github.com/alibaba/nacos.git cd nacos/ mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U ls -al distribution/target/ // change the $version to your actual path cd distribution/target/nacos-server-$version/nacos/bin
Enter the corresponding version of nacos and execute the command
cd nacos-server-1.2.1/nacos/bin -- standalone Stand alone mode sh startup.sh -m standalone
The default port for nacos startup is 8848, the context is / nacos, and the default user name and password is nacos/nacos
You can access the nacos management interface in the browser, such as
http://localhost:8848/nacos
Close nacos server command
sh $Nacos_HOME/bin/shutdown.sh
Nacos cluster construction
Here, three Nacos nodes are used to build the cluster
1. We can copy the extracted nacos folders, named nacos, nacos 1 and nacos 2 respectively
2. Cluster exists in the conf directory of all nacos directories Conf.example and name it cluster Conf and configure the ip:port of each node
127.0.0.1:8848 127.0.0.1:8849 127.0.0.1:8850
3. Start in cluster mode
In each $Nacos_ Execute the command under home / bin
./startup.sh -m cluster
4. After successful startup, nacos can be accessed at any of 127.0.0.1:8848, 127.0.0.1:8849 and 127.0.0.1:8850 nodes
Persistent nacos configuration data
By default, the configuration data in Nacos is stored in the memory based detby database. In order to prevent data loss after server downtime, it is necessary to persist the configuration data to the database.
Nacos supports MySQL database. The specific configuration is as follows:
1. Create a new database. For example, the database name is Nacos, and import the initialization file of the database. The file is $NACOS_HOME/conf/nacos-mysql.sql
2. Modify $NACOS_HOME/conf/application.properties, add mysql database related configuration
### If use MySQL as datasource: spring.datasource.platform=mysql ### Count of DB: db.num=1 ### Connect URL of DB: db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user=root db.password=root
3. Then restart the nacos server
Problems encountered during installation
Problem: after upgrading the mac to bigsur, start.up in nacos SH failed to start. Check start in nacos The following errors are found in the out log:
nohup: /Library/Internet: No such file or directory
Answer: this question is actually related to the mac environment. The mac comes with a jdk. As shown below, there are two. The first is the system's own jdk, and the second is the self installed jdk
/usr/libexec/java_home -v -- Built in system java_home: option requires an argument -- v -- Self installed /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
The key to the problem is that the jdk matched by nacos is the system's own, that is, the first one above, and there is a space in its path Internet plug ins, which will cause the shell script to fail. At present, it should be related to bigsur.
The solution is in startup Manually specify your own Java in Sh_ HOME
For example, will
export JAVA_HOME export JAVA="$JAVA_HOME/bin/java"
Change to
export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home export JAVA="$JAVA_HOME/bin/java"
Then re execute the start command