Setting up the Fisco-bcos environment (I.) configuration and start-up of Genesis node

Source: Internet
Author: User
Chapter II Creation of Genesis node

The Genesis node is the first node in the block chain, building the block chain, starting from the creation node. 2.1 Creating a node environment

Assuming the Genesis node directory is/mydata/nodedata-1/, the creation node environment is as follows:

#创建目录结构
mkdir-p/mydata/nodedata-1/
mkdir-p/mydata/nodedata-1/data/#存放节点的各种文件
mkdir-p/mydata/ nodedata-1/log/#存放日志
mkdir-p/mydata/nodedata-1/keystore/#存放账户秘钥

#拷贝相关文件
cd/mydata/fisco-bcos/ 
CP Genesis.json Config.json log.conf start.sh stop.sh/mydata/nodedata-1/
2.2 Configure God account

God account is the highest level of the block chain and must be configured before starting the block chain. 2.2.1 Generate God account

Cd/mydata/fisco-bcos/web3lib
cnpm Install #安装nodejs依赖, the command needs to be executed once in the directory before the Nodejs script is executed, and no further execution is required.
cd/mydata/fisco-bcos/tool #代码根目录下的tool文件夹
cnpm install #安装nodejs包, run only once, and then if you need to use Nodejs again in the tool directory, You do not need to run this command repeatedly
node accountmanager.js > GodInfo.txt
cat godInfo.txt |grep Address

The address of the generated God account can be obtained as follows. GodInfo.txt please keep it properly.

address:0x27214e01c118576dd5f481648f83bb909619a324
2.2.2 Configure God account

Configure God's address, generated by the above steps, into the Genesis.json God field:

Vim/mydata/nodedata-1/genesis.json

After modification, the god field in Genesis.json is as follows:

"God": "0x27214e01c118576dd5f481648f83bb909619a324",
2.3 Configure node Identity Nodeid

Nodeid uniquely identifies a node in the block chain and must be configured before the node is started. 2.3.1 Configuration Cryptomod.json file

To configure the Nodeid build path in the Cryptomod.json file:

Vim/mydata/fisco-bcos/cryptomod.json

In general, simply configure the Rlpcreatepath to be/MYDATA/NODEDATA-1/DATA/NETWORK.RLP. The following Cryptomod.json are configured:

{"
	cryptomod": "0",
	"Rlpcreatepath": "/MYDATA/NODEDATA-1/DATA/NETWORK.RLP",
	"Datakeycreatepath": "",
	"Keycenterurl": "",
	"Superkey": ""
}

Cryptomod.json Other Field descriptions refer to Appendix: 11.2 Cryptomod.json Description 2.3.2 Generating node identity file

Using the modified Cryptomod.json file to generate the node identity file, the build path is the path configured in Cryptomod.json.

cd/mydata/fisco-bcos/ 
fisco-bcos--gennetworkrlp  cryptomod.json #需要一段时间
ls/mydata/nodedata-1/data/

You can see that the node identity files (NETWORK.RLP and network.rlp.pub) are generated under/mydata/nodedata-1/data/.

Where NETWORK.RLP is the node identity's private key binary file. Network.rlp.pub is the Nodeid file of the node identity.

NETWORK.RLP  network.rlp.pub
2.3.3 Configuration Genesis node Nodeid

(1) View Nodeid

Cat/mydata/nodedata-1/data/network.rlp.pub

Get the following similar Nodeid

24b98c6532ff05c2e9e637b3362ee4328c228fb4f6262c1c751f51952012cd68da2cbd8655de5072e49b950a503326942297cfaa9ca919b369be4359b 4dccd56

(2) Modify Genesis.json

Configure the Nodeid into the Genesis.json initminernodes field, which specifies that the node for this nodeid is the creation node.

Vim/mydata/nodedata-1/genesis.json

After modification, the Initminernodes fields in Genesis.json are as follows:

"Initminernodes": [" 24b98c6532ff05c2e9e637b3362ee4328c228fb4f6262c1c751f51952012cd68da2cbd8655de5072e49b950a503326942297cfaa9ca919b369be4359b 4dccd56 "]

(3) Modify Config.json

Configure the Nodeid into the Nodeid field of the Nodeextrainfo in Config.json.

Vim/mydata/nodedata-1/config.json

After modification, the Nodeextrainfo fields in Config.json are as follows:

"Nodeextrainfo": [
	{
		"Nodeid": " 24b98c6532ff05c2e9e637b3362ee4328c228fb4f6262c1c751f51952012cd68da2cbd8655de5072e49b950a503326942297cfaa9ca919b369be4359b 4dccd56 ",
		" Nodedesc ":" Node1 ",
		" Agencyinfo ":" Node1 ",
		" PeerIP ":" 0.0.0.0 ",
		" Identitytype ": 1,
		"Port": 30303,
		"IDX": 0
	}
]
2.4 Configuring Certificates

Communication between nodes in a block chain requires authentication of certificates. Before the node is run, you need to configure the certificate for the node. Certificates include: CA.CRT: Root certificate Public key, whole block chain shared. Ca.key: Root certificate private key, private key should be kept confidential, only used when generating node certificate public private key. SERVER.CRT: The public key of the node certificate. Server.key: The private key of the node certificate, the private key should be kept confidential. 2.4.1 Generate root certificate

Copy the public key generation script to the data directory and execute the command to generate the root certificate public key ca.key,ca.crt.

cp/mydata/fisco-bcos/genkey.sh/mydata/nodedata-1/data/ 
cd/mydata/nodedata-1/data/
chmod +x genkey.sh
./genkey.sh CA 365 #生成ca根证书有效期为365天

The certificate Public private key CA.KEY,CA.CRT was generated under the data directory. The ca.key should be kept confidential and properly saved for subsequent generation of more nodes ' public private keys. 2.4.2 Generation Node Certificate

Generates the node's own certificate with the generated root certificate public private key CA.CRT and Ca.key.

./genkey.sh server./ca.key./CA.CRT 365 #注意key和crt前后顺序不能错; This step needs to enter some information as prompted; The build server certificate is valid for 365 days

The generated Server.key, SERVER.CRT is the node certificate file

ls/mydata/nodedata-1/data/

The following files should exist in the directory at this time:

CA.CRT  network.rlp  network.rlp.pub  server.crt  Server.key
2.5 Configuring the related configuration file

Node startup depends on three profiles: Creation block file: Genesis.json node Profile: Config.json Log profile: log.conf 2.5.1 Configuration Genesis.json (creation block file)

The information of the creation block is configured in the Genesis.json, which is the necessary information for node initiation.

Vim/mydata/nodedata-1/genesis.json

The main configuration of God and Initminernodes fields, has been configured in the previous steps, CONFIGURED Genesis.json as follows:

{"
     nonce": "0x0", "
     difficulty": "0x0",
     "Mixhash": "0x0", "Coinbase":
     "0x0",
     "timestamp": "0x0", "
     Parenthash": "0x0", "
     extradata": "0x0",
     "Gaslimit": "0x13880000000000",
     "God": " 0x27214e01c118576dd5f481648f83bb909619a324 ","
     Alloc ": {},
     " Initminernodes ": [" 24b98c6532ff05c2e9e637b3362ee4328c228fb4f6262c1c751f51952012cd68da2cbd8655de5072e49b950a503326942297cfaa9ca919b369be4359b 4dccd56 "]
}

Genesis.json Other Field descriptions refer to Appendix: 11.3 Genesis.json Description 2.5.2 Configuration Config.json (node profile)

Config.json the various information of the configuration node, including network address, file directory, node identity and so on.

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.