一、介绍星舟平台
1、星舟简介
2、网关kong的介绍
3、客户端
1)、服务注册:Eureka
2)、客户端负载均衡:Ribbon
4、服务器端
1)、服务注册:Marathon+Marathon-LB、HAProxy+Confd+Etcd
2)、服务端负载均衡:HAProxy
5、pinpoint调用链技术
traceid 透明数据传输
6、服务调用可以使用ELK采集
7、服务隔离与降级hystrix
8、统一配置中心:Spring Cloud ConfigServer
9、服务契约 Swagger,可以产生一个线上的文档
10、星舟灰度发布
三种方式
1、不定向发布:按比例发布
2、定向挑选:和微服务路径相关
3、定向挑选:业务无关,和header有关
11、devops的实操过程
jenkins on mesos,相当于jenkins集群
每个jenkins都有其master和slave
12、基于深度学习框架Tensorflow的微服务弹性扩缩
13、下一步演进 service mesh(服务网格)
二、开启微服务之旅-SpringBoot入门
需要安装的软件
idea
jdk
git
postman
1、spring boot 的版本,只能选择1.5.X版本
2、使用idea做一个Hello World!
步骤:
1)、创建一个spring boot
GRoup 为com.unicom.microserv.px
artifact:px190327_学号,我的是px190327_38023
选择web 和actuator
finish
删除一些目录,.mvn相关的三个文件或者目录等
http://localhost:8080/health
有正常返回即可:{"status":"UP"}
2)、增加HelloWorld
增加一个包controller
增加一个类HelloController
增加类注解
@RestController
@RequestMapping(value="/px190327/38023")
在类中增加一个类
并增加注解,代码如下:
@RequestMapping(
value = "hello",
method = RequestMethod.GET
)
public String hello() {
return "Hello World!38023";
}
3)、访问http://localhost:8080/px190327/38023/hello
Hello World!
3、Spring Boot的5种传参方式
注解 传参方式
@PathVariable 路径参数
@RequestParam Query参数;
表单@RequestBody Body参数
@RequestHeader Header参数
@CookieValue Cookie参数
@PathVariable和@RequestParam的使用
并增加注解,代码如下:
@RequestMapping(
value = "hello/{name}",
method = RequestMethod.GET
)
public String hello(@PathVariable String name,
@RequestParam ("say") String say) {
return "Hello World!" + name +"speak"+say;
}
访问http://localhost:8080/px190327/38023/hello/38023?say="Here Are You!"
2019年3月27日下午
三、Git学习(版本控制)
GitLab地址:http://10.172.49.22:8825/
账户:注册
星舟管理平台:地址:http://10.172.49.22:8086/microservadmin/login
账户: 同GitLab
天宫DCOS:地址:http://10.172.49.2/#/dashboard
账户:skyark_XXX/skyark_XXX(注意不要使用其他账号)
网络环境需要打开
http://10.125.128.49:9999/service/jenkins/job/cbproject1_feature_1036_release20190112/1/console
Git的工作区、缓存区、版本库 Working Directory /staging Directory/history Directory
git命令:
git add
git commit; #提交版本
git status
git rm
git mv
gitignore 不做版本控制的文件列表
git init 创建仓库
git remote add origin {URL} 添加远程库
git push [–u origin master] 推送到远程库
git pull 拉取到本地
git checkout {branch-name} 切换分支
git status 查看文件状态
本地分支和github/gitlabrary 服务器上分支
idea的工程的本地版本管理
vcs->->import into version control->create Git repostory
这是文件变红,表示未更新,右下角 有关各 git master
工程目录 右键 -》git ->add
工程目录 右键 -》git ->commit directory ,需要填写 commit text 和 username 以及邮件 ,username 以及邮件见邮件,正常提交后文件颜色恢复正常
星舟配置http://10.172.49.22:8086/microservadmin/login
登录后
研发流程管理->CICD->Git项目管理,新建项目
组名px190327
Git工程名 和本地一样,我的是px190327_38023
拷贝出来git地址http://10.172.49.22:8825/px190327/px190327_38023.git
idea中
git-repository-remote弹出一个对话框,点击+ ,origin不动,在输入框后粘贴拷贝出来的git地址,提交后,弹出需要输入用户名+密码 ok
git-repository-push,push成功
在天舟中可以看到对应的项目中的分支为master ,证明上传成功。
注意:
如果刚开始在填写用户名和右键是输入和远程的用户名不一致时,会出现问题,需要删除重新增加,在控制面板->用户账户->凭据管理器->管理windows凭据 删除
切换分支
星舟管理平台,项目管理,找到自己的工程,点击右侧的添加分支 起名为feature_0327,在idea中git-repository-pull,选中服务器上的feature_0327分支,在idea的右下角git master 点击后选择新的分支。即可使用分支开发
checkout,即切换到新的分支
完成修改后,push后,在星舟平台会自动构建,完成后,在天宫平台登录的组件仓库中可以看到该组件,点击操作下的安装组件包,点击 预览及运行,点击运行,等几分钟后再服务中可以看到
在服务->px190327中可以看到对应的服务运行起来了,点击服务,再点击具体的服务名,并在详情中可以看到服务地址和端口http://10.125.128.22:15295
浏览器中打开
http://10.125.128.22:15295/px190327/38023/hello/38023?say="I LOVE YOU!" 本地没问题,这里还有问题
疑问:怎么看marathon转后的地址和前面的地址
服务实践:
URL 动作 功能
/users GET 获取所有用户列表
/users POST 增加一个用户
/users/{id} GET 根据ID获取用户
/users/{id} PUT 修改ID为1的用户
/users/{id} DELETE 删除ID删除用户
/users/name/{name} GET 根据name查找用户
/users/{id}/age GET 获取用户的年龄
怎么发布?
增加一个User类(包含age和name两个属性)
public class User {
Integer age;
String name;
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
新增加一个类UserController,增加方法 如下
@RequestMapping(
value = "users",
method = RequestMethod.GET
)
public String getAllUser() {
return "返回所有user信息!";
} //这里可以修改为返回user列表
@RequestMapping(
value = "user",
method = RequestMethod.POST
)
public String createUser() {
return "增加一个用户!";
}
http://localhost:8080/px190327/38023/users,为空即可
接口文档的编写:http://10.172.49.22:8825/peixun/peixun_demo1/wikis/home这里有说明,见Swagger的学习.docx
1、增加Swagger依赖到Maven
2. 入口类注解@EnableSwagger2
3. Swagger配置类SwaggerConfig.java
4. 注解到接口方法@ApiOperation
5. localhost:8080/swagger-ui.html
6. @ApiIgnore 入口类
@ApiOperation 方法说明 value 为标题 ,notes为说明,不限制长度
@ApiModel 类说明
@ApiModelProperty 类的属性说明
操作过程
1、增加Swagger依赖到Maven
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
2、在入口增加注解 @EnableSwagger2,代码变为
@SpringBootApplication
@EnableSwagger2
public class Px19032738023Application {
public static void main(String[] args) {
SpringApplication.run(Px19032738023Application.class, args);
}
}
3、新增加config包增加配置类SwaggerConfig.java
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Sets.newHashSet("application/json"))
.consumes(Sets.newHashSet("application/json"))
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors
.basePackage("com.unicom"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo()
{
return new ApiInfoBuilder()
.title("peixun_liuyf")
.version("1.0.0")
.build();
}
}
4、增加说明
getAllUser方法上增加说明
@ApiOperation(
value="使用get获取user列表",
notes="通过get方法获取所有用户的列表,这里是示例,仅适用STring,正式环境需要有列表来返回!"
)
User属性增加注解和说明
@ApiModelProperty(value="年龄",notes="user的年龄",example = "23") //这个是引入swagger类以后增加
Integer age;
@ApiModelProperty(value="姓名",notes="user的姓名",example = "张三") //这个是引入swagger类以后增加
String name;
5、增加类getUserById定义
@RequestMapping(
value = "getUserById",
method = RequestMethod.GET
)
@ApiOperation(
value="根据id使用get获取user列表",
notes="根据Id 通过get方法获取所有用户的列表!"
)
public User getUserById(@RequestParam ("userId") Integer userId) {
User user=new User();
user.setAge(1);
user.setName("luhq7");
return user;
}
访问测试:http://localhost:8080/px190327/38023/getUserById?userId=9,
6、测试Swagger效果
访问:http://localhost:8080/swagger-ui.html
属性相关的说明可以在对应的接口中的model中看到
在接口的说明中可以看到@ApiOperation的说明