Smartbi V11版本支持前后端分离部署。
本文档主要是使用nginx的缓存(proxy_cache)功能,把静态资源缓存到nginx服务器,提升smartbi的性能。
前后端分离部署简化模式架构图
如上图,使用nginx,即做负载均衡,也做缓存服务器。
外部网络的客户端,通过nginx,把请求转发到内网的smartbi的服务器,smartbi响应请求后,由nginx先缓存静态资源,然后再返回给到外部网络的客户端。后续客户端访问smartbi的资源,静态资源会优先从nginx获取,降低内部网络smartbi节点的资源消耗。
部署说明
后端服务器部署
后端smartbi服务器部署,可以参考通用的smartbi部署文档操作。安装Smartbi(tomcat中间件)
需要配置知识库连接,license文件等。
如果项目有扩展包,也要在后端服务器部署。
其他的数据库的驱动,字体文件等,都只在后端服务器上更新。
前端服务器部署
只需要部署nginx,具体配置可以参考下一个章节(nginx配置)。
nginx配置
前端的nginx,除了配置转发smartbi的请求,还需要配置为静态资源缓存服务器。
nginx配置注意事项
1、nginx的匹配规则是从上到下的,所以以下规则顺序不能颠倒。
2、如果后端服务器有多个smartbi节点,则upstream需要配置会话保持功能。
3、如果使用nginx的check模块进行健康检测,必须使用/smartbi/vision/healthcheck.jsp 接口。
##设置nginx的proxy的缓存路径 proxy_cache_path /usr/local/nginx/smartbi_cache levels=1:2 keys_zone=smartbi_cache:10m max_size=10g inactive=60m; ## proxy_cache_path 指定缓存文件目录,启动nginx的用户,需要对这个目录有读写权限。 ## levels 缓存的层次结构,每层可以用1(最多16中选择,0-f)或2(最多256种选择,00-ff)表示,中间用 [冒号] 分隔。levels=1:2 表示开启1、2层级(第2层级理论有16*256个目录)。 ## keys_zone 指定一个共享内存空间,所有活动的键和缓存数据相关的信息都被存放在共享内存中,这样nginx可以快速判断一个request是否命中或者未命中缓存,1m可以存储8000个key,10m可以存储80000个key; ## max_size 缓存使用的最大磁盘空间。如果不指定,会用掉所有磁盘空间,当缓存超过超max_size配置,将会基于LRU算法移除旧数据,以减少缓存占用空间。 ## inactive inactive=60m 表示 60 分钟没有被访问的文件会被清理,inactive的默认值是10分钟。 upstream smartbi-all { server 10.10.204.100:18080; server 10.10.204.101:18080; ##会话保持配置,nginx默认不带这个功能,需要自行编译才能使用。 ##不同的sticky模块,配置可能不同。需要参考具体的sticky模块配置说明。 ##以下是tengine的会话保持配置示例 sticky cookie=smartbi_cookie fallback=on path=/smartbi mode=insert option=indirect; ##健康检测配置。nginx默认不带这个功能,需要自行编译才能使用。 ##不同的check模块,配置可能不同。需要参考具体的check模块的配置说明。 ##以下是tengine的健康检测配置示例 check interval=3000 rise=2 fall=5 timeout=1000 type=http; ## 可以使用以下的配置进行smartbi的健康检测。其中xxxx需要换为访问的smartbi的ip或域名。 check_http_send "HEAD /smartbi/vision/healthcheck.jsp HTTP/1.0\r\nHost: xxxx\r\n\r\n"; check_http_expect_alive http_2xx http_3xx; } server { listen 8088; server_name 10.10.204.150; location = /smartbi/vision/gbk.jsp { proxy_cache smartbi_cache; ## 默认缓存200,301,302的数据,缓存有效期1小时,可以根据实际需要,配置缓存有效期时间。 proxy_cache_valid 1h; proxy_pass http://smartbi-all; } location ~ /smartbi/app/.* { proxy_cache smartbi_cache; proxy_cache_valid 1h; proxy_pass http://smartbi-all; } location ~ /smartbi/vision/ssreport/htmls/.* { proxy_pass http://smartbi-all; } location ~ /smartbi/vision/aichat/proxy/.* { proxy_pass http://smartbi-all; } location ~ /smartbi/vision/officehtmls/.* { proxy_pass http://smartbi-all; } location ~ /smartbi/vision/.*(\.bmp|\.css|\.cur|\.db|\.eot|\.gif|\.GIF|\.htm|\.html|\.ico|\.jpg|\.JPG|\.js|\.json|\.map|\.otf|\.patch|\.png|\.PNG|\.svg|\.swf|\.template|\.ts|\.ttf|\.ttfx|\.txt|\.woff|\.woff2|\.xls|\.xml|\.yml)$ { proxy_cache smartbi_cache; proxy_cache_valid 1h; proxy_pass http://smartbi-all; } location ~ /smartbi/smartbix/min/.* { proxy_cache smartbi_cache; proxy_cache_valid 1h; proxy_pass http://smartbi-all; } location ~ /smartbi/smartbix/static/.* { proxy_cache smartbi_cache; proxy_cache_valid 1h; proxy_pass http://smartbi-all; } location ~ /smartbi/.* { proxy_pass http://smartbi-all; } }
测试验证
部署完成后,可以查看后端服务器的tomcat/logs/localhost_access_log的文件,查看请求分发是否正常。
第一次请求会到smartbi后端服务器,第二次请求就会到nginx获取静态资源。
请求类型 | 请求接口 |
---|---|
静态请求 | /smartbi/vision/gbk.jsp /smartbi/app/.* /smartbi/vision/.*(\.bmp|\.css|\.cur|\.db|\.eot|\.gif|\.GIF|\.htm|\.html|\.ico|\.jpg|\.JPG|\.js|\.json|\.map|\.otf|\.patch|\.png|\.PNG|\.svg|\.swf|\.template|\.ts|\.ttf|\.ttfx|\.txt|\.woff|\.woff2|\.xls|\.xml|\.yml) /smartbi/smartbix/min/.* /smartbi/smartbix/static/.* |
动态请求 | 除去以上的静态请求,剩下的都是动态请求。 |
清除缓存
如果smartbi进行版本更新,建议清理nginx中的缓存数据。
## 删除缓存数据目录,具体路径在nginx.conf 的proxy_cache_path 参数中配置。 rm -rf /usr/local/nginx/smartbi_cache/* ## 重新启动nginx ./nginx -s reload