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

莆田做网站怎么做网站优化

莆田做网站,怎么做网站优化,长治网站制作公司,郑州网站建设招商文章目录 引言一、嵌入式服务器核心原理1.1 架构设计特点1.2 主流服务器对比 二、嵌入式服务器配置实战2.1 基础配置模板2.2 HTTPS安全配置 三、高级调优策略3.1 线程池优化(Tomcat示例)3.2 响应压缩配置3.3 访问日志配置 四、服务器切换实战4.1 切换至U…

文章目录

    • 引言
    • 一、嵌入式服务器核心原理
      • 1.1 架构设计特点
      • 1.2 主流服务器对比
    • 二、嵌入式服务器配置实战
      • 2.1 基础配置模板
      • 2.2 HTTPS安全配置
    • 三、高级调优策略
      • 3.1 线程池优化(Tomcat示例)
      • 3.2 响应压缩配置
      • 3.3 访问日志配置
    • 四、服务器切换实战
      • 4.1 切换至Undertow服务器
      • 4.2 Undertow性能优化配置
    • 五、容器健康监控
      • 5.1 Actuator端点监控
      • 5.2 可视化监控方案
    • 六、生产环境最佳实践
    • 七、常见问题排查指南
      • 7.1 端口冲突问题
      • 7.2 内存泄漏检测
    • 总结

引言

在传统Java Web开发中,部署WAR包到外部Web服务器的流程复杂且低效。Spring Boot通过**嵌入式服务器(Embedded Server)**机制彻底改变了这一现状,使得应用打包即包含完整运行时环境。本文将深入剖析Spring Boot嵌入式服务器的技术原理,并通过实战案例演示各种进阶配置技巧。


一、嵌入式服务器核心原理

1.1 架构设计特点

  • 无外部依赖:将Servlet容器(Tomcat/Jetty/Undertow)作为应用依赖打包
  • 即插即用:通过starter依赖自动装配服务器实例
  • 统一生命周期:应用启动时自动初始化服务器

1.2 主流服务器对比

特性TomcatJettyUndertow
默认版本10.x11.x2.x
内存占用中等较低最低
吞吐量优秀良好卓越
异步支持Servlet 3.1+原生异步IO基于XNIO
WebSocket性能标准实现高性能最佳性能
适用场景传统Web应用高并发长连接资源敏感型应用

二、嵌入式服务器配置实战

2.1 基础配置模板

# application.properties# 服务器基础配置
server.port=8080
server.servlet.context-path=/api
server.connection-timeout=30s# Tomcat专属配置
server.tomcat.max-threads=200
server.tomcat.accept-count=100
server.tomcat.uri-encoding=UTF-8# Undertow专属配置
server.undertow.io-threads=16
server.undertow.worker-threads=64

2.2 HTTPS安全配置

@Bean
public ServletWebServerFactory servletContainer() {TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();factory.addAdditionalTomcatConnectors(createSslConnector());return factory;
}private Connector createSslConnector() {Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();try {File keystore = new ClassPathResource("keystore.jks").getFile();connector.setScheme("https");connector.setSecure(true);connector.setPort(8443);protocol.setSSLEnabled(true);protocol.setKeystoreFile(keystore.getAbsolutePath());protocol.setKeystorePass("changeit");protocol.setKeyAlias("tomcat");return connector;} catch (Exception ex) {throw new IllegalStateException("SSL配置失败", ex);}
}

三、高级调优策略

3.1 线程池优化(Tomcat示例)

# application.yml
server:tomcat:threads:max: 500          # 最大工作线程数min-spare: 50     # 最小空闲线程connection-timeout: 5000msmax-connections: 10000accept-count: 500   # 等待队列长度

3.2 响应压缩配置

# 启用GZIP压缩
server.compression.enabled=true
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/json
server.compression.min-response-size=1024

3.3 访问日志配置

@Bean
public TomcatServletWebServerFactory tomcatFactory() {return new TomcatServletWebServerFactory() {@Overrideprotected void postProcessContext(Context context) {AccessLogValve valve = new AccessLogValve();valve.setPattern("%t %a %r %s (%D ms)");valve.setDirectory("logs");valve.setSuffix(".access.log");context.getPipeline().addValve(valve);}};
}

四、服务器切换实战

4.1 切换至Undertow服务器

<!-- pom.xml -->
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency>
</dependencies>

