frp 是一個可用於內網穿透的高性能的反向代理應用,支持 tcp, udp, http, https 協議
目前主要的場景是內網穿透,能夠用於本地調試微信接口、本地站點公網訪問等。linux
本文主要講解:git
frp執行區分不一樣的平臺,在服務器上執行命令:github
arch
若是輸出x86_64則須要下載帶linux_amd64的那個壓縮包;
若是輸出的是其餘的,則在文件列表中找 linux 的對應架構的壓縮包web
frp_0.20.0_darwin_amd64.tar.gz
macfrp_0.20.0_linux_arm64.tar.gz
linuxfrp_0.20.0_windows_386.zip
windows而後嘗試運行./frps --help
, 正常會輸出幫助信息。windows
若是提示-bash: ./frps: cannot execute binary file: Exec format error
就說明你下錯版本了。api
客戶端和服務端版本號一致,目前使用的是v0.20.0
。安全
啓動命令:bash
./frpc -c frpc.ini
frpc.ini
客戶端配置(必須)服務器
[common] # frp 服務器端地址,ip或域名 server_addr = frp.xxx.com # frp 服務端端口,即填寫服務端配置中的 bind_port server_port = 7000 token = xxxxx
[apixxx] # http 或 https type = http # 默認不須要改變ip,指向本地 local_ip = 127.0.0.1 # 對應服務的端口號 local_port = 9000 # http 能夠考慮加密和壓縮一下 use_encryption = true use_compression = true # 自定義訪問網站的用戶名和密碼,若是不定義的話誰均可以訪問,會不安全 http_user = admin http_pwd = admin # 對應遠程的訪問地址web0.frp.xxx.com:10080 # frp.idayer.com 爲服務端配置的 subdomain_host subdomain = web0
# 自定義一個配置名稱,格式爲「[range:名稱]」,放在開頭 [range:multi-port] type = tcp local_ip = 127.0.0.1 use_encryption = false use_compression = false # 本地端口和遠程端口能夠指定多個範圍,以下格式,且範圍之間必須一一對應 local_port = 6010-6020,6022,6024-6028 remote_port = 16010-16020,16022,16024-16028
最後咱們的配置結果以下:微信
[common] server_addr = frp.xxx.com server_port = 7000 token = xxx [apixxx] type = http local_ip = 127.0.0.1 local_port = 9000 use_encryption = true use_compression = true http_user = admin http_pwd = admin subdomain = web0
更多配置能夠看目錄下的frpc_full.ini
,以及參考(frp配置)[https://github.com/fatedier/f...]
登陸服務端的 dashboard,看看是否鏈接成功,測試各項轉發是否可用
啓動命令:
# 使用 -c 參數指定配置文件 ./frps -c frps.ini
服務端配置以下:
[common] # frp 服務端端口(必須) bind_port = 7000 # frp 服務端密碼(必須) token = 12345678 # 認證超時時間,因爲時間戳會被用於加密認證,防止報文劫持後被他人利用 # 所以服務端與客戶端所在機器的時間差不能超過這個時間(秒) # 默認爲900秒,即15分鐘,若是設置成0就不會對報文時間戳進行超時驗證 authentication_timeout = 900 # 儀表盤端口,只有設置了才能使用儀表盤(即後臺) dashboard_port = 7500 # 儀表盤訪問的用戶名密碼,若是不設置,則默認都是 admin dashboard_user = admin dashboard_pwd = admin # 若是你想要用 frp 穿透訪問內網中的網站(例如路由器設置頁面) # 則必需要設置如下兩個監聽端口,不設置則不會開啓這項功能 vhost_http_port = 10080 vhost_https_port = 10443 # 此設置須要配合客戶端設置,僅在穿透到內網中的 http 或 https 時有用(可選) # 假設此項設置爲 example.com,客戶端配置 http 時將 subdomain 設置爲 test, # 則你將 test.example.com 解析到服務端後,可使用此域名來訪問客戶端對應的 http subdomain_host = example.com
能夠經過nohup [command] &
操做來讓命令後續執行。
nohup /root/frp/frps -c /root/frp/frps.ini &
pkill frps
編輯/etc/rc.local
文件,將啓動那句命令加到exit 0
語句以前(若是有)
注意修改其中的EXEC
,OPTIONS
目錄。
#!/bin/bash # chkconfig: - 85 15 # # description: frp init script RETVAL=0 PROG="frpc" EXEC="/usr/bin/frpc" LOCKFILE="/var/lock/subsys/$PROG" OPTIONS="-c /etc/frp/frpc.ini" # Source function library. if [ -f /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions else echo "/etc/rc.d/init.d/functions is not exists" exit 0 fi start() { if [ -f $LOCKFILE ] then echo "$PROG is already running!" else echo -n "Starting $PROG: " #$EXEC $OPTIONS & nohup $EXEC $OPTIONS >/dev/null 2>&1 & RETVAL=$? [ $RETVAL -eq 0 ] && touch $LOCKFILE && success || failure echo return $RETVAL fi } stop() { echo -n "Stopping $PROG: " killproc $EXEC RETVAL=$? [ $RETVAL -eq 0 ] && rm -r $LOCKFILE && success || failure echo } restart () { stop sleep 1 start } case "$1" in start) start ;; stop) stop ;; status) status $PROG ;; restart) restart ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit $RETVAL
chmod 755 /etc/init.d/frp
chkconfig frp on
啓動服務:service frp start
中止服務:service frp stop
查看狀態:service frp status
重啓服務:service frp restart
更多方案能夠參考
本文同步發表博客: 內網穿透神器FRP