spring cloud: eureka搭建

1. 添加pom 依赖:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<!-- 加密解密jar begin -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.14</version>
</dependency>
<!-- 加密解密jar end -->
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>

</dependencies>
</dependencyManagement>
</project>

2. 写启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}

3. 配置:

server:
port: 8759
security:
user:
name: admin
password: ENC(8tNuxZqCsf0G0sxRS+cc6g==)
basic:
enabled: true
jasypt:
encryptor:
password: wp3Lcomaohuidongl4ym8ofoYAYA==
eureka:
instance:
hostname: test
server:
#enable-self-preservation: false
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://localhost:${server.port}/eureka

4. 加密解密main

public class SecretMain {
private static final Logger LOG = LoggerFactory.getLogger(SecretMain.class);

public static void main(String[] args) {

//第一种方式加�? admin
BasicTextEncryptor text1= new BasicTextEncryptor();
text1.setPassword("wp3Lcomaohuidongl4ym8ofoYAYA==");
String newPassword = text1.encrypt("admin");
LOG.info("newPassword={}",newPassword);

// //第一种方式解�? admin
// BasicTextEncryptor text2 = new BasicTextEncryptor();
// text2.setPassword("wp3Lcomaohuidongl4ym8ofoYAYA==");
// String oldPassword = text2.decrypt("MrmNu24HSDHHnNYMnosl2g==");
// LOG.info("oldPassword={}",oldPassword);
//
// LOG.info("--------------------------------------------");
// //第二种方式加密admin
// StandardPBEStringEncryptor standard = new StandardPBEStringEncryptor();
// standard.setPassword("wwwwp3Lcomaohuidongl4ym8ofoYAYAAA==");
// String standardNewPassword = standard.encrypt("admin12");
// LOG.info("standardNewPassword={}",standardNewPassword);
//
// //第二种方式解�?
// StandardPBEStringEncryptor oldStandard = new StandardPBEStringEncryptor();
// oldStandard.setPassword("wwwwp3Lcomaohuidongl4ym8ofoYAYAAA==");
// String old = oldStandard.decrypt("+yKjbX67r7BrfFRdtePcrQ==");
// LOG.info("old={}",old);
}

}

5. 多注册中心的配置

spring:
profiles:
active: eureka3
security:
user:
name: ENC(3WnMCLtpRE7IkTDsvYIUjQ==)
password: ENC(3WnMCLtpRE7IkTDsvYIUjQ==)
jasypt:
encryptor:
password: wp3Lcomaohuidongl4ym8ofoYAYA==
---
spring:
application:
name: ym-eureka-server
profiles: eureka1
server:
port: 8761
eureka:
instance:
hostname: ym-eureka-server1
client:
#registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://admin:admin@ym-eureka-server2:8762/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
---
spring:
application:
name: ym-eureka-server
profiles: eureka2
server:
port: 8762
eureka:
instance:
hostname: ym-eureka-server2
client:
#registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server3:8763/eureka/
---
spring:
application:
name: ym-eureka-server
profiles: eureka3
server:
port: 8763
eureka:
instance:
hostname: ym-eureka-server3
client:
#registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://admin:admin@ym-eureka-server1:8761/eureka/,http://admin:admin@ym-eureka-server2:8762/eureka/

上一篇:Python中编码和字符串


下一篇:分享几个能用的 editplus 注册码