Bootstrap

Ubuntu Server 20.04 搭建Nacos集群

概况

Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。

Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。 Nacos 是构建以“服务”为中心的现代应用架构 (例如微服务范式、云原生范式) 的服务基础设施。

1.准备

maven环境:

$ sudo apt install maven

配置为阿里镜像和本地目录:

 /home/ubuntu/maven/repo
 
       
	  nexus-aliyun    
	  nexus-aliyun  
	  http://maven.aliyun.com/nexus/content/groups/public    
	  central      
	

官网下载 Nacos:

之前安装 kvm 准备三台虚拟机:192.168.2.31,192.168.2.32,192.168.33

安装 kvm 虚拟机:

2.安装

将导入MySQL数据库;

修改文件

#it is ip
#example
192.168.2.31:8848
192.168.2.32:8848
192.168.2.33:8848

修改文件

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql  #设置数据库为mysql

### Count of DB:
# db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.2.16:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=nacos
db.password.0=nacos

3.启动

集群启动命令,启动三台虚拟机上的nacos。

sh startup.sh

如果启动成功,可以分别通过网址访问到三台虚拟机上的nacos。

http://192.168.2.31:8848/nacos
http://192.168.2.32:8848/nacos
http://192.168.2.33:8848/nacos

4.配置nginx

找一台机子安装(比如安装到上),修改,指向刚才的三台。

 upstream nacos {
        server  192.168.2.31:8848;
        server  192.168.2.32:8848;
        server  192.168.2.33:8848;
    }


 server {
        listen       8848;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://nacos;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

然后通过访问。