Automatically deploy FRP server and client services using Docker via bash script
Automatically deploy FRP server and client services using DockerAutomatically deploy fast reverse proxy server and client services using Docker.pngIt is an easy way to deploy FRP server and client services using Docker, which simplifies the setup process by breaking it down into four parts.Breakdown of contentPart1, Menu Settings function display_menu { echo "Please select a service as you want to deploy:" echo "1. FRP(S) Service" echo "2. FRP(C) Service" echo "0. Exit" }2023-03-21_120127.pngThe script starts with a menu that presents the user with three options to choose from. This menu is essential to guide the user through the rest of the process.Part2, FRP Server service deploy function handle_option_1 { }This part sets up the FRP server service as a function.include the followingif ! command -v docker &> /dev/null then echo "Docker is not installed. Installing Docker now..." curl -O https://kingtam.win/usr/uploads/script/install-docker.sh && chmod +x install-docker.sh && ./install-docker.sh fiIt detects if Docker is installed and if not, installs it.echo "What port would you like to use for the frps service? Press enter to use the default port of 7000, type 'r' to generate a random port, or enter a port number:" read -r port_choice if [[ $port_choice == "r" ]]; then port=$(shuf -i 7001-9000 -n 1) elif [[ -z $port_choice ]]; then port=7000 else port=$port_choice fi echo "What port would you like to use for the HTTP service? Press enter to use the default port of 80, or enter a port number:" read -r http_choice if [[ -z $http_choice ]]; then http=80 else http=$http_choice fi echo "What port would you like to use for the HTTPS service? Press enter to use the default port of 443, or enter a port number:" read -r https_choice if [[ -z $https_choice ]]; then https=443 else https=$https_choice fi echo "Would you like to generate a random token or enter a password for the frps service? Press enter to generate a random token, or enter a password:" read -r token_choice if [[ -z $token_choice ]]; then token=$(openssl rand -hex 16) else token=$token_choice fiThen it prompts the user to create the FRP server service, HTTP, HTTPS, and token.if [ ! -d "./frps/tmp" ]; then mkdir -p "./frps/tmp" else sudo rm -rf "./frps" && mkdir -p "./frps/tmp" fiIt also checks if the folder ./frps/tmp exists and creates it if it doesn't.cat >> "./frps/frps.ini" << EOF [common] bind_addr = 0.0.0.0 bind_port = $port vhost_http_port = $http vhost_https_port = $https dashboard_tls_mode = false enable_prometheus = true log_file = /tmp/frps.log log_level = info log_max_days = 3 disable_log_color = false detailed_errors_to_client = true authentication_method = token authenticate_heartbeats = false authenticate_new_work_conns = false token = $token max_pool_count = 5 max_ports_per_client = 0 tls_only = false EOF cat >> "./frps/docker-compose.yml" << EOF version: '3' services: frps: image: snowdreamtech/frps:latest container_name: frps network_mode: "host" restart: always volumes: - "$PWD/frps/frps.ini:/etc/frp/frps.ini" - "$PWD/frps/tmp:/tmp:rw" EOF docker-compose -f "./frps/docker-compose.yml" up -d sleep 3 sudo cat "./frps/tmp/frps.log" echo -e "\033[1;32mServer IP Address:\033[0m $(curl -s ifconfig.co)" echo -e "\033[1;32mService Port:\033[0m $port" echo -e "\033[1;32mToken:\033[0m $token" echo -e "\033[1;32mHTTP Port:\033[0m $http" echo -e "\033[1;32mHTTPS Port:\033[0m $https"Finally, it creates the FRP server config file, docker-compose.yml file, starts up the docker-compose, and prints the frps.log with information in color.2023-03-21_120218.pngPart3, FRP Client service deploy function handle_option_2 { }This part sets up the FRP client service as a function.include the followingif ! command -v docker &> /dev/null then echo "Docker is not installed. Installing Docker now..." curl -O https://kingtam.win/usr/uploads/script/install-docker.sh && chmod +x install-docker.sh && ./install-docker.sh fiIt also detects if Docker is installed and installs it if it isn't.read -p "Enter the FRP(S) Server ip address or domain: " frpsip read -p "Enter the FRP(S) Service port (press Enter for default **7000** or manual to input a port): " port if [ -z "$port" ] then port=7000 else read -p "Enter the FRP(S) Service port: " port fi read -p "Enter the FRP(S) Service token: " token read -p "Enter the port of FRP(C) admin console (press Enter for default **7400** or manual to input a port): " cport if [ -z "$cport" ] then cport=7400 else read -p "Enter the FRP(C) admin console port: " cport fi read -p "Enter the username of FRP(C) console (press Enter for default **admin** or manual to input a name): " cname if [ -z "$cname" ] then cname=admin else read -p "Enter the username of FRP(C) console: " cname fi echo "Would you like to generate a Random Console Password (Press Enter) or enter a password for the FRP(C) console?" read cpasswd if [[ -z $cpasswd ]]; then ctoken=$(openssl rand -hex 12) else ctoken=$cpasswd fiThen the user is prompted to create the FRP client service, FRP server IP address or domain, port, token, admin address, console, and console token.if [ ! -d "./frpc/tmp" ]; then mkdir -p ./frpc/tmp else sudo rm -rf ./frpc && mkdir -p ./frpc/tmp fiIt also checks if the folder ./frpc/tmp exists and creates it if it doesn't.cat >> frpc/frpc.ini << EOF [common] server_addr = $frpsip server_port = $port token = $token log_file = /tmp/frpc.log log_level = info log_max_days = 3 disable_log_color = false admin_addr = 0.0.0.0 admin_port = $cport admin_user = $cname admin_pwd = $ctoken EOF cat >> frpc/docker-compose.yml << EOF version: '3' services: frpc: image: snowdreamtech/frpc:latest container_name: frpc network_mode: "host" restart: always volumes: - ./frpc.ini:/etc/frp/frpc.ini - ./tmp:/tmp:rw EOF docker-compose -f ./frpc/docker-compose.yml up -d sleep 3 sudo cat ./frpc/tmp/frpc.log echo -e "Please use below information to Login console and setup your FRP(C) services" echo -e "The address of console: \033[1;32mhttp://localhost:$cport\033[0m" echo -e "The username of console: \033[1;32m$cname\033[0m" echo -e "The password of console: \033[1;32m$ctoken\033[0m"Finally, it creates the FRP client config file, docker-compose.yml file, starts up the docker-compose, and prints the frpc.log with information in color.2023-03-21_120312.pngPart4, Use case statement display_menu read -p "Enter your choice [0-2]: " choice case $choice in 1) handle_option_1 ;; 2) handle_option_2 ;; 0) echo "Exiting..." exit 0 ;; *) echo "Invalid choice" ;; esacThe case statement that evaluates the value of $choice and executes the corresponding code block. If the user enters a value that is not one of the three options, the * case matches and an error message is displayed.Use The Script:Save the contents of the script in a file, e.g., frp.sh.Make the script executable with chmod +x frp.sh.Run the script as root or with sudo: sudo ./frp.sh.Also, We can using a single command line in the terminal. (Root Privileges is requires)curl -O https://kingtam.win/usr/uploads/script/frp.sh && chmod +x frp.sh && ./frp.shThis command will download the script from URL, make it executable, and then run it. If any of the commands fail, the subsequent commands will not be executed.Conclusion:This bash script simplifies the deployment of FRP server and client services using Docker. Its four parts guide the user through the setup process, making it easy to create and run the services. By breaking down the process into manageable parts, this script reduces the complexity of the setup process for users.Related:Use Docker to Deploy FRP ServicesLet NPM and FRP share 80/443 ports with Wildcard Domain Name
Use Docker to deploy FRP services.drawio.pngAbout FRPFRP standard for fast reverse proxy, is an open-source, concise and easy-to-use, high-performance reverse proxy software, supporting TCP, UDP, HTTP, HTTPS and other protocols.Table of ContentsRequirementHow it WorkDeploy FRP servicesServer configurationClient configurationConclusionReferenceRequirementMust have a server with an Public IP address (e.g. VPC).How it workarchitecture.pngThe server runs, listens on a main port (default 7000), and waits for the client to connect;The client connects to the main port of the server, and tells the server the port and forwarding type to listen on.The server open new process session to listen on the specified port by the client;Users on the Internet connects to the specified port by the client, and the server forwards data to the client through the connection with the client.The client forwards the data to the local service, make the internal services expose to the Public Network.Deploy FRP servicesThe configuration tutorial is mainly divided into two partsOne is the configuration of the server (Internet)One is the configuration of the client (Intranet)Server configurationCreate a frps.ini configuration file on Server[common] bind_addr = 0.0.0.0 bind_port = 7000 vhost_http_port = 80 vhost_https_port = 443 log_file = /tmp/frps.log authentication_method = token token = yM1nDMBFihB93zs376uRParameterDescriptionbind_addr0.0.0.0 means listen on any IP addressbind_portDefault port 7000 is used to bind with the servervhost_http_portVirtual host HTTP portvhost_https_portVirtual host HTTPS portlog_file/tmp/frps.log logFile pathauthentication_methodSpecifies authentication method (e.g. token)tokenAuthentication token is yM1nDMBFihB93zs376uRFull configuration file for frps (Server)Use Docker Compose to Build the frps serviceversion: '3' services: frps: image: snowdreamtech/frps:latest container_name: frps network_mode: host restart: always volumes: - ./frps.ini:/etc/frp/frps.ini - ./tmp:/tmp:rwAfter modification, the following tree structure is displayed.├── docker-compose.yml├── frps.ini└── tmp (folder)Create and start frps containerdocker-compose up -dParameterDescriptionupCreate and start containers--detach , -dDetached mode: Run containers in the backgroundOpen ports in firewall (option)Ubuntu Firewall:sudo ufw allow 7000/tcpCentOS Firewall:sudo firewall-cmd --permanent --add-port=7000/tcpClient configurationCreate a frpc.ini configuration file on Server[common] server_addr = 12.34.56.78 server_port = 7000 token = yM1nDMBFihB93zs376uR [web01] type = http local_ip = 127.0.0.1 local_port = 80 custom_domains = web01.yourdomain.comParameterDescriptionserver_addr12.34.56.78 means the Public IP of frpsserver_portsame as server bind_porttokensame as server authentication token[web01]Local service nametypewhich type of service select (e.g. HTTP)local_ip127.0.0.1 means localhostlocal_portLocal service port (e.g. 80)custom_domainsComplete domain name for user to access via Internet==For HTTP/HTTPS services, DNS management is required.==Full configuration file for frpc (Client)Use Docker Compose to Build the frpc serviceversion: '3' services: frpc: image: snowdreamtech/frpc container_name: frpc network_mode: host restart: always volumes: - ./frpc.ini:/etc/frp/frpc.iniAfter modification, the following tree structure is displayed.├── docker-compose.yml├── frpc.iniCreate and start frpc containerdocker-compose up -dVerify whether the container service is successfully starteddocker-composeCheck the log outputdocker-compose logs -f --tail="all"Conclusion:Here it is, congratulations, you have basically succeeded. but frp have many functions and features let us discovery.e.g. TCP connection, Forward DNS query requests, Forward Unix Domain Socket, Expose your service privately, P2P Mode, etc.Reference:GitHub - fatedier/frp: A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.snowdreamtech/frpc - Docker Image | Docker HubRelated:Let NPM and FRP share 80/443 ports with Wildcard Domain Name Automatically deploy FRP server and client services using Docker
Let NPM and FRP share 80/443 ports with Wildcard Domain Name
2023-03-06_165215.pngPreface:Let NPM (Nginx Proxy Manager) and FRP (Fast Reverse Proxy) share 80/443 ports with wildcard domain nameConfiguration:frps.ini configsince NPM occupies port 80/443, and then in frps.ini please replace with a different port. such as: 1080/1443[common] bind_addr = 0.0.0.0 bind_port = 17000 vhost_http_port = 1080 vhost_https_port = 1443 # dashboard TLS mode dashboard_tls_mode = false authentication_method = token authenticate_heartbeats = false authenticate_new_work_conns = false token = yM1nDMBFihB93zs376uR # pool_count in each proxy will change to max_pool_count if they exceed the maximum value max_pool_count = 5 # max ports can be used for each client, default value is 0 means no limit max_ports_per_client = 0 # tls_only specifies whether to only accept TLS-encrypted connections. By default, the value is false. tls_only = false # if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file subdomain_host = kingtam.win # Enable golang pprof handlers in dashboard listener. # Dashboard port must be set first pprof_enable = false frpc.ini configIf Wildcard Domain Name is configured, then the Domain Name parameter in Fill in only the second-level domain name header. e.g. subdomain = navi[common] server_addr = frps.kingtam.win server_port = 17000 token = yM1nDMBFihB93zs376uR pool_count = 5 tcp_mux = true user = OneCloud login_fail_exit = false protocol = tcp tls_enable = true [navi] type = http subdomain = navi local_ip = 127.0.0.1 local_port = 5005Moreover, If Wildcard Domain Name is not configured, then the Domain Name parameter in Requires a complete domain name. e.g. custom_domains = navi.kingtam.win instead of subdomain = naviDNS management for Wildcard Domain Name (kingtam.win)image-20230307120041855.pngNPM configNPM reverse FRPS port 1080 to HTTPS with wildcard domain (*.kingtam.win)image-20230306164838962.pngimage-20230306164323507.pngproxy_pass http://127.0.0.1:1080; , written as .HTTP Never HTTPS , and the port 1080 is refer from frps.ini vhost_http_port = 1080proxy_set_header Host $host:80; Note that port 80 needs to be added, causing the web page to fail to open and prompting too many redirects ERR_TOO_MANY_REDIRECTS. location / { proxy_pass http://127.0.0.1:1080; proxy_redirect off; proxy_set_header Host $host:80; proxy_ssl_server_name on; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; }Result:After each configuration is completed, the result is as shown on the screen.image-20230306164133340.pngReference:GitHub - fatedier/frp: A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.https://nginxproxymanager.com/Configure NGINX and FRPS coexistence 80/443 ports and wildcard domain name support tutorial - Siyoucloud - IOIOXRelated:Use Docker to Deploy FRP ServicesAutomatically deploy FRP server and client services using Docker
入坑IMTNAS星際魔盒2 - MCS7配置免費內網穿透frp[shadow]MCS7_frp_01.png[/shadow]簡言:在IPV4地址短缺的情況之下，不是每個家庭都分配到公網的IPV4地址。如要訪問家中的設備就變得不方便，坊間有五花八門方法可以實現訪問家中設備，如TeamViewer、 Zero-Tier、 花生殼 等等， 但因為每地區的網絡環境不同，體驗也不一樣。 這裡我推薦frp實現家中設備在內網穿透到網外。為什麼是frp:frp 是一個高性能的反向代理應用，可以幫助您輕鬆地進行內網穿透，對外網提供服務，支持 tcp, http, https 等協議類型，並且 web 服務支持根據域名進行路由轉發。MCS7_frp_02.png配置前準備:申請域名1個, 無論是付費還是免費的(如果沒有, 可以購買一個也很便宜)DNSPod 域名MCS7_frp_03.pngMCS7_frp_04.png華為雲 域名MCS7_frp_05.png以CloudFlare設定為例:我的域名是: kingsir.ga想新增一個別名稱為imtnas給魔盒做訪問MCS7_frp_06.png[tip]選取: DNS記錄類型為: CNAME名稱: imtnas 目標: free.frp.ioiox.com[/tip]目標: free.frp.ioiox.com 是免費的frp服務器MCS7_frp_07.png等片刻，PING一下，兩個地址是否一樣.安裝frpc(即frpc客戶端):首先SSH登陸星際魔盒及獲得root權限MCS7_frp_08.png用戶名: admin密碼: adminsudo -iMCS7_frp_09.png下載及安裝frp客戶端(ARMV7):FRP_VERSION="0.36.2" && wget https://github.com/fatedier/frp/releases/download/v${FRP_VERSION}/frp_${FRP_VERSION}_linux_arm.tar.gz && tar -zxvf frp_${FRP_VERSION}_linux_arm.tar.gz && mv frp_${FRP_VERSION}_linux_arm/frpc /usr/local/bin && rm frp_${FRP_VERSION}_linux_arm.tar.gz && rm -rf frp_${FRP_VERSION}_linux_arm建立一個空白的資料夾 (存放frpc 配置文件):mkdir -p /etc/frpMCS7_frp_10.png創建frpc 配置文件:cat >> /etc/frp/frpc.ini << EOF [common] server_addr = free.frp.ioiox.com server_port = 7007 token = www.ioiox.com admin_addr = 10.10.1.51 admin_port = 7400 admin_user = admin admin_pwd = admin [imtnas] type = http local_ip = 10.10.1.51 local_port = 8060 custom_domains = imtnas.kingsir.ga EOF配置文件說明:admin_addr = 10.10.1.51 # 坊問Dashboard的地址 (即魔盒IP)admin_port = 7400 # Dashboard端口admin_user = admin # Dashboard用戶名admin_pwd = admin # Dashboard密碼[imtnas] # 服務名稱(多個服務不能重名)type = http # http協議local_ip = 10.10.1.51 # 需穿透的設備內網IP(我的魔盒是10.10.1.51)local_port = 8060 # 8060是導航頁面的端口custom_domains = imtnas.kingsir.ga # 填寫你登記的域名增設frpc為系統服務:系統服務可以做到 啟動/停止/重新啟動/查看狀態 的功能.創建frpc的守護進程文件:(在ssh內貼上, enter)cat >> /etc/init.d/frpc << EOF #!/bin/sh ### BEGIN INIT INFO # Provides: frpc # Required-Start: $local_fs $network # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: frpc service deamon # Description: frpc service daemon ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/bin/frpc DAEMON_OPTS=-c\ /etc/frp/frpc.ini NAME=frpc USER=root set -e . /lib/lsb/init-functions start() { echo -n "Starting $NAME: " start-stop-daemon --start \ --user $USER \ -m --pidfile /var/run/$NAME.pid \ -b --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." } stop() { echo -n "Stopping $NAME: " start-stop-daemon --stop \ --pidfile /var/run/$NAME.pid || true echo "$NAME." } status() { status_of_proc -p /var/run/$NAME.pid "$DAEMON" $NAME && exit 0 || exit $? } case "$1" in start) start ;; stop) stop ;; status) status ;; restart) stop sleep 2 start ;; *) echo "Usage: $NAME {start|stop|restart|status}" exit 1 ;; esac exit 0 EOF增加可執行權限:chmod +x /etc/init.d/frpc啟動frpc/etc/init.d/frpc start重新啟動frpc/etc/init.d/frpc restart狀態觀察:/etc/init.d/frpc status現在可以透過域名地址瀏覽導航頁面MCS7_frp_11.png添加開機啟動frpc進程:sed -i -e ''/# By default this script does nothing./a\/etc/init.d/frpc start' /etc/rc.local在MCS7使用"update-rc.d frpc defaults"這命令不能新增開機啟動，如有解決方法請告知. 謝謝!frp Dashboard通過瀏覽器查看 frp 的狀態以及編輯 frpc.ini 中內容如新增穿透設備， 更新域名等MCS7_frp_12.png打開瀏覽器通過 http://魔盒IP:7400 訪問 dashboard 界面。 舉個例子:我想新增FileBrowser服務到網外訪問以CloudFlare設定為例:我的域名是: kingsir.ga 想新增一個名稱為files的別名 訪問FileBrowser服務MCS7_frp_13.png[tip]選取: DNS記錄類型為: CNAME名稱: files目標: free.frp.ioiox.com[/tip]目標: free.frp.ioiox.com 是免費的frp服務器MCS7_frp_14.png打開瀏覽器通過 http://魔盒IP:7400 訪問 dashboard 界面。應用IP地址端口子目錄Frp(Dashboard)魔盒IP7400 MCS7_frp_15.png加入這段內容:[filebrowser]type = httplocal_ip = 10.10.1.51local_port = 8080custom_domains = files.kingsir.gaMCS7_frp_16.pngMCS7_frp_17.pngMCS7_frp_18.png通過瀏覽器 http://files.kingsir.ga 訪問 FileBrowser服務結語: 本人使用frp已經2年，十分穩定，可以在複雜的網路環境中做穿透(如公司大內網), 而且功能非常豐富。 雖然設定上有少許煩瑣，但是配置成功，就能一勞永逸。frp客戶端的連線速度更多時候取決與frp伺服務器的帶寬，如果長期有大文件操作還是建議自行架設frp伺服務器使用。參考資料:frp原作者 : fatedierhttps://github.com/fatedier/frp開機啟動和後台運行https://github.com/fatedier/frp/issues/176免費提供frp服務器(IOIOX):https://www.ioiox.com/frp.html另一免費內網穿透服務Sakura Frphttps://www.natfrp.com/