only-office以Docker方式安裝使用


安裝Docker

安裝

# 安裝必要依賴
yum install -y yum-utils device-mapper-persistent-data lvm2

# 添加aliyum docker-ce yum源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 重建yum緩存
yum makecache

# 安裝指定版本docker,版本19.03.12
yum install -y docker-ce-19.03.12-3.el7

# 確保網絡模塊開機自動加載
lsmod | grep overlay
lsmod | grep br_netfilter

cat > /etc/modules-load.d/docker.conf <<EOF
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

# 使橋接流量對iptables可見
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

# 驗證是否生效,下面兩個命令結果需均返回 1
sysctl -n net.bridge.bridge-nf-call-iptables
sysctl -n net.bridge.bridge-nf-call-ip6tables

配置Docker

# 創建docker鏡像存儲目錄
cd ~
mkdir data
cd data/
mkdir docker
cd docker/
mkdir data-root
cd data-root/
pwd #輸出結果:/root/data/docker/data-root

# 創建docker配置文件目錄
mkdir /etc/docker

# 修改cgroup驅動為systemd[k8s官方推薦]、限制容器日志量、修改存儲類型,最后的docker根目錄可修改
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ],
  "registry-mirrors": ["https://7uuu3esz.mirror.aliyuncs.com"],
  "data-root": "/root/data/docker/data-root"
}
EOF

# 添加開機自啟動,並立即啟動
systemctl enable --now docker

驗證docker是否正常

# 查看docker信息,判斷是否與配置一致
docker info

# hello-docker測試
docker run --rm hello-world

# 刪除測試的image
docker rmi hello-world

驗證能否通過IP:Port方式訪問Docker站點

# 查看docker server信息,確認最后一行是否報錯
docker info

# 錯誤信息見下面最后一行,目前無錯誤信息
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc version: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1127.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 1.777GiB
 Name: localhost.localdomain
 ID: 2HIV:6EH2:KI53:BUGY:YD72:Q3BI:Y4MJ:X65V:YF2N:TFUZ:BRTD:ZOA3
 Docker Root Dir: /root/data/docker/data-root
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://7uuu3esz.mirror.aliyuncs.com/
 Live Restore Enabled: false

安裝only-office server

參考地址:https://helpcenter.onlyoffice.com/installation/docs-community-install-docker.aspx?_ga=2.248226951.1825569553.1616058768-1266077697.1607495094

系統需求

  • CPU: dual core 2 GHz or better
  • RAM: 2 GB or more
  • HDD: at least 40 GB of free space
  • Additional requirements: at least 4 GB of swap
  • OS: amd64 Linux distribution with kernel version 3.10 or later
  • Additional requirements
    • Docker: version 1.10 or later

創建數據目錄

  • /var/log/onlyoffice for ONLYOFFICE Docs logs
  • /var/www/onlyoffice/Data for certificates
  • /var/lib/onlyoffice for file cache
  • /var/lib/postgresql for database
# 進入數據存儲目錄
cd /root/data
mkdir onlyoffice
cd onlyoffice
mkdir DocumentServer
cd DocumentServer
pwd
# 顯示路徑:/root/data/onlyoffice/DocumentServer

# 創建對應目錄
mkdir logs
mkdir data
mkdir lib
mkdir db
ls

啟動docker容器

# 啟動docker容器,默認啟動端口為80,可以進行修改
docker run -i -t -d -e TZ="Asia/Shanghai" -p 81:80 --restart=always \
    -v /root/data/onlyoffice/DocumentServer/logs:/var/log/onlyoffice  \
    -v /root/data/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data  \
    -v /root/data/onlyoffice/DocumentServer/lib:/var/lib/onlyoffice \
    -v /root/data/onlyoffice/DocumentServer/db:/var/lib/postgresql  onlyoffice/documentserver
    
# 查看鏡像下載
docker images

# 查看容器
docker ps

# 查看啟動日志
docker logs -f 容器ID

開放防火牆端口

# 開放端口
firewall-cmd --add-port=81/tcp --permanent

# 重新加載配置
firewall-cmd --reload

# 查看防火牆開放情況
firewall-cmd --list-port

# 驗證外網是否可以訪問,查看此文件能否查看或打開
http://192.168.110.129:81/

可配置的參數

