1 Reference Link:

www.bilibili.com/video/BV1MW… Blog.csdn.net/daiqi552715…

2 Domain Name Resolution

3 Go Environment Construction

3.1 Reference Address:

docs.studygolang.com/doc/install

  • Download and unzip the Go file
Sudo -i CD/usr/local/wget https://studygolang.com/dl/golang/go1.16.4.src.tar.gz tar - xf go1.16.4. SRC. Tar. Gz ln -s /usr/local/go/bin/* /usr/bin/Copy the code
  • Set the environment variables and edit the /etc/profile file
export GOROOT=/usr/local/go

export PATH=$PATH:$GOROOT/bin

Copy the code
  • Run the following command to make the environment variables take effect
source /etc/profile
Copy the code
  • After the installation is complete, execute the following commands to check
go version

go env
Copy the code

4 installed Ngrok

  • Download the ngrok source package with Git
cd /usr/local

git clone https://github.com/inconshreveable/ngrok.git

Copy the code
  • Configure the environment variables for ngrok
export GOPATH=/usr/local/ngrok/

export NGROK_DOMAIN="ngrok.xxxx.com"

Copy the code
  • The ngrok certificate is generated
cd /usr/local/ngrok

openssl genrsa -out rootCA.key 2048 

openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=$NGROK_DOMAIN" -days 5000 -out rootCA.pem  

openssl genrsa -out server.key 2048 

openssl req -new -key server.key -subj "/CN=$NGROK_DOMAIN" -out server.csr

openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000

Copy the code
  • Cover nGROk source installation package original certificate
cp rootCA.pem assets/client/tls/ngrokroot.crt

cp server.crt assets/server/tls/snakeoil.crt

cp server.key assets/server/tls/snakeoil.key

Copy the code

5 Generate the server

cd /usr/local/ngrok

GOOS=linux GOARCH=amd64 make release-server

Copy the code

After execution, the ngrokd file will be found under /usr/local/ngrok/bin

5.1 Commands executed during server software generation vary according to the system type

System type digits An instruction to
Linux 32 GOOS=linux GOARCH=386 make release-server
Linux 64 GOOS=linux GOARCH=amd64 make release-server
Windows 32 GOOS=windows GOARCH=386 make release-server
Windows 64 GOOS=windows GOARCH=amd64 make release-server
Mac 32 GOOS=darwin GOARCH=386 make release-server
Mac 64 GOOS=darwin GOARCH=amd64 make release-server
ARM There is no limit GOOS=linux GOARCH=arm make release-server

6 Generate a client

GOOS=linux GOARCH=amd64 make release-client
Copy the code

After execution, the ngrok file will be found under /usr/local/ngrok/bin

6.1 Commands executed during client software generation vary according to the system type

System type digits An instruction to
Linux 32 GOOS=linux GOARCH=386 make release-client
Linux 64 GOOS=linux GOARCH=amd64 make release-client
Windows 32 GOOS=windows GOARCH=386 make release-client
Windows 64 GOOS=windows GOARCH=amd64 make release-client
Mac 32 GOOS=darwin GOARCH=386 make release-client
Mac 64 GOOS=darwin GOARCH=amd64 make release-client
ARM There is no limit GOOS=linux GOARCH=arm make release-client

7 The server is started

/usr/local/ngrok: /usr/local/ngrok: /usr/local/ngrok: /usr/local/ngrok /bin/ngrokd -tlskey =server.key -tlscrt =server. CRT -domain="ngrok.xx.com" -httpaddr =":8080" -httpsaddr =":4433" -tunnelAddr=":4443" # nohup starts nohup./bin/ngrokd -tlskey =server.key -tlscrt =server.crt -domain="ngrok.xx.com" -httpAddr=":8080" -httpsAddr=":4433" -tunnelAddr=":4443" &Copy the code

7.1 Enable automatic startup upon startup

vim /etc/rc.d/init.d/ngrok
Copy the code
  • Enter the following information:
#! /bin/bash #chkconfig: - 99 01 #description:ngrok case "$1" in start) echo "start ngrok service.." cd /usr/local/ngrok/ setsid ./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt -domain="ngrok.xxxx.com" -httpAddr=":8080" -httpsAddr=":4433" -tunnelAddr=":4443" ;; *) exit 1 ;; ### CD /usr/local/ngrok/ /bin/ngrokd -tlskey =server.key -tlscrt =server.crt -domain="abc.club" -httpaddr =":80" -httpsaddr =":443" -tunnelAddr=":4443" : Start the ngrok server commandCopy the code
  • Give permission to the configuration file
chmod 755 ngrok
Copy the code
  • Register as a system service
chkconfig --add ngrok
Copy the code
  • Start the
service ngrok start
Copy the code
  • Added the boot option
Systemctl enable ngrok.service // Add the systemctl daemon-reload // reload the configuration fileCopy the code

8 Deploy clients in Linux

  • Log in as the root user, create the ngrok folder, and then pass in the files via FTP
cd /root

mkdir ngrok
Copy the code

Files in Baidu network disk:

Link: https://pan.baidu.com/s/1NS74SZGnX7EXFb49KglTSg

Extraction code: AN98