基于服务器部署思源笔记并加入OneDrive同步
前提
- 安装docker
- 挂载OneDrive笔记目录
挂载OneDrive目录到服务器
安装
yum
yum install rclone
脚本
curl https://rclone.org/install.sh | sudo bash
初始化配置
输入
rclone config
2022/05/29 17:08:32 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults No remotes found - make a new one n) New remote s) Set configuration password q) Quit config
- 输入
n
新建配置 输出
name
(随意)name> oneDriver Type of storage to configure. Enter a string value. Press Enter for the default (""). Choose a number from below, or type in your own value 1 / 1Fichier \ "fichier" 2 / Alias for an existing remote \ "alias" 3 / Amazon Drive \ "amazon cloud drive" 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, and Tencent COS \ "s3" 5 / Backblaze B2 \ "b2" 6 / Box \ "box" 7 / Cache a remote \ "cache" 8 / Citrix Sharefile \ "sharefile" 9 / Compress a remote \ "compress" 10 / Dropbox \ "dropbox" 11 / Encrypt/Decrypt a remote \ "crypt" 12 / Enterprise File Fabric \ "filefabric" 13 / FTP Connection \ "ftp" 14 / Google Cloud Storage (this is not Google Drive) \ "google cloud storage" 15 / Google Drive \ "drive" 16 / Google Photos \ "google photos" 17 / Hadoop distributed file system \ "hdfs" 18 / Hubic \ "hubic" 19 / In memory object storage system. \ "memory" 20 / Jottacloud \ "jottacloud" 21 / Koofr \ "koofr" 22 / Local Disk \ "local" 23 / Mail.ru Cloud \ "mailru" 24 / Mega \ "mega" 25 / Microsoft Azure Blob Storage \ "azureblob" 26 / Microsoft OneDrive \ "onedrive" 27 / OpenDrive \ "opendrive" 28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH) \ "swift" 29 / Pcloud \ "pcloud" 30 / Put.io \ "putio" 31 / QingCloud Object Storage \ "qingstor" 32 / SSH/SFTP Connection \ "sftp" 33 / Sugarsync \ "sugarsync" 34 / Tardigrade Decentralized Cloud Storage \ "tardigrade" 35 / Transparently chunk/split large files \ "chunker" 36 / Union merges the contents of several upstream fs \ "union" 37 / Webdav \ "webdav" 38 / Yandex Disk \ "yandex" 39 / Zoho \ "zoho" 40 / http Connection \ "http" 41 / premiumize.me \ "premiumizeme" 42 / seafile \ "seafile"
- 选择
onedrive 26
client_id
可以直接回车默认,client_secret
也可以直接回车默认1 / Microsoft Cloud Global \ "global" 2 / Microsoft Cloud for US Government \ "us" 3 / Microsoft Cloud Germany \ "de" 4 / Azure and Office 365 operated by 21Vianet in China \ "cn"
选择
1
进阶配置选择,如下:
Edit advanced config? (y/n) y) Yes n) No (default) y/n>
选择
n
自动配置
Remote config Use auto config? * Say Y if not sure * Say N if you are working on a remote or headless machine y) Yes (default) n) No
选择
n
获取授权码
For this to work, you will need rclone available on a machine that has a web browser available. For more help and alternate methods see: https://rclone.org/remote_setup/ Execute the following on the machine with the web browser (same rclone version recommended): rclone authorize "onedrive" Then paste the result below:
授权码需要在本地电脑上获取,访问 https://rclone.org/downloads/ 根据你的电脑系统版本下载对应的 Rclone。
进入下载的文件夹里,在
cmd
里执行以下命令rclone authorize "onedrive"
- 在弹出的网页中登录并授权,出现
success!
则代表授权成功 将
cmd
里的json
串(授权信息)复制战列到linux终端选择授权的类型
Choose a number from below, or type in an existing value 1 / OneDrive Personal or Business \ "onedrive" 2 / Root Sharepoint site \ "sharepoint" 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite) \ "url" 4 / Search for a Sharepoint site \ "search" 5 / Type in driveID (advanced) \ "driveid" 6 / Type in SiteID (advanced) \ "siteid" 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr) \ "path"
这里选择
1
OneDrive Personal or Business然后根据提示输入序号
Your choice> 1 Found 1 drives, please select the one you want to use: 0: (personal) id=e93acbe1b98f1996
输入
0
选择Chose drive to use:> 0 Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=xxxxxxxxxxxx Is that okay? y) Yes (default) n) No y/n>
这里根据序号查找到账号,确认后输入
y
再次输入
y
确认配置
挂载
挂载命令
# 格式
rclone mount configName:OneDriveLocation dir --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000
其中 configName
为配置名称,OneDriveLocation
是要挂载的 OneDrive
目录 ,dir
是本地要挂载的目录(服务器目录)。
例如将刚刚配置的 name
为 onedriver
的 文档/SiYuan-workspace/SiYuan
目录配置挂载到本地的 onedrive
目录下,则命令为:
rclone mount onedrive:/文档/siYuan /data/siyuan --copy-links --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode full
挂载完后不会显示任何内容,通过命令查看挂载情况
df -h
常见挂载错误提示
问题一
2022/05/29 17:52:14 NOTICE: One drive root '文档/SiYuan-workspace/SiYuan': --vfs-cache-mode writes or full is recommended for this remote as it can't stream 2022/05/29 17:52:14 Fatal error: failed to mount FUSE fs: fusermount: exec: "fusermount": executable file not found in $PATH
需要安装 fuse
CentOS/Fedora 安装 fuse
yum install -y fuse
Ubuntu/Debian 安装 fuse
apt install -y fuse
- 重新执行挂载命令
问题二
2022/05/29 17:54:38 NOTICE: One drive root '文档/SiYuan-workspace/SiYuan': --vfs-cache-mode writes or full is recommended for this remote as it can't stream 2022/05/29 17:54:39 Fatal error: failed to mount FUSE fs: mountpoint does not exist: /data/onedrive
创建本地服务器文件
cd /data mkdir onedrive
Docker启动思源笔记
官方文档
在服务器上伺服思源最简单的方案是通过 Docker 部署。
- 镜像名称
b3log/siyuan
- 镜像地址
文件结构
整体程序位于 /opt/siyuan/
下,基本上就是 Electron 安装包 resources 文件夹下的结构:
- appearance:图标、主题、多语言
- guide:帮助文档
- stage:界面和静态资源
- kernel:内核程序
启动入口
构建 Docker 镜像时设置了入口:ENTRYPOINT [ "/opt/siyuan/kernel" ]
,使用 docker run b3log/siyuan
并带参即可启动:
--workspace
指定工作空间文件夹路径,在宿主机上通过-v
挂载到容器中workspace_dir_host
:宿主机上的工作空间文件夹路径workspace_dir_container
:容器内工作空间文件夹路径,和后面--workspace
指定成一样的
用户权限
镜像中是使用默认创建的普通用户 siyuan
(uid 1000/gid 1000)来启动内核进程的,所以在宿主机创建工作空间文件夹时请注意设置该文件夹所属用户组:chown -R 1000:1000 /siyuan/workspace
,在启动容器时需要带参数 -u 1000:1000
。
隐藏端口
使用 NGINX 反向代理可以隐藏 6806 端口,请注意:
- 配置 WebSocket 反代
/ws
配置
docker启动命令
# 示例
docker run --name siyuan -it -u 1000:1000 \
--restart=always \
-v /home/SiYuan:/home/SiYuan \
-p 6806:6806 b3log/siyuan \
--workspace=/home/SiYuan \
-accessAuthCode 123456 \
--servePath=biji.baidu.com
docker-compose启动命令
version: '3'
services:
siyuan-mc:
image: b3log/siyuan:v2.0.14
container_name: siyuan-mc
restart: always
command: [--workspace=/home/SiYuan,--ssl=true,--servePath=mc.chaospring.com]
volumes:
- /data/siyuan/mc:/home/SiYuan #数据文件挂载
ports:
- 6806:6806
配置nginx
配置反代端口,在反代端口上加入以下配置
location ^~ /ws {
proxy_pass http://127.0.0.1:6806;
proxy_read_timeout 60s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'Upgrade';
}