Please refer the docker run command options for the --env-file flag where you can specify all required environment variables in a single file. This will save you from writing a potentially long docker run command.

  • ONLYOFFICE_HTTPS_HSTS_ENABLED: Advanced configuration option for turning off the HSTS configuration. Applicable only when SSL is in use. Defaults to true.
  • ONLYOFFICE_HTTPS_HSTS_MAXAGE: Advanced configuration option for setting the HSTS max-age in the onlyoffice NGINX vHost configuration. Applicable only when SSL is in use. Defaults to 31536000.
  • SSL_CERTIFICATE_PATH: The path to the SSL certificate to use. Defaults to /var/www/onlyoffice/Data/certs/onlyoffice.crt.
  • SSL_KEY_PATH: The path to the SSL certificate private key. Defaults to /var/www/onlyoffice/Data/certs/onlyoffice.key.
  • SSL_DHPARAM_PATH: The path to the Diffie-Hellman parameter. Defaults to /var/www/onlyoffice/Data/certs/dhparam.pem.
  • SSL_VERIFY_CLIENT: Enable verification of client certificates using the CA_CERTIFICATES_PATH file. Defaults to false.
  • POSTGRESQL_SERVER_HOST: The IP address or the name of the host where the PostgreSQL server is running.
  • POSTGRESQL_SERVER_PORT: The PostgreSQL server port number.
  • POSTGRESQL_SERVER_DB_NAME: The name of a PostgreSQL database to be created on the image startup.
  • POSTGRESQL_SERVER_USER: The new user name with superuser permissions for the PostgreSQL account.
  • POSTGRESQL_SERVER_PASS: The password set for the PostgreSQL account.
  • AMQP_SERVER_URL: The AMQP URL to connect to the message broker server.
  • AMQP_SERVER_TYPE: The message broker type. Supported values are rabbitmq or activemq. Defaults to rabbitmq.
  • REDIS_SERVER_HOST: The IP address or the name of the host where the Redis server is running.
  • REDIS_SERVER_PORT: The Redis server port number.
  • NGINX_WORKER_PROCESSES: Defines the number of NGINX worker processes.
  • NGINX_WORKER_CONNECTIONS: Sets the maximum number of simultaneous connections that can be opened by a NGINX worker process.
  • JWT_ENABLED: Specifies the enabling the JSON web token validation by ONLYOFFICE Docs. Defaults to false.
  • JWT_SECRET: Defines the secret key to validate the JSON web token in the request to ONLYOFFICE Docs. Defaults to secret.
  • JWT_HEADER: Defines the HTTP header that will be used to send the JSON web token. Defaults to Authorization.

使用文檔

官方文檔地址:https://api.onlyoffice.com/editors/basic.

添加中文字體

編輯字體

  • 在Windows目錄的C:\Windows\Fonts查找常用中文字體文件;
  • 使用字體編輯軟件FontCreator修改參數配置:
    • 選擇 字體屬性;
    • 將字體家族改為中文;
      字體子族改為常規;
      注意:這里字體家族中間得加個空格。
  • 將修改后的字體導出為新的字體包。

刪除自帶字體

# 進入容器內
docker ps
docker exec -it 51 bash

# 刪除原版自帶字體
cd /usr/share/fonts/
rm -rf *

cd /var/www/onlyoffice/documentserver/core-fonts/
rm -rf *

將字體文件導入docker容器,此種方式設置后字體生效,但是字體選擇列表中中文字體顯示亂碼

# 在服務器創建字體目錄
cd /root/data/onlyoffice
mkdir fonts
cd fonts/

# 將字符文件復制到該目錄
rz

# 將字體復制到容器的對應目錄下
docker cp /root/data/onlyoffice/fonts/ 51e38c77ddbd:/usr/share/fonts/truetype/custom


docker cp /root/data/onlyoffice/dockerImage/Contents.json e13c3a79dc43:/var/www/onlyoffice/documentserver/web-apps/apps/documenteditor/main/resources/help/zh


# 進入容器內
docker ps
docker exec -it 51 bash

# 確認字體文件是否是最新的
cd /usr/share/fonts/truetype/custom/fonts
ll

# 執行字體重新加載腳本
cd /usr/bin/
./documentserver-generate-allfonts.sh

# 輸出內容如下:
Generating AllFonts.js, please wait...Done
Generating presentation themes, please wait...Done
ds:docservice: stopped
ds:docservice: started
ds:converter: stopped
ds:converter: started

# 生成的字體JS配置文件
/var/www/onlyoffice/documentserver/server/FileConverter/bin/AllFonts.js

文件預覽

創建Html頁面,在html文件中編寫對應預覽代碼。

documentType參數說明

# 5.4.2 版本
# 字符串類型,定義文檔打開類型:

1、text(.doc, .docm, .docx, .dot, .dotm, .dotx, .epub, .fodt, .htm, .html, .mht, .odt, .ott, .pdf, .rtf, .txt, .djvu, .xps);

2、spreadsheet(.csv, .fods, .ods, .ots, .xls, .xlsm, .xlsx, .xlt, .xltm, .xltx);

3、presentation(.fodp, .odp, .otp, .pot, .potm, .potx, .pps, .ppsm, .ppsx, .ppt, .pptm, .pptx).

World

<!DOCTYPE html>
<html style="height: 100%;">
<head>
    <title>ONLYOFFICE Word</title>
    <link rel="icon" href="https://oa.cnki.net/v/home/cnki.ico" type="image/x-icon" />
    <link rel="shortcut icon" href="https://oa.cnki.net/v/home/cnki.ico" type="image/x-icon" />
</head>
<body style="height: 100%; margin: 0;">
    <div id="placeholder" style="height: 100%"></div>
    <script type="text/javascript" src="http://192.168.110.129:81/web-apps/apps/api/documents/api.js"></script>

    <script type="text/javascript">

        window.docEditor = new DocsAPI.DocEditor("placeholder",
            {
                "document": {
                    "fileType": "docx",
                    "key": "D24A86BDE9A2-01-10",
                    "permissions": {
                        "comment": false,
                        "copy": true,
                        "download": true,
                        "edit": false,
                        "fillForms": false,
                        "modifyContentControl": false,
                        "modifyFilter": true,
                        "print": true,
                        "review": false
                    },
                    "title": "test.docx",
                    "url": "http://192.168.110.129/onlyoffice/word01.docx"
                },
                "documentType": "word",
                "editorConfig": {
                    "mode": "view",
                    "lang": "zh-CN",
                    "customization": {
                        "chat": false,
                        "comments": false,
                        "compactHeader": false,
                        "compactToolbar": false,
                        "compatibleFeatures": false,
                        "customer": {
                            "address": "北京",
                            "info": "中國知網",
                            "logo": "https://oa.cnki.net/v/home/cnki.ico",
                            "mail": "oa@cnki.net",
                            "name": "中國知網",
                            "www": "https://oa.cnki.net"
                        },
                        "feedback": {
                            "url": "https://oa.cnki.net",
                            "visible": false
                        },
                        "help": false,
                        "hideRightMenu": true,
                        "logo": {
                            "image": "https://oa.cnki.net/v/home/cnki.ico",
                            "imageEmbedded": "https://oa.cnki.net/v/home/cnki.ico",
                            "url": "https://oa.cnki.net"
                        },
                        "plugins": false,
                        "toolbarHideFileName": true
                    }
                },
                "type": "desktop",
                "height": "100%",
                "width": "100%"
            });

    </script>
</body>
</html>

Excel

<!DOCTYPE html>
<html style="height: 100%;">
<head>
    <title>ONLYOFFICE Excel</title>
</head>
<body style="height: 100%; margin: 0;">
    <div id="placeholder" style="height: 100%"></div>
    <script type="text/javascript" src="http://10.120.160.113:81/web-apps/apps/api/documents/api.js"></script>

    <script type="text/javascript">

        window.docEditor = new DocsAPI.DocEditor("placeholder",
            {
                "document": {
                    "fileType": "xlsx",
                    "key": "138E9734B413-01",
                    "title": "Example Spreadsheet Title.xlsx",
                    "url": "http://oa.cnki.net/api/file/File/Download?fileId=065F87CE9C724D2AA26313E449A59809" //"http://10.120.160.100/fs/test-onlyoffice/test01.xlsx"
                },
                "documentType": "cell",
                "editorConfig": {
                    "mode": "view"
                },
                "height": "100%",
                "width": "100%"
            });

    </script>
</body>
</html>

PPT

<!DOCTYPE html>
<html style="height: 100%;">
<head>
    <title>ONLYOFFICE PPT</title>
</head>
<body style="height: 100%; margin: 0;">
    <div id="placeholder" style="height: 100%"></div>
    <script type="text/javascript" src="http://10.120.160.113:81/web-apps/apps/api/documents/api.js"></script>

    <script type="text/javascript">

        window.docEditor = new DocsAPI.DocEditor("placeholder",
            {
                "document": {
                    "fileType": "pptx",
                    "key": "D24A86BDE9A2-01-03-123",
                    "title": "Example Presentation Title.pptx",
                    "url": "http://10.120.160.100/fs/test-onlyoffice/ppt01.pptx"
                },
                "documentType": "slide",
                "editorConfig": {
                    "mode": "view"
                },
                "height": "100%",
                "width": "100%"
            });

    </script>
