搭建私有云存储系统-NextCloud

这里主要介绍使用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 <

关于容器更多使用,需要参考: 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//files , 如果没有上传过数据,就没有 files 文件夹。

所以部署上我们可以这样:

$mkdir -p /home/share/nextcloud_files
$ln -s /var/www/html/data//files /home/share/nextcloud_files/

但是问题是nextcloud的数据目录: /var/www/html/data 有权限的控制,导致其它人(除了 rootwww-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、根据提示输入用户名及密码

你可能感兴趣的:(搭建私有云存储系统-NextCloud)