升级到 10.0.x

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

主要变更

通知服务

通知服务允许桌面同步客户端和挂载盘客户端通过 websocket 立即获得资料库的更改通知。这样做有两个好处:

  1. 减少将新更改同步到本地的时间。
  2. 减少服务器的负载,因为删除了定期拉取。当您拥有 1000 多个客户端时,负载会显着减少。

通知服务适用于 Seafile 同步客户端 9.0+ 和挂载盘客户端 3.0+。

请按照文档启用通知服务器:seafile.conf

seafile.conf 中的 Memcached 部分(仅限Pro版本)

如果您使用存储后端或集群,请确保 memcached 部分位于 seafile.conf 中。

自版本 10.0 起,所有 memcached 选项都合并为以下选项。

修改 seafile.conf:

[memcached]
memcached_options = --SERVER=<the IP of Memcached Server> --POOL-MIN=10 --POOL-MAX=100

SAML 单点登录改进(仅限Pro版本)

Seafile 中 SAML SSO 的配置大大简化。现在只需要三个选项:

ENABLE_ADFS_LOGIN = True
SAML_REMOTE_METADATA_URL = 'https://login.microsoftonline.com/xxx/federationmetadata/2007-06/federationmetadata.xml?appid=xxx'
SAML_ATTRIBUTE_MAPPING = {
    'mail': 'contact_email',
    'name': 'display_name',
    ...
}

详情请查看新的 SAML SSO 文档。

注:因 10.0.5 数据库有变更,从 10.0.x 小版本升级到 10.0.5 需要手工执行数据库升级语句

ALTER TABLE `org_saml_config` ADD COLUMN IF NOT EXISTS `domain` varchar(255) NOT NULL;
ALTER TABLE `org_saml_config` ADD UNIQUE IF NOT EXISTS (`domain`);

角色速率限制(仅限Pro版本)

从 10.0 版本开始,Seafile 允许管理员通过以下两个步骤为不同角色的用户配置上传和下载速度限制:

1. 在 seahub_settings.py 中为不同角色配置速率限制

ENABLED_ROLE_PERMISSIONS = {
    'default': {
    ...
        'upload_rate_limit': 2000,  # unit: kb/s
        'download_rate_limit': 4000,
    ...
    },
    'guest': {
    ...
        'upload_rate_limit': 100,
        'download_rate_limit': 200,
    ...
    },
}

2. 在 seafile-server-latest 目录中运行以下命令,使配置生效

./seahub.sh python-env python3 seahub/manage.py set_user_role_upload_download_rate_limit

Elasticsearch 改进(仅限Pro版本)

Elasticsearch升级到8.x版本,修复和改进文件搜索功能的一些问题。

elasticsearch 从 7.x 开始,默认分片数从5变为1,因为索引分片数过多会过度占用系统资源;但单个分片数据过大时,也会降低搜索性能。Seafile 从 10.0 版本开始,支持在配置文件中自定义分片数。

您可以使用以下命令查询当前每个分片的大小,以确定最适合您的分片数:

curl 'http{s}://<es IP>:9200/_cat/shards/repofiles?v'

官方建议每个分片的大小应在 10G-50G 之间:https://www.elastic.co/guide/en/elasticsearch/reference/8.6/size-your-shards.html#shard-size-recommendation

修改 seafevents.conf 配置文件:

[INDEX FILES]
...
shards = 10     # default is 5
...

钉钉集成(仅限Pro版本)

若您使用了钉钉集成,相关功能请修改以下配置项。

# 默认为True,新用户扫码登录后自动新建 seafile 用户。设置为False后,禁止新用户扫码注册,原有账号依旧可以扫码登录,并且管理员依旧可以通过导入钉钉用户的方式添加新用户。
DINGTALK_OAUTH_CREATE_UNKNOWN_USER = True 

# 默认为True,新用户扫码注册后,新建的 seafile 用户会自动激活。设置为False后,新用户扫码注册后需要管理员手动激活。
DINGTALK_OAUTH_ACTIVATE_USER_AFTER_CREATION = True

安装 Python 依赖

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

sudo pip3 install future==0.18.* mysqlclient==2.1.* pillow==9.3.* captcha==0.4 django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1

升级到 10.0.x

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

    ```sh upgrade/upgrade_9.0_10.0.sh

    ```

    如果您使用的是专业版,请根据需要修改 seafile.conf 中的 memcached 选项和 SAML SSO 配置。

  3. 启动 Seafile-10.0.x 服务。

升级 Elasticsearch (仅限Pro版本)

您可以选择其中一种方法来升级您的索引数据。

