Spring Cloud Eureka集群部署注意事项

一.需要在启动配置文件(application.yml或application.properties)中增加多profile配置

spring:
  application:
    name: eureka
---#注意这里是三个"减号"
spring:
  profiles: eureka1
security:
  basic:
    enabled: true
  user:
    name: user
    password: password123
server:
  port: 8761
eureka:
  instance:
    hostname: eureka1
  client:
    service-url:
      defaultZone: http://user:password123@eureka2:8762/eureka
---#注意这里是三个"减号"
spring:
  profiles: eureka2
security:
  basic:
    enabled: true
  user:
    name: user
    password: password123
server:
  port : 8762
eureka:
  instance:
    hostname: eureka2
  client:
    service-url:
      defaultZone: http://user:password123@eureka1:8761/eureka

二.在启动的时候添加参数启动

nohup java -jar eureka.jar --spring.profiles.active=eureka1 > eureka1.out &

说明:
1.nohup 以及最后的 & 表示启动程序的时候在后台运行,执行完此命令后不打出日志,并且关掉ssh后当前进程不会停止。
2.java -jar eureka.jar 表示用java命令以jar包的形式启动eureka.jar
3.–spring.profiles.active=eureka1 两个减号及后台的参数表示启动的时候加载spring.profiles名字为eureka1的一系列参数,在上面的例子中表示加载下面的参数:

spring:
  profiles: eureka1
security:
  basic:
    enabled: true
  user:
    name: user
    password: password123
server:
  port: 8761
eureka:
  instance:
    hostname: eureka1
  client:
    service-url:
      defaultZone: http://user:password123@eureka2:8762/eureka

4.> eureka1.out表示将日志输出到eureka1.out

三.需要在hosts配置文件中增加域名映射
windows系统保存在文件:C:\Windows\System32\drivers\etc\hosts
linux系统保存在文件:/etc/hosts
我的文件修改如下:

# localhost name resolution is handled within DNS itself.
    127.0.0.1       localhost eureka1 eureka2
#   ::1             localhost

如果windows系统是win7以上版本,在修改hosts文件时,需要以管理员身份运行记事本并打开hosts文件

Tips:部署eureka集群如果在同一台服务器上启动,则只需要部署一个jar即可,只是需要启动两次,并且两次启动时分别利用–spring.profiles.active参数实现加载不同的配置文件中的内容即可。

猜你喜欢

转载自blog.csdn.net/l1h2l3/article/details/72875972