Adi的小破站

TELEGRAM官方MTPROXY搭建教程

  • 为什么手动搭建?!
  • 因为大多数一键脚本有TLS伪装。会导致专线入口被通报

Debian/Ubuntu

apt install git curl build-essential libssl-dev zlib1g-dev

github拉取文件

git clone https://github.com/TelegramMessenger/MTProxy
cd MTProxy

进行编译

执行make进行编译,生成的二进制文件在 objs/bin/mtproto-proxy

Makefile文件中的CFLAGS行(第15行)最后添加 -fcommon ,后再进行编译步骤。

make && cd objs/bin

获取TELEGRAM通信密匙

curl -s https://core.telegram.org/getProxySecret -o proxy-secret

获取当前TELEGRAM代理配置(官方建议每天更新此文件)

curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf

生成代理密匙(可跳过)

head -c 16 /dev/urandom | xxd -ps

没有安装head可以复制我以下所生成的,修改个别字符即可。

生成的密钥:5de7612139995eea038478ada5d342b0

启动MTP服务端

./mtproto-proxy -u nobody -p 8008 -H 65432 -S 5de7612139995eea038478ada5d342b0 --aes-pwd proxy-secret proxy-multi.conf -M 1

./mtproto-proxy -u nobody -p 8008 -H 65432 -S 5de7612139995eea038478ada5d342b0 –aes-pwd proxy-secret proxy-multi.conf -M 1

标红地方可自定义修改

8008 本地端口

63328 用于客户端连接的端口

5de7612139995eea038478ada5d342b0 密钥

tg:// 直连链接格式

tg://proxy?server=服务器IP&port=端口&secret=SECRET

例:tg://proxy?server=1.2.3.4&port=65432&secret=5de7612139995eea038478ada5d342b0

运行结果

[60910][2025-10-23 20:00:51.349577 local] Invoking engine mtproxy-0.01 compiled at Oct 23 2025 19:35:21 by gcc 12.2.0 64-bit after commit dc0c7f3de40530053189c572936ae4fd1567269b
[60910][2025-10-23 20:00:51.349971 local] config_filename = 'proxy-multi.conf'
[60910][2025-10-23 20:00:51.350530 local] creating 1 workers
[60910][2025-10-23 20:00:51.351751 local] Started as [ip:8008:60910:1761220851]
[60910][2025-10-23 20:00:51.352027 local] configuration file proxy-multi.conf re-read successfully (752 bytes parsed), new configuration active
[60911][2025-10-23 20:00:51.352075 local] Started as [ip:8008:60911:1761220851]
[60911][2025-10-23 20:00:51.352266 local] configuration file proxy-multi.conf re-read successfully (752 bytes parsed), new configuration active
[60911][2025-10-23 20:00:51.352711 local] main loop
[60910][2025-10-23 20:00:51.352889 local] main loop

没有报错就说明成功了

Ctrl + C 先结束程序

后台运行

cat > /etc/systemd/system/mtproxy.service <<EOF
[Unit]
Description=MTProxy
After=network.target

[Service]
ExecStart=/root/MTProxy/objs/bin/mtproto-proxy -u nobody -p 8008 -H 63328 \
  -S 5de7612139995eea038478ada5d342b0 \
  --aes-pwd proxy-secret proxy-multi.conf -M 1
WorkingDirectory=/root/MTProxy/objs/bin
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target
EOF

创建 MTProxy systemd 服务

systemctl daemon-reload
systemctl enable --now mtproxy
systemctl status mtproxy

启动服务

*重要

原版 Telegram 官方源码老旧(从 2018 年后就几乎没维护),
在新系统上会因为 PID 位宽限制而崩溃。

echo "kernel.pid_max=65535" >> /etc/sysctl.conf
sysctl -p

绕过 PID 限制(会影响全局进程号上限)

创建重启任务(可选)

因为MTP经常会卡死,所以创建一个定时重启任务。每分钟重启一次,可自定义。

cat > /etc/systemd/system/mtproxy-restart.service <<EOF
[Unit]
Description=Restart MTProxy Service

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart mtproxy
EOF

重启服务的 systemd 文件

cat > /etc/systemd/system/mtproxy-restart.timer <<EOF
[Unit]
Description=Restart MTProxy every 1 minutes

[Timer]
OnBootSec=1min
OnUnitActiveSec=1min
Unit=mtproxy-restart.service

[Install]
WantedBy=timers.target
EOF

定时器文件(每 1 分钟重启一次)

OnBootSec=1min → 开机 1 分钟后第一次执行

OnUnitActiveSec=1min → 每隔 1 分钟执行一次 (可自定义时间)

systemctl daemon-reload
sudo systemctl enable --now mtproxy-restart.timer
# 查看定时器状态
systemctl list-timers | grep mtproxy

启动定时器服务

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注