Environment to prepare

The server name IP instructions
MySQL 192.168.223.135 Deploy the MySQL database and Nginx
Nacos 192.168.223.137 Deploy the Nacos cluster

With limited resources, MySQL is deployed on one machine and Nginx and Nacos clusters are deployed on another. If deployed in a production environment, you can tailor it to your needs.

The configuration steps

Download: github.com/alibaba/nac…

Copy the compressed package to the machine where Nacos is deployed

  1. MySQL database configuration

MySQL Installation tutorial

After installing MySQL, you need to initialize the MySQL database. The database initialization file is in nacos-mysql. SQL in the conf file and the SQL file is imported to the corresponding database environment

Enter the MySQL terminal
mysql -u root -p123456
mysql> create database nacos_config;
mysql> use nacos_config;
mysql> source /root/nacos-mysql.sql
Copy the code
  1. Application. The properties configuration

In nacos nacos extract directory/conf directory, there are the application configuration file. The properties and modifying the conf/application. The properties files, increase support for MySQL data source configuration

Spring. The datasource. Platform = mysql db. Num = 1 db. Url. 0 = JDBC: mysql: / / 192.168.223.135:3306 / nacos_config? characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user=root db.password=123456Copy the code
  1. Configure the cluster configuration file

In the conf directory of nacos/, the configuration file cluster.conf exists. Set each line to IP :port. (Please configure 3 or more nodes)

cp cluster.conf.example cluster.conf
vim cluster.conf
Copy the code

  1. Edit the startup script startup.sh of Nacos so that it can accept different startup ports

Before the change

The modified

  1. Configure Nginx as the load balancer

Nginx installation tutorial

In the nginx.conf file #gzip on; Add the following information below

Upstream cluster {server 192.168.223.137:3333; Server 192.168.223.137:4444; Server 192.168.223.137:5555; } server { listen 1111; server_name localhost; location / { #root front; #index index.htm; proxy_pass http://cluster; }}Copy the code
  1. Start the test
Start the NACOS cluster
sh startup.sh -p 3333
sh startup.sh -p 4444
sh startup.sh -p 5555
ps -ef | grep nacos | grep -v grep | wc -l
# start nginx
/usr/local/nginx/sbin/nginx
ps -ef | grep nginx
# Browser access
http://192.168.223.135:1111/nacos
Copy the code

Add a new configuration to test to see if it is saved to the database

In nacos-spring-cloud-provider-example, change the registered address of the service in application.properties to Spring. Cloud. Nacos. Discovery. Server – addr = 192.168.223.135:1111 to test