1 基础知识
1.1 kkFileView的简介
– 文档在线预览项目解决方案基于Spring Boot框架构建
– 文档在线预览项目解决方案被称为万能的文件预览开源项目
– 文档在线预览项目解决方案支持主流的文档格式预览
1.2 kkFileView的特点
– 使用spring boot开发,预览服务搭建部署非常简便
– rest接口提供服务,跨平台特性(java,php,python,go,php,….)都支持,应用接入简单方便
– 支持普通http/https文件下载url、http/https文件下载流url、ftp下载url等多种预览源
– 提供zip,tar.gz发行包,提供一键启动脚本和丰富的配置项,方便部署使用
– 提供Docker镜像发行包,方便在容器环境部署
– 抽象预览服务接口,方便二次开发,非常方便添加其他类型文件预览支持
1.3 kkFileView支持的格式
– 支持doc, docx, xls, xlsx, xlsm, ppt, pptx, csv, tsv, dotm, xlt, xltm, dot, dotx,xlam, xla等Office 办公文档
– 支持wps, dps, et, ett, wpt等国产WPS Office办公文档
– 支持odt, ods, ots, odp, otp, six, ott, fodt, fods等OpenOffice、LibreOffice办公文档
– 支持vsd, vsdx等Visio流程图文件
– 支持wmf, emf等Windows 系统图像文件
– 支持psd等Photoshop 软件模型文件
– 支持pdf ,ofd, rtf等文档
– 支持xmind 软件模型文件
– 支持bpmn 工作流文件
– 支持eml 邮件文件
– 支持epub 图书文档
– 支持obj, 3ds, stl, ply, gltf, glb, off, 3dm, fbx, dae, wrl, 3mf, ifc, brep, step, iges, fcstd, bim等3D 模型文件
– 支持dwg, dxf等CAD 模型文件
– 支持txt, xml(渲染), md(渲染), java, php, py, js, css等所有纯文本
– 支持zip, rar, jar, tar, gzip, 7z等压缩包
– 支持jpg, jpeg, png, gif, bmp, ico, jfif, webp等图片预览(翻转,缩放,镜像)
– 支持tif, tiff 图信息模型文件
– 支持tga 图像格式文件
– 支持svg 矢量图像格式文件
– 支持mp3,wav,mp4,flv等音视频格式文件
– 支持avi,mov,rm,webm,ts,rm,mkv,mpeg,ogg,mpg,rmvb,wmv,3gp,ts,swf等视频格式转码预览
2 最佳实践
2.1 系统环境配置
2.1.1 主机信息
ip address = 192.168.0.51
hostname = kkfileview.cmdschool.org
2.1.2 关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
2.1.3 安装常用工具包
dnf install -y wget net-tools
2.2 软件环境配置
2.2.1 安装LibreOffice
dnf install -y libreoffice-*
2.2.2 创建运行账户
groupadd -g 890 kkfileview useradd -u 890 -g 890 -d /usr/kkfileview -s /sbin/nologin kkfileview -c "kkfileview user"
2.2.3 部署JDK环境
笔者部署完毕后,运行以下版本检查命令,
java -version
可见如下提示,
openjdk version "18.0.2" 2022-07-19 OpenJDK Runtime Environment (build 18.0.2+9-61) OpenJDK 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing)
2.2.4 部署Maven环境
笔者部署完毕后,运行以下版本检查命令,
mvn -v
可见如下提示,
Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9) Maven home: /opt/apache-maven-3.9.4 Java version: 18.0.2, vendor: Oracle Corporation, runtime: /usr/java/jdk-18.0.2 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-348.el8.x86_64", arch: "amd64", family: "unix"
2.3 编译打包kkfileview源代码
2.3.1 下载安装包
cd ~ wget https://codeload.github.com/kekingcn/kkFileView/tar.gz/refs/tags/v4.3.0 -O kkFileView-4.3.0.tar.gz
以上只是演示,如果你无法下载或需要其他版本,请从如下链接中下载,
https://github.com/kekingcn/kkFileView/releases
2.3.2 解压安装包
cd ~ tar -xf kkFileView-4.3.0.tar.gz
2.3.3 打包源代码
cd ~/kkFileView-4.3.0/server
使用如下命令确定打包配置文件存在,
ls pom.xml
使用如下命令打包,
mvn clean mvn package
如果遇到如下错误提示,
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.158 s -- in cn.keking.ServerMainTests LibreOffice 6.4 - Fatal Error: The application cannot be started. [context="shared"] caught unexpected com.sun.star.ucb.NameClashException: folder exists and overwrite forbidden [INFO] [INFO] Results: [INFO] [ERROR] Failures: [ERROR] WebUtilsTests.encodeUrlFullFileNameTestWithParams:30 [INFO] [ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 40:20 min [INFO] Finished at: 2023-09-03T22:17:45-04:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test (default-test) on project kkFileView: There are test failures. [ERROR] [ERROR] Please refer to /root/kkFileView-4.3.0/server/target/surefire-reports for the individual test results. [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
以上提示是测试错误,你可以选择使用如下命令忽略测试则可以跳过此错误,
mvn package -Dmaven.test.skip=true
如果看到如下信息,则打包成功,
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 57.517 s [INFO] Finished at: 2023-09-04T01:22:36-04:00 [INFO] ------------------------------------------------------------------------
另外,如果你懒得打包可以通过加入KK开源社区获取,该项目组需要定期收取一点入会费^_^,
https://public.zsxq.com/groups/48844125114258.html
2.4 部署和配置kkFileView
2.4.1 创建软件目录
mkdir -p /usr/kkfileview mkdir -p /etc/kkfileview mkdir -p /var/log/kkfileview chown kkfileview:kkfileview /var/log/kkfileview chmod 770 -R /var/log/kkfileview
2.4.2 部署源代码
cd ~/kkFileView-4.3.0/server cp ./target/classes/application.properties /etc/kkfileview/ cp ./target/kkFileView-4.3.0.jar /usr/kkfileview/
2.4.3 测试服务启动
cd /usr/kkfileview sudo -u kkfileview /usr/java/jdk-18.0.2/bin/java -jar /usr/kkfileview/kkFileView-4.3.0.jar -Dspring.config.location=/etc/kkfileview/application.properties
以上按下【Ctrl + C】可以手动结束程序,服务启动后,你可以使用如下命令查看服务启动的进程,
pgrep -u kkfileview java -a
可见如下显示,
1708 /usr/java/jdk-18.0.2/bin/java -jar /usr/kkfileview/kkFileView-4.3.0.jar -Dspring.config.location=/etc/kkfileview/application.properties
然后,你可以使用如下命令查看服务启动的倾听端口,
netstat -antp | grep `pgrep -u kkfileview java`
可见如下显示,
tcp6 0 0 :::8012 :::* LISTEN 1708/java tcp6 0 0 127.0.0.1:42946 127.0.0.1:2002 ESTABLISHED 1708/java tcp6 0 0 127.0.0.1:36516 127.0.0.1:2001 ESTABLISHED 1708/java
根据倾听端口,你需要使用如下命令打开防火墙,
firewall-cmd --permanent --add-port 8012/tcp firewall-cmd --reload firewall-cmd --list-all
2.4.4 创建服务脚本
vim /etc/systemd/system/kkfileview.service
加入如下脚本,
[Unit] Description=kkfileview Documentation=https://github.com/kekingcn/kkFileView After=syslog.target After=network.target [Service] WorkingDirectory=/usr/kkfileview ExecStart=/usr/java/jdk-18.0.2/bin/java -jar /usr/kkfileview/kkFileView-4.3.0.jar -Dspring.config.location=/etc/kkfileview/application.properties User=kkfileview Type=simple StandardOutput=file:/var/log/kkfileview/kkfileview.log StandardError=file:/var/log/kkfileview/kkfileview.log SuccessExitStatus=143 TimeoutStopSec=120 Restart=always [Install] WantedBy=multi-user.target
文件创建后,我们需要使用如下命令重载使服务生效,
systemctl daemon-reload
2.4.5 尝试启动服务
systemctl start kkfileview.service systemctl stop kkfileview.service systemctl restart kkfileview.service systemctl status kkfileview.service
然后,你还需要使用如下命令设置服务默认启动
systemctl enable kkfileview.service
2.5 测试kkFileView服务
http://192.168.0.51:8012/
如上图所示,
输入Work文档地址,范例为“https://www.cctv.com/download/teleplayvip/smygdxyfjgg.doc”
单击【预览】
窗口显示如下,
参阅文档
==================
官方主页
—————
https://kkview.cn/
kkview的github
——————
https://github.com/kekingcn/kkFileView
spring boot打包的方法
——————–
https://blog.miniasp.com/post/2022/09/19/Spring-Boot-Quick-Start-From-Scratch
https://stackoverflow.com/questions/3365553/how-to-build-a-jar-using-maven-ignoring-test-results
没有评论