我们要实现一个订阅推特用户并将消息推送到 telegram 上,这里我们用 rss 的方式来实现,所以决定采用 rsshub 来生成订阅源,再用 rsstt 来实现订阅对应用户的 rss 源。这样就可以将订阅的推特用户消息推送到 telegram 频道或者用户上。
由于我买的是国内的服务器,但是访问 推特/telegram 需要科学上网。所以我们需要先在服务器上配置科学上网。
当然,如果你的服务器可以直接访问国外的网站,那就不需要配置科学上网这一步了。同时后续的 docker-compose.yml 文件里的 proxy 代理相关配置也不需要了。
配置科学上网
相关链接: https://github.com/spencer17x/clash-for-linux
- 克隆 clash 项目
| 1
 | $ git clone https://github.com/spencer17x/clash-for-linux
 | 
- 进入到项目目录,编辑 .env文件,修改变量CLASH_URL的值。
注意: .env 文件中的变量 CLASH_SECRET 为自定义 Clash Secret,值为空时,脚本将自动生成随机字符串。
- 启动程序
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 
 | $ sudo bash start.sh
 正在检测订阅地址...
 Clash订阅地址可访问!                                      [  OK  ]
 
 正在下载Clash配置文件...
 配置文件config.yaml下载成功!                              [  OK  ]
 
 正在启动Clash服务...
 服务启动成功!                                             [  OK  ]
 
 Clash Dashboard 访问地址:http://<ip>:9090/ui
 Secret:xxxxxxxxxxxxx
 
 请执行以下命令加载环境变量: source /etc/profile.d/clash.sh
 
 请执行以下命令开启系统代理: proxy_on
 
 若要临时关闭系统代理,请执行: proxy_off
 
 | 
| 12
 
 | $ source /etc/profile.d/clash.sh$ proxy_on
 
 | 
- 检查服务端口
| 12
 3
 4
 5
 
 | $ netstat -tln | grep -E '9090|789.'tcp        0      0 127.0.0.1:9090          0.0.0.0:*               LISTEN
 tcp6       0      0 :::7890                 :::*                    LISTEN
 tcp6       0      0 :::7891                 :::*                    LISTEN
 tcp6       0      0 :::7892                 :::*                    LISTEN
 
 | 
- 检查环境变量
| 12
 3
 
 | $ env | grep -E 'http_proxy|https_proxy'http_proxy=http://127.0.0.1:7890
 https_proxy=http://127.0.0.1:7890
 
 | 
以上步鄹如果正常,说明服务clash程序启动成功,现在就可以体验高速下载 github 资源了。
从 https://github.com/spencer17x/clash-for-linux/blob/master/start.sh#L163-L178 可以看出,clash 采用了 nohup 实现了系统后台运行程序。
- 由于上述只完成了 clash 配置以及后台运行,但是每次登陆到服务器还要实现启动代理,所以需要配置启动代理。
| 12
 
 | # 在 ~/.bashrc 文件末尾添加一段 proxy_on 即可$ vi ~/.bashrc
 
 | 
通过 curl https://www.google.com 即可测试科学上网是否配置成功,如果成功了即返回正常的数据,失败了则需要继续排查问题。
相关链接: https://docs.rsshub.app/zh/install#docker-compose-%E9%83%A8%E7%BD%B2
这里使用是 docker-compose 来部署。
- 新建个项目,命名为 rsshub-rsstt
| 1
 | $ mkdir rsshub-rsstt && cd rsshub-rsstt
 | 
- 配置 rsshub
参考: https://docs.rsshub.app/zh/install#docker-compose-%E9%83%A8%E7%BD%B2
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | # 下载 docker-compose.yml$ wget https://raw.githubusercontent.com/DIYgod/RSSHub/master/docker-compose.yml
 
 # 检查有无需要修改的配置
 $ vi docker-compose.yml
 
 # 创建 volume 持久化 Redis 缓存
 $ docker volume create redis-data
 
 # 启动
 $ docker-compose up -d
 
 | 
