自建Nextcloud私有云盘

安装

从Nextcloud官方网站下载server的安装包,复制到/var/www目录解压。

详细安装过程参考官方文档

1、按照官方文档安装完善php模块

必须要安装的模块

  • PHP (see System requirements for a list of supported versions)

  • PHP module ctype

  • PHP module curl

  • PHP module dom

  • PHP module fileinfo (included with PHP)

  • PHP module filter (only on Mageia and FreeBSD)

  • PHP module GD

  • PHP module hash (only on FreeBSD)

  • PHP module JSON (included with PHP >= 8.0)

  • PHP module libxml (Linux package libxml2 must be >=2.7.0)

  • PHP module mbstring

  • PHP module openssl (included with PHP >= 8.0)

  • PHP module posix

  • PHP module session

  • PHP module SimpleXML

  • PHP module XMLReader

  • PHP module XMLWriter

  • PHP module zip

  • PHP module zlib

选择合适的数据库模块:

  • PHP module pdo_sqlite (>= 3, usually not recommended for performance reasons)

  • PHP module pdo_mysql (MySQL/MariaDB)

  • PHP module pdo_pgsql (PostgreSQL)

推荐安装的模块:

  • PHP module bz2 (recommended, required for extraction of apps)

  • PHP module intl (increases language translation performance and fixes sorting of non-ASCII characters)

2、Apache配置文件

新增配置文件vim /etc/apache2/sites-available/nextcloud.conf,复制以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<VirtualHost *:80>
DocumentRoot /var/www/nextcloud/
ServerName your.server.com

<Directory /var/www/nextcloud/>
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews

<IfModule mod_dav.c>
Dav off
</IfModule>
</Directory>
</VirtualHost>

保存,然后运行:

1
a2ensite nextcloud.conf

启用必要的Apache模块:

1
2
3
4
5
6
a2enmod rewrite

a2enmod headers
a2enmod env
a2enmod dir
a2enmod mime

If you’re running mod_fcgi instead of the standard mod_php also enable:

1
a2enmod setenvif

最后重启Apache:

1
service apache2 restart

现在就可以访问http://your.server.com安装Nextcloud。

Redis缓存配置

修改配置文件nextcloud/config/config.php

Small/Private home server

Only use APCu:

1
'memcache.local' => '\OC\Memcache\APCu',

Organizations with single-server

Use Redis for everything except local memcache:

1
2
3
4
5
6
7
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
'host' => 'localhost',
'port' => 6379,
],

Organizations with clustered setups

Use APCu for local cache and either Redis cluster …:

1
2
3
4
5
6
7
8
9
'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis.cluster' => [
'seeds' => [ // provide some/all of the cluster servers to bootstrap discovery, port required
'cache-cluster:7000',
'cache-cluster:7001',
],
]

APCu is disabled by default on CLI which could cause issues with nextcloud’s cron jobs. Please make sure you set the apc.enable_cli to 1 on your php.ini config file or append --define apc.enable_cli=1 to the cron job call.

1
vim /etc/php/8.1/cli/php.ini

在末尾添加apc.enable_cli=1,否则当你运行occ命令的时候也会提示你APCu不可用。

OCC命令的使用

直接运行occ命令,不带任何选项,就会列出occ命令的所有可用的选项和用法:

1
sudo -u www-data php8.1 /var/www/nextcloud/occ

