fatedier / frp

A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.
Apache License 2.0
86.44k stars 13.37k forks source link

Autorun on OpenWRT #3317

Closed lavinkabul closed 1 year ago

lavinkabul commented 1 year ago

Describe the feature request

I am new to linux and OpenWRT in particular. I installed the frp server on my Ubuntu VPS using the auto-installation script and it was automatically added to startup. How to do the same with frp client on router with OpenWRT? Maybe there is a universal auto-installation script, with the subsequent ability to edit the configuration from luci? In addition, my VPS sometimes reboots (due to the fault of the provider), I would like the frp client to constantly try to reconnect when it loses connection with the server (for example, with a pause of 5 minutes). Could you tell me how to do this? I have OpenWRT 21.02.5

Describe alternatives you've considered

No response

Affected area

guokun1998 commented 1 year ago

Openwrt is base on Linux. You should kown your openwrt arch. It is usually arm64/misple/etc. And you can find releases package in https://github.com/fatedier/frp/releases. Like, frp_0.47.0_linux_arm64.tar.gz

lavinkabul commented 1 year ago

I have already installed frpc on OpenWRT and configured to work with remote frps server on Ubuntu OS. Everything works fine until restarting the router (Openwrt). After rebooting the router, frpc does not start on the router. Therefore, I would like to somehow register in autoload and cyclic restart of frpc, if suddenly the remote server where frps is located was not available for some time (for example, there was no Internet or the remote server rebooted)

guokun1998 commented 1 year ago
  1. Run server
  2. Run client
  3. Stop server
  4. wait
  5. Restart server

client log is :

2023/02/17 15:22:37 [I] [control.go:242] [33bc36f644381f25] control writer is closing
2023/02/17 15:22:37 [I] [visitor_manager.go:60] [33bc36f644381f25] gracefully shutdown visitor manager
2023/02/17 15:22:38 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:22:38 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 1s for another retry
2023/02/17 15:22:39 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:22:40 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 2s for another retry
2023/02/17 15:22:42 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:22:42 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 4s for another retry
2023/02/17 15:22:46 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:22:46 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 8s for another retry
2023/02/17 15:22:54 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:22:54 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 16s for another retry
2023/02/17 15:23:09 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:23:09 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 20s for another retry
2023/02/17 15:23:30 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:23:30 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 20s for another retry
2023/02/17 15:23:49 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:23:49 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 20s for another retry
2023/02/17 15:24:10 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:24:10 [W] [service.go:214] [33bc36f644381f25] reconnect to server error: dial tcp 192.168.99.61:7000: connect: connection refused, wait 20s for another retry
2023/02/17 15:24:31 [I] [service.go:211] [33bc36f644381f25] try to reconnect to server...
2023/02/17 15:24:32 [I] [service.go:299] [33bc36f644381f25] login to server success, get run id [33bc36f644381f25], server udp port [0]
2023/02/17 15:24:32 [I] [proxy_manager.go:142] [33bc36f644381f25] proxy added: [ssh]
2023/02/17 15:24:32 [I] [control.go:172] [33bc36f644381f25] [ssh] start proxy success

When server close, clinet will reconnect. I am using v0.47.0.

lavinkabul commented 1 year ago

When OpenWRT restarts, frpc does not start automatically. I need to do it manually

guokun1998 commented 1 year ago

It can use init.d bash in OpenWRT.

lavinkabul commented 1 year ago

I created a file in /etc/init.d/frpc and wrote to it:

START=99
USE_PROCD=1

start_service() {
    procd_open_instance "frpc"
    procd_set_param command /root/frpc -c /root/frpc.ini
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_set_param user root
    procd_close_instance
}

Did chmod 755 (rwxr-xr-x) for this file.

Next, frpc and frpc.ini placed in the /root folder Also did chmod 755 (rwxr-xr-x)

From the ssh command line, I run the command: /root/frpc -c /root/frpc.ini and everything works great. Next, to check the operation of frpc, I reboot the router. But frpc won't start.

I understand that the mistake is in some trifle, but I can not understand what.

Becods commented 1 year ago

opkg install luci-app-frpc Then go to openwrt's web management interface to configure.

lavinkabul commented 1 year ago

opkg install luci-app-frpc Then go to openwrt's web management interface to configure.

I started from the web interface and started setting up frpc. For example, what to choose here: OpenWRT_frpc

I tried different values (root, daemon). But frpc does not start automatically in any way. Can it be configured somehow through "Scheduled Tasks", could you tell me if such a solution is suitable and how to implement it?

lavinkabul commented 1 year ago

I'll add more. If I manually start frpc at http://192.168.1.1/cgi-bin/luci/admin/system/startup , the fast reverse proxy client starts up fine: OpenWRT_frpc_start

My guess is that maybe I need to add a pause before starting frpc after the router boots up. Only I don’t know which file to edit for this and which command to write.

lavinkabul commented 1 year ago

In general, after searching the Internet, a solution was found. Checking for the presence of a process using the scheduler:

*/1 * * * * root ps -A | grep frpc > /dev/null || /etc/init.d/frpc start

The presence of the frpc process will be checked every minute.

Write it down on the page http://192.168.1.1/cgi-bin/luci/admin/system/crontab

github-actions[bot] commented 1 year ago

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.