forked from Vasilii888/Manual
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Установка и настройка NextCloud на UbuntuSRV, Collabora.txt
617 lines (474 loc) · 22.3 KB
/
Установка и настройка NextCloud на UbuntuSRV, Collabora.txt
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
//////////////////////////////////
// 001. Настройка Ubuntu Server //
//////////////////////////////////
1. "Установить UbuntuServer"
----------------------------------------------------------------
2. "При установке разметить диски"
/dev/sda
2G ext4 /boot
/dev/sdb
root-vg (lvm)
ext4 / root-lv (lvm)
----------------------------------------------------------------
3. "После установки извлечь установочный диск и перезагрузить"
----------------------------------------------------------------
4. "Обновить и очистить пакеты"
sudo apt update
sudo apt upgrade
sudo apt autoremove
----------------------------------------------------------------
5. "Настроить hostname"
sudo vim /etc/hostname
cloud
sudo vim /etc/hosts
127.0.1.1 cloud
----------------------------------------------------------------
6. "Настроить timezone"
sudo timedatectl set-timezone Europe/Moscow
----------------------------------------------------------------
7. "# make sure that “network: {config: disabled}” entry is there. If the entry is missing, we have to create it."
sudo cat /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
network: {config: disabled}
----------------------------------------------------------------
8. "Настроить сетевые интерфейсы"
sudo cat /etc/netplan/00-installer-config.yaml
sudo cp -a /etc/netplan/00-installer-config.yaml{,.orig} # back up the file /etc/netplan/00-installer-config.yaml
ip a
sudo vim /etc/netplan/00-installer-config.yaml
network:
version: 2
renderer: networkd
ethernets:
ens18:
addresses:
- 192.168.1.11/24
nameservers:
addresses: [192.168.1.1, 8.8.8.8]
ens19:
addresses:
- 8.8.4.4/29
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
routes:
- to: default
via: 8.8.8.1
sudo netplan try
----------------------------------------------------------------
9. "Добавить пользователя"
adduser vol
usermod -aG sudo vol
----------------------------------------------------------------
10. "Настроить SSH по ключу"
# linux
sudo apt install openssh
# windows
winget install openssh
# перейти в папку .ssh на локальной машине
cd ~/.ssh
# Сгенерировать ключ на локальной машине
ssh-keygen -t rsa -b 4096
# посмотреть созданные ключи
ls
# создание папки ssh на удаленном сервере
#ssh [remote_username]@[server_ip_address] mkdir -p .ssh
ssh vol@volgraft.ru mkdir -p .ssh
# скопировать публичный ключ на удаленный сервер
# scp .\[key.pub] [remote_username]@[server_ip_address]:/home/vol/.ssh/[key.pub]
scp C:\Users\admin\.ssh\key.pub vol@volgraft.ru:/home/vol/.ssh/key.pub
# подключится к удаленному серверу по ssh
# экспорт публичного ключа в uthorized_keys
cat ~/.ssh/key.pub >> ~/.ssh/authorized_keys
# отредактировать sshd_config
sudo vim /etc/ssh/sshd_config
Port 2822 # поменять порт SSH
UsePAM yes
PasswordAuthentication no
PermitRootLogin no
# перезагрузить sshd сервис
sudo systemctl restart sshd
# Включить ssh агент
Start-Service ssh-agent
Get-Service ssh-agent
Get-Service ssh-agent | Select StartType
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
# Добавить ключ в SSH агент
# ssh-add <path to new private key file>
ssh-add c:/Users/admin/.ssh/key
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// 002. Установка и настройка NextCloud (установка сервера, базы данных; монтирование директории data) //
/////////////////////////////////////////////////////////////////////////////////////////////////////////
1. "Установка и настройка базы данных"
sudo apt install mariadb-server
systemctl status mariadb
----------------------------------------------------------------
2. "Настройки безопасности MariaDB"
sudo mysql_secure_installation
Enter current password for root (enter for none): none
Switch to unix_socket authentication [Y/n] : n
Change the root password? [Y/n]: y
Remove anonymous users? [Y/n]: y
Disallow root login remotely? [Y/n]: y
Remove test database and access to it? [Y/n]: y
Reload privilege tables now? [Y/n]: y
----------------------------------------------------------------
3. "Создание базы nextcloud"
sudo mariadb
CREATE DATABASE nextcloud;
SHOW DATABASES;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'localhost' IDENTIFIED BY 'mypassword';
FLUSH PRIVILEGES;
exit
# сменить пароль юзера maiadb (если забыл)
# ALTER USER 'user'@'localhost' IDENTIFIED BY 'new_password'; сменить пароль юзера maiadb
# FLUSH PRIVILEGES;
# exit
----------------------------------------------------------------
4. "Установка WEB сервера"
sudo apt install php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml
systemctl status apache2 # apache2 должен установится как зависимость вместе с предыдущей командой
----------------------------------------------------------------
5."Enable PHP extensions"
sudo phpenmod bcmath gmp imagick intl
----------------------------------------------------------------
6. "Скачать дистрибутив Nextcloud"
https://nextcloud.com/
wget https://download.nextcloud.com/server/releases/latest.zip
----------------------------------------------------------------
7. "Распаковать и установить Nextcloud"
sudo apt install unzip
unzip latest.zip
sudo mv nextcloud /var/www/
rm latest.zip
----------------------------------------------------------------
8. "Сменить владельца /var/www/nextcloud/"
sudo chown -R www-data:www-data /var/www/nextcloud/
----------------------------------------------------------------
9. "apache2 disable default site"
sudo a2dissite 000-default.conf
----------------------------------------------------------------
10. "Настроить сайт nextcloud"
sudo vim /etc/apache2/sites-available/nextcloud.conf
<VirtualHost *:80>
DocumentRoot "/var/www/nextcloud"
ServerName cloud
<Directory "/var/www/nextcloud/">
Options MultiViews FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
TransferLog /var/log/apache2/nextcloud.log
ErrorLog /var/log/apache2/nextcloud.log
</VirtualHost>
----------------------------------------------------------------
11. "apache2 enable nextcloud site"
sudo a2ensite nextcloud.conf
----------------------------------------------------------------
12. "Конфигурирование appache сервера"
# sudo vim /etc/php/8.1/apache2/php.ini
# провести проверку текущих настроек через cat
cat /etc/php/8.1/apache2/php.ini | grep 'memory_limit = '
cat /etc/php/8.1/apache2/php.ini | grep 'upload_max_filesize ='
cat /etc/php/8.1/apache2/php.ini | grep 'max_execution_time ='
cat /etc/php/8.1/apache2/php.ini | grep 'post_max_size ='
cat /etc/php/8.1/apache2/php.ini | grep 'date.timezone ='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.enable='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.interned_strings_buffer='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.max_accelerated_files='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.memory_consumption='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.save_comments='
cat /etc/php/8.1/apache2/php.ini | grep 'opcache.revalidate_freq='
# заменить требуемые строки настроек
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 200M/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/max_execution_time = 30/max_execution_time = 360/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 200M/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;date.timezone =/date.timezone = Europe\/Moscow/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.enable=1/opcache.enable=1/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.save_comments=1/opcache.save_comments=1/g' /etc/php/8.1/apache2/php.ini
sudo sed -i 's/;opcache.revalidate_freq=2/opcache.revalidate_freq=1/g' /etc/php/8.1/apache2/php.ini
# провести проверку через cat снова, результат ниже:
memory_limit = 512M
upload_max_filesize = 200M
max_execution_time = 360
post_max_size = 200M
date.timezone = Europe/Moscow
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=1
----------------------------------------------------------------
13. "Перепроверить модификаторы appache и перезагрузить appache"
sudo a2enmod dir env headers mime rewrite ssl
sudo systemctl restart apache2
----------------------------------------------------------------
14. "Перейти на сайт и завершить установку nextcloud"
/////////////////////////////////////////////
// 003. Дополнительные настройки и сервисы //
/////////////////////////////////////////////
1. "Дополнительный софт"
sudo apt install libapache2-mod-php imagemagick ffmpeg php-bz2 php-redis redis-server unzip redis-server php-redis cron ncdu lnav net-tools iotop htop
----------------------------------------------------------------
2. "Добавить в 'trusted_domains' все адреса, к которым будет осуществляться подключение"
sudo vim /var/www/nextcloud/config/config.php
'trusted_domains' =>
array (
0 => 'cloud.volgraft.ru',
),
----------------------------------------------------------------
3. "Дополнительные настройки в nextcloud/config/config.php"
sudo vim /var/www/nextcloud/config/config.php
'memcache.local' => '\\OC\\Memcache\\APCu',
'default_phone_region' => 'RU',
'simpleSignUpLink.shown' => false,
'config_is_read_only' => true,
'maintenance' => false,
----------------------------------------------------------------
4. "Убрать ошибку Image Magick error"
sudo apt install libmagickcore-6.q16-6-extra
----------------------------------------------------------------
5. "Настроить certbot"
https://certbot.eff.org/instructions
----------------------------------------------------------------
6. "Enabling Strict Transport Security"
sudo vim /etc/apache2/sites-available/nextcloud-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
............
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains" # добавить эту строку
............
</VirtualHost>
</IfModule>
----------------------------------------------------------------
7. "Reditect to 443"
sudo vim /etc/apache2/sites-available/nc-redir.conf
<VirtualHost *:80>
ServerName nc.domain.org
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
sudo systemctl restart apache2
----------------------------------------------------------------
8. "Настроить cron"
# Configuration settings > Basic settings > Enable Cron
sudo apt install cron
sudo systemctl enable cron
sudo crontab -e
*/5 * * * * php -f /var/www/nextcloud/cron.php # вставить в конце, не забыть про перенос на новую строку в конце
sudo crontab -l
----------------------------------------------------------------
9. "Настроить redis"
ps ax | grep redis
sudo apt install redis-server php-redis
ps ax | grep redis
sudo usermod -a -G redis www-data
sudo systemctl restart apache2
sudo vim /etc/redis/redis.conf
unixsocket /var/run/redis/redis-server.sock
unixsocketperm 770
port 0
sudo systemctl restart redis
sudo vim /var/www/nextcloud/config/config.php
# удалить строку
'memcache.local' => '\\OC\\Memcache\\APCu',
# и добавить строки
'filelocking.enabled' => true,
'memcache.distributed' => '\\OC\\Memcache\\Redis',
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.locking' => '\\OC\\Memcache\\Redis',
'redis' =>
array (
'host' => '/var/run/redis/redis-server.sock',
'port' => 0,
),
sudo php /var/www/nextcloud/occ background:cron
----------------------------------------------------------------
10. "Настроить fail2ban"
sudo apt install fail2ban
sudo cp /etc/fail2ban/fail2ban.conf /etc/fail2ban/fail2ban.local
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo vim /etc/fail2ban/jail.local
ignoreip = 127.0.0.1/8 ::1
# Create a file in /etc/fail2ban/filter.d named nextcloud.conf with the following contents:
sudo vim /etc/fail2ban/filter.d/nextcloud.conf
[Definition]
_groupsre = (?:(?:,?\s*"\w+":(?:"[^"]+"|\w+))*)
failregex = ^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Login failed:
^\{%(_groupsre)s,?\s*"remoteAddr":"<HOST>"%(_groupsre)s,?\s*"message":"Trusted domain error.
datepattern = ,?\s*"time"\s*:\s*"%%Y-%%m-%%d[T ]%%H:%%M:%%S(%%z)?"
# Create a file in /etc/fail2ban/jail.d named nextcloud.local with the following contents:
sudo vim /etc/fail2ban/jail.d/nextcloud.local
[nextcloud]
backend = auto
enabled = true
port = 80,443
protocol = tcp
filter = nextcloud
maxretry = 3
bantime = 86400
findtime = 3600
logpath = /var/log/nextcloud.log
# config sshd
sudo vim /etc/fail2ban/jail.d/sshd.local
[sshd]
backend = systemd
enabled = true
port = ssh
protocol = tcp
filter = sshd
maxretry = 1
bantime = 1d
findtime = 60m
logpath = %(sshd_log)s
# создать файл логов
sudo touch /var/log/nextcloud.log
sudo chown www-data:www-data /var/log/nextcloud.log
sudo chmod 660 /var/log/nextcloud.log
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
sudo systemctl status fail2ban
----------------------------------------------------------------
11. "ufw"
sudo apt-get install ufw
sudo vim /etc/default/ufw
IPV6=yes
sudo ufw default deny
sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
----------------------------------------------------------------
12. "Логи"
sudo vim /var/www/nextcloud/config/config.php
# в конец
'log_type' => "file",
'logfile' => '/var/log/nextcloud.log',
'loglevel' => 1,
'logdateformat' => "F d, Y H:i:s",
sudo touch /var/log/nextcloud.log
sudo chown -R root:www-data /var/log/nextcloud.log
sudo systemctl restart apache2
# lnav - просмотр логов
sudo tail -n 100 /var/log/nextcloud.log
sudo tail -n 100 /var/log/apache2/nextcloud.log
----------------------------------------------------------------
13. "Удалить index.php из URL"
sudo vim /var/www/nextcloud/config/config.php
'htaccess.RewriteBase' => '/',
sudo php /var/www/nextcloud/occ maintenance:update:htaccess
----------------------------------------------------------------
14. "Настроить права доступа к nextcloud/config/config.php"
sudo chmod 660 /var/www/nextcloud/config/config.php
sudo chown root:www-data /var/www/nextcloud/config/config.php
//////////////////////////////
// 004. Установка Collabora //
//////////////////////////////
0. Создать DNS запись
Cоздать A запись collabora.volgraft.ru = IP вашего nextcloud
----------------------------------------------------------------
1. Установка
В web интерфейсе установить приложение "Nextcloud Office"
----------------------------------------------------------------
2. Импорт ключа официального репозитория
sudo apt install gnupg
cd /usr/share/keyrings
sudo wget https://collaboraoffice.com/downloads/gpg/collaboraonline-release-keyring.gpg
----------------------------------------------------------------
3. Добавить репозиторий
sudo vim /etc/apt/sources.list.d/collaboraonline.sources
Types: deb
URIs: https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-ubuntu2204
Suites: ./
Signed-By: /usr/share/keyrings/collaboraonline-release-keyring.gpg
----------------------------------------------------------------
4. Установить необходимые пакеты
sudo apt update && sudo apt install coolwsd code-brand hunspell collaboraoffice*
----------------------------------------------------------------
5. Настройка Apache для Collabora
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/collabora.conf
sudo vim /etc/apache2/sites-available/collabora.conf
- настроить ServerName (collabora.volgraft.ru)
- удалить ServerAdmin и DocumentRoot
sudo a2ensite collabora && sudo systemctl reload apache2
----------------------------------------------------------------
6. Получить SSL сертификат с помощью certbot
sudo certbot --apache
----------------------------------------------------------------
7. Включить модули apache
sudo a2enmod proxy proxy_wstunnel proxy_http proxy_connect
----------------------------------------------------------------
8. Настроить SSL конфиг Collabora на локальную работу
sudo vim /etc/apache2/sites-enabled/collabora-le-ssl.conf
Options -Indexes
AllowEncodedSlashes NoDecode
ProxyPreserveHost On
# static html, js, images, etc. served from coolwsd
# browser is the client part of Collabora Online
ProxyPass /browser http://127.0.0.1:9980/browser retry=0
ProxyPassReverse /browser http://127.0.0.1:9980/browser
# WOPI discovery URL
ProxyPass /hosting/discovery http://127.0.0.1:9980/hosting/discovery retry=0
ProxyPassReverse /hosting/discovery http://127.0.0.1:9980/hosting/discovery
# Capabilities
ProxyPass /hosting/capabilities http://127.0.0.1:9980/hosting/capabilities retry=0
ProxyPassReverse /hosting/capabilities http://127.0.0.1:9980/hosting/capabilities
# Main websocket
ProxyPassMatch "/cool/(.*)/ws$" ws://127.0.0.1:9980/cool/$1/ws nocanon
# Admin Console websocket
ProxyPass /cool/adminws ws://127.0.0.1:9980/cool/adminws
# Download as, Fullscreen presentation and Image upload operations
ProxyPass /cool http://127.0.0.1:9980/cool
ProxyPassReverse /cool http://127.0.0.1:9980/cool
# Compatibility with integrations that use the /lool/convert-to endpoint
ProxyPass /lool http://127.0.0.1:9980/cool
ProxyPassReverse /lool http://127.0.0.1:9980/cool
ErrorLog /var/log/apache2/collabora-error.log
CustomLog /var/log/apache2/collabora-access.log combined
----------------------------------------------------------------
9. Настройка файлов логов
sudo touch /var/log/apache2/collabora-error.log
sudo touch /var/log/apache2/collabora-access.log
sudo chown root:cool /var/log/apache2/collabora-error.log
sudo chown root:cool /var/log/apache2/collabora-access.log
----------------------------------------------------------------
10. Перезапустить apache
sudo systemctl restart apache2
----------------------------------------------------------------
11. Настроить конфиг Collabora
sudo vim /etc/coolwsd/coolwsd.xml
de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru
>
ru en_US
sudo coolconfig set ssl.enable false
sudo coolconfig set ssl.termination true
----------------------------------------------------------------
12. Перезапустить Collabora
sudo systemctl restart coolwsd
sudo systemctl status coolwsd
----------------------------------------------------------------
13. Включить Collabora в Nextcloud
В WEB интерфейсе в настройках найти опцию Office и подключится к настроенному серверу https://collabora.volgraft.ru
Заполнить опцию Allow list for WOPI requests , IP адресом collabora сервера
Troubleshoot
# https://sdk.collaboraonline.com/docs/installation/Collabora_Online_Troubleshooting_Guide.html
journalctl -e -u coolwsd | lnav
journalctl -r -u coolwsd | lnav
///////////////
// ИСТОЧНИКИ //
///////////////
- Установка и настройка Nextcloud
# https://docs.nextcloud.com/server/latest/admin_manual/configuration_server
# https://www.youtube.com/@LearnLinuxTV/videos
# https://www.youtube.com/@NerdOnTheStreet/videos
- Установка Collabora
# Installation example on Ubuntu https://docs.nextcloud.com/server/latest/admin_manual/office/example-ubuntu.html
# Reverse proxy https://docs.nextcloud.com/server/latest/admin_manual/office/proxy.html
# Proxy settings https://sdk.collaboraonline.com/docs/installation/Proxy_settings.html
# Setting up and configuring https://www.collaboraoffice.com/code/linux-packages/
# Video https://nerdonthestreet.com/wiki?find=Install+Nextcloud+21%2C+Collabora%2C+and+HPB+on+Debian+10