Nacos AP架构集群搭建(Windows)

news/2024/7/7 20:43:27

手写SpringCloud项目地址,求个star
github:https://github.com/huangjianguo2000/spring-cloud-lightweight
gitee:https://gitee.com/huangjianguo2000/spring-cloud-lightweigh

目录:

一:初始化MySQL

二:复制粘贴三份Nacos文件,修改配置文件

2.1 修改数据库连接

2.2 修改集群文件

三: 启动服务

四: 注册服务

五:Nginx改造,实现代理加负载均衡

六:服务注册失败,400

一:初始化MySQL

MySql中执行\conf文件夹下的nacos-mysql.sql,建表。 直接复制粘贴运行SQL语句就行。

在这里插入图片描述

二:复制粘贴三份Nacos文件,修改配置文件

在这里插入图片描述

2.1 修改数据库连接

在这里插入图片描述
在这个文件夹里面添加

在这里插入图片描述

spring.datasource.platform=mysql
 
db.num=1
 
db.url.0=jdbc:mysql://ip:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=root

数据库地址账号密码记得修改。

2.2 修改集群文件

在conf文件夹下新建这个文件。里面内容是nacos集群的ip地址的端口。

在这里插入图片描述
在这里插入图片描述

四:注册服务

这里随便填写集群中的一个IP地址, 启动应用可以看见就注册进去了,可以看见所以的集群里面都可以看见这个实例。
server:
  port: 9001

spring:
  application:
    name: nacos-payment-provider
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848

五:Nginx搭建

配置文件配置负载均衡策略。启动nginx, 用8847代理我们的集群。后序我们访问和注册都访问8847, 8848,8849,8850就不用了。

在这里插入图片描述


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}




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

    sendfile        on;
	
	upstream myserver {
		ip_hash;
		server 127.0.0.1:8848 weight=1;
		server 127.0.0.1:8850 weight=1;
		server 127.0.0.1:8849 weight=1;
	}
	
    server {
        listen       8847;
        server_name  localhost;



        location / {
            root   html;
            index  index.html index.htm;
			location ~ .* {
				 proxy_pass http://myserver;
			}
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

}

六:注册服务失败

: nacos registry, nacos-payment-provider register failed...NacosRegistration Caused by: com.alibaba.nacos.api.exception.NacosException: failed to req API:/api//nacos/v1/ns/instance after all servers([127.0.0.1:8848]) tried:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Sun Aug 13 14:01:12 CST 2023
There was an unexpected error (type=Bad Request, status=400).
receive invalid redirect request from peer 127.0.0.1
at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:496) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:401) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.reqAPI(NamingProxy.java:397) ~[nacos-client-1.2.1.jar:na] at com.alibaba.nacos.client.naming.net.NamingProxy.registerService(NamingProxy.java:212) ~[nacos-client-1.2.1.jar:na]

IP地址配置错了(据说是网卡原因), 这里会多出来四个地址,我们把之前的IP地址改成新出来的那个IP地址就行。

在这里插入图片描述


http://lihuaxi.xjx100.cn/news/1441415.html

相关文章

Visual Studio 2019 解决scanf函数报错问题

前言 Visual Studio 2019 解决scanf函数报错问题 博主博客链接:https://blog.csdn.net/m0_74014525 关注博主,后期持续更新系列文章 *****感谢观看,希望对你有所帮助***** 系列文章 第一篇:Visual Studio 2019 详细安装教程&…

网络安全 Day30-容器架构上

容器架构上 1. 容器架构1.1 什么是容器1.2 容器 vs 虚拟机(化) :star::star:1.3 Docker极速上手指南1)使用rpm包安装docker2) docker下载镜像加速的配置3) 载入镜像大礼包(老师资料包中有) 1.4 Docker使用案例1) 案例01&#xff1…

Vue3.2+TS在v-for的时候,循环处理时间,将其变成xx-xx-xx xx:xx:xx格式,最后教给大家自己封装一个时间hooks,直接复用

Vue3.2TS在v-for的时候&#xff0c;循环处理时间&#xff0c;将其变成xx-xx-xx xx:xx:xx格式 最后教给大家自己封装一个时间hooks&#xff0c;直接复用 1.没有封装&#xff0c;直接使用 <template><div><ul><li v-for"item,index in arr" :k…

shell脚本自定义函数及其调用

1. 在util.sh脚本中自定义函数 #!/usr/bin/env bash# 检查环境变量是否存在 function assert_env_var_exist {local var_name$1if [ -z $var_name ];thenlog "ERROR: " "${BASH_SOURCE[*]}" "${LINENO}" "Failed: Check env var: $var_nam…

WiFi小工具homedale,可以切换同名WiFi节点

有一个很小众的需求&#xff0c;就是多个路由器组网时候&#xff0c;PC有时不会自动切换同名WiFi&#xff0c;homedale这个工具可以满足手动切换需求 这个界面可以看到所有节点列表&#xff0c;可以看到有很多同名的 可以选择自己想要的那个&#xff0c;比如信道/信号强度&am…

Monkey测试真的靠谱吗?

Monkey测试&#xff0c;顾名思义&#xff0c;就是模拟一只猴子在键盘上乱敲&#xff0c;从而达到测试被测系统的稳定性。Monkey测试&#xff0c;是Android自动化测试的一种手段&#xff0c;Monkey测试本身非常简单&#xff0c;Android SDK 工具支持adb Shell命令&#xff0c;实…

bs4练习

bs4练习 工具目的代码运行结果 工具 pycharm 目的 网址:http://ip.yqie.com/ipproxy.htm,原url不能用&#xff0c;更换url为&#xff1a;http://www.66ip.cn/index.html 用bs4来做一个简单的爬虫&#xff0c;爬取某个ip网址里的免费ip&#xff0c;获取每个ip的代理IP地址、端…

Vue中路由缓存问题及解决方法

一.问题 Vue Router 允许你在你的应用中创建多个视图&#xff0c;并根据路由来动态切换这些视图。默认情况下&#xff0c;当你从一个路由切换到另一个路由时&#xff0c;Vue Router 会销毁前一个路由的组件实例并创建新的组件实例。然而&#xff0c;有时候你可能希望保持一些页…