Nextcloud上でOfficeファイルをオンライン閲覧/編集

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【4/18開催】VSCode Dev Containersで楽々開発環境構築祭り〜Python/Reactなどなど〜
Visual Studio Codeの拡張機能であるDev Containersを使ってReactとかPythonとかSpring Bootとかの開発環境をラクチンで構築する方法を紹介するイベントです。
https://tech-lab.connpass.com/event/311864/

こんにちは、今回は以前ご紹介した「Nextcloud」上でOfficeファイルを閲覧/編集可能にする方法をご紹介します。通常では「Nextcloud」上で「.docx」や「.xlsx」などのOfficeファイルをクリックした場合、ファイルのダウンロードになってしまいますが、この方法を行えば、ダウンロードせずに閲覧や編集が可能になります。

Azure上のCentOSにNextcloudを構築!!

Officeファイルのオンライン編集は「Nextcloud」と「ONLYOFFICE」を連携させることで実現します。「ONLYOFFICE」は Microsoft Office互換 のオープンソースのオフィススイートです。
まずは「ONLYOFFICE Document Server」を構築しましょう。連携元の「Nextcloud」は上記記事により構築済とします。

ONLYOFFICE Document Server 構築

「ONLYOFFICE」は制約として「Nextcloud」とは別のサーバに構築します。
以降はroot権限で操作し、SELinuxは無効化しています。

システム要件

CPU:2GHz 2Core以上
RAM:2GB以上
HDD:40GB以上
Swap:2GB
OS:RHEL 7 もしくは CentOS 7

PostgreSQL:バージョン 9.1 以上
NGINX:バージョン 1.3.13 以上
Node.js:バージョン 6.9.1 以上
Redis:バージョン指定なし
RabbitMQ:バージョン指定なし

仮想マシン構成

【インスタンスサイズ】
Standard A2 (2 vcpu 数、3.5 GB メモリ)

【OS】
CentOS release 7.4 x86_64

※DNS名(FQDN)は設定済とします。

スワップ領域作成

AzureのLinuxインスタンスには初期状態ではスワップ領域がありません。
そのため、手動でスワップ領域を作成します。

# dd if=/dev/zero of=/swap bs=1M count=2048
# chmod 600 /swap
# mkswap /swap
# swapon /swap

OS再起動時の自動マウント
# cp -p /etc/fstab /etc/fstab.orig
# echo -e "/swap          swap       swap    defaults        0 0" >> /etc/fstab
# cat /etc/fstab
# shutdown -r now

Node.js インストール

Node.jsをインストールします。

# curl -sL https://rpm.nodesource.com/setup_6.x | sudo bash -
# yum install nodejs

NGINX インストール/初期設定

NGINXをインストール及び初期設定を実施します。

