升级到 9.0.x

这些说明提供了有关指定版本的更改。其他信息请始终遵循升级指南

主要变更

9.0 版本主要的变更项目包括

安装 Python 依赖

注意,需要使用 root 用户或者 sudo 命令在系统范围内来安装 Python 依赖。

pip3 install  pycryptodome==3.12.0  cffi==1.14.0

升级到 9.0.x

  1. 停止 Seafile-8.0.x 服务.
  2. 进入 Seafile-9.0.x 目录, 运行以下脚本:

    ```sh upgrade/upgrade_8.0_9.0.sh

    ```

  3. 开启 Seafile-9.0.x 服务.

ElasticSearch 升级

方法一,重建索引,弃用旧的索引数据

如果你的数据量不大,建议部署 ElasticSearch 最新的 7.x 版本,然后重建新的索引。具体步骤如下

拉取 ElasticSearch 镜像

docker pull elasticsearch:7.16.2

创建 Elasticsearch 数据映射目录,并给目录 777 权限,否则 elasticsearch 启动会报路径权限问题

mkdir -p /opt/seafile-elasticsearch/data  && chmod -R 777 /opt/seafile-elasticsearch/data/

启动 ElasticSearch 容器

sudo docker run -d --name es -p 9200:9200 -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" -e "xpack.security.enabled=false" --restart=always -v /opt/seafile-elasticsearch/data:/usr/share/elasticsearch/data -d elasticsearch:7.16.2

删除旧的索引数据