方法一,reindex旧的索引数据

1. 下载 Elasticsearch 镜像(如果当前的 Elasticsearch 版本已经是 7.17.x,则跳过该步骤):

docker pull elasticsearch:7.17.9

给旧索引数据的映射目录 777 权限,否则 elasticsearch 启动会报路径权限问题(如果原目录已具有777权限,则跳过该步骤):

chmod -R 777 /opt/seafile-elasticsearch/data/

运行镜像:

sudo docker run -d --name es-7.17 -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.17.9

PS: ES_JAVA_OPTS可以根据您的需要进行调整。

2. 创建兼容 elasticsearch 8.x 版本的 index:

# 创建 repo_head 索引
curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/repo_head_8?pretty=true' -d '
{
  "mappings" : {
    "properties" : {
      "commit" : {
        "type" : "keyword",
        "index" : false
      },
      "repo" : {
        "type" : "keyword",
        "index" : false
      },
      "updatingto" : {
        "type" : "keyword",
        "index" : false
      }
    }
  }
}'

# 创建 repofiles 索引,number_of_shards为分片数,这里设置为5,您也可以修改为最适合您的分片数:
curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/repofiles_8/?pretty=true' -d '
{
  "settings" : {
    "index" : {
      "number_of_shards" : "5",
      "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"
      }
    }
  }
}'

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

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/repo_head_8/_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/repofiles_8/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : "-1",
    "number_of_replicas" : 0
  }
}'

4. 使用 reindex API 将旧索引数据复制到新索引中:

curl -X POST -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/_reindex/?wait_for_completion=false&pretty=true' -d '
{
  "source": {
    "index": "repo_head"
  },
  "dest": {
    "index": "repo_head_8"
  }
}'

curl -X POST -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/_reindex/?wait_for_completion=false&pretty=true' -d '
{
  "source": {
    "index": "repofiles"
  },
  "dest": {
    "index": "repofiles_8"
  }
}'

5. 使用如下命令查看 reindex 任务是否已完成:

# Get the task_id of the reindex task:
$ curl 'http{s}://{es server IP}:9200/_tasks?actions=*reindex&pretty'
# Check to see if the reindex task is complete:
$ curl 'http{s}://{es server IP}:9200/_tasks/:<task_id>?pretty'

6. 将 refresh_intervalnumber_of_replicas 重置为旧索引中使用的值:

curl -X PUT -H 'Content-Type: application/json' 'http{s}://{es server IP}:9200/repo_head_8/_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/repofiles_8/_settings?pretty' -d '
{
  "index" : {
    "refresh_interval" : null,
    "number_of_replicas" : 1
  }
}'

7. 等待索引健康状态变为green(单节点状态为 yellow 即可)。

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

8. 使用 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": "repo_head_8", "alias": "repo_head"}},
    {"add": {"index": "repofiles_8", "alias": "repofiles"}}
  ]
}'

9. 停用 7.17 容器,拉取 8.x 镜像并运行:

$ docker stop es-7.17

$ docker rm es-7.17

$ docker pull elasticsearch:8.6.2

$ 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:8.6.2

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

1. 拉取 Elasticsearch 镜像:

docker pull elasticsearch:8.6.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:8.6.2

2. 修改 seafevents.conf:

[INDEX FILES]
...
external_es_server = true
es_host = http{s}://{es server IP}
es_port = 9200
shards = 10   # default is 5.
...

重启 Seafile 服务器:

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

3. 删除旧索引数据:

rm -rf /opt/seafile-elasticsearch/data/*

4. 创建新的索引数据:

$ cd /opt/seafile/seafile-server-latest
$ ./pro/pro.py search --update

方法三,适用于集群环境

1. 按照方法二部署 elasticsearch 8.x。使用Seafile 10.0版本部署新的后端节点,修改seafevents.conf文件。后台节点不启动 Seafile后台服务,只是手动运行命令./pro/pro.py search --update

2. 将其他节点升级到 Seafile 10.0 版本并使用新的 Elasticsearch 8.x 服务器。

3. 然后停用旧的后端节点和旧版本的 Elasticsearch。

Last modified by 马宇航, 2023-08-08

主要变更
通知服务
seafile.conf 中的 Memcached 部分(仅限Pro版本)
SAML 单点登录改进(仅限Pro版本)
角色速率限制(仅限Pro版本)
Elasticsearch 改进(仅限Pro版本)
钉钉集成(仅限Pro版本)
安装 Python 依赖
升级到 10.0.x
升级 Elasticsearch (仅限Pro版本)