CentOS 7 using Ngrok set up within the network through service
Reliance installation
Installation go locale
sudo yum install -y golang
Verify go locale
go env
Install the latest version of git
sudo yum remove git
sudo yum install epel-release
sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sudo yum install git2u
Verify git version
git --version
Installation Ngrok
Download the latest source Ngrok
Ngrok Gtihub Address:
https://github.com/inconshreveable/ngrok/releases
Save Ngrok source
cd /usr/local/
git clone https://github.com/inconshreveable/ngrok.git
Generate a self-signed certificate
Which replaced xxx.com own domain name
cd /usr/local/ngrok/
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj "/CN=xxx.com" -days 5000 -out rootCA.pem
openssl genrsa -out server.key 2048
openssl req -new -key server.key -subj "/CN=xxx.com" -out server.csr
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 5000
After the certificate generation, copy it, overwriting the original certificate Ngrok:
prompted whether to overwrite copy of the source file, to input y
cp rootCA.pem assets/client/tls/ngrokroot.crt
cp server.crt assets/server/tls/snakeoil.crt
cp server.key assets/server/tls/snakeoil.key
Generating the client software
The server runs the compiled software
cd /usr/local/ngrok/
GOOS=linux GOARCH=amd64 make release-server
The software generates directory: / usr / local / ngrok / bin
server software file name: ngrokd
The client software runs compiled:
# 32位linux客户端:
GOOS=linux GOARCH=386 make release-client
# 64位linux客户端:
GOOS=linux GOARCH=amd64 make release-client
#32位windows客户端:
GOOS=windows GOARCH=386 make release-client
#64位windows客户端:
GOOS=windows GOARCH=amd64 make release-client
#32位mac平台客户端:
GOOS=darwin GOARCH=386 make release-client
#64位mac平台客户端:
GOOS=darwin GOARCH=amd64 make release-client
#ARM平台linux客户端:
GOOS=linux GOARCH=arm make release-client
The software generates directory: / usr / local / ngrok / bin /
Linux platform client software file name: ngrok
Windows platform 64-: windows_amd64 / ngrok.exe
mac 64-platform: darwin_amd64 / ngrok
Run Software
Firewall settings
Ngrok permanently open port services
firewall-cmd --add-port=6666/tcp --zone=public --permanent
firewall-cmd --reload
DNS Configuration
You need to parse the configuration:
主机记录 记录值
* 服务器公网 ip
@ 服务器公网 ip
www 服务器公网 ip
Run the server software
The xxx.com replace with your own domain name
Run directly
cd /usr/local/ngrok/bin/
ngrokd -domain="xxx.com" -httpAddr=":8864" -httpsAddr=":8865" -tunnelAddr=":6666" &
Start using certificates
cd /usr/local/ngrok/bin/
ngrokd -domain="xxx.com" -tlsKey="../assets/server/tls/snakeoil.key" -tlsCrt="../assets/server/tls/snakeoil.
Start the client software
Ngrok.yml need to create a profile at the same level software file folder before running client software
server_addr: "xxx.com:6666"
trust_host_root_certs: false
Run cmd in the client directory
client
ngrok.exe -config ngrok.yml -subdomain api 8022
-subdomain: ground behind second-level domain name
8022: Local port mapping
Optimization ngrok service - set boot
First, in the program directory ngrok create a startup script, for example:
start.sh
path=/software/git/ngrok
$path
./bin/ngrokd -tlsKey=server.key -tlsCrt=server.crt
-domain = "your domain" -httpAddr = ": 80" -httpsAddr = ": 8082"
path is the path to the current directory of
the startup script to write a script to start the background behind the project start to write according to their own needs
Second, the program made into a system service ngrok
Create a service project (ngrok) in /etc/rc.d/init.d directory, as follows:
#!/bin/sh
#chkconfig:2345 70 30
#description:ngrok
ngrok_path=/software/git/ngrok
case "$1" in
start)
echo "start ngrok service.."
sh ${ngrok_path}/start.sh
;;
*)
exit 1
;;
esac
Assigned to the file permissions 755
chmod 755 ngrok
Third, since the launch of the service registration ngrok
chkconfig --add ngrok
Test whether the service can start successfully
service ngrok start
Check since the launch of the service
chkconfig