rm -rf /opt/seafile/pro-data/search/data/*

修改 seafevents.conf

[INDEX FILES]
external_es_server = true
es_host = 127.0.0.1
es_port = 9200

重启seafile服务

su seafile
cd seafile-server-latest/
./seafile.sh stop && ./seahub.stop 
./seafile.sh start && ./seahub.start 

方法二,升级已有的索引数据

如果你的数据量比较大,给所有的 Seafile 资料库重建索引会消耗比较长的时间,那么你可以升级已有的索引数据。这需要以下的步骤

具体过程如下

下载 ES 镜像:

docker pull elasticsearch:7.16.2

PS:seafile 9.0 版本,需要手动在宿主机上创建 elasticsearch 的映射路径,并且给 777 权限,否则 elasticsearch 启动会报路径权限问题,命令如下

mkdir -p /opt/seafile-elasticsearch/data 

把原来的索引数据放在/opt/seafile-elasticsearch/data/并授权

mv /opt/seafile/pro-data/search/data/* /opt/seafile-elasticsearch/data/
chmod -R 777 /opt/seafile-elasticsearch/data/

运行镜像

sudo docker run -d --name es -p 9200:9200 -e "discovery.type=single-node" -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" -e "xpack.security.enabled=false" --restart=always -v /opt/seafile-elasticsearch/data:/usr/share/elasticsearch/data -d elasticsearch:7.16.2

PS: ES_JAVA_OPTS的值可以根据需求来更改大小

创建兼容 7.x 版本 mapping 的索引

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repo_head?include_type_name=false&pretty=true' -d '
{
  "mappings" : {
    "properties" : {
      "commit" : {
        "type" : "text",
        "index" : false
      },
      "repo" : {
        "type" : "text",
        "index" : false
      },
      "updatingto" : {
        "type" : "text",
        "index" : false
      }
    }
  }
}'

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repofiles/?include_type_name=false&pretty=true' -d '
{
  "settings" : {
    "index" : {
      "number_of_shards" : 5,
      "number_of_replicas" : 1,
      "analysis" : {
        "analyzer" : {
          "seafile_file_name_ngram_analyzer" : {
            "filter" : [
              "lowercase"
            ],
            "type" : "custom",
            "tokenizer" : "seafile_file_name_ngram_tokenizer"
          }
        },
        "tokenizer" : {
          "seafile_file_name_ngram_tokenizer" : {
            "type" : "ngram",
            "min_gram" : "3",
            "max_gram" : "4"
          }
        }
      }
    }
  },
  "mappings" : {
    "properties" : {
      "content" : {
        "type" : "text",
        "term_vector" : "with_positions_offsets"
      },
      "filename" : {
        "type" : "text",
        "fields" : {
          "ngram" : {
            "type" : "text",
            "analyzer" : "seafile_file_name_ngram_analyzer"
          }
        }
      },
      "is_dir" : {
        "type" : "boolean"
      },
      "mtime" : {
        "type" : "date"
      },
      "path" : {
        "type" : "keyword"
      },
      "repo" : {
        "type" : "keyword"
      },
      "size" : {
        "type" : "long"
      },
      "suffix" : {
        "type" : "keyword"
      }
    }
  }
}'

refresh_interval 设置为 -1number_of_replicas 设置为 0,以提高 reindex 的效率:

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repo_head/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : "-1",
    "number_of_replicas" : 0
  }
}'

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repofiles/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : "-1",
    "number_of_replicas" : 0
  }
}'

使用 reindex API 将 5.x 的索引内容复制到新创建的索引中。

curl -X POST -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/_reindex/?pretty' -d '
{
  "source": {
    "index": "repo_head",
    "type": "repo_commit"
  },
  "dest": {
    "index": "new_repo_head",
    "type": "_doc"
  }
}'

curl -X POST -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/_reindex/?pretty' -d '
{
  "source": {
    "index": "repofiles",
    "type": "file"
  },
  "dest": {
    "index": "new_repofiles",
    "type": "_doc"
  }
}'

refresh_intervalnumber_of_replicas 重置为旧索引中使用的值。

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repo_head/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : null,
    "number_of_replicas" : 1
  }
}'

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/new_repofiles/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : null,
    "number_of_replicas" : 1
  }
}'

等待索引健康状态变为green

curl http{s}://{es server IP}:9200/_cluster/health?pretty

使用 aliases API 删除旧索引,然后将具有旧索引名称的别名添加到新索引中。

curl -X POST -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/_aliases?pretty' -d '
{
  "actions": [
    {"remove_index": {"index": "repo_head"}},
    {"remove_index": {"index": "repofiles"}},
    {"add": {"index": "new_repo_head", "alias": "repo_head"}},
    {"add": {"index": "new_repofiles", "alias": "repofiles"}}
  ]
}'

升级完索引后,修改 Seafile 中的配置。

修改 seafevents.conf

[INDEX FILES]
external_es_server = true
es_host = 127.0.0.1
es_port = 9200

重启 seafile 服务

su seafile
cd seafile-server-latest/
./seafile.sh stop && ./seahub.stop 
./seafile.sh start && ./seahub.start 

方法三,如果你是集群环境

部署一个新的 ElasticSeach 7.x 服务,使用 Seafile 9.0 版本部署一个新的后台节点,并对接 ElasticSeach 7.x 。后台节点不启动 Seafile 后台服务,只手工运行命令 ./pro/pro.py search --update ,建立完索引后再把其他节点升级到 Seafile 9.0 版,并使用新的 ElasticSeach 7.x。然后停用旧的后台节点和旧版的 ElasticSeach。

从 9.0.2 升级到 9.0.3+

如果你已经从 8.0 版本升级到了 9.0.2 版,9.0.2 版使用的是 ElasticSearch 6.8.20,在升级到 9.0.3+ 版时,需要按照上面的步骤升级一下索引。

如果你是全新部署的 9.0.2 版,那么你只需要把 ElasticSearch 的版本升级为 7.x 版,不需要升级索引。

内置 Office 文件预览 升级

如果你使用 OnlyOffice 来进行 Office 文件的预览和编辑,可以跳过这个步骤。

内置office升级指南

(可选)启用 Go fileserver

如需启用 Go fileserver,需要在 seafile.conf 中加入一个配置:

[fileserver]
use_go_fileserver = true

启动 seafile 之后,可以观察到有一个 fileserver 进程,监听的端口与原来的 fileserver 模块一致(默认 8082)。

Last modified by 王先生, 2023-03-25

主要变更
安装 Python 依赖
升级到 9.0.x
ElasticSearch 升级
从 9.0.2 升级到 9.0.3+
内置 Office 文件预览 升级
(可选)启用 Go fileserver