這裏主要介紹使用Docker方式部署NextCloud的過程。
安裝啓動
$docker pull nextcloud
$docker pull mysql
$mkdir /home/nextcloud
way1: basic docker
$docker run --name mysql -v ?:? -e MYSQL_ROOT_PASSWORD=12345678 -p 33306:3306 -d mysql
$docker exec -it mysql mysql -u root -p
CREATE DATABASE nextcloud;
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;
exit;
$docker run --name nextcloud --link mysql:nextcloud_db -p 80:80 -v /home/nextcloud:/var/www/html/ -d nextcloud
way2: docker-compose
#mkdir -p /home/nextcloud/mysql
#mkdir -p /home/nextcloud/www/html
#chown -R www-data:root /home/nextcloud
$docker network create nextcloud_net
$cat docker-compose.yml
version: '2'
services:
db:
container_name: mysql_db
image: mysql
volumes:
- "/home/nextcloud/mysql:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: 12345678
MYSQL_DATABASE: nextcloud
app:
container_name: nextcloud_app
depends_on:
- db
image: nextcloud
volumes:
- "/home/nextcloud/www/html:/var/www/html"
- "/home/share:/home/share"
links:
- db
ports:
- 80:80
restart: always
networks:
default:
external:
name: nextcloud_net
$docker-compose up -d
數據庫初始信息
容器內
在 mysql_db
啓動後,立即檢查初始數據庫信息如下:
# mysql --user=root --password=12345678
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nextcloud |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> use nextcloud
Database changed
mysql> show tables;
Empty set (0.00 sec)
宿主機
szscm@vmcnszs207:/home/nextcloud/mysql$ ls
auto.cnf ca-key.pem '#ib_16384_0.dblwr' ib_logfile0 mysql private_key.pem sys
binlog.000001 ca.pem '#ib_16384_1.dblwr' ib_logfile1 mysql.ibd public_key.pem undo_001
binlog.000002 client-cert.pem ib_buffer_pool ibtmp1 nextcloud server-cert.pem undo_002
binlog.index client-key.pem ibdata1 '#innodb_temp' performance_schema server-key.pem
雜亂
version: '2'
services:
db:
container_name: cloud_db
image: mysql:5.7
volumes:
- "/home/mysql:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: mysql_root_pwd #mysql root用戶密碼,nextcloud後續初始化需要使用。
MYSQL_DATABASE: nextcloud #專爲nextcloud新建的數據庫,nextcloud後續初始化需要使用。
app:
container_name: cloud_app
depends_on:
- db
image: nextcloud
volumes:
- /home/nextcloud:/var/www/html
links:
- db
ports:
- "80:80" # 前一個80是宿主機也就是阿里雲主機對外的端口號,需注意阿里雲主機安全組規則是否開放了這個端口。
restart: always
cron:
container_name: cloud_cron
image: nextcloud
links:
- db
volumes_from:
- app
user: www-data
entrypoint: |
bash -c 'bash -s <<EOF
trap "break;exit" SIGHUP SIGINT SIGTERM
while /bin/true; do
/usr/local/bin/php /var/www/html/cron.php
sleep 900
done
EOF'
restart: always
networks:
default:
external:
name: nextcloud
關於容器更多使用,需要參考: https://hub.docker.com/_/nextcloud/
因爲計劃使用數據庫,需要藉助:–link db_nextcloud:db_nextcloud是因爲要鏈接數據庫的docker。
- https://www.jianshu.com/p/f1eb37d0e97d: doker compose 啓動nextcloud
- https://www.cnblogs.com/steinven/p/11357295.html: docker手動啓動nextcloud
配置
數據庫配置
初始化配置
首次打開網頁: 172.16.246.207
進入NextCloud初始頁面。
- 設置NEXTCLOUD管理員賬戶密碼
- 數據目錄選擇:
/var/www/html/data
- 選擇MySQL數據庫
- 輸入MySQL的root賬戶密碼:root/12345678
- 選擇MySQL數據庫
- 選擇MySQL主機
如下:
最後點擊完成。
初始化配置後的數據庫信息
這裏只在 mysql_db
容器內查看相關內容即可。如下
root@3159365f7181:/# mysql --user=root --password=12345678
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 60
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select database();
+------------+
| database() |
+------------+
| NULL |
+------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nextcloud |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use nextcloud
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-----------------------------+
| Tables_in_nextcloud |
+-----------------------------+
| oc_accounts |
| oc_activity |
| oc_activity_mq |
| oc_addressbookchanges |
| oc_addressbooks |
| oc_appconfig |
| oc_authtoken |
| oc_bruteforce_attempts |
| oc_calendar_invitations |
| oc_calendar_reminders |
| oc_calendar_resources |
| oc_calendar_resources_md |
| oc_calendar_rooms |
| oc_calendar_rooms_md |
| oc_calendarchanges |
| oc_calendarobjects |
| oc_calendarobjects_props |
| oc_calendars |
| oc_calendarsubscriptions |
| oc_cards |
| oc_cards_properties |
| oc_collres_accesscache |
| oc_collres_collections |
| oc_collres_resources |
| oc_comments |
| oc_comments_read_markers |
| oc_credentials |
| oc_dav_cal_proxy |
| oc_dav_shares |
| oc_direct_edit |
| oc_directlink |
| oc_federated_reshares |
| oc_file_locks |
| oc_filecache |
| oc_filecache_extended |
| oc_files_trash |
| oc_flow_checks |
| oc_flow_operations |
| oc_flow_operations_scope |
| oc_group_admin |
| oc_group_user |
| oc_groups |
| oc_jobs |
| oc_login_flow_v2 |
| oc_migrations |
| oc_mimetypes |
| oc_mounts |
| oc_notifications |
| oc_notifications_pushtokens |
| oc_oauth2_access_tokens |
| oc_oauth2_clients |
| oc_preferences |
| oc_privacy_admins |
| oc_properties |
| oc_recent_contact |
| oc_schedulingobjects |
| oc_share |
| oc_share_external |
| oc_storages |
| oc_systemtag |
| oc_systemtag_group |
| oc_systemtag_object_mapping |
| oc_text_documents |
| oc_text_sessions |
| oc_text_steps |
| oc_trusted_servers |
| oc_twofactor_backupcodes |
| oc_twofactor_providers |
| oc_user_transfer_owner |
| oc_users |
| oc_vcategory |
| oc_vcategory_to_object |
| oc_webauthn |
| oc_whats_new |
+-----------------------------+
74 rows in set (0.00 sec)
mysql>
mysql> select * from oc_users;
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
| uid | displayname | password | uid_lower |
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
| szscm | NULL | 3|$argon2id$v=19$m=65536,t=4,p=1$Z1pnTGovd0ZDT1g0LmpqbQ$nDjmkB85OP6Lm8DDImFh/60QxHDU0D21HIiErTuNNcA | szscm |
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
1 row in set (0.00 sec)
mysql> select * from oc_accounts;
Empty set (0.01 sec)
mysql> select * from oc_group_admin;
Empty set (0.00 sec)
mysql> select * from oc_group_user;
+-------+-------+
| gid | uid |
+-------+-------+
| admin | szscm |
+-------+-------+
1 row in set (0.00 sec)
mysql> select * from oc_groups;
+-------+-------------+
| gid | displayname |
+-------+-------------+
| admin | admin |
+-------+-------------+
1 row in set (0.00 sec)
mysql> select * from oc_credentials;
Empty set (0.00 sec)
mysql> select * from oc_user_transfer_owner;
Empty set (0.00 sec)
可見,建立了很多表。
用戶管理
方法一:圖形界面
在瀏覽器登入NextCloud的管理員用戶後,新建 test 用戶, 分組爲 szic 。
過程如下:
添加szic羣組
選擇 配置->添加分組
, 輸入 szic
如下:
添加test用戶
選擇 配置->新建用戶
, 輸入 test
以及相關信息。這裏密碼設置是: 123456
。
如下:
注意: 由於默認要求必須用8位高強度密碼,如果想要去掉這個限制,需要在頁面中找到 設置->管理->安全
進行密碼規則設定:
方法二:命令行方式
登陸nextcloud的容器
$docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2de00e21130c nextcloud "/entrypoint.sh apac…" 6 minutes ago Up 6 minutes 0.0.0.0:80->80/tcp nextcloud_app
3159365f7181 mysql "docker-entrypoint.s…" 3 days ago Up 3 days 3306/tcp, 33060/tcp mysql_db
$docker exec -it -u www-data nextcloud_app /bin/bash
www-data@2de00e21130c:~/html$export OC_PASS="123456"
www-data@2de00e21130c:~/html$php /var/www/html/occ user:add --password-from-env --display-name="test" --group="szic" "test"
這樣便建立默認密碼爲 123456
用戶組爲 szic
的用戶 test
, 如果不用 --password-from-env
則需手動輸入密碼。
查看數據庫
添加完用戶後,相關的數據庫信息
root@3159365f7181:/# mysql --user=root --password=12345678
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 120
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use nextcloud
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from oc_users;
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
| uid | displayname | password | uid_lower |
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
| szscm | NULL | 3|$argon2id$v=19$m=65536,t=4,p=1$Z1pnTGovd0ZDT1g0LmpqbQ$nDjmkB85OP6Lm8DDImFh/60QxHDU0D21HIiErTuNNcA | szscm |
| test | NULL | 3|$argon2id$v=19$m=65536,t=4,p=1$V09Jc2IwMzZqdjVMSDNVVw$ff+VwF+3Mrj4KeOIU6GdbAyAuQCubTYbI4qu5HHIcUY | test |
+-------+-------------+-----------------------------------------------------------------------------------------------------+-----------+
2 rows in set (0.00 sec)
mysql> select * from oc_accounts;
+-------+------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
| uid | data
|
+-------+------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------+
| szscm | {"displayname":{"value":"szscm","scope":"contacts","verified":"0"},"address":{"value":"","scope":"private","verified":"0"},"website":{"value":"","scope":"private","verified":"0"},"email":{"value":null,"scope":"contacts","verified":"0"},"avatar":{"scope":"contacts"},"phone":{"value":"","scope":"private","verified":"0"},"twitter":{"value":"","scope":"private","verified":"0"}} |
| test | {"displayname":{"value":"test","scope":"contacts","verified":"0"},"address":{"value":"","scope":"private","verified":"0"},"website":{"value":"","scope":"private","verified":"0"},"email":{"value":null,"scope":"contacts","verified":"0"},"avatar":{"scope":"contacts"},"phone":{"value":"","scope":"private","verified":"0"},"twitter":{"value":"","scope":"private","verified":"0"}} |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> select * from oc_group_admin;
Empty set (0.01 sec)
mysql> select * from oc_group_user;
+-------+-------+
| gid | uid |
+-------+-------+
| admin | szscm |
| szic | test |
+-------+-------+
2 rows in set (0.00 sec)
mysql> select * from oc_groups;
+-------+-------------+
| gid | displayname |
+-------+-------------+
| admin | admin |
| szic | szic |
+-------+-------------+
2 rows in set (0.00 sec)
mysql> select * from oc_credentials;
Empty set (0.00 sec)
mysql> select * from oc_user_transfer_owner;
Empty set (0.00 sec)
mysql>
默認文件
某個用戶登陸NextCloud後會看到默認的文件。
這些默認文件的存放在: /home/nextcloud/www/html/core/skeleton
, 如果修改這裏的內容,那麼新用戶登陸看到的默認文件也隨之變化。但是,當Nextcloud升級時,這個 core/skeleton
就會被替換,你所做的修改也就不存在了。
如果自定義配置:
config/config.php
,
自定義默認文件添加如下:
'skeletondirectory' => 'core/custom_skeleton',
這樣,Nextcloud在安裝或創建新用戶時就會從core/custom_skeleton複製文件,當Nextcloud更新時,這個目錄也不會被替換以至於丟失自定義的默認文件。
'skeletondirectory' => '',
這樣Nextcloud就不會去複製任何文件,這樣用戶的文件夾默認就是空的。
使用
客戶端下載: https://nextcloud.com/install/#install-clients
問題
主機與NextCloud數據同步
NEXTCLOUD數據存於磁盤,但是網頁上只能看到nextcloud中上傳的文件,看不到手動傳輸到對應數據目錄的文件。
默認數據存放位置:
與主機共享數據的方案
方案1、webdav掛載
1、安裝 davfs2
2、輸入命令進行掛載
mount -t davfs http://webdav地址 /掛載路徑
3、根據提示輸入用戶名及密碼
方案2、掃描文件同步
# nextcloud={nextcloud安裝目錄}
# cd $nextcloud
# su -s /bin/bash -c “/usr/bin/php $nextcloud/occ file:scan” apache
期間的問題
實時同步
結合 inotify,使用舉例:
#!/bin/bash
#inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e create,attrib,move,delete,modify,close_write ./notify_check | \
lastpath=""
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' -e create,modify,delete,move ./notify_check | \
while read d t p f; do
echo "time is:$d$t"
echo "file path is: $p$f"
#Don't process with action if event happens in same filepath
if [ "x$lastpath" != "x$p$f" ]
then
echo "Action path:$p$f!"
lastpath=$p$f
fi
done
其中檢測到文件變化的動作,改成 occ file:scan
即可(有待實踐)。
文件夾部署
默認nextcloud中上傳的數據存儲路徑是: /var/www/html/data/<username>/files
, 如果沒有上傳過數據,就沒有 files
文件夾。
所以部署上我們可以這樣:
$mkdir -p /home/share/nextcloud_files
$ln -s /var/www/html/data/<username>/files /home/share/nextcloud_files/<username>
但是問題是nextcloud的數據目錄: /var/www/html/data
有權限的控制,導致其它人(除了 root
與 www-data
)無法訪問, 進而創建的軟連接也無法進行了。目前只能手動用 chmod
方式修改,過一段時間或重啓後自動恢復成不可訪問了。
其它
一些計劃
一些參考
數據遷移:https://help.nextcloud.com/t/tutorial-how-to-migrate-mass-data-to-a-new-nextcloud-server/9418/20
參考: https://www.cnblogs.com/zhouzhifei/p/11548503.html
來源:https://wzfou.com/question/9883/
baoang54 2018年11月23日 0 個評論
站長推薦過這個私有云工具,在ownCloud 和它之間我選了後者,安裝什麼的照站長的說明順利完成倒不難,但一段時間用下來有個問題。
有些東西我可以從網上下載,一般是用wget ,那我就找到它的數據目錄,比如Nextcloud /data /user ,大概是這個,然後運行wget 就下到這裏。我的想法是如此操作後,通過網頁登陸或手機客戶端登錄後能在網盤裏看到這個文件,可是試過之後發現網盤或網頁登錄後沒有這個下載的文件。
想問站長,理論上我的想法應當是對的,但爲什麼顯示不出來呢?是否Nextcloud 還需要進行其他的配置?
Avatar for 逗婦乳
逗婦乳14 回答於2018年11月28日 1 評論
nextcloud 列出文件都是查詢數據庫記錄的,你手動添加的文件是沒有記錄信息的,需要手動掃描
# nextcloud={nextcloud安裝目錄}
# cd $nextcloud
# su -s /bin/bash -c “/usr/bin/php $nextcloud/occ file:scan” apache
baoang 評論於 2018年11月28日
Avatar for 逗婦乳
baoang 評論於 2018年11月28日
哦,原來是這樣。 看了下官方論壇的文檔: https://help.nextcloud.com/t/tutorial-how-to-migrate-mass-data-to-a-new-nextcloud-server/ 結果想到那個關鍵的php——我編譯LEMP的時候用了個參數: –disable-cli 這下使不上勁了
來源:https://www.cnblogs.com/gaosf/p/11690601.html
創建 nextcloud 所需的數據庫和賬戶
打開數據庫管理命令行,默認root沒密碼,回車進入
sudo mysql -u root -p
創建 nextcloud 數據庫,命令包含後面的分號
CREATE DATABASE nextcloud;
//創建用戶nextclouduser,password可自定義
create user nextclouduser@localhost identified by 'nextpassword';
//用以下命令授予必要的權限爲數據庫和用戶授權
grant all privileges on nextcloud.* to nextclouduser@localhost identified by 'nextpassword';
//用命令更新數據庫配置:
flush privileges;
注意操作時,指令後需加‘;’使執行
來源:https://blog.xiaolee.net/zt/679.html
1、安裝 davfs2
2、輸入命令進行掛載
mount -t davfs http://webdav地址 /掛載路徑
3、根據提示輸入用戶名及密碼