# 數位發展部 ODF 文件 Web 應用元件伺服器佈署手冊

本文件介紹如何部署數位發展部 ODF 文件 Web 應用元件伺服器。

# 壹、安裝基礎系統

本章節說明數位發展部「ODF 文件 Web 應用元件」伺服器端的佈署流程，並提供所需 Linux 系統的下載及安裝方式。

# 下載並安裝 Rocky Linux 作業系統

請見 [Rocky Linux 8 基本安裝](https://docs.ossii.com.tw/books/rocky-linux-8)。

# 貳、安裝 ODF 文件 Web 應用元件套件

本章節主要介紹如何安裝 ODF 文件 Web 應用元件套件，請注意，本章節提到的軟體版本號可能會隨時間更新，請以當時最新的版本為主。目前提供兩種安裝方式，可視需求選用。方式一：請利用WinSCP將「ODF雲端編輯工具」相關安裝套件上傳至Linux主機後，執行以下方式一的安裝指令。方式二：可以利用網路安裝方式，將「ODF雲端編輯工具」安裝至Linux主機，請參考以下方式二的安裝指令。

# 一、安裝系統主程式

#### (1)方式一：離線安裝

```
# cd /root
# unzip MODAODFWEB-V3.8.zip
# cd MODAODFWEB-V3.8/modaodfsys
# dnf localinstall modaodfsys* -y
```

#### (2)方式二：線上安裝

直接到[第三節](https://docs.ossii.com.tw/books/odf-web-cny/page/odfwebcny)。

# 二、安裝函式庫

#### (1)方式一：離線安裝

```
# cd /root/MODAODFWEB-V3.8/poco
# dnf localinstall poco* -y
```

#### (2)方式二：線上安裝

直接到[第三節](https://docs.ossii.com.tw/books/odf-web-cny/page/odfwebcny)。

# 三、安裝ODF文件Web應用元件主程式

#### (1)方式一：離線安裝

```
# cd /root/MODAODFWEB-V3.8/modaodfweb
# dnf localinstall modaodfweb* -y
```

#### (2)方式二：線上安裝

請先下載 [https://free.nchc.org.tw/odfrepo/online/modaodfweb-v3.8-el8.repo](https://free.nchc.org.tw/odfrepo/online/modaodfweb-v3.8-el8.repo)，並將其儲存在 `/etc/yum.repos.d/` 下，然後執行以下命令：
```
# dnf upgrade -y 
# dnf groupinstall "MODAODFWEB Group" -y
```

# 四、啟動ODF文件Web應用元件主程式並確認狀態

```
# systemctl enable modaodfweb
# systemctl restart modaodfweb
```

使用以下指令就可以確認初始化服務是否已正常啟動，指令如下：

`# netstat -tlnp`

> Active Internet connections (only servers)<br />
> Proto	Recv-Q	Send-Q Local Address	Foreign Address	State		PID/Program name<br />
> tcp	0	0 0.0.0.0:22		0.0.0.0:*		LISTEN		748/sshd<br />
> tcp	0	0 127.0.0.1:25		0.0.0.0:*		LISTEN		902/master<br />
> tcp6	0	0 :::80 			:::*			LISTEN		744/httpd<br />
> tcp6	0	0 :::22			:::*			LISTEN		748/sshd<br />
> tcp6	0	0 ::1:25			:::*			LISTEN		902/master<br />
> <span style="color:orange;">tcp6	0	0 :::9980		:::*			LISTEN		26766/modaodfweb</span>

如果出現9980那行，代表「ODF文件Web應用元件」服務已啟動，您可以重新啟動系統，再測試服務是否可正常啟動。

# 五、進階設定

#### (1)設定使用對外服務位置

本文件前面所描述之使用情境，皆預設在「<span style="color:red;">**內網 IP 環境**</span>」，若機關佈署的環境開放以下二種情境者，需額外進行進階的設定，二種情境如下：

1. 使用真實 IP 對外開放服務(例如：117.56.68.133)
2. 使用 FQDN 做為服務主機名稱(例如：odf.nat.gov.tw)

請進入 modaodfweb 主機上，修改 `/etc/modaodfweb/modaodfweb.xml` 的內容，找到以下這段：

```
<wopi desc="Allow/deny wopi storage. Mutually exclusive with webdav." allow="true">
<host desc="Regex pattern of hostname to allow or deny." allow="true">localhost</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">172\.1[6789]\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">172\.2[0-9]\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">172\.3[01]\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">192\.168\.[0-9]{1,3}\.[0-9]{1,3}</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">117\.56\.68\.133</host>
<host desc="Regex pattern of hostname to allow or deny." allow="true">odf\.nat\.gov\.tw</host>
<host desc="Regex pattern of hostname to allow or deny." allow="false">192\.168\.1\.1</host>
<max_file_size desc="Maximum document size in bytes to load. 0 for unlimited." type="uint">0</max_file_size>
</wopi>
```

請加入上述 117\.56\.68\.133 與 odf\.nat\.gov\.tw 那二行的範例內容，儲存後跳出，重新啟動 modaodfweb 的服務即可。

`# systemc restart modaodfweb`

另外開放對外可連到這台主機以下的連接埠號：80、9980

就可正常使用 ODF 雲端編輯器。

#### (2)使用 ODF API 的額外設定

若要使用 ODF API 進行作業，因自 2.X 版開始已將 ODF API 伺服器整合至 ODF 雲端編輯元件中，必須在其設定檔中進行額外的設定才能正常運作，請進入 modaodfweb 主機上，修改 `/etc/modaodfweb/modaodfweb.xml` 的內容，找到以下這段：

`<server_name desc="External hostname:port of the server running modaodfweb. If empty, it's derived from the request (please set it if this doesn't work). Must be specified when behind a reverse-proxy or when the hostname is not reachable directly." type="string" default=""></server_name>`

請在 `</server_name>` 前，`<……default=””>` 後插入此 ODF 雲端編輯元件的完整 URL（一般情況下需包含連接埠號，例如192.168.3.1:9980），然後儲存後跳出，重新啟動 modaodfweb 的服務即可。

`# systemc restart modaodfweb`

#### (3)設定啟用 SSL 憑證

若服務的主機運作在 SSL 協定上時，則可透過以下設定方式啟動 SSL，憑證申請的流程可參考 GCA 資證申請作業流程。

[https://gcp.nat.gov.tw/](https://gcp.nat.gov.tw/)

申請好了之後，請將相關的憑證上傳至 modaodfweb 主機上，建議可將憑證檔案放在 `/etc/httpd/ssl` 目錄下。

- Apache  Web Server 的設定

先安裝 ssl 套件

```
# yum install -y mod_ssl
# vim /etc/httpd/conf.d/ssl.conf
```

修改以下三行（請依照實際的路徑設定）

```
SSLCertificateFile /etc/httpd/ssl/certificate.crt
SSLCertificateKeyFile /etc/httpd/ssl/private.key
SSLCACertificateFile /etc/httpd/ssl/ca_bundle.crt
```

存檔後，重啟服務。

`# systemctl restart httpd`

- ODF文件Web應用元件主程式

請進入 modaodfweb 主機上，修改 /etc/modaodfweb/modaodfweb.xml 的內容，找到以下這段：

`<enable type="bool" desc="Controls whether SSL encryption is enable (do not disable for production deployment). If default is false, must first be compiled with SSL support to enable." default="true">true</enable>`

請將 `</enable>` 前由原本的 false 改為 true。

另外再指定以下三個憑證位置（路徑可與上述 httpd 的 SSL 憑證相同），例子如下：

```
<cert_file_path desc="Path to the cert file" relative="false">/etc/httpd/ssl/certificate.crt</cert_file_path>
<key_file_path desc="Path to the key file" relative="false">/etc/httpd/ssl/private.key</key_file_path>
<ca_file_path desc="Path to the ca file" relative="false">/etc/httpd/ssl/ca_bundle.crt</ca_file_path>
```

儲存後跳出，重新啟動 modaodfweb 的服務即可。

`# systemc restart modaodfweb`

依照上述設定，正常就可以使用以下的連結使用服務：

https://yourhostname:9980 → 為「ODF文件Web應用元件主程式」（一般安裝說明如第貳章所示）測試服務位置，出現OK字樣，並且瀏覽器端會顯示為合法憑證。

https://yourhostname/odfweb → 為預設「ODF文件Web應用元件網路儲存空間軟體」（一般安裝說明如第參章所示）進入點，此時可成為加密型態。

# 參、安裝 ODF 文件 Web 應用元件網路儲存空間軟體

本章節介紹如何安裝 ODF 文件 Web 應用元件網路儲存空間軟體。

# 一、安裝基本架構

請參閱[在 Rocky Linux 8 安裝 Apache + MariaDB + PHP](https://docs.ossii.com.tw/books/rocky-linux-8-apache-mariadb-php)。