技术视野 | 如何搭建维基链单节点私有链?
维基链WICC 2019-09-05 14:02:26发布
25838
摘要:本期“技术视野”,将为你介绍如何通过自动化脚本的方式搭建单节点私有链。  

本期“技术视野”,将为你介绍如何通过自动化脚本的方式搭建单节点私有链。

基于Dockerfile创建docker镜像

生成Dockerfile

FROM phusion/baseimage:0.9.18

MAINTAINER coredev@waykichainhk.com

ARG branch='release'

ARG debug='-debug'

# Install prrequisite components

RUN echo exit 0 > /usr/sbin/policy-rc.d

RUN add-apt-repository ppa:bitcoin/bitcoin -y && apt-get update

RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --force-yes build-essential libtool autotools-dev automake \

pkg-config libssl-dev libevent-dev bsdmainutils python3 \

libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev \

libboost-test-dev libboost-thread-dev software-properties-common libdb4.8-dev libdb4.8++-dev git-core

# Build WaykiChain source on its release branch

RUN SHA=$(curl -s 'https://api.github.com/repos/WaykiChain/WaykiChain/commits' | grep sha | head -1 | cut -c 13-20) \

mkdir -p /opt/src && cd /opt/src && git clone -b $branch 'https://github.com/WaykiChain/WaykiChain.git' --recursive

RUN cd /opt/src/WaykiChain/linuxshell && sh ./linux.sh \

&& cd /opt/src/WaykiChain/ && sh ./autogen-coin-man.sh "coin${debug}" \

&& make && strip /opt/src/WaykiChain/src/coind \

&& mkdir /opt/wicc && mv /opt/src/WaykiChain/src/coind /opt/wicc/ \

&& rm -rf /opt/src

ENV PATH="/opt/wicc:${PATH}"

WORKDIR /opt/wicc/

EXPOSE 6968 8920 18920

CMD [“./coind"]

build镜像

$ docker build -t waykicoind .

准备相应的环境

创建文件夹目录

$ sudo mkdir -p /opt/docker-instances/waykicoind-regtest

到新创建目录,创建data conf目录

$ sudo mkdir data conf

修改WaykiChain.conf,确保regtest=1设置成功

创建bin目录,并添加run-waykicoind-regtest.sh

cd /opt/docker-instances/waykicoind-regtest \

&& docker run --name waykicoind-regtest -p18920:18920 -p 1968:6968 \

      -v `pwd`/conf/WaykiChain.conf:/root/.WaykiChain/WaykiChain.conf \

      -v `pwd`/data:/root/.WaykiChain/regnet \

      -v `pwd`/bin:/opt/wicc/bin \

      -d waykicoind

启动容器

sh ./bin/run-waykicoind-regtest.sh

初始化节点

导入矿工节点

coind importprivkey Y6J4aK6Wcs4A3Ex4HXdfjJ6ZsHpNZfjaS4B9w7xqEnmFEYMqQd13

coind importprivkey Y5F2GraTdQqMbYrV6MG78Kbg4QE8p4B2DyxMdLMH7HmDNtiNmcbM

coind importprivkey Y7HWKeTHFnCxyTMtCEE6tVkqBzXoN1Yjxcx5Rs8j2dsSSvPxvF7p

coind importprivkey Y871eB5Xiss2ugKWQRb4nmMhKTnmXAEyUqBimTCupogzoSTVCSU9

coind importprivkey Y9cAUsEhfsihbePnCYYCETpN1PVovqTMX4kauKRsZ9ERdz1uumeK

coind importprivkey Y4unEjiFk1YJQi1jaT3deY4t9Hm1eSk9usCam35LcN85cUA2QmZ5

coind importprivkey Y5XKsR95ymf2pEyuhDPLtuvioHRo6ogDDNnaf4YU91ABvLb68QBU

coind importprivkey Y7diE8BXuwTkjSzgdZMnKNhzYGrU8oSk31anJ1mwipSCcnPakzTA

coind importprivkey YCjoCrtGEvMPZDLzBoY9GP3r7pqWa5mgzUxqAsVub6xnUVBwQHxE

coind importprivkey Y6bKBN4ZKBNHJZpQpqE7y7TC1QpdT32YtAjw4Me9Bvgo47b5ivPY

coind importprivkey Y8G5MwTFVsqj1FvkqFDEENzUBn4yu4Ds83HkeSYP9SkjLba7xQFX

coind importprivkey YAq1NTUKiYPhV9wq3xBNCxYZfjGPMtZpEPA4sEoXPU1pppdjSAka

注意事项

1.  如果是更新节点,务必备份data目录的wallet.dat,并导出钱包私钥。

2.  节点更新的流程包括以下步骤:

准备build环境的dockerfile。

FROM phusion/baseimage:0.9.18

MAINTAINER will<zhixiang.liu@waykichainhk.com>

ARG branch='test'

ARG debug='-debug'

# Install prerequisites componets

RUN add-apt-repository ppa:bitcoin/bitcoin -y && apt-get update

ADD prepare_prerequisites.sh /tmp/

RUN apt-get install sudo

RUN sh /tmp/prepare_prerequisites.sh

# Create workdir

RUN mkdir -p /opt/src && cd /opt/src

RUN git config --global user.email "will-liu@live.com"

RUN git config --global user.name "will-lzx"

RUN cd /opt/src &&  git clone -b $branch 'https://github.com/WaykiChain/WaykiChain.git' --recursive

RUN cd /opt/src/WaykiChain/linuxshell && sh ./linux.sh \

&& cd /opt/src/WaykiChain/ && sh ./autogen-coin-man.sh "coin${debug}"

WORKDIR /opt/src/WaykiChain/

CMD bash

获取最近代码并编译,输出coind文件。

$ docker build -t wick-build .

-  docker run -i --rm -v `pwd`/waykichain/:/tmp/waykichain \

wicc-build \

sh -c " git pull || true && git reset --hard origin/test && sh ./autogen-coin-man.sh coin && make && strip ./src/coind  && mv ./src/coind /tmp/waykichain/“

编译出coind,即可替换已有节点的coind程序,然后重启容器。

验证是否正常出区块即可。

点击进入招聘详情>
微信扫一扫
关注区块链新金融
扫一扫
下载数链APP
内容合作/商务合作:
gxcj@gongxiangcj.com
联系电话:
021-31128751