# yum install epel-release
# yum install nginx
# cp -p /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
# vim /etc/nginx/nginx.conf
serverディレクティブを一部をコメントアウト
    server {
        listen       80 default_server;
        #listen       [::]:80 default_server;
        #server_name  _;
        root         /usr/share/nginx/html;

PostgreSQL インストール/初期設定

PostgreSQLをインストール及び初期設定を実施します。

# yum install postgresql postgresql-server
# postgresql-setup initdb
# cp -p /var/lib/pgsql/data/pg_hba.conf /var/lib/pgsql/data/pg_hba.conf.orig
# vim /var/lib/pgsql/data/pg_hba.conf
権限設定を以下のように変更
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust
# systemctl start postgresql
# cd /tmp
# sudo -u postgres psql -c "CREATE DATABASE onlyoffice;"
CREATE DATABASE
# sudo -u postgres psql -c "CREATE USER onlyoffice WITH password 'onlyoffice';"
CREATE ROLE
# sudo -u postgres psql -c "GRANT ALL privileges ON DATABASE onlyoffice TO onlyoffice;"
GRANT

Redis インストール

Redisをインストールします。

# yum install redis
# systemctl start redis
# systemctl enable redis

RabbitMQ インストール

RabbitMQをインストールします。

# yum install rabbitmq-server
# systemctl start rabbitmq-server
# systemctl enable rabbitmq-server

ONLYOFFICE Document Server インストール

ONLYOFFICE Document Serverをインストールします。

# yum install https://download.onlyoffice.com/repo/centos/main/noarch/onlyoffice-repo.noarch.rpm
# yum install onlyoffice-documentserver-de
# systemctl start supervisord
# systemctl enable supervisord
# systemctl start nginx
# systemctl enable nginx

SSLサーバ証明書作成

「Nextcloud」と「ONLYOFFICE」との連携は「HTTPS」接続が必須となるため、Let’s Encryptで無料SSLサーバ証明書を作成します。もし、作成に失敗する場合はAzure側のネットワーク設定などを確認してください。

# yum install certbot
# certbot certonly --webroot -w /usr/share/nginx/html -d [★ONLYOFFICEサーバのFQDN]
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
https-01 challenge for [★ONLYOFFICEサーバのFQDN]
Using the webroot path /usr/share/nginx/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/[★ONLYOFFICEサーバのFQDN]/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/[★ONLYOFFICEサーバのFQDN]/privkey.pem
   Your cert will expire on 2018-07-09. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

NGINX 設定

HTTPS接続設定を有効化します。

HTTP接続設定ファイルを削除
# rm /etc/nginx/conf.d/onlyoffice-documentserver.conf
rm: remove symbolic link '/etc/nginx/conf.d/onlyoffice-documentserver.conf'? y
HTTPS接続設定ファイルをコピー
# cp -p /etc/onlyoffice/documentserver/nginx/onlyoffice-documentserver-ssl.conf.template /etc/nginx/conf.d/onlyoffice-documentserver.conf
# vim /etc/nginx/conf.d/onlyoffice-documentserver.conf
以下のように変更
ssl_certificate /etc/letsencrypt/live/[ONLYOFFICEサーバのFQDN]/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/[ONLYOFFICEサーバのFQDN]/privkey.pem;
# systemctl restart nginx

ONLYOFFICE Document Server 初期設定

# bash /usr/bin/documentserver-configure.sh
Configuring PostgreSQL access...
Host: localhost
Database name: onlyoffice
User: onlyoffice
Password: onlyoffice ★入力
Trying to establish PostgreSQL connection... OK
Installing PostgreSQL database... OK
Configuring redis access...
Host: localhost

Trying to establish redis connection... OK
Configuring RabbitMQ access...<a href="https://tech-lab.sios.jp/wp-content/uploads/2018/04/nextcoud_onlyoffice_s.jpg"><img src="https://tech-lab.sios.jp/wp-content/uploads/2018/04/nextcoud_onlyoffice_s.jpg" alt="nextcoud_onlyoffice_s" width="678" height="318" class="alignnone size-full wp-image-8626" /></a>
Host: localhost:5672
User: guest
Password: guest ★入力
Trying to establish RabbitMQ connection... OK
Restarting services... OK

Nextcloud との連携

アプリの有効化

ブラウザからNextcloudに管理者権限でログインし、アプリ一覧から「ONLYOFFICE」を有効化します。

IF

設定 > 基本設定 > ONLYOFFICE へ移動し、「Document Editing Service address」に
https://[★ONLYOFFICEサーバのFQDN]/
を入力し、「Save」をクリックします。
画面上部に「Settings have been succussfully updated」と表示されれば成功です。

20180411124744

あとは、Nextcloud上でOfficeファイルをクリックすれば、自動的に編集画面が表示されるはずです。

IF

フォント追加

ONLYOFFICEの標準では、日本語入力に適したフォントがあまり入っていません。そのため、フォントを追加します。

①/usr/share/fonts/配下にフォントファイル(.ttfフォーマット)を格納する
②以下コマンドを実行

# /usr/bin/documentserver-generate-allfonts.sh

最後に

本家で作成されたOfficeファイルを「ONLYOFFICE」で開いた場合、若干レイアウトが崩れる場合があります。そのため、「ONLYOFFICE」で編集する際は、簡単な編集の場合のみ利用した方がいいかもしれません。しかし、スマートフォンなどOfficeアプリを入れないで即時閲覧できるは非常に便利ですので、お試し頂ければと思います。

サイオステクノロジー株式会社 山田

アバター画像
About 山田康裕 27 Articles
20代前半からLinux系OSSや認証基盤を中心とした提案/設計/構築を担当。特に仕事を選ばない、何でも屋さん。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

3人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる