1.修改軟件源
# 備份并編輯source.list文件
$ cp /etc/apt/sources.list /etc/apt/sources.back.list
$ nano /etc/apt/sources.list
# 注釋所有內(nèi)容粹排,添加以下內(nèi)容
deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib
# 備份并編輯raspi.list文件
$ cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.back.list
$ nano /etc/apt/sources.list.d/raspi.list
# 注釋所有內(nèi)容敢会,替換如下內(nèi)容
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main
2.刷新軟件源并更新操作系統(tǒng)
sudo apt-get update && sudo apt-get upgrade -y
3.安裝nginx redis mariadb PHP及模塊:
sudo apt-get install -y nginx
sudo apt-get install -y redis
sudo apt-get install -y mariadb-server
sudo apt-get install -y php php-fpm php-curl php-gd php-dom php-iconv php-openssl php-redis php-mysql php-zip php-bz2 php-intl php-imagick php-opcache
4.下載nextcloud軟件包并解壓
https://nextcloud.com/install/#instructions-server
解壓部署程序:
unzip nextcloud-19.0.1.zip
將nextcloud文件移動到網(wǎng)站根目錄
sudo mv nextcloud /var/www/html/
5. 創(chuàng)建數(shù)據(jù)目錄忌傻,更改目錄權(quán)限
# 創(chuàng)建數(shù)據(jù)目錄
mkdir /mnt/data
mount -o umask=0007,uid=www-data,gid=www-data /dev/sda1 /mnt/data/
# 配置文件夾權(quán)限
cd /var/www/html/
sudo chown -R root:root nextcloud
更改子文件夾權(quán)限
cd /var/www/html/nextcloud
sudo chown -R www-data:www-data config apps
6.配置mysql
優(yōu)化mysqld
sudo vim /etc/mysql/my.cnf
[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
[client]
default-character-set = utf8mb4
[mysqld]
bind-address = 192.168.31.180
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1
skip-name-resolve
innodb_buffer_pool_size = 256M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
innodb_io_capacity=4000
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow-query-log = 1
slow-query-log-file = /var/log/mysql/slow.log
long_query_time = 1
sudo systemctl restart mariadb.service
設(shè)置mariadb管理員密碼并創(chuàng)建nextlcoud數(shù)據(jù)庫
mysqladmin -uroot password 'P@ssw0rd'
mysql -uroot -pP@ssw0rd -e 'CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;'
mysql -uroot -pP@ssw0rd -e 'GRANT ALL PRIVILEGES on nextcloud.* to "nextcloud"@"localhost" IDENTIFIED BY "nextcloud";'
mysql -uroot -pP@ssw0rd -e 'FLUSH privileges;'
7.配置php
sudo vim /etc/php/7.3/fpm/php.ini
expose_php = off
date.timezone = Asia/Shanghai
#啟用opcache
opcache.enable=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.validate_timestamps=1
opcache.revalidate_freq=30
#啟用大文件上傳,更改文件限制:
upload_max_filesize=16G
post_max_size=16G
max_input_time = 3600
max_execute_time = 3600
memory_limit = 512M
8.配置php-fpm
sudo vim /etc/php/7.3/fpm/pool.d/www.conf
clear_env=no
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
# 設(shè)置動態(tài)進(jìn)程數(shù)量:
pm = dynamic
pm.max_children = 50
pm.start_servers = 3
pm.min_spare_servers = 3
pm.max_spare_servers = 10
sudo systemctl restart php7.3-fpm.service
9.配置nginx:
在/etc/nginx/sites-enabled目錄下深纲,創(chuàng)建一個nextcloud文件波桩,其內(nèi)容如下:
生成SSL證書
sudo mkdir /etc/nginx/nextcloud_SSL/
cd /etc/nginx/nextcloud_SSL/
sudo openssl genrsa -out privkey.pem 2048
sudo openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
sudo vim /etc/nginx/sites-enabled/nginx
#nextcloud
upstream php-handler {
server unix:/var/run/php/php7.3-fpm.sock;
}
#server {
# listen 6080;
# listen [::]:6080;
# server_name szy.nextcloud.local;
# enforce https
# return 301 https://$server_name:6088$request_uri;
#}
server {
listen 6088 ssl http2;
#listen [::]:6088 ssl http2;
server_name szy.nextcloud.local;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
# NOTE: some settings below might be redundant
ssl_certificate /etc/nginx/nextcloud_SSL/cacert.pem;
ssl_certificate_key /etc/nginx/nextcloud_SSL/privkey.pem;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /var/www/html/nextcloud;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
# The following rule is only needed for the Social app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/webfinger /public.php?service=webfinger last;
location = /.well-known/carddav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host:$server_port/remote.php/dav;
}
# set max upload size
client_max_body_size 16G;
fastcgi_buffers 64 128K;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
location / {
rewrite ^ /index.php;
}
location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy)\.php(?:$|\/) {
fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
# Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
# Enable pretty urls
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js, css and map files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap|mp4|webm)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
sudo systemctl restart nginx php7.3-fpm
10.nextcloud性能優(yōu)化
1.用cron替代后臺ajax刷新執(zhí)行定時任務(wù)邮辽。執(zhí)行命令:
crontab -u www-data -e
*/5 * * * * php -f /var/www/nextcloud/cron.php
crontab -u www-data -l
sudo echo '*/5 * * * * www-data php /var/www/html/nextcloud/cron.php' >> /etc/crontab
2.使用緩存臀突。需要安裝redis以及編輯nextcloud的配置文件并使用redis鎖代替文件鎖
sudo apt-get install php-apcu php-redis
sudo vim /etc/redis/redis.conf
daemonize = yes
unixsocket /var/run/redis/redis-server.sock
unixsocketperm 777
# 授權(quán)redis
usermod -g www-data redis
chown -R redis:www-data /var/run/redis
systemctl restart redis-server.service
sudo vim /var/www/html/nextcloud/config/config.php
'memcache.local' => '\OC\Memcache\APCu',
'filelocking.enabled' => true,
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => [
'host' => '/var/run/redis/redis.sock',
'port' => 0,
'dbindex' => 0,
'password' => 'secret',
'timeout' => 1.5,
],
# 其他優(yōu)化:
sudo nano /var/www/html/nextcloud/config/config.php
'check_data_directory_permissions' => false,
接著編輯/etc/nginx/nginx.conf欠动,在http塊中修改上傳限制:
client_max_body_size 16G;
fastcgi_read_timeout 360S;