感觉新学期背诵压力会很大,就想起以前看到过的Anki,最近正在琢磨使用方法。发现Ankiweb的速度不够理想,打算自己搞个同步服务器,在这个过程中遇到了很多坑,总共花了将近三小时,已经身心俱疲了,意识到docker真是个好东西。

升级Python3.10

ankisyncd需要Python3.8及以上版本,这里索性升级到Python3.10。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 淘宝源Python安装包
wget https://registry.npmmirror.com/-/binary/python/3.10.2/Python-3.10.2.tgz
# 解压
tar -xvf Python-3.10.2.tgz
# 安装编译所需依赖
yum -y install gcc zlib* libffi-devel
# 删除原Python文件
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3
# 开始编译
cd Python-3.10.2/
./configure --prefix=/usr/local/bin/python3
make
make install
# 创建软链接
ln -s /usr/local/bin/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/bin/python3/bin/pip3 /usr/bin/pip3

安装

1
2
3
4
5
6
7
8
# 下载源码
wget https://ghproxy.com/https://github.com/ankicommunity/anki-sync-server/archive/refs/tags/v2.3.0.zip
# 解压
unzip v2.3.0.zip
rm -rf v2.3.0.zip
# 安装依赖
cd anki-sync-server-2.3.0/
pip3 install -r src/requirements.txt

弹出ModuleNotFoundError: No module named '_sqlite3'

解决错误

在网上搜索后执行yum install sqlite3-devel -y,系统镜像又出问题,发现是CentOS8官方源下线了,国内的镜像更换了地址,依照阿里源官方文档进行替换。

1
2
3
# 更换阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum makecache

然后发现没有用(

只能按照网上大多数推荐的办法,安装sqlite3后重新安装Python。

1
2
3
4
5
6
wget https://sqlite.org/2022/sqlite-autoconf-3370200.tar.gz
tar -xvzf sqlite-autoconf-3370200.tar.gz
cd sqlite-autoconf-3370200/
./configure --prefix=/usr/local/sqlite
make
make install

Python-3.10.2/setup.py中发现sqlite_inc_paths已经包含了'/usr/local/sqlite/include'和'/usr/local/sqlite/include/sqlite3'就不需要再添加了,直接重新安装Python即可。

1
2
3
./configure --enable-loadable-sqlite-extensions --prefix=/usr/local/bin/python3
make
make install

继续安装并使用

1
2
3
4
5
cd anki-sync-server-2.3.0/src/
# 重装完Python需要重新安装依赖
pip3 install -r requirements.txt
# 创建用户
./ankisyncctl.py adduser 用户名

参照下方配置nginx。

1
2
3
4
5
6
7
8
server {
listen 80;
server_name default;
location / {
proxy_http_version 1.0;
proxy_pass http://127.0.0.1:27701/;
}
}

然后输入python -m ankisyncd

若打开网页显示Anki Sync Server,则运行成功。

进程守护

vim /usr/lib/systemd/system/ankisyncd.service

1
2
3
4
5
6
7
8
9
[Unit]
Description=anki-sync-server Service
After=network.target

[Service]
ExecStart=/bin/sh -c 'cd /anki-sync-server-2.3.0/src && python3 -m ankisyncd'

[Install]
WantedBy=default.target
1
2
3
4
# 更新配置
systemctl daemon-reload
# 启动服务
systemctl start ankisyncd

参考链接:

https://blog.plotcup.com/2022/02/03/anki-sync-server-deploy/

https://github.com/ankicommunity/anki-sync-server

https://blog.csdn.net/TechRoadMan/article/details/107847493

https://www.jianshu.com/p/dd4532457b9f

https://junyixu.github.io/2021/02/19/Build-Anki-Sync-Server/