</body>
</html>

測試預覽URL

http://192.168.110.129/onlyoffice/index-word.html

http://192.168.110.129/onlyoffice/index-word-cnki.html

http://192.168.110.129/onlyoffice/index-excel.html

http://192.168.110.129/onlyoffice/index-ppt.html

文檔下載接口測試:http://oa.cnki.net/api/file/File/Download?fileId=065F87CE9C724D2AA26313E449A59809

文件編輯

下面以word文件編輯作為示例進行驗證。

在文檔編輯時,需指定編輯的回調地址,此回調程序使用Java語言編寫,以jar包方式在服務器上面運行,因此需要在服務器上面安裝JDK環境。

<!DOCTYPE html>
<html style="height: 100%;">
<head>
    <title>ONLYOFFICE Api Documentation</title>
</head>
<body style="height: 100%; margin: 0;">
    <div id="placeholder" style="height: 100%"></div>
    <script type="text/javascript" src="http://192.168.110.129:82/web-apps/apps/api/documents/api.js"></script>

    <script type="text/javascript">

        window.docEditor = new DocsAPI.DocEditor("placeholder",
            {
                "document": {
                    "fileType": "docx",
                    "key": "E7FAFC9C2210-020",
                    "title": "word01.docx",
                    "url": "http://192.168.110.129/onlyoffice/word01.docx"
                },
                "documentType": "text",
                "editorConfig": {
                    "lang": "zh-cn",
                    "callbackUrl": "http://192.168.110.129:8080/test/getRequestData",
                    "customization": {
                        "chat": false,
                        "comments": false,
                        "compactHeader": false,
                        "compactToolbar": false,
                        "compatibleFeatures": false,
                        "customer": {
                            "address": "北京",
                            "info": "中國知網",
                            "logo": "https://oa.cnki.net/v/home/cnki.ico",
                            "mail": "oa@cnki.net",
                            "name": "中國知網",
                            "www": "https://oa.cnki.net"
                        },
                        "feedback": {
                            "url": "https://oa.cnki.net",
                            "visible": false
                        },
                        "help": false,
                        "hideRightMenu": true,
                        "logo": {
                            "image": "https://oa.cnki.net/v/home/cnki.ico",
                            "imageEmbedded": "https://oa.cnki.net/v/home/cnki.ico",
                            "url": "https://oa.cnki.net"
                        },
                        "plugins": false,
                        "toolbarHideFileName": true
                    }
                },
                "height": "100%",
                "width": "100%"
            });

    </script>
</body>
</html>

測試編輯URL

# word
http://192.168.110.129/onlyoffice/edit-word.html

http://192.168.110.129/onlyoffice/edit-word-cnki.html

# 查看驗證
http://192.168.110.129/onlyoffice/index-word.html

# 協同編輯
http://192.168.110.129/onlyoffice/co-edit-01.html
http://192.168.110.129/onlyoffice/co-edit-02.html

回調樣例數據

// 進入編輯
{ 
  "actions" : [ {
    "type" : 1,
    "userid" : "uid-1617000391704"
  } ],
  "forcesavetype" : 0,
  "key" : "E7FAFC9C22A8",
  "status" : 1,
  "users" : [ "uid-1617000391704" ]
}

////////////////////////////////////////////////////////////////////////////////////////////////////////

// 關閉頁面后,自動保存的回調
{
  "actions" : [ {
    "type" : 0,
    "userid" : "uid-1617000391704"
  } ],
  "changesurl" : "http://192.168.110.129:81/cache/files/E7FAFC9C22A8_2529/changes.zip/changes.zip?md5=tOXiIFPV9i59huCMjv5iMg&expires=1617001678&disposition=attachment&filename=changes.zip",
  "forcesavetype" : 0,
  "history" : {
    "changes" : [ {
      "created" : "2021-03-29 06:46:57",
      "user" : {
        "id" : "uid-1617000391704",
        "name" : "Anonymous"
      }
    } ],
    "serverVersion" : "6.1.0"
  },
  "key" : "E7FAFC9C22A8",
  "status" : 2,
  "url" : "http://192.168.110.129:81/cache/files/E7FAFC9C22A8_2529/output.docx/output.docx?md5=ROMKlDaRuRgCBti99kZH2Q&expires=1617001678&disposition=attachment&filename=output.docx",
  "users" : [ "uid-1617000391704" ]
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM