ubuntu14.04 spring cloud config server + gradle搭建
Server端:
在eclipse上,创建Java Project项目。自带的src包删掉手动建文件夹。基础的目录文件都创建上
|--ZSpringCloud
|--build.gradle
|----src
|------main
|--------java
|--------resources
配置build.gradle文件:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.7.RELEASE")
classpath("org.springframework:springloaded:1.2.0.RELEASE")
classpath("nz.org.geonet:gradle-build-version-plugin:1.0.4")
classpath("io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE")
}
} apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management' jar {
baseName = 'spring-cloud-service'
version = '0.0.1'
} repositories {
maven { url "https://repo.spring.io/libs-milestone" }
mavenLocal()
mavenCentral()
} dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-netflix:1.2.0.M1'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR2'
}
} sourceCompatibility = 1.8
targetCompatibility = 1.8 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile("org.springframework.cloud:spring-cloud-starter-parent:Brixton.SR4")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.cloud:spring-cloud-config-server")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
}
当时报了很多错,从晚上找了很多东西,不记得哪个是解决问题的了,所有的依赖都粘上了应该有没用的。
现在已经有了空文件夹,和一个写好的build.gradle文件,打开一个终端进入ZSpringCloud目录。
gradle eclipse
eclipse调成Spring的视图看的更舒服写。执行完成后这个样子(现在还没有build文件夹),确保项目没有一个大感叹号。
在src/main/java里创建main类(Application名字随便起),先建个空的。
public class Application {
public static void main(String[] args) {
}
}
现在有程序入口,在终端执行
gradle build
gradle eclipse
确保执行成功,中间应该不会出错了,出错搜一下。
修改Application类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Configuration; @Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
在src/main/resources里创建两个文件,application.properties和bootstarp.properties
#<application.properties>
server.port=8888 #Server跑的端口 security.basic.enabled=false #这两个spring验证的,不加这个两个会报一个
management.security.enabled=false #Spring的安全的什么错误,应该能解决,但是现在先不管。如果不加访问的时候需要用户名和密码,这个用户和密码不知道在哪
#<bootstrap.properties>
spring.cloud.config.server.git.uri=git@192.168.1.6:fzk/SpringCloudTest.git #是从哪个地方获取配置文件,ssh路径的跑通了,http待研究
#spring.cloud.config.server.git.uri=http://192.168.1.6/root/SpringCloudTest.git
spring.cloud.config.server.git.searchPaths=repo #这个是进入上面的路径后,从哪个文件夹搜索文件 #spring.application.name=configserver
#spring.application.label=master #label名,分支名,如果写了,以后在获取的时候需要加上{label}
现在就已经能启动项目了,先启动一下看看哪里报错了。没报错先放着,还有一大堆服务器的东西需要配置。
我自己在另外一个虚拟机上搭了一个gitlab,这个可以不用自己搭,随便找个gitlab库能放代码就可以了。如果自己搭了最好设成静态ip。(虚拟机ip:192.168.1.6)
在gitlab上建一个存配置文件的项目<SpringCloudTest>,在本地建一个SpringCloudTest的文件夹,在里面建一个repo文件夹,repo里建一个fzk-beta.properties文件
|SpringCloudTest
|--repo
|----fzk-beta.properties
把这个项目推上gitlab建的项目上,从本地文件夹push的方法在gitlab剪完项目后最下面的那块告诉怎么弄了。
gitlab剪完项目后点击项目名就看见两个地址,ssh和http,就是在Server端 bootstrap.properties的 spring.cloud.config.server.git.uri 配置的路径。
现在项目已经建完了,开始服务器的配置。现在有两个服务器,一个是跑Server的A,一个gitlab的B。
在A上,用什么用户跑这个程序就用什么用户生成一对秘钥,我全是用普通用户跑的。在A上执行
ssh-keygen -t rsa
在用户的~/.ssh/ 目录下会生成一对秘钥,id_rsa id_rsa.pub。把id_rsa.pub的内容复制到gitlab项目的Deploy Keys中
Deploy Keys的位置在:在浏览器上找到你的那个项目,右上角有个一看就是设置的按钮,点开就能找到Deploy Keys ,点击进入title就是随便起的名,下面大的文本框里粘贴上刚才从公钥中复制的内容。确保最下面秘钥列表中刚才弄的那个公钥是enable的。默认就是。
在A上通过ssh 链接一下gitlab的服务器,保证A上能识别这个ip。问是不是永久储存在knowhosts中,yes。
ssh root@192.168.1.6
如果现在就开始访问,还是不成功,说什么不识别B的ip或者秘钥不对之类的错误。
在A上进入 ~/.ssh/ 目录,vim config。把下面内容复制上,改一下。
Host 192.168.1.6 #B的域名或ip
RSAAuthentication yes #是否公钥验证
StrictHostKeyChecking no #看这个意思应该是什么严格的验证之类的
IdentityFile /home/fzk/.ssh/id_rsa #通过公钥验证的私钥的位置
User fzk #在gitlab上注册的用户名,登陆的时候的那个
好,现在就已经全部完事了。
在浏览器上输入:
http://localhost:8888/fzk/beta
{"name":"fzk","profiles":["beta"],"label":"master","version":"ebcf17eac0699644200aca3b8b0d1a23563ce242","state":null,"propertySources":[{"name":"git@192.168.1.6:fzk/SpringCloudTest.git/repo/fzk-beta.properties","source":{"server.port":"8013","fzk.nick":"badboy"}}]}
http://localhost:8888/fzk-beta.properties
fzk.nick: badboy
server.port: 8013
访问格式:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
ubuntu14.04 spring cloud config server + gradle搭建的更多相关文章
- 为Spring Cloud Config Server配置远程git仓库
简介 虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更 ...
- Spring Cloud Config Server 节点迁移引起的问题,请格外注意这一点!
前言: 虽然强烈推荐选择使用国内开源的配置中心,如携程开源的 Apollo 配置中心.阿里开源的 Nacos 注册&配置中心. 但实际架构选型时,根据实际项目规模.业务复杂性等因素,有的项目还 ...
- 搭建spring cloud config
很久没更新了,因为不是专职研究spring cloud,因此更新速度得看工作强度大不大,每天能抽出的时间不多,如果更新太慢了,并且有小伙伴看的话,请见谅了. Spring Cloud简介 Spring ...
- Spring Cloud Config(三):基于JDBC搭建配置中心
1.简介 本文主要内容是基于jdbc搭建配置中心,使应用从配置中心读取配置信息并成功注册到注册中心,关于配置信息表结构仅供参考,大家可以根据具体需要进行扩展. 2.Config Server 搭建 2 ...
- Spring Cloud Config(二):基于Git搭建配置中心
1.简述 本文选用Git作为配置仓库,新建两个环境的配置文件夹,dev 和 test,文件夹中分别存放 Config Client 端的配置文件,目录结构如下: ├ ─ ─ dev └ ─ ─ con ...
- Spring Cloud搭建手册(2)——Spring Cloud Config
※在Dalston.SR2版本以后,均不能正常加密,如果必须使用此功能,需要降级到SR1或Camden SR7. 1.首先需要创建一个config-server工程,作为配置中心的服务器,用来与git ...
- Spring Cloud Config 搭建Config 服务
配置中心: open API 配置生效监控 一致性的K-V存储 统一配置的实时推送 配置全局恢复.备份.历史版本 高可用集群 通过config 获取配置,流程: 下面介绍,基于spring cloud ...
- Spring Cloud config之三:config-server因为server端和client端的健康检查导致服务超时阻塞问题
springcloud线上一个问题,当config-server连不上git时,微服务集群慢慢的都挂掉. 在入口层增加了日志跟踪问题: org.springframework.cloud.config ...
- Spring Cloud官方文档中文版-Spring Cloud Config(上)
官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...
随机推荐
- 读jQuery源码之整体框架分析
读一个开源框架,大家最想学到的就是设计的思想和实现的技巧.最近读jQuery源码,记下我对大师作品的理解和心得,跟大家分享,权当抛砖引玉. 先附上jQuery的代码结构. (function(){ / ...
- <context:annotation-config/>、<context:component-scan/>
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredA ...
- 前端自动化Grunt教程
最近在学习Bootstrap,了解一部分之后,发现Bootstrap使用了LESS,好嘛,开始学习LESS,LESS了解部分,发现自动编译工具Grunt,了解Grunt过程发现需要使用node.js的 ...
- Android 使用SwipeBackLayout实现滑动返回上一级页面——实战来袭
我们知道.APP在设计上习惯性的把返回button放在屏幕的左上角,那么,在非常多时候(尤其是大屏幕手机),操作改返回button,就会有诸多不便了.为了更加方便实现"返回"功能. ...
- go学习资料
go书单 1.代码规范 https://github.com/golang/go/wiki/CodeReviewComments 2.基础知识 先看: https://github.com/mikel ...
- mysql 主从切换
4)提升slave为master Stop slave: Reset master; Reset slave all; 在5.6.3版本之后 Reset slave; 在5.6.3版本之前 查看sla ...
- Atitit.sql ast 表达式 语法树 语法 解析原理与实现 java php c#.net js python
Atitit.sql ast 表达式 语法树 语法 解析原理与实现 java php c#.net js python 1.1. Sql语法树 ast 如下图锁死1 2. SQL语句解析的思路和过程3 ...
- Verilog利用$fdisplay命令往文件中写入数据
最近在做的事情是,用FPGA生成一些满足特定分布的序列.因此为了验证我生成的序列是否拥有预期的性质,我需要将生成的数据提取出来并且放到MATLAB中做数据分析. 但是网上的程序很乱,表示看不懂==其实 ...
- 基于CentOS7的服务器搭建(LAMP环境)
基于CentOS7的服务器环境搭建(LAMP环境) 一.安装MySQL组件 1.由于在CentOS7中,默认yum安装库中不含有mysql,我们可以下载mysql的分支MariaDB,如果必须要下my ...
- Android发短信
设置应用一打开时候的背景图片 去掉相对布局时候的标题 去除标题必须在setContentView(R.layout.activity_main)之前. @Override protected void ...