01 | n2n虚拟局域网
1 n2n简介
为了满足两个不同局域网的机器进行通信,让不同网段的机器能够进行P2P( 点对点 peer-to-peer ) 通信。
2 n2n源码
https://github.com/ntop/n2n.git
3 n2n名词
3.1 SuperNode 超级节点
SuperNode 相当与注册中心, 它会记录边缘节点的连接信息,告诉各个边缘节点如何去找到其它的边缘节点。如果超级节点发生故障,那么边缘节点之间将不能正常的进行通信。在整个N2N网络中必须至少拥有一个SuperNode。
3.2 Edge 边缘节点
边缘节点是指所有通过 SuperNode 组网而成的节点,无论你处于哪个位置哪种网络环境下,edge节点之间都能进行通信。一台计算机可以拥有多个edge, 局域网根据子网掩码来决定两台机器是否处于同一个网段,而edge需要添加一组账号密码,在N2N 里面称作 GroupName 和 password ,Group0 和 Group 1 里面的 10.0.0.1 是不一样的。
4 n2n配置
版本:
Welcome to n2n v.2.8.0 for Debian
4.1 下载n2n
#创建一个 n2n 的目录,用于存放各版本源码
mkdir n2n#进入n2n 目录
cd n2n
#下载 n2n 包
git clone https://github.com/ntop/n2n.git
#进入n2n-3.1.1目录
cd n2n
4.2 安装依赖
# 安装 openssl
yum install -y openssl-devel cmake net-tools gcc gcc-c++
4.3 进行编译
4.3.1 第一步
# 新建 build 目录
cmake -E make_directory build
# 进入 build 目录
cd build
# 在当前目录生成 makefile
cmake ..
# cmake 的执行结果:
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Build for version: 3.1.1-76-g709590d
-- Configuring done
-- Generating done
-- Build files have been written to: /home/n2n/n2n/build
4.3.2 第二步
# 编译过程中会有一些告警提示,可以忽略
cmake --build . --config Release
#编译过程
/usr/bin/cmake -H/home/n2n/n2n -B/home/n2n/n2n/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/n2n/n2n/build/CMakeFiles /home/n2n/n2n/build/CMakeFiles/progress.marks
/usr/bin/gmake -f CMakeFiles/Makefile2 all
gmake[1]: Entering directory `/home/n2n/n2n/build'
/usr/bin/gmake -f CMakeFiles/doc.dir/build.make CMakeFiles/doc.dir/depend
gmake[2]: Entering directory `/home/n2n/n2n/build'
....................
gmake[2]: Leaving directory `/home/n2n/n2n/build'
/usr/bin/cmake -E cmake_progress_report /home/n2n/n2n/build/CMakeFiles 52
[100%] Built target tests-wire
gmake[1]: Leaving directory `/home/n2n/n2n/build'
/usr/bin/cmake -E cmake_progress_start /home/n2n/n2n/build/CMakeFiles 0
4.3.3 第三步
# 将编译后的执行文件安装到 sbin 或 bin 目录下
make install
# 编译安装目标目录示例
[100%] Built target tests-wire
make[1]: Leaving directory `/home/n2n/n2n/build'
/usr/bin/cmake -E cmake_progress_start /home/n2n/n2n/build/CMakeFiles 0
make -f CMakeFiles/Makefile2 preinstall
make[1]: Entering directory `/home/n2n/n2n/build'
make[1]: Nothing to be done for `preinstall'.
make[1]: Leaving directory `/home/n2n/n2n/build'
Install the project...
/usr/bin/cmake -P cmake_install.cmake
-- Install configuration: ""
-- Installing: /usr/local/sbin/edge
-- Installing: /usr/local/sbin/supernode
-- Installing: /usr/local/bin/n2n-benchmark
-- Installing: /usr/share/man/man8/edge.8.gz
-- Installing: /usr/share/man/man1/supernode.1.gz
-- Installing: /usr/share/man/man7/n2n.7.gz
4.4 设置开机自启及火墙配置
4.4.1 设置开机自启
# 先查询一下这个端口是否被占用
netstat -anp|grep 8864
# 编辑开机自启文件
vi /etc/rc.local

