Преглед изворни кода

修改服务器的配置。

yangzhijie пре 6 година
родитељ
комит
1d84524881

+ 28 - 24
src/main/java/com/leanwo/gateway/GatewayApp.java

@@ -1,25 +1,29 @@
-package com.leanwo.gateway;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
-
-
-@SpringBootApplication
-//@EnableDiscoveryClient//开启Eureka的客户端发现
-@EnableZuulProxy// 开启Zuul的网关功能
-public class GatewayApp {
-	
-	private static Logger logger = LoggerFactory.getLogger(GatewayApp.class);
-
-	public static void main(String[] args) throws Exception {
-		
-		SpringApplication.run(GatewayApp.class, args);
-
-		logger.info("网关服务器启动成功。");
-
-	}
+package com.leanwo.gateway;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
+
+import com.leanwo.gateway.util.ProgramStopUtil;
+
+
+@SpringBootApplication
+@EnableDiscoveryClient//开启Eureka的客户端发现
+@EnableZuulProxy// 开启Zuul的网关功能
+public class GatewayApp {
+	
+	private static Logger logger = LoggerFactory.getLogger(GatewayApp.class);
+
+	public static void main(String[] args) throws Exception {
+		
+		SpringApplication.run(GatewayApp.class, args);
+
+		logger.info("网关服务器启动成功。");
+		
+		ProgramStopUtil.generateStopBat();
+
+	}
 }

+ 58 - 0
src/main/java/com/leanwo/gateway/util/ProgramStopUtil.java

@@ -0,0 +1,58 @@
+package com.leanwo.gateway.util;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 程序关闭通用类
+ * @author YangZhiJie
+ *
+ */
+public class ProgramStopUtil {
+	private static Logger logger = LoggerFactory.getLogger(ProgramStopUtil.class);
+
+	/**
+	 * 生成停止程序的BAT文件
+	 */
+	public static void generateStopBat() {
+		File file = new File("stop.bat");
+		if(file.exists() == false) {
+			try {
+				file.createNewFile();
+			} catch (IOException e) {
+				logger.error("stop.bat文件创建失败.");
+				e.printStackTrace();
+			}
+		}
+		
+		logger.info("stop.bat文件的路径如下:" + file.getAbsolutePath());
+		
+		try {
+	         BufferedWriter out = new BufferedWriter(new FileWriter(file, false));
+	         String command = "taskkill /pid " + getPid() + " -t -f";
+	         out.write(command);
+	         out.close();
+		} catch (IOException e) {
+			logger.error("stop.bat文件写入失败。");
+		}
+	}
+	
+	/**
+	 * 获取PID
+	 * @return
+	 */
+	private static String getPid() {
+		// get name representing the running Java virtual machine.    
+		String name = ManagementFactory.getRuntimeMXBean().getName();    
+		// get pid    
+		String pid = name.split("@")[0];    
+		logger.debug("Pid is:" + pid);
+		return pid;
+	}
+}

+ 52 - 31
src/main/resources/Application.yml

@@ -1,31 +1,52 @@
-#端口号
-server:
-  port: 80
-spring:
-  application:
-    # 应用名称,会在Eureka中作为服务的id标识(serviceId)
-    name: gateway-server
-    
-#Eureka Server服务器地址.
-eureka:
-  instance:
-    #Eureka客户端向服务端发送心跳的时间间隔,单位为秒(客户端告诉服务端自己会按照该规则),默认30
-    lease-renewal-interval-in-seconds: 5
-    #Eureka服务端在收到最后一次心跳之后等待的时间上限,单位为秒,超过则剔除(客户端告诉服务端按照此规则等待自己),默认90
-    lease-expiration-duration-in-seconds: 10
-  client:
-    fetch-registry: true
-    register-with-eureka: true
-    serviceUrl:
-      defaultZone: http://localhost:88/eureka/
-
-zuul:
-  #  隐藏所有微服务名称(即使用微服务名称无法访问到服务)
-  ignored-services: "*"
-  #  服务前缀名,想要访问项目之前要加上此路径
-  # prefix: /file-server
-  routes:
-    #只要访问以/editor/开头的多层目录都可以路由到服务名为file-server的服务上.
-    file-server:
-      serviceId: file-server
-      path: /**
+#端口号
+server:
+  port: 443
+  #ssl证书相关配置
+  ssl:
+    key-store: classpath:key_2019/3070974_prodog.leanwo.com.pfx
+    key-store-password: E70iVODH
+    key-store-type: PKCS12
+spring:
+  application:
+    # 应用名称,会在Eureka中作为服务的id标识(serviceId)
+    name: gateway-server
+    
+#Eureka Server服务器地址.
+eureka:
+  instance:
+    prefer-ip-address: true
+    #Eureka客户端向服务端发送心跳的时间间隔,单位为秒(客户端告诉服务端自己会按照该规则),默认30
+    lease-renewal-interval-in-seconds: 5
+    #Eureka服务端在收到最后一次心跳之后等待的时间上限,单位为秒,超过则剔除(客户端告诉服务端按照此规则等待自己),默认90
+    lease-expiration-duration-in-seconds: 10
+  client:
+    fetch-registry: true
+    register-with-eureka: true
+    serviceUrl:
+      defaultZone: http://localhost:88/eureka/
+
+zuul:
+  #  隐藏所有微服务名称(即使用微服务名称无法访问到服务)
+  ignored-services: "*"
+  #添加主机头
+  addHostHeader: true
+  #是否默认支持重试
+  retryable: true
+  #路由前缀,想要访问项目之前要加上此路径
+  prefix: /
+  routes:
+    applicationserver:
+      path: /api/**
+      serviceId: prodog-server
+      # 去除路由前缀,默认为true,改为false即使user-serivce这条路由的/api路径不做去除
+      strip-prefix: false  
+    #只要访问以/开头的多层目录都可以路由到服务名为file-server的服务上.
+    fileserver:
+      path: /**
+      serviceId: file-server
+      
+ribbon:
+  #请求处理的超时时间
+  ReadTimeout: 12000000
+  #请求连接的超时时间
+  ConnectTimeout: 3000000

+ 4 - 4
src/main/resources/run.bat

@@ -1,5 +1,5 @@
-title File Server
-set current_path="%cd%"
-cd %current_path%
-java -jar %current_path%\GatewayServer.jar
+title Gateway Server
+set current_path="%cd%"
+cd %current_path%
+java -jar %current_path%\GatewayServer.jar
 pause