0、安装准备
如果是局域网,部署的电脑拥有固定ip(下文叫宿主机,切记)。电脑能打开cup的虚拟功能。如果部署到云主机,道理是一样的。
环境是win7以上,win10以下。Win10区别就是安装的docker软件不同而已。
第一步:确定电脑打开了cpu虚拟打开。https://jingyan.baidu.com/article/22fe7ced3b4c003002617f17.html
第二步:下载和安装docker toolbox,默认安装即可。下载地址http://get.daocloud.io/,下载支持旧版windows的docker toolbox,win10就直接下载docker了。
第三步:启动docker后在里面拉取Onlyoffice Document Server 的Docker镜像
1、拉取ONLYOFFICE Document Server 的Docker镜像
拉取镜像sudo docker pull onlyoffice/documentserver
建议用离线的:
(存出命令[email protected] ~/winfont
$ dockersave -o onlyofficedocumentserver.tar onlyoffice/documentserver)
dockerload < onlyofficedocumentserver.tar
2、启动——映射至9000端口
docker run-i-t-d-p9000:80onlyoffice/documentserver
3、替换容器onlyofficedocument server的字体
//进入容器(运行的镜像)内
$ dockerexec -it 38e27 /bin/bash
[email protected]:/#dir或者ls –al
[email protected]:~#cd /usr/share/fonts/
[email protected]:/usr/share/fonts#ls
truetype X11
//删除文件夹X11
[email protected]:/usr/share/fonts#rm -R dir X11
rm:cannot remove dir: No such file or directory
[email protected]:/usr/share/fonts#ls
truetype
[email protected]:/usr/share/fonts#cd truetype
[email protected]:/usr/share/fonts/truetype#ls –al
[email protected]:/usr/share/fonts/truetype#ls -al
total462392
drwxr-xr-x11 root root 4096 Feb 19 04:17 .
………………
//删除trutype文件夹下所有文件
[email protected]:/usr/share/fonts/truetype#rm -R dir *.*
rm:cannot remove dir: No such file or directory
[email protected]:/usr/share/fonts/truetype#rm -R dir *
rm:cannot remove dir: No such file or directory
rm:cannot remove custom: Device or resource busy
[email protected]:/usr/share/fonts/truetype#ls
custom
[email protected]:/usr/share/fonts/truetype#ls -al
total 12
drwxr-xr-x10 root root 4096 Feb 19 10:14 .
drwxr-xr-x 6 root root 4096 Feb 19 10:12 ..
drwxr-xr-x 2 root root 4096 Feb 19 03:48 custom
……
[email protected]:/usr/share/fonts/truetype#exit
exit
[email protected] ~/winfont
//将当前文件夹C:\Users\Administrator\下的winfont文件夹内的字体全部拷贝到容器的文件夹/usr/share/fonts/truetype中
$ tar -cv* | docker exec -i 6df tar x -C /usr/share/fonts/truetype
kaiu.ttf
msjh.ttc
msjhbd.ttc
msjhl.ttc
msyh.ttc
msyh.ttf
msyhbd.ttc
msyhl.ttc
simfang.ttf
simhei.ttf
simkai.ttf
simli.ttf
simsun.ttc
simsunb.ttf
simyou.ttf
……
[email protected] ~/winfont
//进入容器内
$ dockerexec -it 6df /bin/bash
[email protected]:/#sudo mkfontscale
[email protected]:/#sudo mkfontdir
[email protected]:/#sudo fc-cache -fv
/usr/share/fonts:caching, new cache contents: 0 fonts, 1 dirs
…………
fc-cache:succeeded
[email protected]:/#exit
exit
//退出容器
[email protected] ~/winfont
$ dockerexec 6df /usr/bin/documentserver-generate-allfonts.sh
GeneratingAllFonts.js, please wait...Done
onlyoffice-documentserver:docservice:stopped
onlyoffice-documentserver:docservice:started
onlyoffice-documentserver:converter:stopped
onlyoffice-documentserver:converter:started
4、二次开发EngineerCMS
4.1 协作编辑页面
[html] view plain copy
- <!DOCTYPE html>
- <html style="height: 100%;">
- <head>
- <title>fei-OnlyOffice</title>
- </head>
- <body style="height: 100%; margin: 0;">
- <dividdivid="placeholder" style="height: 100%"></div>
- <script type="text/javascript"src="http://安装docker电脑的ip:9000/web-apps/apps/api/documents/api.js"></script>
- <scripttypescripttype="text/javascript">
- //alert({{.Doc.FileName}});
- window.docEditor = newDocsAPI.DocEditor("placeholder",
- {
- "document": {
- "fileType": "{{.fileType}}",
- "key": "{{.Key}}",//"Khirz6zTPdfd7"
- "title": "{{.Doc.FileName}}",
- "url": "http://运行engineercms电脑的ip/attachment/onlyoffice/{{.Doc.FileName}}"
- },
- "documentType":"{{.documentType}}",
- "editorConfig": {
- "callbackUrl": "http:// 运行engineercms电脑的ip /url-to-callback?id={{.Doc.Id}}",
- "user": {
- "id": "{{.Uid}}",
- "name": "{{.Uname}}"
- },
- "lang": "zh-CN",//"en-US",
- },
- "height": "100%",
- "width": "100%"
- });
- </script>
- </body>
- </html>
4.2 协作页面的保存和回调
[plain] view plain copy
- type Callback struct {
- Key string `json:"key"`
- Status int `json:"status"`
- Url string `json:"url"`
- Changesurl string `json:"changesurl"`
- History history `json:"history"`
- Users []string `json:"users"`
- Actions []action `json:"actions"`
- Lastsave string `json:"lastsave"`
- Notmodifiedbool `json:"notmodified"`
- }
- type action struct {
- Type int
- userid string
- }
- type history struct {
- changes []change
- serverVersionstring
- }
- type change struct {
- created string
- User User1
- }
- type User1 struct {
- id string
- name string
- }
- //关闭浏览器标签后获取最新文档保存到文件夹
- func (c *OnlyController) UrltoCallback() {
- // pk1 :=c.Ctx.Input.RequestBody
- id :=c.Input().Get("id")
- //pid转成64为
- idNum, err :=strconv.ParseInt(id, 10, 64)
- if err != nil {
- beego.Error(err)
- }
- //根据附件id取得附件的prodid,路径
- onlyattachment,err := models.GetOnlyAttachbyId(idNum)
- if err != nil {
- beego.Error(err)
- }
- var callbackCallback
- json.Unmarshal(c.Ctx.Input.RequestBody,&callback)
- ifcallback.Status == 1 || callback.Status == 4 {
- c.Data["json"]= map[string]interface{}{"error": 0}
- c.ServeJSON()
- } else ifcallback.Status == 2 {
- resp, err :=http.Get(callback.Url)
- if err != nil{
- beego.Error(err)
- }
- body, err :=ioutil.ReadAll(resp.Body)
- if err != nil{
- beego.Error(err)
- }
- deferresp.Body.Close()
- if err != nil{
- beego.Error(err)
- }
- f, err :=os.OpenFile(".\\attachment\\onlyoffice\\"+onlyattachment.FileName,os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
- if err != nil{
- beego.Error(err)
- }
- deferf.Close()
- _, err =f.Write(body)
- if err != nil{
- beego.Error(err)
- } else {
- err =models.UpdateOnlyAttachment(idNum)
- if err !=nil {
- beego.Error(err)
- }
- }
- c.Data["json"]= map[string]interface{}{"error": 0}
- c.ServeJSON()
- }
- }
原文地址:http://blog.51cto.com/8200238/2085285