首先需要下载kkFileView至自己指定的目录,并解压,此服务文件位置需要记住,后面会对其中的配置做修改:
tar -xzvf kkFileView-4.0.0.tar.gz
安装7.2.2版本的LibreOffice
cd /opt
#下载
wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/7.2.2/rpm/x86_64/LibreOffice_7.2.2_Linux_x86-64_rpm.tar.gz
wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/7.2.2/rpm/x86_64/LibreOffice_7.2.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
# 解压
tar xzvf LibreOffice_7.2.2_Linux_x86-64_rpm.tar.gz
tar xzvf LibreOffice_7.2.2_Linux_x86-64_rpm_langpack_zh-CN.tar.gz
yum install /opt/LibreOffice_7.2.2_Linux_x86-64_rpm/RPMS/*.rpm
yum install /opt/LibreOffice_7.2.2_Linux_x86-64_rpm_langpack_zh-CN/RPMS/*.rpm
检查有没有进程正在运行LibreOffice,有就杀掉进程
ps -ef|grep libreoffice
配置nginx请求转发,比如我只开放了一个8381端口,所有向8381端口后file-view这一路由的请求全部转发至kkFileView
server {
listen 8381;
location /file-view {
proxy_pass http://localhost:8012;
}
}
再在刚刚解压的kkFileView目录中找到config与bin文件夹
cd config
vi application.properties
更改application.properties中的三项配置
server.servlet.context-path= /file-view
office.home = /opt/libreoffice7.2
base.url = http://项目ip:端口/file-view
cd ../bin
#执行
./startup.sh
#第一次执行完毕后建议再执行查看日志脚本
./showlog.sh
[root@localhost bin]# ./showlog.sh
_ _ ______ _ _ __ __ _
| | | | | ____| (_) | | \ \ / / (_)
| | __ | | __ | |__ _ | | ___ \ \ / / _ ___ __ __
| |/ / | |/ / | __| | | | | / _ \ \ \/ / | | / _ \ \ \ /\ / /
| < | < | | | | | | | __/ \ / | | | __/ \ V V /
|_|\_\ |_|\_\ |_| |_| |_| \___| \/ |_| \___| \_/\_/
=> Spring Boot :: (v2.4.2) QQ1 :: 613025121
=> kkFileView :: (v4.0.0) QQ2 :: 484680571
=> github :: https://github.com/kekingcn/kkFileView
=> gitee :: https://gitee.com/kekingcn/file-online-preview
2021-11-20 11:44:06.661 INFO 41979 --- [ main] org.eclipse.jetty.util.log : Logging initialized @4962ms to org.eclipse.jetty.util.log.Slf4jLog
2021-11-20 11:44:07.092 INFO 41979 --- [ main] o.s.b.w.e.j.JettyServletWebServerFactory : Server initialized with port: 8012
2021-11-20 11:44:07.101 INFO 41979 --- [ main] org.eclipse.jetty.server.Server : jetty-9.4.35.v20201120; built: 2020-11-20T21:17:03.964Z; git: bdc54f03a5e0a7e280fab27f55c3c75ee8da89fb; jvm 1.8.0_282-b08
2021-11-20 11:44:07.191 INFO 41979 --- [ main] o.e.j.s.h.ContextHandler.application : Initializing Spring embedded WebApplicationContext
2021-11-20 11:44:07.192 INFO 41979 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2806 ms
2021-11-20 11:44:07.594 INFO 41979 --- [ main] org.eclipse.jetty.server.session : DefaultSessionIdManager workerName=node0
2021-11-20 11:44:07.595 INFO 41979 --- [ main] org.eclipse.jetty.server.session : No SessionScavenger set, using defaults
2021-11-20 11:44:07.599 INFO 41979 --- [ main] org.eclipse.jetty.server.session : node0 Scavenging every 600000ms
2021-11-20 11:44:07.627 INFO 41979 --- [ main] o.e.jetty.server.handler.ContextHandler : Started o.s.b.w.e.j.JettyEmbeddedWebAppContext@74e52303{application,/file-view,[file:///tmp/jetty-docbase.8012.5985362194341337627/],AVAILABLE}
2021-11-20 11:44:07.629 INFO 41979 --- [ main] org.eclipse.jetty.server.Server : Started @5935ms
2021-11-20 11:44:07.647 INFO 41979 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation is not supported on static methods: public static void cn.keking.config.ConfigConstants.setFileUploadDisable(java.lang.Boolean)
2021-11-20 11:44:07.901 INFO 41979 --- [ main] cn.keking.service.FileConvertQueueTask : 队列处理文件转换任务启动完成
2021-11-20 11:44:08.097 INFO 41979 --- [ main] o.a.j.office.ProcessPoolOfficeManager : ProcessManager implementation is LinuxProcessManager
2021-11-20 11:44:08.162 INFO 41979 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1' and profileDir '/tmp/.jodconverter_socket_host-127.0.0.1_port-2001'
2021-11-20 11:44:08.216 INFO 41979 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : started process; pid = 42030
2021-11-20 11:44:09.085 WARN 41979 --- [ProcessThread-0] o.a.j.office.ManagedOfficeProcess : office process died with exit code 81; restarting it
2021-11-20 11:44:09.139 INFO 41979 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1' and profileDir '/tmp/.jodconverter_socket_host-127.0.0.1_port-2001'
2021-11-20 11:44:09.191 INFO 41979 --- [ProcessThread-0] o.a.jodconverter.office.OfficeProcess : started process; pid = 42039
2021-11-20 11:44:09.851 INFO 41979 --- [ProcessThread-0] o.a.j.office.OfficeConnection : connected: 'socket,host=127.0.0.1,port=2001,tcpNoDelay=1'
2021-11-20 11:44:09.992 INFO 41979 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir '/tmp/.jodconverter_socket_host-127.0.0.1_port-2002'
2021-11-20 11:44:10.056 INFO 41979 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : started process; pid = 42092
2021-11-20 11:44:10.817 WARN 41979 --- [ProcessThread-1] o.a.j.office.ManagedOfficeProcess : office process died with exit code 81; restarting it
2021-11-20 11:44:10.866 INFO 41979 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : starting process with acceptString 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1' and profileDir '/tmp/.jodconverter_socket_host-127.0.0.1_port-2002'
2021-11-20 11:44:10.918 INFO 41979 --- [ProcessThread-1] o.a.jodconverter.office.OfficeProcess : started process; pid = 42102
2021-11-20 11:44:11.452 INFO 41979 --- [ProcessThread-1] o.a.j.office.OfficeConnection : connected: 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1'
2021-11-20 11:44:12.179 INFO 41979 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-11-20 11:44:12.436 INFO 41979 --- [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2021-11-20 11:44:12.470 INFO 41979 --- [ main] cn.keking.config.WebConfig : Add resource locations: /home/daqisuo/data/file-view/kkFileView-4.0.0/file/
2021-11-20 11:44:13.111 INFO 41979 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2021-11-20 11:44:13.169 INFO 41979 --- [ main] o.e.j.s.h.ContextHandler.application : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-11-20 11:44:13.169 INFO 41979 --- [ main] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2021-11-20 11:44:13.172 INFO 41979 --- [ main] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms
2021-11-20 11:44:13.220 INFO 41979 --- [ main] o.e.jetty.server.AbstractConnector : Started ServerConnector@6fe7aac8{HTTP/1.1, (http/1.1)}{0.0.0.0:8012}
2021-11-20 11:44:13.223 INFO 41979 --- [ main] o.s.b.web.embedded.jetty.JettyWebServer : Jetty started on port(s) 8012 (http/1.1) with context path '/file-view'
2021-11-20 11:44:13.275 INFO 41979 --- [ main] cn.keking.ServerMain : kkFileView 服务启动完成,耗时:10.603732337s,演示页请访问: http://127.0.0.1:8012
查看访http://项目ip:端口/file-view/index是否能进入index页面
到此就配置完毕了,在vue中使用3.0以上版本时需要在packaje.json引入"js-base64": "3.7.2"
在需要使用预览功能的组件中import { Base64 } from 'js-base64';
并在methods中定义:
previewFile(url) {
window.open('http://项目ip:端口/file-view/onlinePreview?url=' + encodeURIComponent(Base64.encode(url)));
},