Bläddra i källkod

注册中心eureka

larry 5 år sedan
incheckning
399298a5a8

+ 9 - 0
.gitignore

@@ -0,0 +1,9 @@
1
+log
2
+.idea
3
+*.iml
4
+/target/
5
+/bin/
6
+.project
7
+.classpath
8
+/log/
9
+.settings

+ 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
README.md

@@ -0,0 +1,8 @@
1
+## spring-cloud-eureka-server
2
+
3
+这是一个公共的服务注册中心项目
4
+
5
+地址为 localhost:9001  您也可以进行修改。
6
+
7
+如果您想做到高可用,那么请复制一份代码进行相互注册。eureka 会自动将本工程数据复制到注册的的eureka中。
8
+例如您可以这么做: 三台:A->B->C->A   两台:A<->B

+ 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
+}

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

@@ -0,0 +1,18 @@
1
+server:
2
+  port: 9001
3
+
4
+spring:
5
+  application:
6
+    name: eureka
7
+# register-with-eureka  自身并不注册到自身,eureka 是一个服务端,但又是一个客户端.所以需要关闭自注册
8
+eureka:
9
+  client:
10
+    register-with-eureka: false
11
+    fetch-registry: false
12
+    service-url:
13
+      defaultZone: http://localhost:9001/eureka
14
+  # server.enable-self-preservation 关闭自我保护,默认为true。 开发环境可以这样设置,生成环境需要设置为true
15
+  server:
16
+    enable-self-preservation: false
17
+logging:
18
+  path: ./log

+ 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
+}