The fruit of revolution is sweetest
The laboring people are the most glorious
The software requirements
- Git
- Go
- ntp
Instructions:
The domain name must be a second-level domain name
The level-1 domain name is baidu.com
The secondary domain name is XXX.baidu.com. Do not use the occupied secondary domain name
The proposal reanalyzes one, anyway does not spend money right
Otherwise there will be some inexplicable error
: (
The following primary domain names are secondary domain names: test.baidu.com
The secondary domain name is ngrok.test.baidu.com
PS: This description is not accurate, please refer to last
Remember to turn off the firewall. If you forget, you’ll get sick
Specifies the relationship between the server domain name and the client domain name
Environment:
- The server is in Ali cloud, the system version of Ali cloud is CentOS 7 AMD64
- The client is many-to-many, with centos, Windows, Raspberry Pi, and almost all Linux, Windows, and ARM platforms
- Use raspberry PI for the time being
Start configuration:
Git installation (not detailed)
➜ ngrok git:(master) qualify yum install mercurial git GCC golang NTPCopy the code
NTP is used for time synchronization
Both server and client are required, otherwise there will be nasty errors
➜ ngrok git:(master) qualify ntpdate cn.pool.ntp.orgCopy the code
To clone ngrok
Since the 2.x version seems to be no longer open source, we use 1.7, which is not official git but is better XD than the official version
Thanks to the open source community, long live open source!
➜ ngrok git:(master) qualify gitclone https://github.com/tutumcloud/ngrok.git ngrokCopy the code
Clone configuration is complete
✗ ➜ ngrok git: (master)export NGROK_DOMAIN="Master domain name"✗ ➜ ngrok git: (master)cd ngrok Copy the code
Generate certificate after entering directory (you copy is done)
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 5000Copy the code
Copy the certificate to the specified location (you are done copying)
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.keyCopy the code
Start compiling the ngrok server
Here I mainly generate arm and Linux versions. Continue in the original directory:
# Default is Linux 64-bit, same as me
# My client is Raspberry PI➜ ngrok git:(master) qualify make releight-server ➜ ngrok git:(master) qualify GOOS= Linux GOARCH=arm make releight-client# Linux + Win + MAC + ARM configuration
#GOOS=linux GOARCH=amd64 make release-client release-server
#GOOS=windows GOARCH=amd64 make release-client release-server
#GOOS=darwin GOARCH=amd64 make release-client release-server
#GOOS=linux GOARCH=arm make release-client release-serverCopy the code
Different platforms use different versions of GOOS and GOARCH. The previous compilation options refer to Go OS, the operating system compiled by Go (Windows, Linux, Darwin). Go Arch, corresponding architecture (386, AMD64, ARM)
- Linux platform 32-bit system: GOOS= Linux GOARCH=386
-
Linux platform 64-bit system: GOOS= Linux GOARCH= AMd64
- Windows 32-bit system: GOOS= Windows GOARCH=386
-
Windows platform 64-bit system: GOOS= Windows GOARCH= AMd64
- MAC platform 32-bit system: GOOS= Darwin GOARCH=386
-
MAC platform 64-bit systems: GOOS= Darwin GOARCH= AMd64
- GOOS= Linux GOARCH= ARM
Ngrokd and ngrok files are generated in ngrok/bin. The former is a server program, and the latter is a client program.
The generated executable files may be in different folders depending on the version. For example, raspberry PI client is in Linux_ARM
Upload the generated client to the corresponding server
Options:
- FTP
- lyzsz
FTP needs to be setup
Recommend lyzsz
Use Git when you can’t
Needless to
Configuring the client
- Create folder ngrok
- chmod 777
- Import the client
- New file ngrok.cfg(contents as follows)
Server_addr: Domain name :4443 trust_host_root_certs:falseCopy the code
Starting the server
Server operations are in the ngrok directory➜ ngrok git:(master) qualify./bin/ ngrokd-tlskey =server.key -tlsCrt=server.crt -domain="Master domain name" -httpAddr=": 8081" httpsAddr=": 8082"Copy the code
- HttpAddr is the port number used to access normal HTTP, followed by the secondary domain name :8081 to access the service
- HttpsAddr is the port number used to access HTTPS, same as above, except that HTTPS services need to access this port
- TunnelAddr is the channel port number. This port is used by Ngrok to communicate, so this port must be set on the server and the client to be connected properly. By default, it is left blank, like 4443
# Indicates that the server is successfully started➜ ngrok git:(master) qualify./bin/ ngrokd-tlskey =server.key -tlsCrt=server.crt -domain="Master domain name" -httpAddr=": 8081" httpsAddr=": 8082"
[19:43:13 CST 2018/09/04] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [registry] [tun] No affinity cache specified
[19:43:13 CST 2018/09/04] [INFO] (ngrok/log.Info:112) Listening for public http connections on [::]:8081
[19:43:13 CST 2018/09/04] [INFO] (ngrok/log.Info:112) Listening for public https connections on [::]:443
[19:43:13 CST 2018/09/04] [INFO] (ngrok/log.Info:112) Listening for control and proxy connections on [::]:4443
[19:43:13 CST 2018/09/04] [INFO] (ngrok/log.(*PrefixLogger).Info:83) [metrics] Reporting every 30 secondsCopy the code
Start the client
#linux➜ ngrok git:(master) Qualify./ ngrok-config. /ngrok.cfg -subdomain subdomain prefix (e.g. Ngrok) -proto HTTP 80#windowsNgrok. exe -subdomain= subdomain name prefix (for example, ngrok) -config=ngrok.cfg 80Copy the code
This secondary domain name prefix is best to avoid confusing error
Log: -log=ngrok_log. TXT is used to record ngrok logs
The following
➜ ngrok git:(master) Qualify./ ngrok-log =ngrok_log.txt -config./ngrok.cfg -subdomain subdomain prefix (e.g. Ngrok) -proto HTTP 80./ngrokCopy the code
The client is started successfully
If Tunnel Status is online, the link is successful
If there are reconnecting connections
Please do yourself a favor
: (
Secondary Update:
The link is automatically disconnected after you exit the terminal
Then looked for background running process information
Results are as follows
Server:
➜ ngrok git:(master) qualify nohup./bin/ ngrokd-tlskey =server.key -tlsCrt=server.crt -domain="Master domain name" -httpAddr=": 8081" httpsAddr=": 8082"& [1] 1784nohUp: Ignores input and appends output to"nohup.out"
Use tail to view log output➜ ngrok git:(master) qualify tail-f nohup.out
#1784 is the process ID➜ ngrok git: (master) ✗ ps aux | grep ngrokEnd the process using kill✗ ➜ ngrok git: (master)kill1784-9Copy the code
Client:
➜ ngrok git:(master) qualify setsid. / ngrok-log =ngrok_log.txt - config. /ngrok.cfg -subdomain ngrok-proto HTTP 80 ➜ ngrok Git: (master) ✗ ps aux | grep ngrok ➜ ngrok git: (master) ✗ kil - 9, 1744Copy the code
This keeps the server running smoothly even if the server is not connected
This paper focuses on the relationship between server domain name and client domain name
Set the domain name to baidu.com➜ ngrok git:(master) qualify nohup./bin/ ngrokd-tlskey =server.key -tlsCrt=server.crt -domain="Domain name" -httpAddr=": 8081" httpsAddr=": 8082" &
# client subdomain hostname is ngrok➜ ngrok git:(master) qualify setsid./ ngrok-log =ngrok_log.txt -config./ngrok.cfg -subdomain ngrok -proto HTTP 80The domain name is ngrok.baidu.com
-----------------------------------------------------
# If the server domain name is set to test.baidu.com➜ ngrok git:(master) qualify nohup./bin/ ngrokd-tlskey =server.key -tlsCrt=server.crt -domain="Domain name" -httpAddr=": 8081" httpsAddr=": 8082" &
# client subdomain hostname is ngrok➜ ngrok git:(master) qualify setsid./ ngrok-log =ngrok_log.txt -config./ngrok.cfg -subdomain ngrok -proto HTTP 80The domain name is ngrok.test.baidu.com
## Note whether ngrok.baidu.com or ngrok.test.baidu.com
The final domain name must be resolved in the domain name provider!!
Copy the code