realm是什么
作者自己简介:用rust编写的简单的、高性能的中转软件。
- 根据众多用户的反馈:优势是资源占用低,执行速度快,命令简单
所以,记录下realm使用方法
realm的获取
# github源
mkdir /opt/realm && cd /opt/realm;
wget -O /opt/realm/conf.toml https://github.com/zhboner/realm/raw/master/examples/ws.toml
wget -O realm.tar.gz https://github.com/zhboner/realm/releases/download/v2.3.4/realm-x86_64-unknown-linux-gnu.tar.gz && tar -xvf realm.tar.gz && chmod +x realm && rm -rf realm.tar.gz;
#国内加速下载
mkdir /opt/realm && cd /opt/realm;
wget -O /opt/realm/conf.toml https://zsobs.obs.cn-north-4.myhuaweicloud.com/public/static/more/realm/conf.toml
wget -O realm.tar.gz https://zsobs.obs.cn-north-4.myhuaweicloud.com/public/static/more/realm/realmv2.5.1-x86_64-unknown-linux-gnu.tar.gz && tar -xvf realm.tar.gz && chmod +x realm && rm -rf realm.tar.gz
#service文件下载
wget -O /etc/systemd/system/realm.service https://zsobs.obs.cn-north-4.myhuaweicloud.com/public/static/more/realm/realm.service
#启动命令
/opt/realm/realm -c /opt/realm/conf.toml
realm的用法
转发信息:
- 中转VPS和端口:1.1.1.1:1111
- 落地VPS和端口:8.8.8.8:8888
1. 极简用法:
在中转VPS上直接执行命令:
./realm -l 0.0.0.0:1111 -r 8.8.8.8:8888
2. 使用配置文件:
新建TOML文件:
nano config.toml
在config.toml文件中填入内容,并保存:
[log]
level = "warn"
output = "/var/log/realm.log"
[network]
no_tcp = false
use_udp = true
[[endpoints]]
listen = "0.0.0.0:1111"
remote = "8.8.8.8:8888"
使用配置文件启动realm:
./realm -c config.toml
2. 命令配置脚本:
- 通过systemctl start/stop/restart/status realm 控制
- 新建一个realm.service文件,添加如下代码:
[Unit]
Description=realm
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
DynamicUser=true
ExecStart=/opt/realm/realm -c /opt/realm/conf.toml
[Install]
WantedBy=multi-user.target
远程下载脚本:
wget -O /etc/systemd/system/ https://zsobs.obs.cn-north-4.myhuaweicloud.com/public/static/more/realm/realm.service
__注意:ssh远程登录vps直接使用命令,需要自己查找处理退出后命令终止的问题。
个人比较中意Docker,所以再补充一下docker的用法。
realm的Docker版
由于作者的docker版本设置了private,所以没有办法pull,需要自己build,所以首先我们来build一下realm docker版本:
新建Dockerfile
新建Docker/Realm目录,然后进入目录,新建Dockerfile
mkdir /root/Docker/Realm
cd /root/Docker/Realm
nano Dockerfile
填入内容,并保存:
FROM alpine:3.9
ARG VERSION="v2.3.4"
WORKDIR /realm
RUN wget https://github.com/zhboner/realm/releases/download/${VERSION}/realm-x86_64-unknown-linux-musl.tar.gz \
&& tar -zxvf realm-x86_64-unknown-linux-musl.tar.gz \
&& cp realm /usr/bin/realm \
&& chmod +x /usr/bin/realm
ENTRYPOINT ["/usr/bin/realm"]
编译Docker Image
编译Docker Image 【注意代码后最后一个符号“点”】
docker build -t realm:v2.3 .
等待10几秒编译完成后,查看镜像,看到realm
% docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
realm v2.3 692ce2fa59dc 10 seconds ago 15.7MB
启动Docker
新建docker-compose.yml
nano docker-compose.yml
填入内容,并保存
version: '3'
services:
realm-2.3:
image: realm:v2.3
network_mode: "host"
volumes:
- ./conf:/home
command:
- "-c=/home/config.toml"
新建配置文件夹
mkdir conf
新建配置文件
nano conf/config.toml
填入配置,并保存
[log]
level = "warn"
output = "/var/log/realm.log"
[network]
no_tcp = false
use_udp = true
[[endpoints]]
listen = "0.0.0.0:1111"
remote = "8.8.8.8:8888"
启动realm docker:
docker-compose up -d
判断是否启动成功的方法:
查看日志
docker-compose logs
## 查看系统开放端口
ss -luntp
Realm帮助文件
Realm 2.3.4 [hook][proxy][transport][multi-thread]
A high efficiency relay tool
USAGE:
realm [FLAGS] [OPTIONS]
FLAGS:
-h, --help show help
-v, --version show version
-d, --daemon run as a unix daemon
-u, --udp force enable udp forward
-t, --ntcp force disable tcp forward
-f, --tfo force enable tcp fast open -- deprecated
-z, --splice force enable tcp zero copy -- deprecated
OPTIONS:
-c, --config <path> use config file
-l, --listen <address> listen address
-r, --remote <address> remote address
-x, --through <address> send through ip or address
-i, --interface <device> bind to interface
-a, --listen-transport <options> listen transport
-b, --remote-transport <options> remote transport
SYS OPTIONS:
-n, --nofile <limit> set nofile limit
-p, --pipe-page <number> set pipe capacity
-j, --pre-conn-hook <path> set pre-connect hook
LOG OPTIONS:
--log-level <level> override log level
--log-output <path> override log output
DNS OPTIONS:
--dns-mode <mode> override dns mode
--dns-min-ttl <second> override dns min ttl
--dns-max-ttl <second> override dns max ttl
--dns-cache-size <number> override dns cache size
--dns-protocol <protocol> override dns protocol
--dns-servers <servers> override dns servers
PROXY OPTIONS:
--send-proxy send proxy protocol header
--send-proxy-version <version> send proxy protocol version
--accept-proxy accept proxy protocol header
--accept-proxy-timeout <second> accept proxy protocol timeout
TIMEOUT OPTIONS:
--tcp-timeout <second> override tcp timeout
--udp-timeout <second> override udp timeout
SUBCOMMANDS:
convert convert your legacy configuration into an advanced one