NextCloud 安裝架設
OS 環境:Ubuntu 22.04 並安裝 Docker (本篇架設服務皆只使用同一台主機)
DNS 網域名稱:nc2.domain.com.tw 和 collabora.domain.com.tw
IP:10.1.1.1
下載官方 yml 格式
# mkdir nextcloud
# cd nextcloud
# curl -f -L https://github.com/nextcloud/docker/raw/master/stack.yml -o docker-compose.yml
修改內文如下:
version: '3.2'
services:
db:
image: mariadb:10.6
restart: always
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_PASSWORD=123456
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
redis:
image: redis:alpine
restart: always
app:
# image: nextcloud
image: nextcloud:27.1.5
restart: always
ports:
- 8080:80
volumes:
- nextcloud:/var/www/html
environment:
- REDIS_HOST=redis
- MYSQL_PASSWORD=123456
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
depends_on:
- db
- redis
cron:
# image: nextcloud
image: nextcloud:27.1.5
restart: always
volumes:
- nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- db
collabora:
image: collabora/code
restart: always
ports:
- 9980:9980
environment:
- domain=collabora\.domain\.com\.tw
- username=admin
- password=admin
cap_add:
- MKNOD
volumes:
- "/etc/localtime:/etc/localtime:ro"
- "/usr/local/share/fonts/truetype/:/opt/collaboraoffice/share/fonts/truetype/local/:ro"
volumes:
db:
nextcloud:
-----------------------------------------------------------------------------------------------------
下載和啟動
# docker-compose -f docker-compose.yml pull
# docker-compose -f docker-compose.yml up -d
# docker-compose logs -f
開啟 Chrome 瀏覽器,輸入網址:http://10.1.1.1:8080
輸入新建立的管理員帳號、密碼
開始安裝,推薦的應用程式:Calendar、Contacts、Mail、Nextcloud Office、Notes、Talk
docker volume 位置,包含設定檔、及上傳的照片、文件...等等
/var/lib/docker/volumes/nextcloud_nextcloud/_data/data/admin/files/
日誌紀錄
# vi /var/lib/docker/volumes/nextcloud_nextcloud/_data/data/nextcloud.log
清空日誌紀錄
# truncate /var/lib/docker/volumes/nextcloud_nextcloud/_data/data/nextcloud.log --size 0
# vi /var/lib/docker/volumes/nextcloud_nextcloud/_data/config/config.php
修改 trusted domains 指定哪些主機及信任的網域可以連線
'trusted_domains' =>
array (
0 => 'nc2.domain.com.tw',
1 => '10.1.1.1:8080',
2 => '*:8080',
3 => '*:443',
),
'overwrite.cli.url' => 'https://nc2.domain.com.tw',
'overwritehost' => 'nc2.domain.com.tw:443',
'overwriteprotocol' => 'https',
'trusted_proxies' =>
array (
0 => '10.1.1.1',
),
'allow_local_remote_servers' => true,
'logtimezone' => 'Asia/Taipei',
'default_timezone' => 'Asia/Taipei',
'default_phone_region' => 'TWN',
"default_language" => "zh_TW",
"default_locale" => "zh_Hant_TW",
'maintenance_window_start' => 1,
'mail_smtpmode' => 'smtp',
'mail_smtpauthtype' => '',
'mail_smtphost' => '10.1.1.20',
'mail_smtpport' => '25',
'mail_smtptimeout' => 30,
'mail_sendmailmode' => 'smtp',
'mail_from_address' => 'nextcloud',
'mail_domain' => 'domain.com.tw',
'mail_send_plaintext_only' => false,
'mail_smtpauth' => 0,
'mail_smtpname' => '',
'mail_smtppassword' => '',
'mail_smtpstreamoptions' => array(
'ssl' => array(
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
)
),
-----------------------------------------------------------------------------------------------------
使用 Nginx (Ubuntu IP:10.1.1.1)來架設 Reverse Proxy 反向代理伺服器,
在 Ubuntu 這台 Docker 伺服器上,安裝 Nginx 來架設 Reverse Proxy 反向代理伺服器
讓 https 443 Port 導到 8080 Port
# sudo apt update
# sudo apt install nginx
防火牆請記得設定,Ubuntu 預設是關閉
# systemctl status nginx
# systemctl enable nginx
編輯 https://nc2.domain.com.tw 網站
# vi /etc/nginx/sites-available/nextcloud
新增如下:
upstream nextcloud {
zone nextcloud-general 64k;
server 10.1.1.1:8080;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name nc2.domain.com.tw;
root /usr/share/nginx/html;
ssl_certificate "/etc/ssl/domain.com.tw.pem";
ssl_certificate_key "/etc/ssl/private/domain.com.tw_KEY.key";
ssl_protocols TLSv1.1 TLSv1.2;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://10.1.1.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
access_log /var/log/nginx/nextcloud.access.log;
error_log /var/log/nginx/nextcloud.error.log;
}
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
}
編輯 https://collabora.domain.com.tw 網站
# vi /etc/nginx/sites-available/collabora
server {
listen 80;
listen 443 ssl;
server_name collabora.domain.com.tw;
ssl_certificate "/etc/ssl/domain.com.tw.pem";
ssl_certificate_key "/etc/ssl/private/domain.com.tw_KEY.key";
error_log /var/log/nginx/collabora.error;
# static files
location ~ /browser {
proxy_pass https://localhost:9980;
proxy_set_header Host $host;
}
# WOPI discovery URL
location ~ /hosting/discovery {
proxy_pass https://localhost:9980;
proxy_set_header Host $host;
}
# Main websocket
location ~ ^/cool/(.*)/ws$ {
proxy_pass https://localhost:9980;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_read_timeout 36000s;
}
# Admin Console websocket
location ~ /cool/adminws {
proxy_buffering off;
proxy_pass https://localhost:9980;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_read_timeout 36000s;
}
# download, presentation and image upload
location ~ /cool {
proxy_pass https://localhost:9980;
proxy_set_header Host $host;
}
# Endpoint with information
location ~ /hosting/capabilities {
proxy_pass https://localhost:9980;
proxy_set_header Host $host;
}
}
啟動網站
# rm /etc/nginx/sites-enabled/default
# ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/nextcloud
# ln -s /etc/nginx/sites-available/collabora /etc/nginx/sites-enabled/collabora
檢查 conf 的語法是否正確
# nginx -t
# systemctl restart nginx.service
或 重新載入 Nginx 的新設定
# nginx -s reload
開啟 Chrome 瀏覽器,網址輸入: https://nc2.domain.com.tw
admin 登入 → 個人設定 → 隱私 → 您的資料位於: 台灣 (這樣所有 user 的時區就會在台灣)
Collabora Online 管理主控台網址:
https://collabora.domain.com.tw:9980/browser/dist/admin/admin.html
帳號、密碼為 admin
到 NextCloud 上管理設定 Office 【使用您自己的伺服器】輸入:
原本:https://nc.domain.com.tw:443/custom_apps/richdocumentscode/proxy.php?req=
改成:https://collabora.domain.com.tw
停用證書驗證 (不安全) 打勾
-----------------------------------------------------------------------------------------------------
Collabora Online 安裝 Windows 字型:
先從 Windows 10 複製出細明體 mingliu.ttc、標楷體 DFKai-SB、微軟正黑體 Microsoft-JhengHei-1、2、3.ttc 到 Ubuntu 上
# mkdir /usr/local/share/fonts/truetype/windows
# cp Microsoft-JhengHei-1.ttc /usr/local/share/fonts/truetype/windows
# apt install fontconfig
# fc-cache -f -v
# fc-list :lang=zh
更新系統磁碟
# docker exec -it 1bec7b1c66f7 bash
# coolconfig update-system-template
重啟容器後,到 nextcloud 確認文件是否有新增繁體字型
# docker stop 1bec7b1c66f7
# docker start 1bec7b1c66f7
-----------------------------------------------------------------------------------------------------
更新 Nextcloud ( 升級是破壞性的,且不支援降級 )
要將 Nextcloud 更新到新版本,您只需透過 docker-compose 拉取新映像並重建容器即可。
升級前,請先確認管理設定【記錄】上,是否有不斷出現錯誤log,例如 richdocuments ,請先排除掉,以免升級過程出錯。
# docker-compose stop
# docker-compose rm 刪除 container
# vi docker-compose.yml 修改 image: nextcloud:版號
# docker-compose pull
# docker-compose build --pull
# docker-compose up -d
# docker-compose logs -f 查看 log 情形
Nextcloud 必須逐步升級:
在升級到下一個主要版本之前,Nextcloud 會升級到最新的單點版本。
然後再次運行升級以升級到下一個主要版本的最新點版本。
您不能跳過主要版本。請重新執行升級,直到達到可用(或適用)的最高版本。
範例:18.0.5 -> 18.0.11 -> 19.0.5 -> 20.0.2
測試從 27.1.5 升級至 27.1.6 ,遇到問題:刪除文件檔案時,回收桶是空的
-----------------------------------------------------------------------------------------------------
在 Windows 上,使用 WebDAV 方式掛載存取 Nextcloud 文件
net use N: https://nc2.domain.com.tw/remote.php/dav/files/帳號 /user:帳號 密碼
如果出現:系統發生 67 錯誤。找不到網路名稱。
解法:將 WebClient 服務進行啟動
-----------------------------------------------------------------------------------------------------
備份 mariadb 資料庫
# docker exec -it nextcloud_db_1 bash
# apt update
# apt install vim
# vim /etc/mysql/my.cnf
新增以下帳號密碼,才能放在 script 做排程備份
[mysqldump]
quick
max_allowed_packet = 16M
user=nextcloud
password=123456
# exit
執行容器內的備份指令 ( 使用 backup.sh 做 crontab 排程備份時,請把 -it 拿掉,否則會備份不成功 )
# docker exec -it nextcloud_db_1 mysqldump --single-transaction -u nextcloud nextcloud >> nextcloud-db.sql
備份附件
# tar -zcvf /root/attachments.$date.tar.gz /var/lib/docker/volumes/nextcloud_nextcloud/_data/data/
-----------------------------------------------------------------------------------------------------
還原資料庫
# cd /root/nextcloud
# docker-compose stop app cron
# docker exec -it nextcloud_db_1 bash
# cd /var/lib/mysql/
# mariadb -u nextcloud -p -D nextcloud < nextcloud.20240311.sql
Enter password:123456
# docker-compose start app cron
-----------------------------------------------------------------------------------------------------
留言