🌐N2N部署

50

supernode

1.编译镜像

Dockerfile文件:

FROM alpine:latest AS build-env

RUN apk update && apk upgrade
RUN apk add build-base openssl-dev zstd-dev git linux-headers autoconf automake libtool

WORKDIR /opt

RUN cd /opt && \
git clone https://github.com/ntop/n2n.git && \
cd n2n && \
./autogen.sh && \
./configure --with-zstd --with-openssl CFLAGS="-O3 -march=native" && \
make && \
make install

FROM alpine:latest
RUN apk update && apk upgrade --no-cache && apk add openssl zstd-libs --no-cache
COPY --from=build-env /usr/sbin/supernode /usr/sbin/
COPY --from=build-env /usr/sbin/edge /usr/sbin/
COPY --from=build-env /opt/n2n/packages/etc/n2n /etc/n2n
COPY ./start /usr/sbin/start_edge
CMD /usr/sbin/start_edge

start文件:

[!warning] 注意 start 文件权限必须高于 755

#!/bin/sh

CONF_PATH=/conf
CONF_FILE=$CONF_PATH/supernode.conf
CONF_EXAMPLE=/etc/n2n/supernode.conf.sample
CONF_EXAMPLE_OUTPUT=$CONF_PATH/supernode.conf.sample

if test -f "$CONF_FILE"; then
    supernode $CONF_FILE -f
else
    echo "config file: $CONF_FILE not exist"
    echo "please add config files to /conf"
    mkdir -p /conf
    cp $CONF_EXAMPLE $CONF_EXAMPLE_OUTPUT
    echo "see /conf/supernode.conf.example"
fi

编译

docker build -t odbz/n2n_supernode:v1 -f /opt/Dockerfile /opt/

2.启动容器

docker run -d --name='n2n_supernode' --net='host' -v '/data/odbz_n2n/supernode':'/conf':'rw' odbz/n2n_supernode:v1

3.配置文件生成之后自己修改端口,名字去掉.sample,重启容器即可

示例:设置服务端口为4090

#
#        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: -p=7777
#        This file contains a basic configuration example, please refer to the help (-h) for the full
#        list of available options.
#
#       -p
#        Sets the UDP listening port. 
#
-p=4090
#
#        -c
#        Optionally specifies the allowed communities as listed in community.list file.
#
# -c=community.list

edge

1.编译镜像

Dockerfile文件:

FROM alpine:latest AS build-env

RUN apk update && apk upgrade
RUN apk add build-base openssl-dev zstd-dev git linux-headers autoconf automake libtool

WORKDIR /opt

RUN cd /opt && \
git clone https://github.com/ntop/n2n.git && \
cd n2n && \
./autogen.sh && \
./configure --with-zstd --with-openssl CFLAGS="-O3 -march=native" && \
make && \
make install

FROM alpine:latest
RUN apk update && apk upgrade --no-cache && apk add openssl zstd-libs --no-cache
COPY --from=build-env /usr/sbin/supernode /usr/sbin/
COPY --from=build-env /usr/sbin/edge /usr/sbin/
COPY --from=build-env /opt/n2n/packages/etc/n2n /etc/n2n
COPY ./start /usr/sbin/start_edge
CMD /usr/sbin/start_edge

start文件:

[!warning] 注意 start 文件权限必须高于 755

#!/bin/sh

CONF_PATH=/conf
CONF_FILE=$CONF_PATH/edge.conf
CONF_EXAMPLE=/etc/n2n/edge.conf.sample
CONF_EXAMPLE_OUTPUT=$CONF_PATH/edge.conf.sample

if test -f "$CONF_FILE"; then
    edge $CONF_FILE -f
else
    echo "config file: $CONF_FILE not exist"
    echo "please add config files to /conf"
    mkdir -p /conf
    cp $CONF_EXAMPLE $CONF_EXAMPLE_OUTPUT
    echo "see /conf/edge.conf.example"
fi

编译

docker build -t odbz/n2n_edge:v1 -f /opt/Dockerfile /opt/

2.启动容器

docker run -d --privileged --name='n2n_edge' --net='host' -v '/data/odbz_n2n/edge':'/conf':'rw' odbz/n2n_edge:v1

3.配置文件生成之后,名字去掉.sample,重启容器即可

示例:

#
#         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=n2n0
#
#       -c|--community
#        Specifies the n2n community name the edge belongs to.
#
-c=impart
#
#       -k
#        Sets the encryption key (ASCII). The environment variable N2N_KEY=<key> can also be used. 
#
#-k=mypassword
#
#       -m
#        Specified the MAC address for the TAP interface (random otherwise).
#
# -m=DE:AD:BE:EF:99:99
#
#       -a
#        Sets the interface address. For DHCP use '-r -a dhcp:0.0.0.0'.
#
-a=172.127.1.200
#
#       -p
#        Sets the local UDP port to a fixed port.
#
-p=25000
#
#       -l|--supernode-list
#        Specifies the supernode IP and port.
#
-l=ip:port
#