当前位置: 首页 > news >正文

金融行业网站制作电商网站设计周志

金融行业网站制作,电商网站设计周志,如何做电商,建设速干裤移动网站Spring Boot与监控管理视频 1. 简介 通过引入spring-boot-starter-actuator, 可以使用SpringBoot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过http, jmx, ssh协议来进行操作,自动得到审计、健康及指标信息等。 步骤: 引入spring-boo…

Spring Boot与监控管理视频

1. 简介

通过引入spring-boot-starter-actuator, 可以使用SpringBoot为我们提供的准生产环境下的应用监控和管理功能。我们可以通过http, jmx, ssh协议来进行操作,自动得到审计、健康及指标信息等。

步骤:

  • 引入spring-boot-starter-actuator
  • 通过http方式访问监控端点;
  • 可进行shutdown (post提交,此端点默认关闭);

监控和管理端点:

端点名描述
autoconfig所有自动配置信息
auditevents审计事件
beans所有Bean的信息
configprops所有配置属性
dump线程状态信息
env当前环境信息
health应用健康状况
info当前应用信息
metrics应用的各项指标
mappings应用的@RequestMapping映射路径
shutdown关闭当前应用(默认关闭)
trace追踪信息(最新的http请求)

http://localhost:8080/beans

http://localhost:8080/health

http://localhost:8080/trace

http://localhost:8080/metrics

http://localhost:8080/mappings

http://localhost:8080/info

2. shutdown端点的使用

首先在application中开启shutdown端点,默认是关闭的。

# 关闭认证
management.security.enabled=false
# 开启shutdown端点
endpoints.shutdown.enabled=true

启动应用后,使用postman发送post请求 : http://localhost:8080/shutdown; 发现报跨域访问限制异常。

{"timestamp": 1691418900478,"status": 403,"error": "Forbidden","message": "Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.","path": "/shutdown"
}