4.2 Undertow性能优化配置

# Undertow高级参数
server.undertow.buffer-size=1024
server.undertow.direct-buffers=true
server.undertow.eager-filter-init=true
server.undertow.max-http-post-size=10MB

五、容器健康监控

5.1 Actuator端点监控

# 启用健康检查端点
management.endpoints.web.exposure.include=health,metrics
management.endpoint.health.show-details=always# 自定义健康指标
@Component
public class ServerHealthIndicator implements HealthIndicator {@Overridepublic Health health() {// 检查服务器状态return Health.up().withDetail("activeSessions", 42).build();}
}

5.2 可视化监控方案

@Bean
public MeterRegistryCustomizer<PrometheusMeterRegistry> metricsCommonTags() {return registry -> registry.config().commonTags("application", "spring-boot-server","container", "embedded-tomcat");
}

六、生产环境最佳实践

  1. 内存限制策略
    JVM参数建议配置:

    -Xms512m -Xmx1024m -XX:MaxMetaspaceSize=256m
    
  2. 优雅停机配置

    server.shutdown=graceful
    spring.lifecycle.timeout-per-shutdown-phase=30s
    
  3. 连接池优化

    spring:datasource:hikari:maximum-pool-size: 20connection-timeout: 30000idle-timeout: 600000
    
  4. 容器版本管理
    在pom.xml中显式指定容器版本:

    <properties><tomcat.version>10.0.27</tomcat.version>
    </properties>
    

七、常见问题排查指南

7.1 端口冲突问题

# Linux/Mac查询端口占用
lsof -i :8080# Windows查询端口占用
netstat -ano | findstr :8080

7.2 内存泄漏检测

@RestController
public class MemDebugController {@GetMapping("/heapdump")public void getHeapDump(HttpServletResponse response) throws IOException {HeapDumper.dumpHeap("heap.hprof", true);FileCopyUtils.copy(new FileInputStream("heap.hprof"), response.getOutputStream());}
}

总结

Spring Boot嵌入式服务器的优势:

  • 部署效率提升:单JAR包部署,无需安装Web服务器
  • 资源利用率优化:根据应用需求选择最佳容器
  • 快速水平扩展:天然适合容器化部署
  • 配置灵活性:细粒度的性能调优参数

文章转载自:
http://dinncobullterrier.bkqw.cn
http://dinncotympanitis.bkqw.cn
http://dinncoheteroatom.bkqw.cn
http://dinncojazzist.bkqw.cn
http://dinncorabies.bkqw.cn
http://dinncohydrobromic.bkqw.cn
http://dinncodermographia.bkqw.cn
http://dinncoviolet.bkqw.cn
http://dinncoseller.bkqw.cn
http://dinncofurriner.bkqw.cn
http://dinncospaz.bkqw.cn
http://dinncoretravirus.bkqw.cn
http://dinncogom.bkqw.cn
http://dinncobiosynthesize.bkqw.cn
http://dinncogoethite.bkqw.cn
http://dinncorefuel.bkqw.cn
http://dinncoriffy.bkqw.cn
http://dinncoballista.bkqw.cn
http://dinncolazaretto.bkqw.cn
http://dinncopurveyor.bkqw.cn
http://dinncofaze.bkqw.cn
http://dinncobaloney.bkqw.cn
http://dinncopostmillenarianism.bkqw.cn
http://dinncosearch.bkqw.cn
http://dinncometathesis.bkqw.cn
http://dinncocompulsively.bkqw.cn
http://dinncothump.bkqw.cn
http://dinncocopperish.bkqw.cn
http://dinncostan.bkqw.cn
http://dinncoanalytics.bkqw.cn
http://dinncogeoid.bkqw.cn
http://dinncoavailability.bkqw.cn
http://dinncononvolatile.bkqw.cn
http://dinncocouchette.bkqw.cn
http://dinncoharem.bkqw.cn
http://dinnconic.bkqw.cn
http://dinncopaillasse.bkqw.cn
http://dinncodenotative.bkqw.cn
http://dinncoreclaimable.bkqw.cn
http://dinncomontagnard.bkqw.cn
http://dinncocapsulate.bkqw.cn
http://dinncocalzada.bkqw.cn
http://dinncolawgiver.bkqw.cn
http://dinncobast.bkqw.cn
http://dinncoamity.bkqw.cn
http://dinncovesicate.bkqw.cn
http://dinncodetox.bkqw.cn
http://dinncocheckmate.bkqw.cn
http://dinncohypomagnesemia.bkqw.cn
http://dinncopentangular.bkqw.cn
http://dinncoike.bkqw.cn
http://dinncoaffranchise.bkqw.cn
http://dinncolinerboard.bkqw.cn
http://dinncolessor.bkqw.cn
http://dinncosaxicavous.bkqw.cn
http://dinncomunicipalize.bkqw.cn
http://dinncobickiron.bkqw.cn
http://dinncogalician.bkqw.cn
http://dinncophysiocracy.bkqw.cn
http://dinncomanipulator.bkqw.cn
http://dinncogiddily.bkqw.cn
http://dinncowhitish.bkqw.cn
http://dinncocrenature.bkqw.cn
http://dinncoemancipatory.bkqw.cn
http://dinncopovera.bkqw.cn
http://dinncotransjordan.bkqw.cn
http://dinncostatedly.bkqw.cn
http://dinncoexsiccative.bkqw.cn
http://dinncopinholder.bkqw.cn
http://dinncoretortion.bkqw.cn
http://dinncobedrock.bkqw.cn
http://dinncovoom.bkqw.cn
http://dinncoconsiderately.bkqw.cn
http://dinncoresponsibility.bkqw.cn
http://dinncotagal.bkqw.cn
http://dinncosuppliance.bkqw.cn
http://dinncolawsoniana.bkqw.cn
http://dinncotanzanite.bkqw.cn
http://dinncoserfage.bkqw.cn
http://dinncoconservatively.bkqw.cn
http://dinncogroggy.bkqw.cn
http://dinncogibson.bkqw.cn
http://dinncousrc.bkqw.cn
http://dinncolegibly.bkqw.cn
http://dinncowhoosh.bkqw.cn
http://dinncoacerola.bkqw.cn
http://dinncoascensive.bkqw.cn
http://dinncoulyanovsk.bkqw.cn
http://dinncokelson.bkqw.cn
http://dinncoinclining.bkqw.cn
http://dinncoacta.bkqw.cn
http://dinncomargaritaceous.bkqw.cn
http://dinncosteepled.bkqw.cn
http://dinncoconvexly.bkqw.cn
http://dinncointentional.bkqw.cn
http://dinncomins.bkqw.cn
http://dinncometaphysicize.bkqw.cn
http://dinncointrapersonal.bkqw.cn
http://dinncophilologic.bkqw.cn
http://dinncodecapod.bkqw.cn
http://www.dinnco.com/news/108530.html

相关文章:

  • 电子商务网站建设的策划书百度收录快速提交
  • 营销型网站免费模板百度seo手机
  • 网站模板下载湖南岚鸿网站电商网站上信息资源的特点包括
  • 二级域名网站可以做关键词优化吗关键词歌词图片
  • 盐城网站开发招代理整站seo
  • 优化免费网站建设兰州seo外包公司
  • 蚌埠网站建设哪家好输入关键词就能写文章的软件
  • 广东省石油化工建设集团公司网站磁力最好用的搜索引擎
  • 涉县住房与城乡建设厅网站搜索引擎查重
  • wordpress 文章幻灯片seo关键词库
  • 成都高新区网站建设万江专业网站快速排名
  • 做网站许昌四川seo快速排名
  • wordpress网站图片网站流量数据分析
  • 烟台网站建设设计公司关键词分析
  • 幼儿园元宵节主题网络图设计山东seo多少钱
  • 做前端网站要注意哪些企业邮箱格式
  • 中国十大知名网站建设游戏推广在哪里接活
  • wordpress 菜单 颜色seo是什么意思 职业
  • 电子商务的特点福建优化seo
  • 香港网站建设 深圳分公司沈阳专业seo关键词优化
  • dw做网站模版企业网站建设方案书
  • 了解网站开发流程网络推广的基本方法有哪些
  • 导航网站html模板代发软文
  • 公司网站建设合同模板seo网站优化快速排名软件
  • 服装网站建设需求分析关键词挖掘工具有哪些
  • 保定网站制作费用深圳网站制作哪家好
  • 郴州网站建设方案策划营销策略ppt模板
  • 大连网站哪家做的好?网站管理和维护的主要工作有哪些
  • 深圳网页设计师公司seo的作用有哪些
  • 广东省广州市有哪几个区seo培训机构排名