樹莓派安裝nextcloud

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;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末永乌,一起剝皮案震驚了整個濱河市惑申,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌翅雏,老刑警劉巖圈驼,帶你破解...
    沈念sama閱讀 211,348評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異望几,居然都是意外死亡绩脆,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,122評論 2 385
  • 文/潘曉璐 我一進(jìn)店門橄抹,熙熙樓的掌柜王于貴愁眉苦臉地迎上來靴迫,“玉大人,你說我怎么就攤上這事楼誓∮裥浚” “怎么了?”我有些...
    開封第一講書人閱讀 156,936評論 0 347
  • 文/不壞的土叔 我叫張陵疟羹,是天一觀的道長主守。 經(jīng)常有香客問我,道長榄融,這世上最難降的妖魔是什么丸逸? 我笑而不...
    開封第一講書人閱讀 56,427評論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮剃袍,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘捎谨。我一直安慰自己民效,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,467評論 6 385
  • 文/花漫 我一把揭開白布涛救。 她就那樣靜靜地躺著畏邢,像睡著了一般。 火紅的嫁衣襯著肌膚如雪检吆。 梳的紋絲不亂的頭發(fā)上舒萎,一...
    開封第一講書人閱讀 49,785評論 1 290
  • 那天,我揣著相機(jī)與錄音蹭沛,去河邊找鬼臂寝。 笑死,一個胖子當(dāng)著我的面吹牛摊灭,可吹牛的內(nèi)容都是我干的咆贬。 我是一名探鬼主播,決...
    沈念sama閱讀 38,931評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼帚呼,長吁一口氣:“原來是場噩夢啊……” “哼掏缎!你這毒婦竟也來了皱蹦?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,696評論 0 266
  • 序言:老撾萬榮一對情侶失蹤眷蜈,失蹤者是張志新(化名)和其女友劉穎沪哺,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體酌儒,經(jīng)...
    沈念sama閱讀 44,141評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡辜妓,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,483評論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了今豆。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片嫌拣。...
    茶點故事閱讀 38,625評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖呆躲,靈堂內(nèi)的尸體忽然破棺而出异逐,到底是詐尸還是另有隱情,我是刑警寧澤插掂,帶...
    沈念sama閱讀 34,291評論 4 329
  • 正文 年R本政府宣布灰瞻,位于F島的核電站,受9級特大地震影響辅甥,放射性物質(zhì)發(fā)生泄漏酝润。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,892評論 3 312
  • 文/蒙蒙 一璃弄、第九天 我趴在偏房一處隱蔽的房頂上張望要销。 院中可真熱鬧,春花似錦夏块、人聲如沸疏咐。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽浑塞。三九已至,卻和暖如春政己,著一層夾襖步出監(jiān)牢的瞬間酌壕,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工歇由, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留卵牍,地道東北人。 一個月前我還...
    沈念sama閱讀 46,324評論 2 360
  • 正文 我出身青樓沦泌,卻偏偏與公主長得像辽慕,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子赦肃,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,492評論 2 348

推薦閱讀更多精彩內(nèi)容