1.安装介质与顺序
vcredist_x86.exe
vcredist_x64.exe
otp_win64_20.0.exe
node-v6.11.3-x64.msi
python-2.7.6.msi
node-v6.11.3-x64.msi
Redis-x64-3.2.100.msi
rabbitmq-server-3.6.11.exe
onlyoffice-documentserver5.0.4.exe
mysql-installer-community-5.7.19.0.msi
SQLyog.Ultimate.v8.2
检查redis安装是否成功:
进入Redis的目录,cd C:\Program Files\Redis。输入redis-cli并回车
显示正确端口号,则表示服务已经启动。
检查rabbitMQ安装是否成功:
配置环境变量:
ERLANG_HOME C:\Program Files\erl9.0
PATH %ERLANG_HOME%\bin
RABBITMQ_SERVER C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.11
PATH %RABBITMQ_SERVER%\sbin
以管理员身份运行cmd.exe,进入目录C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.11\sbin(RabbitMQ Server安装目录),运行cmd命令:rabbitmq-plugins.bat enable rabbitmq_management
运行命令:net stop RabbitMQ && net start RabbitMQ
浏览器输入地址:http://localhost:15672,输入默认账号:guest 密码:guest,就能进入RabbitMQ界面了
出现 z:\.erlang.cookie创建失败 请同步Erlang Cookies
操作:将 C:\WINDOWS\.erlang.cookie 拷贝到 C:\Users\%USERNAME%\.erlang.cookie ,用%USERNAME%账号登陆 重启rabbitMQ
2.配置修改
C:\ONLYOFFICE\DocumentServer\config\production-windows.json 添加mysql数据库配置
"utils": {
"utils_common_fontdir": "C:\\Windows\\Fonts"
},
"sql": {
"type": "mysql",
"dbHost": "127.0.0.1",
"dbPort": 3306,
"dbUser": "root",
"dbPass": "123456"
}
3.创建数据库
SQLyog.Ultimate.v8.2 连接mysql(root 123456 安装mysql时自己设置的密码),创建onlyoffice,并执行以下建表语句
CREATE TABLE `task_result` (
`id` varchar(255) NOT NULL,
`status` tinyint(3) NOT NULL,
`status_info` int(10) NOT NULL,
`last_open_date` datetime NOT NULL,
`user_index` int(10) unsigned NOT NULL DEFAULT '1',
`change_id` int(10) unsigned NOT NULL DEFAULT '0',
`callback` text NOT NULL,
`baseurl` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `doc_changes` (
`id` varchar(255) NOT NULL,
`change_id` int(10) unsigned NOT NULL,
`user_id` varchar(255) NOT NULL,
`user_id_original` varchar(255) NOT NULL,
`user_name` varchar(255) NOT NULL,
`change_data` longtext NOT NULL,
`change_date` datetime NOT NULL,
PRIMARY KEY (`id`,`change_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4.运行服务
运行C:\ONLYOFFICE\DocumentServer\bin\documentserver-generate-allfonts.bat 生成字体
重启onlyoffice服务
ONLYOFFICE DocumentServer Converter Service
ONLYOFFICE DocumentServer DocService Service
ONLYOFFICE DocumentServer Gc Service
ONLYOFFICE DocumentServer Proxy Service
ONLYOFFICE DocumentServer Spellchecker Service
访问应用
http://localhost/welcome/ 会出现以下页面
注:
缓存路径
C:\ONLYOFFICE\DocumentServer\server\App_Data\cache\files
乱码修改文件(预览出现乱码时将对应字体后的数字改成与非乱码字体一致,直接改AllFonts.js字体 对应数组,注意清理浏览器缓存)
C:\ONLYOFFICE\DocumentServer\sdkjs\common\AllFonts.js
具体调用代码:<%
String erro=null;
String fileId=null;
Attachment attachment=null;
String documentType=null;
String fileType=null;
FileItem fileItem=null;
try{
fileId=request.getParameter("fileId");
if(fileId!=null){
AttachmentService attachmentService=SpringUtil.getBean(AttachmentService.BEAN_ID);
attachment=(Attachment)attachmentService.get(Attachment.class, Long.parseLong(fileId));
if(attachment==null){
throw new BusinessException("错误的fileId:"+fileId);
}
String fileName=attachment.getFileName();
fileType=FileUtils.getFileType(fileName).toLowerCase();
if("docx".equals(fileType)||"doc".equals(fileType)
||"odt".equals(fileType)||"txt".equals(fileType)
||"rtf".equals(fileType)||"html".equals(fileType)
||"htm".equals(fileType)||"mht".equals(fileType)
||"epub".equals(fileType)||"pdf".equals(fileType)
||"djvu".equals(fileType)||"xps".equals(fileType)){
documentType="text";
}else if("xlsx".equals(fileType)||"xls".equals(fileType)
||"ods".equals(fileType)||"csv".equals(fileType)
||"xlsb".equals(fileType)||"xlsm".equals(fileType)){
documentType="spreadsheet";
}else if("pptx".equals(fileType)||"ppt".equals(fileType)
||"odp".equals(fileType)||"ppsx".equals(fileType)
||"pps".equals(fileType)){
documentType="presentation";
}else{
throw new BusinessException("不支持的文件类型");
}
}else{
throw new BusinessException("参数fileId和itemId不能为空");
}
}catch(Exception e){
erro="错误信息:"+e.getMessage();
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ONLYOFFICE</title>
<link rel="stylesheet" type="text/css" href="editor.css" />
<script type="text/javascript" src="http://localhost/web-apps/apps/api/documents/api.js"></script>
</head>
<body>
<div class="form">
<%if(erro==null){ %>
<div id="iframeEditor"></div>
<%}else{ %>
<%=erro %>
<%} %>
</div>
</body>
<%if(erro==null){ %>
<script type="text/javascript" language="javascript">
//document (.docx, .doc, .odt, .txt, .rtf, .html, .htm, .mht, .epub, .pdf, .djvu, .xps) for viewing or editing - text
//spreadsheet (.xlsx, .xls, .ods, .csv) for viewing or editing - spreadsheet,
//presentation (.pptx, .ppt, .odp, .ppsx, .pps) for viewing or editing - presentation.
new DocsAPI.DocEditor(
"iframeEditor",
{
width : "100%",
height : "100%",
document : {
"fileType" : "<%=fileType%>",
"key" : "<%=PropertiesUtils.get("onlyoffice.systemKey")%><%=fileId%>",
"title" : "<%=attachment.getFileName()%>",
"url" : "<%=PropertiesUtils.get("onlyoffice.fileUrl")%><%=fileId%>&date=<%=DateUtils.format("yyyyMMddHHmmss", new Date())%>",
"permissions": {
"comment": false,
"download": false,
"edit": false,
"print": true,
"review": false
},
},
documentType : "<%=documentType%>"
});
</script>
<%} %>
</html>