Ngrok Server Erection Process

Source: Internet
Author: User
Tags install go subdomain
This is a creation in Article, where the information may have evolved or changed.

Need to install GO environment first
Setting environment variables
12345 # You can adjust the path according to your needs echo ' export Goroot=/usr/local/go ' >>/etc/profileecho ' export path= $PATH: $GOROOT/bin ' >& Gt /etc/profileecho ' export gopath= $HOME/go ' >>/etc/profileecho ' export goroot_bootstrap=/usr/local/go ' >>/ Etc/profile
Download Source Installation
Since the Yum install Go version is 1.4, the latter may be a bit problematic, so here is the source of the installation (the latest version of 2016.03.31 is 1.6) way
123 CD ~/your_download_dirwget Https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gztar-C/USR/LOCAL-XZF Go1.6.linux-amd64.tar.gz
To see if the installation was successful
Go version# Normal will return a message like this: Go version go1.6 linux/amd64
Ngrok Installation
git version
If your git version is >=1.7.9.5, you can skip the git version directly, and if not, you'll need to upgrade it first.
I am on a server version is 1.7.1, during the Ngrok installation process, will always be stuck in a download of something, I am stuck here
1 gopkg.in/inconshreveable/go-update.v0 (download)
It's a good idea to start some git-dependent installations
1 yum-y Install Zlib-devel openssl-devel perl HG cpio expat-devel Gettext-devel Curl curl-devel perl-extutils-makemaker H G wget GCC gcc-c++
Then upgrade the GIT version by first installing the third FountainVest Partners (Rpmfore) and then using that source for git updates.
There is no longer a detailed description of Git upgrade, in general can be done according to this tutorial;
The only difference is that because priorities is enabled, it is always looking for base repo instead of rpmforge repo when Git is last updated, so base,updates such as repo will need to be disabled when updating (refer to this article), as follows:
1 yum--disablerepo=base,updates--enablerepo=rpmforge-extras update git
Download Ngrok Source code
123 CD ~/your_download_dirgit clone Https://github.com/inconshreveable/ngrok.git ngrokcd Ngrok
Generate certificate
Notice there is a ngrok_base_domain;
Assuming that the address you want to provide is aevit.your-domain.com, the Ngrok_base_domain is set to your-domain.com;
Assuming that the address you want to provide is aevit.ngrok.your-domain.com, the Ngrok_base_domain is set to ngrok.your-domain.com;
Let's take ngrok.your-domain.com as an example:
12345 OpenSSL genrsa-out rootca.key 2048openssl req-x509-new-nodes-key rootca.key-subj "/cn=ngrok.your-domain.com"- Days 5000-out rootca.pemopenssl genrsa-out device.key 2048openssl req-new-key device.key-subj "/cn=ngrok.your-domain. com "-out device.csropenssl x509-req-in device.csr-ca rootca.pem-cakey rootca.key-cacreateserial-out device.crt-day S 5000
After executing the above command, it will be reborn into 6 files in the Ngrok directory.
123456 DEVICE.CRTDEVICE.CSRDEVICE.KEYROOTCA.KEYROOTCA.PEMROOTCA.SRL
Ngrok Package The Assets directory (resource file) in the Ngrok source directory into the executable (NGROKD and Ngrok) via Bindata, Assets/client/tls and Assets/server/tls The default certificate files for Ngrok and NGROKD are stored separately, and we need to replace them with our own generated: (so this step must be placed before compiling the executable file)
123 cp Rootca.pem assets/client/tls/ngrokroot.crtcp device.crt assets/server/tls/snakeoil.crtcp device.key assets/ Server/tls/snakeoil.key
Compiling NGROKD and Ngrok
Compiling Linux-side versions
1234 Make clean# if it is a 32-bit system, here Goarch=386goos=linux goarch=amd64 make Release-server release-client
Finally, a bin folder will be generated in the current directory containing the NGROKD and Ngrok files;
Where the Bin/ngrokd file is a service-side program;
The Bin/ngrok file is a client program (note that the GOOS is 64-bit Linux, so this file cannot be run on Mac or other platforms such as win, and the following will explain how to cross-compile)
Compiling the Mac-side version
1234 CD ~/your_download_dir/ngrok# If it is a win-side version, goos=windows; if it is a 32-bit system, Goarch=386goos=darwin GOARCH=AMD64 make Release-client
If you succeed, you will have a file under./bin/darwin_amd64/to download this file to your Mac.
12 # If the server is not installed SZ program, please install (yum-y install lrzsz), or use other methods to download to the native sz./bin/darwin_amd64/ngrok
Set up Domain name resolution
1234567 # If the final desired Ngrok address is: example.your-domain.com, setrecords point to Server ip# if the Ngrok address that you want to end up with is: example.ngrok.your-domain.com, set. Ngrok records point to server ip# or do not want to pan-parse, manually add, such as set example record point to server Ip,example.ngrok record point to server IP
How to use
Service side
Nginx Port Forwarding
Since the 80 port of the machine is already occupied, it is necessary to use Nginx for port forwarding, with the following configuration:
12 # According to your Nginx installation path, adjust the following command automatically vim/usr/local/nginx/conf/vhost/nginx.your-domain.com.conf
The contents are as follows:
123456789101112131415161718 upstream Ngrok {server 127.0.0.1:8777; # Here the port is the same as the port specified when the server is started Ngrok 64;} server {listen; server_name *.ngrok.your-domain.com; access_log/data/wwwlogs/ngrok.your-domain.com_access.log; Error_log/data/wwwlogs/ngrok.your-domain.com_error.log; Location/{Proxy_set_header x-real-ip $remote _addr; proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; Proxy_set_header Host $http _host:8777; # This port must be the same as the port specified when starting the server Ngrok Proxy_set_header x-nginx-proxy true; Proxy_set_header Connection ""; Proxy_pass Http://ngrok; }}
Re-start Nginx
Nginx-tnginx-s Reload
Start the service-side Ngrok
1234567891011 # DOMAIN Fill in just generated the certificate ngrok_base_domain# http and HTTPS port can be specified, here does not use 80 port, because the other program is already occupied, port forwarding on the above Nginx has been configured to complete Bin/ngrokd-domain= "ngrok.your-domain.com"-httpaddr= ": 8777"-httpsaddr= ": 8778" # If you want to start the background, execute the following command Nohup BIN/NGROKD- Domain= "ngrok.your-domain.com"-httpaddr= ": 8777"-httpsaddr= ": 8778" >/dev/null 2>&1 If you want to boot, Execute the following command vim/etc/rc.d/rc.local# add the following, the specific content please adjust the {your-ngrok-dir}/bin/ngrokd-domain= "ngrok.your-domain.com" according to your own situation- Httpaddr= ": 8777"-httpsaddr= ": 8778" >/var/log/ngrok.log &
Client
Make sure that the Mac version Ngrok you just downloaded has execute permissions
1 chmod +x Ngrok
Under the sibling directory of the Ngrok program, write the configuration file
1 Vim ngrok.cfg
The contents are as follows:
12345678910111213141516171819202122232425262728 server_addr: "ngrok.your-domain.com:4443" Trust_host_root_certs: Falsetunnels:example:subdomain: "Example" #定义服务器分配域名前缀 proto:http:80 #映射端口, do not add ip default native https:80 web:subdomain: "Web" #定 The semantic server assigns the domain name prefix proto:http:192.168.1.100:80 #映射端口, can add the IP for the intranet any one mapping https:192.168.1.100:80 web1:hostname: " Ngrok.your-domain.com "proto:http:80 web2:hostname:" your-domain.com "proto:http:80 ssh:remote_port:50001 #服务器分配tcp The forwarding port, if not filled out, is assigned by the server proto:tcp:22 #映射本地的22端口 ssh1: #将由服务器分配端口 proto:tcp:21
Start Ngrok
123456789./ngrok-subdomain example-config=ngrok.cfg 80# or./ngrok-config ngrok.cfg start example# If there is a problem connecting, you want to view the log locally , you can add the log parameter #./ngrok-log ngrok.log-config ngrok.cfg Start example# finally ifTunnel StatusShowonlineIt means success.
Commissioning of the public number locally
Next, the public number can be developed locally, as long as the local nginx (server_name to correspond with the above, such as the above example.ngrok.your-domain.com)
Because only 80 ports are allowed, be sure to make the above Nginx port forwarding settings.
In addition, the Ngrok itself provides 127.0.0.1:4040 this address, you can see all the HTTP packet contents (in PHP file Var_dump can also see things)
Problems encountered
Firewall Issues with Ngrok ports
Because the firewall is turned on on the server, iptables is used, so the above port needs to be added to the whitelist
(Altogether 3, one is the Ngrok own 4443 port, also has the custom 8777http port, 8778https Port)
1 vim/etc/sysconfig/iptables
Add the following content
123-a rh-firewall-1-input-m state-state new-m tcp-p tcp-dport 4443-j accept-a rh-firewall-1-input-m state-state New-m tcp-p tcp-dport 8777-j accept-a rh-firewall-1-input-m state-state new-m tcp-p tcp-dport 8778-j ACCEPT
Restart Iptables
1 Service iptables Restart
Ngrok Cross-compiling
On the server to compile a Mac-side version, said online need to go to the source code, to do GOOS settings:
Cd/usr/local/go/srcgoos=darwin goarch=amd64 cgo_enabled=0./make.bash
But I took another server after the test, do not have to do so, just as mentioned above, in the Ngrok directory to the Mac-side version of the compilation can be.
PS: The following can not be seen, but only some of the problems encountered in the middle of the record
The first time I follow the internet to go to the Go source settings Goos, but will report such a mistake:
123 go./make.bash:eval:line 135:syntax Error near unexpected token (Error:cannot find/root/go1.4/bin/go. Set $GOROOT _bootstrap to a working go tree >= go 1.4. Google, said now that the new go is not written in C, and 1.4 before the C is written, so you need to install 1.4, to compile 1.6, so first installed 1.4, then install 1.6, the steps are as follows: 1234567891011121314151617181920212223242526272829303132333435 echo ' Export goroot=/usr/local/go ' >>/etc/profileecho ' export path= $PATH: $GOROOT/bin ' >>/etc/profileecho ' Export gopath= $HOME/go ' >>/etc/profileecho ' export goroot_bootstrap=/usr/local/go ' >>/etc/ PROFILESOURCE/ETC/PROFILECD ~/your_download_dir# First Download 1.4 of the source code wget https://storage.googleapis.com/golang/ Go1.4.3.linux-amd64.tar.gztar-c/usr/local-xzf go1.4.3.linux-amd64.tar.gz#tar-xzf go1.4.3.linux-amd64.tar.gz#mv. go/usr/local/gocd/usr/local/go/src./all.bash# view version, now is 1.4.3 go version# to change 1.4 of the source directory name to go1.4,go this directory name and so on to 1.6 with mv/usr/ local/go//usr/local/go1.4/vim/etc/profile# The default goroot_bootstrap is: $HOME/go1.4, because I put the /usr/local/go1.4 ', so here you specify the value export GOROOT_BOOTSTRAP=/USR/LOCAL/GO1.4CD ~/your_download_dirwget https:// Storage.googleapis.com/golang/go1.6.linux-amd64.tar.gztar-c/usr/local-xzf go1.6.linux-amd64.tar.gzcd/usr/local/ go/src./all.bash# View version, now 1.6 of Go version
Finally test again to verify that you do not have to install 1.4 and then install 1.6 so troublesome.
Summarize
Although there are some pits in the middle, Google checked the data for several minutes, last night to get more than 2 o'clock in the morning, but finally succeeded, and verified some of the installation process ideas, or quite a sense of accomplishment.
Fortunately, the university has a bit of a toss over Linux, last year to turn the background to use some knowledge, and now the server encountered some basic problems can finally be solved.
So still can not stop the pace of learning ah.
While still young, more toss.

After compiling the server on the Web, this runs
If it's a openwrt system, copy the OpenWrt directly with the WINSCP.
Put NGROKC under/usr/bin to add permissions (chmod +x NGROKC) You can use the Luci interface.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.