larry 4 år sedan
incheckning
93173bd3bd

+ 32 - 0
.gitignore

@@ -0,0 +1,32 @@
1
+<<<<<<< HEAD
2
+<<<<<<< HEAD
3
+log
4
+.idea
5
+*.iml
6
+/target/
7
+/bin/
8
+.project
9
+.classpath
10
+/log/
11
+.settings
12
+=======
13
+=======
14
+>>>>>>> fcf5118f9b1afbb845fb8a8d2a42391627b1ef1c
15
+# ---> Java
16
+*.class
17
+
18
+# Mobile Tools for Java (J2ME)
19
+.mtj.tmp/
20
+
21
+# Package Files #
22
+*.jar
23
+*.war
24
+*.ear
25
+
26
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
27
+hs_err_pid*
28
+
29
+<<<<<<< HEAD
30
+>>>>>>> 5228917df4d1b95b1f3713791d7ff219b3467b41
31
+=======
32
+>>>>>>> fcf5118f9b1afbb845fb8a8d2a42391627b1ef1c

+ 8 - 0
Dockerfile

@@ -0,0 +1,8 @@
1
+FROM 172.16.0.8:31104/library/oracle-jre:8u202
2
+WORKDIR /home
3
+ADD ./target/eureka.jar /home/app.jar
4
+RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
5
+CMD java $JVM_OPTS -Djava.security.egd=file:/dev/./urandom -jar /home/app.jar --server.port=11000 --eureka.server.enable-self-preservation=false
6
+EXPOSE 11000
7
+
8
+

+ 8 - 0
LICENSE

@@ -0,0 +1,8 @@
1
+MIT License
2
+Copyright (c) <year> <copyright holders>
3
+
4
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 20 - 0
README.md

@@ -0,0 +1,20 @@
1
+<<<<<<< HEAD
2
+<<<<<<< HEAD
3
+## spring-cloud-eureka-server
4
+
5
+这是一个公共的服务注册中心项目
6
+
7
+地址为 localhost:9001  您也可以进行修改。
8
+
9
+如果您想做到高可用,那么请复制一份代码进行相互注册。eureka 会自动将本工程数据复制到注册的的eureka中。
10
+例如您可以这么做: 三台:A->B->C->A   两台:A<->B
11
+=======
12
+# depot-eureka-yunnan
13
+
14
+云南注册中心
15
+>>>>>>> 5228917df4d1b95b1f3713791d7ff219b3467b41
16
+=======
17
+# depot-eureka-shanxi
18
+
19
+注册中心初始化--山西项目
20
+>>>>>>> fcf5118f9b1afbb845fb8a8d2a42391627b1ef1c

+ 14 - 0
alaudaci.yml