什么是 CSRF ,这是一个 WEB 应用安全的问题,CSRF(Cross-site request forgery 跨站请求伪造,也被称为“One Click Attack” 或者Session Riding,攻击方通过伪造用户请求访问受信任站点。

因为我在应用中引入了spring-security, 它引入了CSRF,默认是开启。CSRF和RESTful技术有冲突。CSRF默认支持的方法: GET|HEAD|TRACE|OPTIONS,不支持POST。

其实跨域攻击操作过程比较简单,就是如果你不采取任何限制的时候,对 POST 相对风险系数比较高的访问,用户可以伪造请求,然后对服务器进行攻击和修改。比如说通过伪造 POST 请求,然后能够将用户的数据删除。

参考: Spring security CSRF 跨域访问限制问题 - 知乎 (zhihu.com)

我们只需要禁用CSRF就可以了。http.csrf().disable();

@EnableWebSecurity
public class MySecurityConfig extends WebSecurityConfigurerAdapter {/*** 定制请求的授权规则** @param http the {@link HttpSecurity} to modify* @throws Exception*/@Overrideprotected void configure(HttpSecurity http) throws Exception {http.authorizeRequests().antMatchers("/").permitAll()// VIP1角色的用户才能访问level1的页面,其他同理.antMatchers("/level1/**").hasRole("VIP1").antMatchers("/level2/**").hasRole("VIP2").antMatchers("/level3/**").hasRole("VIP3");// 开启自动配置的登录功能
//        http.formLogin();http.formLogin().usernameParameter("uname").passwordParameter("pwd").loginPage("/userlogin").loginProcessingUrl("/userlogin");// 1. 如果没有访问权限,转发到/login请求来到登录页;// 2. 重定向到/login?error表示登录失败。 更多详细规定// 3. 默认post形式的/login代表处理登录提交// 4.如果定制loginPage,那么loginPage的post请求就是登录提交// 开启自动配置的注销功能, 访问/logout表示用户注销,清空session; 注销成功后来到首页;http.logout().logoutSuccessUrl("/");// 开启记住我的功能, 将cookie发给浏览器保存,以后登录带上这个cookie,只要通过服务器端的验证就可以免登录// 如果点击”注销“,也会删除这个cookie
//        http.rememberMe();http.rememberMe().rememberMeParameter("remember");// 禁用csrfhttp.csrf().disable();}/*** 定制认证规则** @param auth the {@link AuthenticationManagerBuilder} to use* @throws Exception*/@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().withUser("zhangsan").password("123456").roles("VIP1", "VIP2").and().withUser("lisi").password("123456").roles("VIP2", "VIP3").and().withUser("wangwu").password("123456").roles("VIP1", "VIP3");}
}

再次访问,应用被关闭。使用 curl -X POST http://localhost:8080/shutdown 也可以。

{"message": "Shutting down, bye..."
}

3. 定制端点信息

  • 定制端点一般通过endpoints + 端点名 + 属性名来设置;
  • 修改端点id (endpoints.beans.id=mybeans);
  • 开启远程应用关闭功能 (endpoints.shutdown.enabled=true);
  • 关闭端点(endpoints.beans.enabled=false);
  • 开启所需端点
    • endpoints.enabled=false;
    • endpoints.beans.enabled=true;
  • 定制端点访问路径 management.context-path=/manage;
  • 关闭http端点 management.port=-1;
management.security.enabled=false
info.app.id=springboot-security
info..app.version=1.0
#endpoints.metrics.enabled=false
#endpoints.autoconfig.enabled=false
endpoints.shutdown.enabled=true
# http://localhost:8080/bean
endpoints.beans.id=mybean
endpoints.beans.path=/bean
# http://localhost:8080/du
endpoints.dump.path=/du
# 关闭所有端点访问
endpoints.enabled=false
# 开启指定端点访问
endpoints.beans.enabled=true
# 所有端点访问根路径 http://localhost:8080/manage/bean
management.context-path=/manage
# 所有端点访问端口 http://localhost:8181/manage/bean
management.port=8181

4. 健康状态监控

开放health端点访问

endpoints.health.enabled=true

http://localhost:8181/manage/health 响应:

{status: "UP",diskSpace: {status: "UP",total: 362095308800,free: 336869535744,threshold: 10485760}
}

现在来模拟服务失败的场景,比如引入redis依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

然后配置reids主机地址

# redis
spring.redis.host=192.168.111.129

因为我虚拟机上的redis服务没有启动,应用是无法连接redis的。我们来查看health端点状态:

http://localhost:8181/manage/health

{status: "DOWN",diskSpace: {status: "UP",total: 362095308800,free: 336868065280,threshold: 10485760
},
redis: {status: "DOWN",error: "org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"}
}

启动远程redis服务后,再次查看health端点, 其实是RedisHealthIndicator提供了监控支持。

{status: "UP",diskSpace: {status: "UP",total: 362095308800,free: 335793897472,threshold: 10485760
},
redis: {status: "UP",version: "6.2.6"}
}

5. 自定义健康状态指示器

编写一个指示器,实现HealthIndicator接口

@Component
public class MyAppHealthIndicator implements HealthIndicator {@Overridepublic Health health() {
//        Health.up().build()  成功// 自定义检查,直接返回失败return Health.down().withDetail("msg", "服务异常").build();}
}

启动应用后,查看健康端点

http://localhost:8181/manage/health

{status: "DOWN",myApp: {status: "DOWN",msg: "服务异常"
},
diskSpace: {status: "UP",total: 362095308800,free: 335793758208,threshold: 10485760
},
redis: {status: "UP",version: "6.2.6"}
}
http://www.yayakq.cn/news/101758/

相关文章:

  • 网站备案和域名备案中国建设信息
  • 建设外汇网站宿迁网站建设流程
  • 做网站和做推广的区别网站建设技术开发
  • 西宁网站建设最好的公司网站开发和网页上传的说法
  • iis 配置网站详解品牌营销策略研究
  • wordpress模板 门户网站河北省住房和城乡建设厅官网
  • 郑州网页网站制作wordpress萨隆设置
  • 网站建设好以后怎么管理网页制作学什么
  • 提供邯郸做移动网站做宣传册的公司
  • 做废钢那个网站好网站服务器租赁费用
  • 深圳微信网站运营网络营销与策划书
  • 简单网站开发实例总结电脑网站兼职在哪里做
  • 苍南县规划建设局网站南宁做网站费用
  • 石家庄网站建设时光wordpress 地理位置签到
  • 用ps怎么做网站背景台州企业网站搭建价格
  • 专题网站建设意义何在网站开发简单的框架
  • 建立网站专业公司婚庆网站哪个网站好
  • 展示型网页设计公司seo建站外贸
  • 娱乐网站建设公司排名qq代刷网站推广免费
  • mmd怎么做下载网站做竞价可以让网站提高快速排名吗
  • 卖链接的网站邢台太行中学简介
  • 正版厦门网站设计公司saas平台是什么意思
  • 合肥建设发展局网站仿系统之家网站源码
  • 李尚荣网站建设常德网站设计字答科技
  • 俄罗斯门户网站有哪些网站建设的说明
  • 顺义区做网站的公司装修3d效果图怎么制作
  • 做网站后端要什么技术福州微信公众号开发
  • 局网站建设工作总结泰安网站建设公司
  • 怎样用云服务器做网站群晖wordpress站点地址
  • 网站月流量是什么意思seo外包网络公司