Advanced Applications: Execute nConnect under soft-routing system "OpenWrt"

There are three parts of this paragraph: 1. background introduction; 2. Compile; 3. Run.

I. Background Introduction

1. Why run nConnect in soft routing?

  • There are several advantages to run nConnect server in soft-routing system:
    • First, Through the reverse proxy, you can access all the devices in your home LAN;
    • Second, Soft routing is basically turned on all day, and there is relatively large redundancy in performance, so it is most suitable as a transit station for intranet penetration;
    • Finally, compared with installing nConnect server to NAS or Computers, the path to access terminal equipment through soft route is the shortest. (theoretically)

2. Hardware Environment

  • Soft routing is r2s with good performance;
  • R2S CPU architecture: armv8 processor Rev 4 (v8l) x 4 (1200MHz)

3. System Environment

  • The system I installed in r2s is based on the branch of openmortalwrt-18.06
  • The system lacks compilation environment, so the first step is to install various basic compilation tools.

II. Compile

There are three steps for compilation process: 1. Build the environment; 2. Download the source code; 3 compilation;

1. Build the environment
In fact, it is the process of installing some basic compilation tools. There are two methods:

  • Method 1: only one command: opkg install GCC automake Autoconf libtool make golang
  • Method 2: open the background > system > software package of openwrt, and install the following compilation tools one by one:
    • gcc、automake、autoconf、libtool、make、golang

2. Download Source Code

3. Start compilation

  • Enter the nConnect source code directory
    • cd /nkn/
  • Compile:
    • Method 1: make
    • Method 2,go build
  • When the nconnect file appears in the source directory, it means that the compilation is successful

4. Maybe you will meet this issue:

  • Error while programming: / usr / bin / LD: cannot find - lpthread
  • The solution is to create an empty libpthread and run: ar - RC / usr / lib / libpthread a

III. Run

1, Enter the working directory of nConnect:

  • cd /nkn
  • This step is necessary. If you do not enter the working directory, you will not be able to open the nConnect configuration page later.

2. Run nConnect

  • Run: ./nConnect -s --tuna --admin-http=172.0.0.1:6666
  • The following 6666 is the port address, which can be customized
  • Note: DO NOT use absolute path like: /nkn/nConnect -s --tuna --admin-http=172.0.0.1:6666

3. Aftter Successfully Started

  • Open the address with “router’s IP + port” via the browser to start configuring page of the nConnect server, such as: 192.168.1.1:6666

  • For information on how to configure the server, please refer to the official tutorials of nConnect.

VI. Auto-Start

Some quick tips:

  1. Systemd
  • (d means: daemon, also known as background process)
  • Although it is controversial, basically used in the latest Linux distributions.
  • While checking the version through the command systemctl – version, I found that the openwrt I am currently using does not have: systemd
  • So we need: procd + init.d, for example
  1. Procd (process management daemon)
  • Procd is a process management service in Openwrt. It is a daemon used to monitor the status of system processes and ensure that some processes restart automatically after abnormal exit. It needs to be used in combination with init script.
  1. Initialization Script Management: /etc/init.d/
  • /etc/rc.d/ is the boot directory of the Linux system
  • But all the startup scripts are in /etc/init.d/ , and then the soft link to /etc/rc.d
  1. Common Commands for Managing Services:
  • The result of following two commands are the same:

    • service nConnect + start , stop, restart, reload, status, enable, disable
    • /etc/init.d/nConnect + start , stop, restart, reload, status, enable, disable
  • Three key commands

    • Service nconnect start starts the service
    • Service nconnect stop stop the service
    • Service nconnect enable sets the service to self start

Complete the Settings in Five Steps:

Step 1:

  • Create a startup run script:
    • vi /etc/init.d/nConnect
  • Fill the following code:
#!/bin/sh /etc/rc.common

START=99
USE_PROCD=1

start_service() {
    procd_open_instance nConnect run
    procd_set_param command sh /nkn/sr/run.sh
    procd_set_param respawn                           
    procd_close_instance                              
    echo service nConnect start
}

stop_service() {
    killall nConnect
    echo service nConnect stop
}

restart_service() {
    stop
    start
}

Step 2:

  • Change the permission of the script in order to execute it.
    • chmod -R 777 /etc/init.d/nConnect

Step 3:

  • Create an execution script file: vi /nkn/sr/run.sh
  • Fill the following code:
rm -f /nkn/nkn.log
echo service nConnect start
cd /nkn/sr/
./nConnect -s --tuna --admin-http="192.168.2.1:33333" > /nkn/nkn.log

Step 4:

  • Turn on self start:
    • /etc/init.d/nConnect enable
  • Reboot the system:
    • reboot

Step 5:

  • Verify that self start is turned on

    • Check the startup item in Openwrt background > system > startup item, find nConnect, and check whether it has been set as startup self startup
  • Verify that nConnect auto-started:

    • ps -ef |grep nConnect
  • If it shows
    " ………nConnect -s --tuna --admin-http=“192.168.2.1:33333”
    means the auto-startup is successful.

  • Or you can open nConnect dashboard, which also means the auto-startup is successful.

Accroding to :https://zhuanlan.zhihu.com/p/483308428

1 Like