返回信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Nextcloud 24.0.12

Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--no-warnings Skip global warnings, show command output only
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
check check dependencies of the server environment
help Display help for a command
list List commands
status show some status information
upgrade run upgrade routines after installation of a new release. The release has to be installed before.
activity
activity:send-mails Sends the activity notification mails
app
app:check-code check code to be compliant
app:disable disable an app
app:enable enable an app
app:getpath Get an absolute path to the app directory
app:install install an app
app:list List all available apps
app:remove remove an app
app:update update an app or all apps
background
background:ajax Use ajax to run background jobs
background:cron Use cron to run background jobs
background:webcron Use webcron to run background jobs
background-job
background-job:execute Execute a single background job manually
broadcast
broadcast:test test the SSE broadcaster
circles
circles:check Checking your configuration
circles:maintenance Clean stuff, keeps the app running
circles:manage:config edit config/type of a Circle
circles:manage:create create a new circle
circles:manage:destroy destroy a circle by its ID
circles:manage:details get details about a circle by its ID
circles:manage:edit edit displayName or description of a Circle
circles:manage:join emulate a user joining a Circle
circles:manage:leave simulate a user joining a Circle
circles:manage:list listing current circles
circles:manage:setting edit setting for a Circle
circles:members:add Add a member to a Circle
circles:members:details get details about a member by its ID
circles:members:level Change the level of a member from a Circle
circles:members:list listing Members from a Circle
circles:members:remove remove a member from a circle
circles:members:search Change the level of a member from a Circle
circles:memberships index and display memberships for local and federated users
circles:remote remote features
circles:shares:files listing shares files
circles:sync Sync Circles and Members
circles:test testing some features
config
config:app:delete Delete an app config value
config:app:get Get an app config value
config:app:set Set an app config value
config:import Import a list of configs
config:list List all configs
config:system:delete Delete a system config value
config:system:get Get a system config value
config:system:set Set a system config value
dav
dav:create-addressbook Create a dav addressbook
dav:create-calendar Create a dav calendar
dav:delete-calendar Delete a dav calendar
dav:list-calendars List all calendars of a user
dav:move-calendar Move a calendar from an user to another
dav:remove-invalid-shares Remove invalid dav shares
dav:retention:clean-up
dav:send-event-reminders Sends event reminders
dav:sync-birthday-calendar Synchronizes the birthday calendar
dav:sync-system-addressbook Synchronizes users to the system addressbook
db
db:add-missing-columns Add missing optional columns to the database tables
db:add-missing-indices Add missing indices to the database tables
db:add-missing-primary-keys Add missing primary keys to the database tables
db:convert-filecache-bigint Convert the ID columns of the filecache to BigInt
db:convert-mysql-charset Convert charset of MySQL/MariaDB to use utf8mb4
db:convert-type Convert the Nextcloud database to the newly configured one
encryption
encryption:change-key-storage-root Change key storage root
encryption:decrypt-all Disable server-side encryption and decrypt all files
encryption:disable Disable encryption
encryption:enable Enable encryption
encryption:encrypt-all Encrypt all files for all users
encryption:list-modules List all available encryption modules
encryption:migrate-key-storage-format Migrate the format of the keystorage to a newer format
encryption:set-default-module Set the encryption default module
encryption:show-key-storage-root Show current key storage root
encryption:status Lists the current status of encryption
federation
federation:sync-addressbooks Synchronizes addressbooks of all federated clouds
files
files:cleanup cleanup filecache
files:recommendations:recommend
files:repair-tree Try and repair malformed filesystem tree structures
files:scan rescan filesystem
files:scan-app-data rescan the AppData folder
files:transfer-ownership All files and folders are moved to another user - outgoing shares and incoming user file shares (optionally) are moved as well.
files_external
files_external:applicable Manage applicable users and groups for a mount
files_external:backends Show available authentication and storage backends
files_external:config Manage backend configuration for a mount
files_external:create Create a new mount configuration
files_external:delete Delete an external mount
files_external:export Export mount configurations
files_external:import Import mount configurations
files_external:list List configured admin or personal mounts
files_external:notify Listen for active update notifications for a configured external mount
files_external:option Manage mount options for a mount
files_external:verify Verify mount configuration
group
group:add Add a group
group:adduser add a user to a group
group:delete Remove a group
group:info Show information about a group
group:list list configured groups
group:removeuser remove a user from a group
integrity
integrity:check-app Check integrity of an app using a signature.
integrity:check-core Check integrity of core code using a signature.
integrity:sign-app Signs an app using a private key.
integrity:sign-core Sign core using a private key.
l10n
l10n:createjs Create javascript translation files for a given app
log
log:file manipulate logging backend
log:manage manage logging configuration
log:tail Tail the nextcloud logfile
log:watch Watch the nextcloud logfile
maintenance
maintenance:data-fingerprint update the systems data-fingerprint after a backup is restored
maintenance:mimetype:update-db Update database mimetypes and update filecache
maintenance:mimetype:update-js Update mimetypelist.js
maintenance:mode set maintenance mode
maintenance:repair repair this installation
maintenance:repair-share-owner repair invalid share-owner entries in the database
maintenance:theme:update Apply custom theme changes
maintenance:update:htaccess Updates the .htaccess file
notification
notification:generate Generate a notification for the given user
notification:test-push Generate a notification for the given user
preview
preview:repair distributes the existing previews into subfolders
preview:reset-rendered-texts Deletes all generated avatars and previews of text and md files
security
security:bruteforce:reset resets bruteforce attemps for given IP address
security:certificates list trusted certificates
security:certificates:import import trusted certificate in PEM format
security:certificates:remove remove trusted certificate
serverinfo
serverinfo:update-storage-statistics Triggers an update of the counts related to storages used in serverinfo
sharing
sharing:cleanup-remote-storages Cleanup shared storage entries that have no matching entry in the shares_external table
sharing:expiration-notification Notify share initiators when a share will expire the next day.
support
support:report Generate a system report
tag
tag:add Add new tag
tag:delete delete a tag
tag:edit edit tag attributes
tag:list list tags
text
text:reset Reset a text document
theming
theming:config Set theming app config values
trashbin
trashbin:cleanup Remove deleted files
trashbin:expire Expires the users trashbin
trashbin:restore Restore all deleted files
trashbin:size Configure the target trashbin size
twofactorauth
twofactorauth:cleanup Clean up the two-factor user-provider association of an uninstalled/removed provider
twofactorauth:disable Disable two-factor authentication for a user
twofactorauth:enable Enable two-factor authentication for a user
twofactorauth:enforce Enabled/disable enforced two-factor authentication
twofactorauth:state Get the two-factor authentication (2FA) state of a user
update
update:check Check for server and app updates
user
user:add adds a user
user:add-app-password Add app password for the named user
user:delete deletes the specified user
user:disable disables the specified user
user:enable enables the specified user
user:info show user info
user:lastseen shows when the user was logged in last time
user:list list configured users
user:report shows how many users have access
user:resetpassword Resets the password of the named user
user:setting Read and modify user settings
versions
versions:cleanup Delete versions
versions:expire Expires the users file versions
workflows
workflows:list Lists configured workflows

