前言
通过frp和跳板机完成局域网服务器访问。工具地址:https://github.com/fatedier/frp
配置frp过程
-
下载frp工具,下载地址如下:
https://github.com/fatedier/frp/releases
这里我选择了v0.57.0
-
解压到本地路径
tar -zxvf xxxxxx.tar.gz
-
配置服务器端和客户端,这里直接从官网copy过来一份:
# 1. Modify frps.toml on server A by setting the bindPort for frp clients to connect to: # frps.toml bindPort = 7000# 2. Start frps on server A: ./frps -c ./frps.toml# 3. Modify frpc.toml on server B and set the serverAddr field to the public IP address of your frps server: # frpc.toml serverAddr = "x.x.x.x" serverPort = 7000[[proxies]] name = "ssh" type = "tcp" localIP = "127.0.0.1" localPort = 22 remotePort = 6000 # Note that the localPort (listened on the client) and remotePort (exposed on the server) are used for traffic going in and out of the frp system, while the serverPort is used for communication between frps and frpc.# 4. Start frpc on server B: ./frpc -c ./frpc.toml# 5. To access server B from another machine through server A via SSH (assuming the username is test), use the following command: ssh -oPort=6000 test@x.x.x.x
-
配置云服务器的安全组端口入站和出站规则,具体查阅网上资料吧
更多信息见官网:https://github.com/fatedier/frp
设置frpc开机自启
-
添加systemd配置文件
vim /usr/lib/systemd/system/frp.service
-
添加如下内容:
[Unit] Description=The nginx HTTP and reverse proxy server After=network.target[Service] Type=simple Restart=on-failure RestartSec=5s ExecStart=/opt/frp_0.57.0_linux_amd64/frpc -c /opt/frp_0.57.0_linux_amd64/frpc.toml # 这里根据实际情况修改 ExecReload=/opt/frp_0.57.0_linux_amd64/frpc reload -c /opt/frp_0.57.0_linux_amd64/frpc.toml # 根据实际情况修改 KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true StandardOutput=syslog StandardError=inherit[Install] WantedBy=multi-user.target
-
设置开机启动
systemctl daemon-reload systemctl enable frp
-
手动启动
systemctl start frp
常见问题
记录了我自己在安装过程中遇到的问题,如下:
问题: Connection closed by remote host
解决:
sudo apt update && sudo apt upgrade && sudo apt install openssh-server
参考: https://github.com/fatedier/frp/issues/2064
问题:Host key verification failed.
解决:
删除本地的know_host
参考:https://blog.csdn.net/Doitm/article/details/127907684
参考资料
- frp设置开机自启服务
- frp开机启动