使用的项目:seriyps/mtproto_proxy: High performance Erlang MTProto proxy that powers https://t.me/socksy_bot
# 需要安装的软件包
apk add coreutils erlang27-dev make git
# 下载代码
curl -L https://github.com/seriyps/mtproto_proxy/archive/master.tar.gz -o mtproto_proxy.tar.gz
# 解压源代码
tar -xvaf mtproto_proxy.tar.gz
mv -T mtproto_proxy-master mtproto_proxy
cd mtproto_proxy/
# 设置监听端口
PORT=443
# 设置 secret
SECRET=`head -c 16 /dev/urandom | od -A n -t x1 -w128 | sed 's/ //g'`
# 设置从 @MTProxybot 获取的 proxy tag
TAG="47b8363ed5431e0868d2bead1a55dd50"
# 设置 TLS 伪装域名
TLS_DOMAIN="s3.amazonaws.com"
# 写入配置文件
echo '
%% -*- mode: erlang -*-
[
{mtproto_proxy,
%% see src/mtproto_proxy.app.src for examples.
[
'${PROTO_ARG}'
{ports,
[#{name => mtp_handler_1,
listen_ip => "0.0.0.0",
port => '${PORT}',
secret => <<"'${SECRET}'">>,
tag => <<"'${TAG}'">>}
]}
]},
%% Logging config
{kernel,
[{logger_level, info},
{logger,
[{handler, default, logger_std_h,
#{level => info,
config => #{type => file,
file => "/var/log/mtproto-proxy/application.log",
max_no_bytes => 104857600, % 100MB
max_no_files => 10,
filesync_repeat_interval => no_repeat}}},
{handler, console, logger_std_h,
#{level => critical,
config => #{type => standard_io}}}
]}]},
{sasl, [{errlog_type, error}]}
].' >config/prod-sys.config
# 编译
make
# 复制到安装路径
cp -r _build/prod/rel/mtp_proxy /opt/
mkdir -m 777 /opt/mtp_proxy/log/
# 查看连接参数 secret
echo -ne "\xee$(echo -n $SECRET | sed 's/../\\x&/g')$TLS_DOMAIN" | base64 -w 0 | tr '+/' '-_'
mtproto-proxy 注册 OpenRC 服务
#!/sbin/openrc-run
#/etc/init.d/mtproto-proxy
description="Starts the mtproto_proxy server"
depend() {
need net
use dns
after local-fs remote-fs
need epmd
}
command="/opt/mtp_proxy/bin/mtp_proxy"
command_args="foreground"
supervisor="supervise-daemon"
name="mtproto-proxy"
extra_commands="reload"
export RUNNER_LOG_DIR="/var/log/mtproto-proxy"
rc_ulimit="-n 40960"
respawn_delay=5
respawn_max=10
stop() {
ebegin "Stopping mtproto_proxy"
$command stop
eend $?
}
reload() {
ebegin "Reloading mtproto_proxy configuration"
$command rpcterms mtproto_proxy_app reload_config
eend $?
}
epmd 注册 OpenRC 服务
#!/sbin/openrc-run
#/etc/init.d/epmd
description="Erlang Port Mapper Daemon"
depend() {
need net
before mtproto-proxy
}
command="/usr/bin/epmd"
command_args="-daemon"
command_user="daemon:daemon"
stop() {
ebegin "Stopping epmd"
$command -kill
eend $?
}
status() {
$command -names
}
设置可执行权限
chmod +x /etc/init.d/epmd /etc/init.d/mtproto-proxy
启动
service epmd start && service mtproto-proxy start
发表回复