@@ -0,0 +1,14 @@
1
+version: "0.1.0"
2
+pre_ci_boot:
3
+  image:  172.16.0.34:5000/alauda-cicd/u14java
4
+  tag: oraclejdk8-1
5
+ci:
6
+  - mkdir -p /tmp/alauda/app &&  cp -r . /tmp/alauda/app/
7
+  - pwd && find .. 
8
+  - cd /tmp/alauda/app
9
+  - pwd && ls -al
10
+  - mvn package
11
+  - cp Dockerfile $ALAUDACI_DEST_DIR/Dockerfile
12
+  - mkdir -p $ALAUDACI_DEST_DIR/target/
13
+  - cp target/*.jar  $ALAUDACI_DEST_DIR/target/
14
+#  - sleep 60

+ 55 - 0
javash/sh.sh

@@ -0,0 +1,55 @@
1
+#java env
2
+#增加操作权限:  chmod +x *.sh
3
+#编译.sh文件命令: sed -i 's/\r$//' *.sh
4
+#启动命令:  ./sh.sh start  停止 ./sh.sh stop
5
+#shell脚本有时候调用linux的环境变量会有问题,所以这里还是把用到的java环境再设置一下
6
+#export JAVA_HOME=/usr/bin/java/jdk1.8.0_171/
7
+
8
+#工程上级文件名称
9
+FILE_NAME=eureka
10
+
11
+SERVICE_DIR=/usr/local/jar/$FILE_NAME
12
+
13
+#工程名称
14
+SERVICE_NAME=eureka
15
+
16
+APP_JAR=$SERVICE_NAME\.jar
17
+#启动app的时候,将进程的pid保存在这里,方便以后杀死进程用
18
+APP_PID=$SERVICE_NAME\.pid
19
+
20
+cd $SERVICE_DIR
21
+
22
+case "$1" in
23
+
24
+    start)
25
+        #/dev/null 就不会有nohup.out文件了。
26
+        nohup java -Xms32m -Xmx128m -Dloader.path="lib/" -jar $APP_JAR >log.file 2>&1 &
27
+        #将pid写入文件
28
+        echo $! > $SERVICE_DIR/$APP_PID
29
+        echo "===== start $SERVICE_NAME"
30
+        ;;
31
+
32
+    stop)
33
+        kill `cat $APP_PID`
34
+        #删除掉pid文件
35
+        rm -f $SERVICE_DIR/$APP_PID
36
+        rm -f $SERVICE_DIR/log.file
37
+        #查看是不是杀死进程了
38
+        sleep 5
39
+                #获得进程号,复制号两边不能留空格
40
+                pid=`ps -ef | grep -w $SERVICE_NAME | grep -v grep | awk '{print $2}'`
41
+        #判断相等两边要留空格
42
+        if ["$pid" == ""];then
43
+            echo "=== kill successfully "
44
+        else
45
+            echo "===== kill fail and try to kill -9"
46
+            echo "====  the pid is  $pid"
47
+            kill -9 $pid
48
+        fi
49
+        echo "stop finished"
50
+        ;;
51
+    *)
52
+        echo "please use start or stop 参数"
53
+        ;;
54
+esac
55
+exit 0

+ 81 - 0
pom.xml

@@ -0,0 +1,81 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+	<modelVersion>4.0.0</modelVersion>
5
+
6
+	<groupId>com.unis.module</groupId>
7
+	<artifactId>eureka</artifactId>
8
+	<version>0.0.1-SNAPSHOT</version>
9
+	<packaging>jar</packaging>
10
+
11
+	<name>eureka</name>
12
+	<description>Demo project for Spring Boot</description>
13
+
14
+	<parent>
15
+		<groupId>org.springframework.boot</groupId>
16
+		<artifactId>spring-boot-starter-parent</artifactId>
17
+		<version>2.0.3.RELEASE</version>
18
+		<relativePath/> <!-- lookup parent from repository -->
19
+	</parent>
20
+
21
+	<properties>
22
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
+		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+		<java.version>1.8</java.version>
25
+		<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
26
+	</properties>
27
+
28
+	<dependencies>
29
+		<dependency>
30
+			<groupId>org.springframework.cloud</groupId>
31
+			<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
32
+		</dependency>
33
+
34
+		<dependency>
35
+			<groupId>org.springframework.boot</groupId>
36
+			<artifactId>spring-boot-starter-test</artifactId>
37
+			<scope>test</scope>
38
+		</dependency>
39
+	</dependencies>
40
+
41
+	<dependencyManagement>
42
+		<dependencies>
43
+			<dependency>
44
+				<groupId>org.springframework.cloud</groupId>
45
+				<artifactId>spring-cloud-dependencies</artifactId>
46
+				<version>${spring-cloud.version}</version>
47
+				<type>pom</type>
48
+				<scope>import</scope>
49
+			</dependency>
50
+		</dependencies>
51
+	</dependencyManagement>
52
+
53
+	<build>
54
+		<plugins>
55
+			<plugin>
56
+				<groupId>org.springframework.boot</groupId>
57
+				<artifactId>spring-boot-maven-plugin</artifactId>
58
+				<!--第一次打包时需要注释到 configuration 节点,因为我们要得到全部的jar包-->
59
+ 				<!--<configuration>
60
+					<layout>ZIP</layout>
61
+					<includes>
62
+						<include>
63
+							<groupId>com.unis.module</groupId>
64
+							<artifactId>eureka</artifactId>
65
+						</include>
66
+					</includes>
67
+				</configuration>-->
68
+			</plugin>
69
+			<!--打包时不进行验证测试-->
70
+			<plugin>
71
+				<groupId>org.apache.maven.plugins</groupId>
72
+				<artifactId>maven-surefire-plugin</artifactId>
73
+				<version>2.21.0</version>
74
+				<configuration>
75
+					<skipTests>true</skipTests>
76
+				</configuration>
77
+			</plugin>
78
+		</plugins>
79
+		<finalName>eureka</finalName>
80
+	</build>
81
+</project>

+ 21 - 0
src/main/java/com/unis/module/eureka/EurekaApplication.java

@@ -0,0 +1,21 @@
1
+package com.unis.module.eureka;
2
+
3
+import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
6
+
7
+/**
8
+ * TODO 功能描述:服务注册中心
9
+ *
10
+ * @author 李兵
11
+ * @version v1.0
12
+ * @date 2018/6/29 11:08
13
+ */
14
+@SpringBootApplication
15
+@EnableEurekaServer
16
+public class EurekaApplication {
17
+
18
+    public static void main(String[] args) {
19
+        SpringApplication.run(EurekaApplication.class, args);
20
+    }
21
+}

+ 53 - 0
src/main/resources/application.yml

@@ -0,0 +1,53 @@
1
+spring:
2
+  profiles:
3
+    active: local_dev
4
+server:
5
+  port: 9001
6
+---
7
+# 本地开发环境
8
+spring:
9
+  profiles: local_dev
10
+#eurekaServer
11
+eureka:
12
+  instance:
13
+    prefer-ip-address: true
14
+    # 仅测试使用,部署上线不使用
15
+    status-page-url-path: /swagger-ui.html
16
+  client:
17
+    register-with-eureka: false
18
+    fetch-registry: false
19
+    service-url:
20
+      defaultZone: http://localhost:9001/eureka/
21
+  server:
22
+    # 关闭自我保护机制(不关闭会在所有服务连接异常85%后不在注销服务)
23
+    enable-self-preservation: false
24
+    # 每隔30s扫描服务列表,移除失效服务(默认60000)
25
+    eviction-interval-timer-in-ms: 30000
26
+management:
27
+  endpoints:
28
+    web:
29
+      exposure:
30
+        include: '*'
31
+#  endpoint:
32
+#    health:
33
+#      show-details: always
34
+---
35
+# 部署环境
36
+spring:
37
+  profiles: prod
38
+eureka:
39
+  instance:
40
+    prefer-ip-address: true
41
+  client:
42
+    register-with-eureka: false
43
+    fetch-registry: false
44
+    service-url:
45
+      defaultZone: http://${spring.cloud.client.ip-address}:${server.port}/eureka/
46
+  server:
47
+    enable-self-preservation: false
48
+    eviction-interval-timer-in-ms: 30000
49
+management:
50
+  endpoints:
51
+    web:
52
+      exposure:
53
+        include: '*'

+ 16 - 0
src/test/java/com/unis/module/eureka/EurekaApplicationTests.java

@@ -0,0 +1,16 @@
1
+package com.unis.module.eureka;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.junit4.SpringRunner;
7
+
8
+@RunWith(SpringRunner.class)
9
+@SpringBootTest
10
+public class EurekaApplicationTests {
11
+
12
+	@Test
13
+	public void contextLoads() {
14
+	}
15
+
16
+}