4.4.2 防火墙配置
# 查看防⽕墙的状态
iptables -L -n -v --line-numbers
# 如果有需要可以给端口创建两个入站规则,这个视不同的公有云服务器的安全配置而定
iptables -I INPUT -p tcp --dport 8864 -j ACCEPT
iptables -I INPUT -p udp --dport 8864 -j ACCEPT
4.4.3 重启
reboot
4.5 验证
查看进程是否进行
# 检查 supernode 进程是否已运行
netstat -anp|grep `ps -ef|grep supernode|grep -v grep|awk {'print $2'}`

5 Linux 环境 edge 的编译、配置与启动
5.1 配置n2n启动脚本
vi /etc/init.d/n2n
#!/bin/sh
### BEGIN INIT INFO
# Provides: n2n
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the n2n VPN
# Description: This script controls the n2n VPN service.
# It is called from the boot, halt and reboot scripts.
# So far, only 1 PVN is supported by this script.
# More can be started via the command line.
### END INIT INFOset -e# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC='n2n P2P VPN'
NAME=n2n
#DAEMON=/usr/sbin/edge
DAEMON=/usr/local/sbin/edge
DAEMON_ARGS=""
# Arguments to run the daemon with
#PIDFILE=/var/run/$NAME-edge.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0# Check config
if [ ! -f "/etc/default/edge.conf" ]
thenecho "Warning: n2n VPN client is not configured, edit config file in /etc/default/edge.conf." 1>&2exit 0
fi# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
. /lib/lsb/init-functions## Make sure /var/run/n2n exists.
#if [ ! -e /var/run/$NAME ] ; then
# mkdir -p /var/run/$NAME
# chown proxy:proxy /var/run/$NAME
# chmod 755 /var/run/$NAME
#fi# Function that starts the daemon/service
#
do_start()
{if [ -r /sys/class/net/edge0 ]; thenecho edge node is already running.exit 0fi# Return# 0 if daemon has been started# 1 if daemon was already running# 2 if daemon could not be startedstart-stop-daemon --start --quiet --user nobody --exec $DAEMON --test > /dev/null \|| return 1start-stop-daemon --start --quiet --user nobody --exec $DAEMON -- \/etc/default/edge.conf \|| return 2
}#
# Function that stops the daemon/service
#
do_stop()
{# Return# 0 if daemon has been stopped# 1 if daemon was already stopped# 2 if daemon could not be stopped# other if a failure occurredstart-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --user nobody --exec $DAEMONRETVAL="$?"[ "$RETVAL" = 2 ] && return 2# Wait for children to finish too if this is a daemon that forks# and if the daemon is only ever run from this initscript.# If the above conditions are not satisfied then add some other code# that waits for the process to drop all resources that could be# needed by services started subsequently. A last resort is to# sleep for some time.start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON[ "$?" = 2 ] && return 2# Many daemons don't delete their pidfiles when they exit.rm -f $PIDFILEreturn "$RETVAL"
}#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {## If the daemon can reload its configuration without# restarting (for example, when it is sent a SIGHUP),# then implement that here.#start-stop-daemon --stop --signal 1 --quiet --name $NAMEreturn 0
}case "$1" instart)[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"do_startcase "$?" in0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;esac# 修改虚拟网卡速度,n2n默认是10M/S,修改为1000M/Sethtool -s edge0 speed 1000 duplex full autoneg off;;stop)[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"do_stopcase "$?" in0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;esac;;status)status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?;;#reload|force-reload)## If do_reload() is not implemented then leave this commented out# and leave 'force-reload' as an alias for 'restart'.##log_daemon_msg "Reloading $DESC" "$NAME"#do_reload#log_end_msg $?#;;restart|force-reload)## If the "reload" option is implemented then remove the# 'force-reload' alias#log_daemon_msg "Restarting $DESC" "$NAME"do_stopcase "$?" in0|1)do_startcase "$?" in0) log_end_msg 0 ;;1) log_end_msg 1 ;; # Old process is still running*) log_end_msg 1 ;; # Failed to startesac;;*)# Failed to stoplog_end_msg 1;;esac;;*)N=/etc/init.d/$NAME#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2exit 3;;
esacexit 0
5.2 配置edge.conf脚本
在/etc/default/目录下创建edge.conf配置文件:
#
# The configuration file is similar to the command line, with one option per line. An equal
# sign '=' should be used between key and value. Example: -c=mynetwork or --community=mynetwork
# This file contains a basic configuration example, please refer to the help (-h) for the full
# list of available options.
#
# -d|--tun-device
# Specifies the name of the TUN interface.
#
#-d=tap0
#
# -c|--community
# Specifies the n2n community name the edge belongs to.
#
-c=
#
# -k
# Sets the encryption key (ASCII). The environment variable N2N_KEY=<key> can also be used.
#
-k=
#
# -m
# Specified the MAC address for the TAP interface (random otherwise).
#
# -m=5E:57:77:58:7F:77
#
# -a
# Sets the interface address. For DHCP use '-r -a dhcp:0.0.0.0'.
#
-a=16.16.16.25
#
# -p
# Sets the local UDP port to a fixed port.
#
-p=60000
#
# -l|--supernode-list
# Specifies the supernode IP and port.
#
-l=168.324.678.8:8864
#
# -z1 ... -z2| compress outgoing data packets,
# -z1 = lzo1x,
# disabled by default
#
-z1
#
#
-bHEerejer
5.3 n2n服务启动
#n2n 服务启动
systemctl daemon-reload
#n2n 服务启动
systemctl start n2n#n2n 服务状态查询
systemctl status n2n#n2n 服务停止
systemctl stop n2n
6 windows环境部署
7 常见问题
问题1:开机启动后/etc/rc.local supdernode没有生效
排查方法:
是rc.local没有执行权限导致
解决方法:
第一种方法:直接加权限
[root@master ~]# ls -l /etc/rc.local
lrwxrwxrwx. 1 root root 13 Sep 17 19:58 /etc/rc.local -> rc.d/rc.local
[root@master ~]#
[root@master ~]#
[root@master ~]# chmod +x /etc/rc.local
第二种方法:
rc-local服务配置路径为/usr/lib/systemd/system/rc-local.service。在[Unit]模块中添加或修改Requires和After项值为network-online.target。
cat /usr/lib/systemd/system/rc-local.service |grep -v “^#” #过滤掉注释