扫描所有用户文件更新:

1
sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan --all

扫描特定用户文件更新:

1
sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan username

扫描特定目录文件更新:

1
sudo -u www-data php8.1 /var/www/nextcloud/occ files:scan --path=/path/to/scan

后台服务优化

后台服务有三种方式:AJAX,Webcron,Cron

systemd

If systemd is installed on the system, a systemd timer could be an alternative to a cronjob.

This approach requires two files: nextcloudcron.service and nextcloudcron.timer. Create these two files in /etc/systemd/system/.

nextcloudcron.service should look like this:

1
2
3
4
5
6
7
[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/nextcloud/cron.php
KillMode=process

Replace the user www-data with the user of your http server and /var/www/nextcloud/cron.php with the location of cron.php in your nextcloud directory.

The KillMode=process setting is necessary for external programs that are started by the cron job to keep running after the cron job has finished.

Note that the .service unit file does not need an [Install] section. Please check your setup because we recommended it in earlier versions of this admin manual.

nextcloudcron.timer should look like this:

1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Run Nextcloud cron.php every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=nextcloudcron.service

[Install]
WantedBy=timers.target

The important parts in the timer-unit are OnBootSec and OnUnitActiveSec. OnBootSec will start the timer 5 minutes after boot, otherwise you would have to start it manually after every boot. OnUnitActiveSec will set a 5 minute timer after the service-unit was last activated.

Now all that is left is to start and enable the timer by running this command:

1
systemctl enable --now nextcloudcron.timer

When the option --now is used with enable, the respective unit will also be started.

客户端下载

直接从这里下载https://download.nextcloud.com/desktop/releases/

自建Nextcloud私有云盘

http://tux.red/2023/08/15/Nas/nextcloud/

作者

redtux

发布于

2023-08-15

更新于

2023-08-22

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.