[Graphic] Nacos cluster deployment + MySQL persistent configuration + Nginx load balancing

Write at the top

Nacos official website document: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html


Environment configuration:

 操作系统: CentOS7 64位
 JDK版本: 1.8
 Nacos版本: 1.1.4
 MySQL版本: 5.7
 Nginx版本: 1.18.0

CentOS7 install JDK1.8: https://blog.csdn.net/single_0910/article/details/113033380
CentOS7 install MySQL5.7: https://blog.csdn.net/qq_42969074/article/details/84853307
CentOS7 install Nginx 1.18 .0: https://blog.csdn.net/single_0910/article/details/113061140


1: Download the Nacos installation package

Download link: https://github.com/alibaba/nacos/releases/tag/1.1.4

The cluster mode recommended by Nacos official website (VIP=virtual IP 虚拟IP, this article uses Nginx1.18.0 to achieve)
Insert picture description here


Create a new blank folder:

mkdir /usr/local/nacos-1.1.4

nacos-server-1.1.4.tar.gzUpload the downloaded file to the /usr/local/nacos-1.1.4 directory, and then unzip:

tar -zxvf nacos-server-1.1.4.tar.gz

After the decompression is complete, a nacosfolder will appear :

cd /usr/local/nacos-1.1.4/nacos

The directory structure is as follows:
Insert picture description here


2. Two schemes of Nacos cluster configuration:

  • 2.1: Copy the decompressed nacosfile into three copies, modify the application.properties in the conf directory, modify the server.port in it to 3333, 4444 and 5555 respectively, and then configure the following contents in their respective cluster.conf:
192.168.226.128:3333
192.168.226.128:4444
192.168.226.128:5555

Note: it 192.168.226.128is my linux system ip, you can use it to hostname -iview ip

Then start nacos separately, and the cluster can be set up successfully.


  • 2.2: Virtual cluster (this method is used in this article, mainly because of laziness)

Please back up ( 万一玩坏了呢) before you fumble , enter the bindirectory, and it will startup.shbe backed up:

cp startup.sh startup.bak

Modify the content of startup.sh: p:and p) PORT=$OPTARG;;
Insert picture description here
add the penultimate line: -Dserver.port=${PORT}
Insert picture description here
configure the following content in cluster.conf in the conf directory:

192.168.226.128:3333
192.168.226.128:4444
192.168.226.128:5555

So far, the Nacos cluster is set up


3. MySQL persistent configuration

Official website help document: https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html
Run sql source file:

cd /usr/local/nacos-1.1.4/nacos/conf

Insert picture description here
Create a new nacos_configdatabase in the MySQL database (required by the official website), executenacos-mysql.sql

Configure Nacos persistence:

vim /usr/local/nacos-1.1.4/nacos/conf/application.properties

Add at the end:

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.226.128:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=test
db.password=Nacos_test123

Description: db.url.0Write the database ip
db.useryou want to configure,
db.passwordwrite the database user name you want to configure, and write the database user password you want to configure


4. Nginx load balancing

Enter the Nginx configuration directory:

cd /usr/local/nginx/conf

Modify nginx.conf:
Insert picture description here

worker_processes  1;

events {
    
    
    worker_connections  1024;
}

http {
    
    
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    keepalive_timeout  65;
   
    upstream cluster {
    
    
     server 192.168.226.128:3333;
     server 192.168.226.128:4444;
     server 192.168.226.128:5555;
  }
 
    server {
    
    
        listen       80;
        server_name  localhost;
        
        location / {
    
    
           #root   html;
           #index  index.html index.htm;
           proxy_pass http://cluster;
        }
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
    
    
            root   html;
        }
      
    }
}

5: Start test

---------------------------------------slightly---------- ------------------------------

Guess you like

Origin blog.csdn.net/single_0910/article/details/113062395