Nextcloud配置和优化

25次阅读
没有评论

共计 4330 个字符,预计需要花费 11 分钟才能阅读完成。

中文 英文 韩语 日语

Nextcloud 配置和优化


Nextcloud 数据库索引修复

当 Nextcloud 数据库丢失索引时,可以通过命令行手动修复。请在 Nextcloud 安装根目录执行以下命令:

 sudo -u www php occ db:add-missing-indices

例如,修复丢失的索引“mail_messages_msgid_idx”:

 sudo -u www php occ db:add-missing-indices

修复后可以显著提高查询速度。

Nextcloud 配置文件(config.php)

 <?php
$CONFIG = array('objectstore' => array('class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' => array('bucket' => 'nextcloud-*******', // 存储桶名称(空间名称)'autocreate' => false,
      'key'  => 'AKID***********', // 替换为用户的 SecretId
      'secret' => '**********', // 替换为用户的 SecretKey
      'hostname' => 'cos.<Region>.myqcloud.com', // 将 <Region> 修改为所属地域,如 ap-shanghai
      'use_ssl' => true,
    ),
  ),
  'instanceid' => 'oc82tpo2f',
  'passwordsalt' => '2GdQCVNsIVYF1KLP3fT3woH69X',
  'secret' => 'VSy0Y+/2wV7g4kvbiKSE0dSa2Yp1ajtvvZpgdV14Lsc',
  'trusted_domains' => array(0 => 'nextcloud.***.***',
  ), // nextcloud 域名
  'datadirectory' => '/www/nextcloud/data', // data 路径,请根据实际情况修改
  'dbtype' => 'mysql',
  'version' => '27.1.5.1',
  'overwrite.cli.url' => 'https://nextcloud.***.***/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '','dbtableprefix'=>'oc_','mysql.utf8mb4'=> true,'dbuser'=>'nextcloud', // 数据库用户名'dbpassword'=>'******', // 数据库密码'installed'=> true,'maintenance'=> false,'updater.secret'=>'\$2y\$10\$0eTb6aJ4u3NAWwlQk2qkUOTlI3.0O6TGLwAQOCyUtH/wmCpC','theme'=>'',
  'loglevel' => 2,
  'filelocking.enabled' => true,
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => array('host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => 0.0,
    'password' => '', // redis 密码
  ),
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => '****', // 请根据实际情况修改
  'mail_domain' => 'outlook.com', // 请根据实际情况修改
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp-mail.outlook.com', // 请根据实际情况修改
  'mail_smtpport' => '587', // 请根据实际情况修改
  'mail_smtpname' => '*****', // 请根据实际情况修改
  'mail_smtppassword' => '****', // 请根据实际情况修改
  'enabledPreviewProviders' => [
    'OC\Preview\MP3',
    'OC\Preview\TXT',
    'OC\Preview\MarkDown',
    'OC\Preview\OpenDocument',
    'OC\Preview\Krita',
    'OC\Preview\Imaginary',
  ],
  'preview_imaginary_url' => 'http://<url of imaginary>',
);

Nextcloud 性能优化

后台任务

设置 cron.php 每 5 分钟运行一次,cron.php 的具体路径在 nextcloud 安装的根目录下。

 crontab -u www -e
*/5 * * * * php -f /PathToNextcloud/cron.php

PHP 配置优化

  1. 注释掉 php.ini 中的 output_buffering 设置:
 ; output_buffering = 4096
  1. 启用 OPcache 以提高性能:
opcache.enable=1
opcache.enable_cli=1
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=80000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=3
  1. 设置 HSTS 以提高安全性,在 apache 的配置文件中加入:
<IfModule mod_headers.c>
  Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>

完整性检查

如果 Nextcloud 文件完整性检查发现问题,可以根据文档中的指导进行修复。例如,.user.ini文件缺失可以创建该文件并设置适当的open_basedir,或者在宝塔面板中开启放跨站。

完整 config.php 设置

<?php
$CONFIG = array('instanceid' => 'xxxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxxxxxxxx',
  'secret' => 'TNFR/+xxxxxxxxxxxxxxxxxxx/',
  'trusted_domains' => 
  array (0 => 'nextcloud.guohao.asia',
  ),
  'datadirectory' => '/www/wwwroot/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '24.0.5.1',
  'overwrite.cli.url' => 'https://nextcloud.guohao.asia', 
  'dbname' => 'xxxxxxxxxxxx',
  'dbhost' => 'localhost',
  'dbport' => '','dbtableprefix'=>'oc_','mysql.utf8mb4'=> true,'dbuser'=>'xxxxxxxxxx','dbpassword'=>'xxxxxxxxx','installed'=> true,'app_install_overwrite' => 
  array (0 => 'tencentcloudcosconfig',
    1 => 'files_external_onedrive',
  ),  
  // 缓存设置
  'memcache.local' => 'OC\\Memcache\\Redis',        
  'memcache.distributed' => 'OC\\Memcache\\Memcached',
  'redis' => [        #Redis
    'host' => 'localhost', #Redis 服务器
    'port' => 6379,     #Redis 端口
    'timeout' => 0.0,       #Redis 超时设定
    'password' => 'XXXXXXXXXXX',        #Redis 密码
    'dbindex' => 1,     #Redis 数据库选择
  ],
  'memcached_servers' => array(        #Memcached 服务器
    array('localhost', 11211),
  ),
  'memcached_options' => array(        #Memcached 选项
    \Memcached::OPT_CONNECT_TIMEOUT => 50,
    \Memcached::OPT_RETRY_TIMEOUT =>   50,
    \Memcached::OPT_SEND_TIMEOUT =>    50,
    \Memcached::OPT_RECV_TIMEOUT =>    50,
    \Memcached::OPT_POLL_TIMEOUT =>    50,
    \Memcached::OPT_COMPRESSION =>          true,
    \Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
    \Memcached::OPT_BINARY_PROTOCOL =>      true,
  ),
  'cache_path' => '/www/wwwroot/nextcloud/cache',        #缓存目录
  'cache_chunk_gc_ttl' => 60*60*24,        #缓存删除时间
  // 腾讯云 COS  
  'objectstore' => 
  array ('class' => '\\OC\\Files\\ObjectStore\\S3',
    'arguments' => 
    array ('key' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
      'bucket' => 'nextcloud-000000000',
      'hostname' => 'cos.ap-beijing.myqcloud.com',
      'use_ssl' => true,
      'autocreate' => false,
    ),
  ),
  // 电话区号
  'default_phone_region' => 'CN',
);

解决 Nextcloud 无法更新应用

config.php 中添加以下内容以启用应用商店:

 'appstoreenabled' => true,
 'appstoreurl' => 'https://www.orcy.net/ncapps/v1/',

更换为国内源(更新进度较官方略慢)。

退出维护模式


了解 一个 HR 的更多信息

订阅后即可通过电子邮件收到最新文章。

正文完
 0
null
版权声明:本站原创文章,由 null 于2024-11-19发表,共计4330字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
0 0 投票数
文章评分
订阅评论
提醒
guest

0 评论
最多投票
最新 最旧
内联反馈
查看所有评论
AI 助手