EhforwarderBot 迁移部署纪录

本文最后更新于 8 个月前,文中所描述的信息可能已发生改变。

EhforwarderBot 主要用于信息聚合,可以把微信/QQ等多个聊天软件的消息同一收集在一个软件上处理。我之前的EFB搭建在Azure100的韩国服务器上,近期尝试续期失败,决定迁移。目前EFB的安装过程感觉依旧较为麻烦,故作记录。

本次的目标是通过EFB实现微信-TG转移,具体安装搭建过程,原理分析请看这篇博文:Tg 收发微信——EFB2(官方安装方法)

配置环境

安装EFB/依赖

bash
apt update && apt install python3 python3-pip python3-setuptools python3-yaml ffmpeg -y

# 使用虚拟环境安装启动
python3 -m venv ehforwarderbot
# 激活虚拟环境 完成后使用 deactivate 退出虚拟环境
source ehforwarderbot/bin/activate

pip install TgCrypto
pip install ehforwarderbot
pip install efb-telegram-master 
pip install efb-wechat-slave
pip install --upgrade Pillow
pip install "efb-telegram-master[tgs]"

安装失败请看文末的方法。

安装中间件

我已经正在使用了一些中间件,包括一些自动语音识别之类的,也需要安装。Github上有同名的仓库,具体介绍了使用方法。

bash
pip install efb-mp-instantview-middleware 
pip install efb-voice-recog-middleware

配置文件

接下来应该是配置文件了,当然是迁移,所以只需要将配置文件完整复制过来就好

首先关闭旧机子上的 EFB 程序,在退出 EFB 之前,记得 先在手机微信里退出网页端先在手机微信里退出网页端先在手机微信里退出网页端 ,不然下次启动有概率会将过去数个小时的消息重新发送一遍

bash
root@bailu:~# systemctl stop efb # 非常缓慢的停止...
...
root@bailu:~#

(会卡住 非常久…当然为了数据不出问题还是不要强制停止了)

接下来使用rsync同步文件(记得在原服务器和新服务器上都安装):

bash
root@bailu:~# rsync -avzhe ssh /root/.ehforwarderbot/ root@1xx.1xx.1xx.1xx:/root/.ethforwarderbot/

root@1xx.1xx.1xx.1xx's password:
sending incremental file list
created directory /root/.thforwarderbot
./
readme.md
...

sent 11.97M bytes  received 320 bytes  2.18M bytes/sec
total size is 38.44M  speedup is 3.21
root@bailu:~#

rsync 参数具体解释如下:

  • -a: 以归档模式同步文件和目录(包括权限、所有者信息、时间戳等)
  • -v: 输出详细日志
  • -z: 压缩传输
  • -h: 人性化显示文件大小
  • -e ssh: 表示通过 SSH 加密连接传输数据

/path/to/old/home/.ehforwarderbot/ 替换成源服务器上 EhforwarderBot目录的路径,1xx.1xx.1xx.1xx替换成目标服务器的IP地址,/path/to/new/home/.ethforwarderbot/ 替换成目标服务器上存放 EhforwarderBot目录的路径。

貌似没什么问题,接下来就是试启动了。

启动/守护进程

bash
root@bailu:~# ehforwarderbot


    Confirm on your phone.
2023-06-05 11:20:56,758 [Level 99]: plugins.blueset.wechat.WeChatChannel (__init__.console_qr_code; __init__.py:198)
    Successfully logged in.
2023-06-05 11:21:02,608 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:140)
     Slave channel WeChat Slave (blueset.wechat) # Default profile is initialized.
2023-06-05 11:21:02,608 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:143)
     Initializing master blueset.telegram...
2023-06-05 11:21:15,855 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:153)
     Master channel Telegram Master (blueset.telegram) # Default profile is initialized.
2023-06-05 11:21:15,855 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:155)
     All channels initialized.
2023-06-05 11:21:15,855 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:157)
     Initializing middleware catbaron.voice_recog...
2023-06-05 11:21:15,860 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:167)
     Middleware Voice Recognition Middleware (catbaron.voice_recog) # Default profile is initialized.
2023-06-05 11:21:15,861 [Level 99]: ehforwarderbot.__main__ (__main__.init; __main__.py:169)
     All middlewares are initialized.

试着发一条消息测试 Telegram 中群组的 Link是否正常(大部分应该都会正常恢复,只有少数几个对话需要重新 Link),在这里基本上整个过程就结束了。

接下来配置守护进程,先 Ctrl+C 退出 EFB(注意先在微信退出网页端)然后创建守护进程配置文件(由于安装过程在虚拟环境中安装,所以需要额外添加 Environment 一行确保可以正确找到包位置):

bash
vim /etc/systemd/system/efb.service

# 复制 保存
[Unit]
Description=ehforwarderbot
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
WorkingDirectory=/root
Environment="PATH=/path/to/home/.ehforwarderbot/ehforwarderbot/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ExecStart=/path/to/home/.ehforwarderbot/ehforwarderbot/bin/ehforwarderbot
Restart=always


systemctl daemon-reload #重新加载进程守护
systemctl start efb.service
systemctl status efb #看不到二维码?没关系,点击日志中的链接在浏览器中打开二维码
systemctl enable efb.service # 开机启动

当有新联系人发送消息的时候,可以自动创建群组并自动 LInk,该功能来自于第三方更改的telegram主端(更推荐使用后者):https://github.com/mlch911/efb-telegram-master, https://github.com/QQ-War/efb-telegram-master

首先要暂停 EhforwarderBot -> 覆盖安装第三方的主端 -> 启动

第一次安装注意配置 blueset.telegram 配置文件,详情见仓库readme后半段,注意两个仓库配置文件有细微差别

bash
systemctl stop efb
pip install git+https://github.com/QQ-War/efb-telegram-master.git
systemctl start efb

圆满结束。

安装报错:Cannot uninstall 'PyYAML'

WARNING注意

在使用 python 虚拟环境后可以避免出现此问题,为了保持主机 python 环境整洁,不再推荐以下方法解决此问题

第一种办法

Cannot uninstall 'PyYAML'

bash
root@xxxxx:~# pip3 install efb-wechat-slave
Collecting efb-wechat-slave
  Using cached efb_wechat_slave-2.0.4-py3-none-any.whl (216 kB)
 省略``
Installing collected packages: PyYaml, itchat, efb-wechat-slave
  Attempting uninstall: PyYaml
    Found existing installation: PyYAML 3.12
ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

最后一句红字报错,翻译过来就是,错误:无法卸载“ PyYAML”。 这是一个 distutils 安装的项目,因此我们无法准确确定属于该文件的文件,这只会导致部分卸载。 pip 10 不再卸载 distutils 软件包。所以降级到 pip 8.1.1,根目录下:

bash
sudo -H pip3 install pip==8.1.1

再次安装 efb-wechat-slave即可

第二种办法

这样也是可以的,来自网页,据说没有什么负面影响,仅仅会产生一些系统垃圾。

bash
pip3 install --ignore-installed PyYAML
Windows连接移动硬盘不自动分配盘符
Nginx 中转 Emby 遇到的问题:播放速度不稳