docker-compose.yml: 参考后面最终的 docker-compose.yml
注: 172.17.0.1 是 docker0 虚拟网卡的主机 ip,在 Windows 和 mac 下机制不同所以不适用。由于我的服务器是 linux 的,所以 PROXY_URI 的 ip 为 172.17.0.1。mac 的需要改为 host.docker.internal。其他的根据自己的需求进行调整。
浏览器地址栏输入 http://ip:1200 可以查看 rsshub 服务是否部署成功。
输入 http://ip:1200/twitter/user/elonmusk 可以查看订阅源是否可以正常生成。
- 配置 rsstt
docker-compose.yml:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 
 | version: '3.9'
 services:
 rsshub:
 
 
 
 image: diygod/rsshub
 restart: always
 ports:
 - '1200:1200'
 environment:
 NODE_ENV: production
 CACHE_TYPE: redis
 REDIS_URL: 'redis://redis:6379/'
 PUPPETEER_WS_ENDPOINT: 'ws://browserless:3000'
 PROXY_URI: 'http://172.17.0.1:7890'
 TWITTER_USERNAME: xxx
 TWITTER_PASSWORD: xxx
 depends_on:
 - redis
 - browserless
 
 browserless:
 image: browserless/chrome
 restart: always
 ulimits:
 core:
 hard: 0
 soft: 0
 
 redis:
 image: redis:alpine
 restart: always
 volumes:
 - redis-data:/data
 
 warp-socks:
 image: monius/docker-warp-socks:latest
 privileged: true
 restart: always
 volumes:
 - /lib/modules:/lib/modules
 cap_add:
 - NET_ADMIN
 - SYS_MODULE
 sysctls:
 net.ipv6.conf.all.disable_ipv6: 0
 net.ipv4.conf.all.src_valid_mark: 1
 healthcheck:
 test: ["CMD", "curl", "-f", "https://www.cloudflare.com/cdn-cgi/trace"]
 interval: 30s
 timeout: 10s
 retries: 5
 
 rsstt:
 image: rongronggg9/rss-to-telegram:dev
 container_name: rsstt
 restart: unless-stopped
 volumes:
 - ./config:/app/config
 environment:
 - TOKEN=xxx
 - MANAGER=xxx
 
 
 
 
 
 
 - TELEGRAPH_TOKEN=
 xxx
 xxx
 xxx
 xxx
 xxx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - T_PROXY=http://172.17.0.1:7890
 - R_PROXY=http://172.17.0.1:7890
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 volumes:
 redis-data:
 
 | 
本地 mac 配置
如果你想在本地配置测试,可参考如下配置:
docker-compose.yml:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 
 | version: '3.9'
 services:
 rsshub:
 
 
 
 image: diygod/rsshub
 restart: always
 ports:
 - '1200:1200'
 environment:
 NODE_ENV: production
 CACHE_TYPE: redis
 REDIS_URL: 'redis://redis:6379/'
 PUPPETEER_WS_ENDPOINT: 'ws://browserless:3000'
 PROXY_URI: 'http://host.docker.internal:7890'
 TWITTER_USERNAME: xxx
 TWITTER_PASSWORD: xx
 depends_on:
 - redis
 - browserless
 
 browserless:
 image: browserless/chrome
 restart: always
 ulimits:
 core:
 hard: 0
 soft: 0
 
 redis:
 image: redis:alpine
 restart: always
 volumes:
 - redis-data:/data
 
 warp-socks:
 image: monius/docker-warp-socks:latest
 privileged: true
 restart: always
 volumes:
 - /lib/modules:/lib/modules
 cap_add:
 - NET_ADMIN
 - SYS_MODULE
 sysctls:
 net.ipv6.conf.all.disable_ipv6: 0
 net.ipv4.conf.all.src_valid_mark: 1
 healthcheck:
 test: ["CMD", "curl", "-f", "https://www.cloudflare.com/cdn-cgi/trace"]
 interval: 30s
 timeout: 10s
 retries: 5
 
 rsstt:
 image: rongronggg9/rss-to-telegram:dev
 container_name: rsstt
 restart: unless-stopped
 volumes:
 - ./config:/app/config
 environment:
 - TOKEN=xxx
 - MANAGER=xxx
 
 
 
 
 
 
 - TELEGRAPH_TOKEN=
 xxx
 xxx
 xxx
 xxx
 xxx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 - T_PROXY=http://host.docker.internal:7890
 - R_PROXY=http://host.docker.internal:7890
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 volumes:
 redis-data:
 
 | 
经测试,rsshub可以正常生成 rss 源,rsstt 也可以正常订阅源。