springboot集成nacos,使用docker部署nacos

1、拉取镜像

docker pull nacos/nacos-server

2、创建本地的映射文件,custom.properties,

mkdir -p /root/nacos/init.d /root/nacos/logs
touch /root/nacos/init.d/custom.properties

在文件custom.properties中写入以下配置

management.endpoints.web.exposure.include=*

 

3、创建容器 使用standalone模式并开放8848端口,并映射配置文件和日志目录,数据库默认使用 Derby

docker run -d -p 8848:8848 -e MODE=standalone -e PREFER_HOST_MODE=hostname -v /root/nacos/init.d/custom.properties:/home/nacos/init.d/custom.properties -v /root/nacos/logs:/home/nacos/logs --restart always --name nacos nacos/nacos-server

4、访问Nacos ,初始用户名nacos 密码nacos

http://ip:8848/nacos

5、springboot集成nacos,导入jar

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    <version>0.2.2.RELEASE</version>
</dependency>

 6、application.properties

# 服务端口
server.port=8111
# 服务名
spring.application.name=service-mywind

# nacos服务地址
spring.cloud.nacos.discovery.server-addr=10.64.160.59:8848

7、启动类

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan(basePackages = {"com.mywind"})
public class MyIntegratedApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyIntegratedApplication.class, args);
    }
}

8、服务中心就有注册进来的服务

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值