Automatically deploy FRP server and client services using Docker
It 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 content |
Part1, 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"
}
The 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 following
if ! 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
fi
It 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
fi
Then 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"
fi
It 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.
Part3, FRP Client service deploy |
function handle_option_2 {
}
This part sets up the FRP client service as a function.
include the following
if ! 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
fi
It 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
fi
Then 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
fi
It 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.
Part4, 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"
;;
esac
The 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.sh
This 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: |
Good day I am so glad I found your web site, I really found you by mistake,
while I was researching on Bing for something else, Anyhow I am
here now and would just like to say many thanks for a remarkable post and a all round interesting blog (I also love the theme/design), I don’t have time to read it all at the moment
but I have saved it and also added in your RSS feeds, so when I have time I will be back to
read a great deal more, Please do keep up the awesome jo.
casino en ligne France
Oh my goodness! Incredible article dude! Thank you
so much, However I am encountering issues with your RSS. I don't understand why I am unable to join it.
Is there anybody else getting similar RSS problems? Anyone that knows the answer will
you kindly respond? Thanx!!
site
Hello, this weekend is fastidious in support of me, since this moment i am reading this
impressive informative piece of writing here at my residence.
casino en ligne France
I need to to thank you for this wonderful read!! I absolutely enjoyed every bit of
it. I've got you book marked to look at new stuff you post…
webpage
This info is priceless. How can I find out more?
casino en ligne fiable
I blog often and I seriously thank you for your information. The article
has truly peaked my interest. I'm going to book mark your
website and keep checking for new information about once a week.
I opted in for your Feed too.
website
I every time used to study paragraph in news papers but now as
I am a user of internet thus from now I am using net for articles or reviews, thanks to web.
casino en ligne
If you want to increase your experience only keep visiting this site and be updated with
the most recent information posted here.
web page
Attractive section of content. I just stumbled upon your website and in accession capital to
assert that I get in fact enjoyed account your blog
posts. Anyway I'll be subscribing to your feeds and even I achievement you access
consistently rapidly.
site
I have been exploring for a bit for any high-quality articles or weblog posts in this sort of
house . Exploring in Yahoo I finally stumbled upon this web site.
Studying this information So i'm satisfied to exhibit that I have a very good uncanny feeling I discovered exactly what I needed.
I so much undoubtedly will make certain to don?t forget this site and give it a
look on a constant basis.
casino en ligne francais
I just like the helpful information you supply for your articles.
I'll bookmark your blog and take a look at once more here frequently.
I am rather certain I'll be told many new stuff right
right here! Best of luck for the following!
website
I'm curious to find out what blog system you are
using? I'm having some small security issues with my
latest blog and I'd like to find something more secure.
Do you have any recommendations?
casino en ligne
I am extremely inspired with your writing skills as neatly as with the structure for your weblog.
Is this a paid theme or did you modify it yourself?
Anyway stay up the nice high quality writing, it's rare to
see a great weblog like this one these days..
web page
Hi, I do think this is an excellent blog. I stumbledupon it ;) I may return once again since I book
marked it. Money and freedom is the best way to change, may you
be rich and continue to help other people.
casino en ligne fiable
Hi, I would like to subscribe for this webpage to get latest updates, therefore where can i do it please help out.
casino en ligne
I visited multiple sites except the audio feature for audio songs present at this web page is genuinely fabulous.
website
This site certainly has all of the info I wanted concerning this subject and didn't know who to ask.
casino en ligne France
Very rapidly this web site will be famous amid all blogging users, due to it's fastidious articles or reviews
casino en ligne
What's up, every time i used to check weblog
posts here in the early hours in the dawn, for the reason that i like to find out more and more.
site
Great blog! Do you have any hints for aspiring writers? I'm planning to start my own website soon but I'm a
little lost on everything. Would you suggest starting with a free platform like Wordpress or go for a paid option? There are so many choices out
there that I'm totally confused .. Any ideas? Thanks a lot!
casino en ligne France
Le comparateur Inventonslemondedapres : votre raccourci vers les casinos en ligne les plus généreux et transparents du marché.