1. Nacos installation and deployment (stand-alone and cluster mode)

Nacos official website

     https://nacos.io/

Download and install

curl  -L -O  https://github.com/alibaba/nacos/releases/download/2.2.1/nacos-server-2.2.1.zip

unzip nacos-server-2.2.1.zip

Note: Since the new version of Nacos2.0 uses the gPRC protocol. Compared with Nacos1.4.x, there are two more ports (9848/9849). The specific ports are as follows:

  • Nacos service port 8848
  • Subtract 1000 for jRaft communication between servers (that is, 7848)
  • Add 1001 to the gRPC protocol port between servers (9849)
  • The client gRPC protocol requests the server to add 1000 (ie 9848)

In versions 2.2.0.1 and 2.2.1 (other versions such as 2.2.2 do not need to be configured), the value must be set in the file confunder the server directory . For details, see Authentication - Custom Key .application.propertiesnacos.core.auth.plugin.nacos.token.secret.key

Note that the default values ​​in the document are public default values SecretKey012345678901234567890123456789012345678901234567890123456789​​and can only be used for temporary testing. Please VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=be sure to replace them with other valid custom values ​​in actual use .

Running in stand-alone mode

The stand-alone mode only requires one node, and Nacos comes with an embedded Derby database (can be configured as MySQL, PostgreSQL and other databases)

cd nacos
./bin/startup.sh -m standalone

After startup, the default port is 8848 (keep this port unobstructed between the client and server network),

Accessible through a browser: http://IP:8848/nacos/

Initial username: nacos / nacos 

 

 Running in cluster mode

Since the Nacos cluster nodes do not synchronize metadata information with each other except for the jRaft protocol, the metadata consistency between Nacos nodes can only be resolved by the database. This determines that the embedded Derby database cannot be used, and the MySQL database needs to be used (currently Nacos only supports the MySQL database by default, and you need to rewrite the source code yourself to support other databases)

Note: The raftPort port is required for communication between cluster nodes (this port is usually the nacos external service port minus 1000), and it is necessary to ensure that the port can be accessed between nodes.

The steps to install Nacos cluster are: 

    1. Install and initialize the MySQL software in advance. The version used here is MySQL8.0.23 (the installation process is omitted here, please refer to: [MySQL Basics] 01: Installation, directory structure, start and stop, and password modification_zyplanke's column-CSDN blog )

    2. Create a nacos user in MySQL. MySQL creates a Schema named Nacos and authorizes the nacos user to access it. The statement is as follows:

mysql> create user 'nacos'@'%' identified by '123456';
Query OK, 0 rows affected (0.02 sec)

mysql> create schema nacos;
Query OK, 1 row affected (0.00 sec)

mysql> grant ALL on nacos.* to 'nacos'@'%';
Query OK, 0 rows affected (0.00 sec)

    3. Use the sql script that comes with the nacos server (under the conf directory) to create the tables and other objects required by nacos

mysql -u nacos -p nacos < nacos-mysql.sql

     3. Modify the configuration file application.properties of nacos, the configuration that needs to be modified is as follows

### 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.0=nacos
db.password.0=123456

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

      3. In order to save machines, here we use three different service ports on the same machine to simulate three nodes. The IPs and ports of the three nodes need to be configured in the cluster.conf file. Use a copy of the cluster.conf.example file that comes with Nacos as the cluster.conf file. Edit the cluster.conf file, the content is as follows:

#it is ip
#example
172.18.182.4:8848
172.18.182.4:8849
172.18.182.4:8850

 Note: This cluster.conf file will automatically write a piece of IP:PORT information of the node to this file when the cluster starts (if the information already exists in the configuration file, it will not be added repeatedly). Its IP automatically takes the IP of the eth0 network card of the node. Therefore, the IP of each node configured here needs to fill in the actual IP of the eth0 network card (if the machine has multiple network cards, you need to specify the IP of this node in application.properties)

       4. Since three nodes are simulated on the same machine, it is necessary to copy the entire directory of nacos three times (the content already configured above will also be copied), and the copied directory names are: nacos8848, nacos8849, nacos8850

 cp -R nacos nacos8848
 cp -R nacos nacos8849
 cp -R nacos nacos8850

       5. Configure the conf/application.properties files in the nacos8848, nacos8849, and nacos8850 directories respectively. Modify the server.port configuration item to the corresponding port number

       6. Enter the nacos8848, nacos8849, and nacos8850 directories respectively, and execute the following commands to start the nacos nodes respectively

./bin/startup.sh -m cluster

       7. It can be accessed through a browser (choose the IP port of a node): http://IP:8848/nacos/        

       Initial username: nacos / nacos 

Guess you like

Origin blog.csdn.net/zyplanke/article/details/120780328