From c5bb6143baa9a9c2a30fd2ef37d58eea52842063 Mon Sep 17 00:00:00 2001
From: zhangdaiscott <zhangdaiscott@163.com>
Date: Tue, 9 Mar 2021 11:40:13 +0800
Subject: [PATCH] nacos server本地化jar方式启动,简化开发

---
 jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml                                | 14 +++++++-------
 jeecg-boot/jeecg-cloud-module/docker-compose.yml                                                           | 22 ++++++----------------
 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/Dockerfile                                                 | 15 +++++++++++++++
 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/pom.xml                                                    | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/java/com/alibaba/nacos/JeecgNacosApplication.java | 35 +++++++++++++++++++++++++++++++++++
 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/resources/application.yml                         | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 jeecg-boot/jeecg-cloud-module/pom.xml                                                                      |  1 +
 7 files changed, 173 insertions(+), 23 deletions(-)
 create mode 100644 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/Dockerfile
 create mode 100644 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/pom.xml
 create mode 100644 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/java/com/alibaba/nacos/JeecgNacosApplication.java
 create mode 100644 jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/resources/application.yml

diff --git a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml
index 0288e1f..c01ff32 100644
--- a/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml
+++ b/jeecg-boot/jeecg-boot-starter/jeecg-boot-starter-cloud/nacos/jeecg-dev.yaml
@@ -35,9 +35,9 @@ spring:
 
       datasource:
         master:
-          url: jdbc:mysql://127.0.0.1:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
-          username: root
-          password: root
+          url: jdbc:mysql://${MYSQL-HOST:jeecg-boot-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:jeecg-boot}?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          username: ${MYSQL-USER:root}
+          password: ${MYSQL-PWD:root}
           driver-class-name: com.mysql.cj.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:
@@ -48,7 +48,7 @@ spring:
   #redis 配置
   redis:
     database: 0
-    host: 127.0.0.1
+    host: jeecg-boot-redis
     lettuce:
       pool:
         max-active: 8   #最大连接数据库连接数,设 0 为没有限制
@@ -60,7 +60,7 @@ spring:
     port: 6379
   #rabbitmq配置
   rabbitmq:
-    host: 127.0.0.1
+    host: jeecg-boot-rabbitmq
     username: guest
     password: guest
     port: 5672
@@ -129,7 +129,7 @@ jeecg :
   #xxl-job配置
   xxljob:
     enabled: false
-    adminAddresses: http://127.0.0.1:9080/xxl-job-admin
+    adminAddresses: http://jeecg-boot-xxljob:9080/xxl-job-admin
     appname: ${spring.application.name}
     accessToken: ''
     logPath: logs/jeecg/job/jobhandler/
@@ -142,7 +142,7 @@ jeecg :
       data-type: yml
   #分布式锁配置
   redisson:
-    address: 127.0.0.1:6379
+    address: jeecg-boot-redis:6379
     password:
     type: STANDALONE
     enabled: true
diff --git a/jeecg-boot/jeecg-cloud-module/docker-compose.yml b/jeecg-boot/jeecg-cloud-module/docker-compose.yml
index f3d73cf..125501d 100644
--- a/jeecg-boot/jeecg-cloud-module/docker-compose.yml
+++ b/jeecg-boot/jeecg-cloud-module/docker-compose.yml
@@ -28,28 +28,18 @@ services:
     hostname: jeecg-boot-redis
 
   jeecg-boot-nacos:
-    restart: always
-    image: nacos/nacos-server:1.4.0
-    container_name: jeecg-boot-nacos
-    hostname: jeecg-boot-nacos
+    restart: on-failure
+    build:
+      context: ./jeecg-cloud-nacos
     ports:
       - 8848:8848
     depends_on:
       - jeecg-boot-mysql
-#    volumes:
-#      - ./init/docker-startup.sh:/home/nacos/bin/docker-startup.sh
-#      - ./init/application.properties:/home/nacos/conf/application.properties
-    environment:
-      MODE: standalone
-      PREFER_HOST_MODE: hostname
-      SPRING_DATASOURCE_PLATFORM: mysql
-      MYSQL_SERVICE_HOST: jeecg-boot-mysql
-      MYSQL_SERVICE_PORT: 3306
-      MYSQL_SERVICE_USER: root
-      MYSQL_SERVICE_PASSWORD: root
-      MYSQL_SERVICE_DB_NAME: nacos
+    container_name: jeecg-boot-nacos
+    hostname: jeecg-boot-nacos
 
   jeecg-boot-gateway:
+    restart: on-failure
     build:
       context: ./jeecg-cloud-gateway
     ports:
diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/Dockerfile b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/Dockerfile
new file mode 100644
index 0000000..df876e1
--- /dev/null
+++ b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/Dockerfile
@@ -0,0 +1,15 @@
+FROM anapsix/alpine-java:8_server-jre_unlimited
+
+MAINTAINER jeecgos@163.com
+
+RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+
+RUN mkdir -p /jeecg-cloud-nacos
+
+WORKDIR /jeecg-cloud-nacos
+
+EXPOSE 8848
+
+ADD ./target/jeecg-cloud-nacos-2.4.2.jar ./
+
+CMD sleep 5;java -Dfile.encoding=utf-8 -Djava.security.egd=file:/dev/./urandom -jar jeecg-cloud-nacos-2.4.2.jar
\ No newline at end of file
diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/pom.xml b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/pom.xml
new file mode 100644
index 0000000..6b46693
--- /dev/null
+++ b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>jeecg-cloud-module</artifactId>
+        <groupId>org.jeecgframework.boot</groupId>
+        <version>2.4.2</version>
+    </parent>
+    <artifactId>jeecg-cloud-nacos</artifactId>
+    <name>jeecg-cloud-nacos</name>
+    <description>nacos启动模块</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tomcat.embed</groupId>
+            <artifactId>tomcat-embed-jasper</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jeecgframework.nacos</groupId>
+            <artifactId>nacos-naming</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jeecgframework.nacos</groupId>
+            <artifactId>nacos-istio</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jeecgframework.nacos</groupId>
+            <artifactId>nacos-config</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jeecgframework.nacos</groupId>
+            <artifactId>nacos-console</artifactId>
+            <version>1.4.1</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/java/com/alibaba/nacos/JeecgNacosApplication.java b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/java/com/alibaba/nacos/JeecgNacosApplication.java
new file mode 100644
index 0000000..959a4a8
--- /dev/null
+++ b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/java/com/alibaba/nacos/JeecgNacosApplication.java
@@ -0,0 +1,35 @@
+package com.alibaba.nacos;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.web.servlet.ServletComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * Nacos 启动类
+ * 引用的nacos console 源码运行,简化开发
+ * 生产建议从官网下载最新版配置运行
+ * @author zyf
+ */
+@SpringBootApplication(scanBasePackages = "com.alibaba.nacos")
+@ServletComponentScan
+@EnableScheduling
+public class JeecgNacosApplication {
+
+    /**
+     * 是否单机模式启动
+     */
+    private static String standalone = "true";
+
+    /**
+     * 是否开启鉴权
+     */
+    private static String enabled = "false";
+
+    public static void main(String[] args) {
+        System.setProperty("nacos.standalone", standalone);
+        System.setProperty("nacos.core.auth.enabled", enabled);
+        System.setProperty("server.tomcat.basedir","logs");
+        SpringApplication.run(JeecgNacosApplication.class, args);
+    }
+}
diff --git a/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/resources/application.yml b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/resources/application.yml
new file mode 100644
index 0000000..1c5cadf
--- /dev/null
+++ b/jeecg-boot/jeecg-cloud-module/jeecg-cloud-nacos/src/main/resources/application.yml
@@ -0,0 +1,55 @@
+server:
+  port: 8848
+  servlet:
+    contextPath: /nacos
+  tomcat:
+    accesslog:
+      enabled: true
+      pattern: '%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i'
+    basedir: ''
+spring:
+  datasource:
+    platform: mysql
+db:
+  num: 1
+  password:
+    '0': ${MYSQL-PWD:root}
+  url:
+    '0': jdbc:mysql://${MYSQL-HOST:jeecg-boot-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:nacos}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
+  user:
+    '0': ${MYSQL-USER:root}
+management:
+  metrics:
+    export:
+      elastic:
+        enabled: false
+      influx:
+        enabled: false
+nacos:
+  core:
+    auth:
+      caching:
+        enabled: true
+      default:
+        token:
+          expire:
+            seconds: 18000
+          secret:
+            key: SecretKey012345678901234567890123456789012345678901234567890123456789
+      enabled: false
+      system:
+        type: nacos
+  istio:
+    mcp:
+      server:
+        enabled: false
+  naming:
+    empty-service:
+      auto-clean: true
+      clean:
+        initial-delay-ms: 50000
+        period-time-ms: 30000
+  security:
+    ignore:
+      urls: /,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
+  standalone: true
\ No newline at end of file
diff --git a/jeecg-boot/jeecg-cloud-module/pom.xml b/jeecg-boot/jeecg-cloud-module/pom.xml
index a240afa..a98b6c2 100644
--- a/jeecg-boot/jeecg-cloud-module/pom.xml
+++ b/jeecg-boot/jeecg-cloud-module/pom.xml
@@ -16,6 +16,7 @@
         <module>jeecg-cloud-gateway</module>
         <module>jeecg-cloud-monitor</module>
         <module>jeecg-cloud-xxljob</module>
+        <module>jeecg-cloud-nacos</module>
     </modules>
 
 
--
libgit2 0.22.2