相关文章:
01 | n2n虚拟局域网
1 n2n简介 为了满足两个不同局域网的机器进行通信,让不同网段的机器能够进行P2P( 点对点 peer-to-peer ) 通信。2 n2n源码 https://github.com/ntop/n2n.git3 n2n名词 3.1 SuperNode 超级节点 SuperNode 相当与注册中心, 它会记录边缘节点的连接信息,…...
MFC界面控件BCGControlBar v33.4 - 支持Win 11 Mica material主题
BCGControlBar库拥有500多个经过全面设计、测试和充分记录的MFC扩展类。 我们的组件可以轻松地集成到您的应用程序中,并为您节省数百个开发和调试时间。BCGControlBar专业版和BCGSuite for MFC v33.4已正式发布了,该版本包含了对Windows 11 Mica materia…...
手把手教你用js实现手机通讯录功能(附源码)
js实现手机通讯录效果图需求需求一:锚点通过#id配合a标签使用css中scroll-behavior属性的使用需求二需求三获取汉字拼音的首字母方法1:使用插件,这里推荐pinyin-pro方法2:使用unicode去重数组中冗余的对象法一:用Map去…...
【C/C++】逗号表达式、算术运算符优先级
一、逗号表达式 1、如下图中代码,为变量d赋值,d的值为逗号表达式中的哪一个呢? 运行结果:d的值为6 2、再举个例子 运行结果:d的结果还是6 3、再举个例子 运行结果 以上面三种不同的逗号表达式为例,…...
携禾生物面试总结
面试时间: 2022年2月3日 1.项目C11的特性具体有用到哪些? 智能指针 lambda表达式 auto unordered_map 2.智能指针用到了哪几种智能指针 3.shared_ptr和weak_ptr区别 4.多线程实现方式 prosix线程》pthread windows的_beginthreaex MFC多线程 ACEM中…...
FPGA纯verilog手写HDMI发送IP 提供源码和技术支持
目录1、前言2、设计思路和框架TMDS 编码算法OSERDESE串并转换3、顶层源码和IP封装4、源码和IP获取1、前言 本设计使用Xilinx原语和自己手写的代码实现了HDMI发送功能,纯verilog手写,有源码,也提供封装好的IP,你喜欢用例化的方式就…...
【知识点】OkHttp 原理 8 连问
前言OkHttp可以说是Android开发中最常见的网络请求框架,OkHttp使用方便,扩展性强,功能强大,OKHttp源码与原理也是面试中的常客但是OKHttp的源码内容比较多,想要学习它的源码往往千头万绪,一时抓不住重点.本文从几个问题…...
【python】深入了解Selenium-PageObject
1、PageObject 定义 Page Object(简称PO)模式,是Selenium实战中最为流行,并且是自动化测试中最为熟悉和推崇的一种设计模式。在设计自动化测试时,把页面元素和元素的操作方法按照页面抽象出来,分离成一定的对象,然后再…...
PAT——7-4 简易测谎 (20 分)
测谎通常使用一套准备好的问题提问被测试者,通过分析被测试者的反应得到结果。比较高级的测谎技术会使用测谎仪,监视被测试者的生理活动状况。我们这里的简易测谎则是通过对问题答案的特征分析来做出判断。 首先我们要求被测试者做完 N 道单选题&#x…...
【力扣】 面试题 05.02.二进制数转字符串(超过c++100%)
二进制数转字符串。给定一个介于0和1之间的实数(如0.72),类型为double,打印它的二进制表达式。如果该数字无法精确地用32位以内的二进制表示,则打印“ERROR”。示例1:输入:0.625输出:"0.10…...
软件质量保证与测试 课堂笔记
...
Costco好市多验厂百问百答
【Costco好市多验厂百问百答】美国仓储式超市Costco,中文好市多,近几年发展势头迅猛,大有赶超传统商超巨头沃尔玛之势。之前有出口企业反馈,Costco采购不仅量大,而且价格好,所以Costco成为国内出口企业纷纷…...
Nginx 通过 header 中的标识进行分发
Nginx可以根据请求头中自定义的标识将请求分发到不同的服务器。具体来说,可以使用map指令将请求头中的自定义标识映射为不同的后端服务器地址,然后使用proxy_pass指令将请求转发到对应的后端服务器。 以下是一个示例配置文件: http {map $h…...
如何实现《电子签名法》要求的可靠电子签名?
电子文档的电子签名怎么弄?我们在工作中经常需要在一些Word、pdf等电子版文件中插入签名,而很多人可能不知道,电子签名怎么弄?怎么做电子签名才有效?电子印章或签名图片属于电子签名吗?当工作或商务交易中&…...
工程项目管理软件有哪些?这六款很好用!
工程项目管理软件哪个好用?这六款很不错! 在现代社会中,软件已经成为了企业信息化、项目管理等方面必不可少的工具。尤其是对于工程项目管理而言,借助软件进行协同、计划、控制等方面的工作,已经成为了必要的手段。但…...
多看看spdk代码学习
多看看spdk代码学习还是干货直接上代码简易讲解详细讲解一下这份代码还是干货直接上代码 #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <signal.h> #include <stdbo…...
宾语从句it做形式主语的句子
It代替从句作形式主语的常见句型 一、it 代替连词 that 引导的从句作形式主语。 1、it be 过去分词 that 从句: It’s said that Tom has come back from abroad . It was reported that dozens of children died in the accident . 可用于该句型的过去分词还有…...
【C#基础】C# 文件与IO
序号系列文章9【C# 基础】C# 异常处理操作10【C#基础】C# 正则表达式11【C#基础】C# 预处理器指令文章目录前言1,文件和IO的概念2,文本文件操作2.1 File 类2.2 FileInfo 类2.3 FileStream 类2.4 StreamReader 类2.5 StreamWriter 类FileStream 和 Stream…...
死锁相关介绍【内含哲学家就餐问题】
死锁 死锁是这样一种情形:多个线程同时被阻塞,它们中的一个或者全部都在等待某个资源被释放。由于线程被无限期地阻塞,因此程序不可能正常终止。 场景1:一个线程,一把锁 一个线程,一把锁,线程…...
Java的Groovy执行器内存泄露(MetaSpace)问题分析与解决办法
环境与背景 在java程序中通过GroovyScriptEvaluator执行器创建脚本Script对象调用Groovy脚本语言来完成某些功能, ,会通过AppClassLoader或者GroovyClassLoader去生产一个随机的名称的Groovy的Script类对象,导致元数据,产生的class类会被AppClassLoader或者GroovyClassLoader内…...
Java 语言特性(面试系列1)
一、面向对象编程 1. 封装(Encapsulation) 定义:将数据(属性)和操作数据的方法绑定在一起,通过访问控制符(private、protected、public)隐藏内部实现细节。示例: public …...
dedecms 织梦自定义表单留言增加ajax验证码功能
增加ajax功能模块,用户不点击提交按钮,只要输入框失去焦点,就会提前提示验证码是否正确。 一,模板上增加验证码 <input name"vdcode"id"vdcode" placeholder"请输入验证码" type"text&quo…...
转转集团旗下首家二手多品类循环仓店“超级转转”开业
6月9日,国内领先的循环经济企业转转集团旗下首家二手多品类循环仓店“超级转转”正式开业。 转转集团创始人兼CEO黄炜、转转循环时尚发起人朱珠、转转集团COO兼红布林CEO胡伟琨、王府井集团副总裁祝捷等出席了开业剪彩仪式。 据「TMT星球」了解,“超级…...
Keil 中设置 STM32 Flash 和 RAM 地址详解
文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...
uniapp微信小程序视频实时流+pc端预览方案
方案类型技术实现是否免费优点缺点适用场景延迟范围开发复杂度WebSocket图片帧定时拍照Base64传输✅ 完全免费无需服务器 纯前端实现高延迟高流量 帧率极低个人demo测试 超低频监控500ms-2s⭐⭐RTMP推流TRTC/即构SDK推流❌ 付费方案 (部分有免费额度&#x…...
网络编程(UDP编程)
思维导图 UDP基础编程(单播) 1.流程图 服务器:短信的接收方 创建套接字 (socket)-----------------------------------------》有手机指定网络信息-----------------------------------------------》有号码绑定套接字 (bind)--------------…...
C++八股 —— 单例模式
文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全(Thread Safety) 线程安全是指在多线程环境下,某个函数、类或代码片段能够被多个线程同时调用时,仍能保证数据的一致性和逻辑的正确性…...
Device Mapper 机制
Device Mapper 机制详解 Device Mapper(简称 DM)是 Linux 内核中的一套通用块设备映射框架,为 LVM、加密磁盘、RAID 等提供底层支持。本文将详细介绍 Device Mapper 的原理、实现、内核配置、常用工具、操作测试流程,并配以详细的…...
Web 架构之 CDN 加速原理与落地实践
文章目录 一、思维导图二、正文内容(一)CDN 基础概念1. 定义2. 组成部分 (二)CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 (三)CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 …...
CRMEB 中 PHP 短信扩展开发:涵盖一号通、阿里云、腾讯云、创蓝
目前已有一号通短信、阿里云短信、腾讯云短信扩展 扩展入口文件 文件目录 crmeb\services\sms\Sms.php 默认驱动类型为:一号通 namespace crmeb\services\sms;use crmeb\basic\BaseManager; use crmeb\services\AccessTokenServeService; use crmeb\services\sms\…...
