Compile & Run
1.compile
First, you need to install the go development environment and make. This part belongs to the technical scope of go. You can consult related documents by yourself. After the environment is set up, enter the following operations
Enter the project root directory and execute the following command
make all
When the command is executed, binary files such as bootnode, geth, etc. will be generated in build/bin. Just copy these two files to the server to be deployed.
Note: It is best to compile on the server or in the same environment as the server to prevent cross-platform problems
2.bootnode and geth
After finishing the above compilation, you will get two files, bootnode and geth. First, explain what these two files are.
2.1 bootnode
A lightweight node: it does not have any computing functions, and is only used for mutual discovery between other nodes. If you have experience in the development of microservices, you can understand it as [Registration Center], so I should understand.
A blockchain network is composed of a large number of nodes. These nodes discover each other and form a network in series, which is realized by the bootnode node.
2.2 geth
The official node: packaging, calculation, and storage are all done by this node, and these nodes form a complete blockchain network
3.start the node
In order to facilitate the demonstration, I have placed all nodes on one server. In the actual environment, depending on the requirements, many servers may need to be prepared
3.1 Start a bootnode node
// Generate key
./bootnode --genkey=boot.key
// Start the bootnode node
./bootnode --nodekey=boot.key -addr=0.0.0.0:20001
// If you want to execute in the background, you can do this
nohup ./bootnode --nodekey=boot.key -addr=0.0.0.0:20001 >>bootnode.log 2>&1 &
After startup, you will see this passage in the console or log file
enode://5cad8d40d27e34cf2f3a3040cd242a569a5eb1e2b79ce4677ccdc4aabf92ab323a12f84da8c4b16a3e20674e4bbdf03aaef8786a83ce7@127.0.0.1:0?discport=20001
Copy it out and change it to this. It will be used when starting geth. If you want to join an existing blockchain network, then this step can be omitted and you can get it from the administrator of the existing network This section of configuration is enough, you don’t need to start the bootnode by yourself
enode://5cad8d40d27e34cf2f3a3040cd242a569a5eb1e2b79ce4677ccdc4aabf92ab323a12f84da8c4b16a3e20674e4bbdf03aaef8786a83ce7@127.0.0.1:20001
Supplementary description:
1. If you want this bootnode to be used by nodes other than this machine, you must open port 20001 and support the udp protocol (it doesn’t have to be 20001, you just set it after -addr How much is open)
2. If you just want to connect to the existing blockchain network, then you don't need to start the bootnode, just start geth directly
3.2 Start geth node
In order to freely switch back to the console of any node, it is best to install screen
sudo apt-get install screen
In order to save the log to the specified file, the configuration file needs to be modified
vi /etc/screenrc
Add this sentence at the end
logfile /data/xt/runner/logs/geth_%t.log
// The value of %t, set when starting the node
Start the geth node (the default is the mainnet, if you want to start with the configuration of the testnet, you can add a parameter --testnet after ./geth)
screen -L -t Log file name (the value of %t in the previous step) -S console name ./geth --networkid="1024" --identity "test1"
--http --http.port "30080"
--datadir data0
--port "30303" --http.addr 0.0.0.0
--http.api="eth,admin,miner,net,web3,personal"
--allow-insecure-unlock --ipcdisable --rpc.allow-unprotected-txs
--bootnodes
"enode://7bdb19d773cd357a3899f7c11ddb8d0c6f90fd20919bd420999bace3f11c124da4eabefa04373100655c2dfd737146f3edff201411387e748912cdaeb1888f2a@127.0.0.1:20001"
--http.corsdomain="*" console
After startup, you will enter the console and see the startup log. If there is no error, it means success. Press ctrl+a+d to switch to the background. For specific front and background operations, see 3.3 [Command for switching between the front and back of the console]
To start the second, third, and Nth node, you only need to change the port number, name and log output path in the above command
Note: If you want this geth to connect to a network other than this machine, you must open port 30303 and support the udp protocol (not necessarily 30303, you are behind --port Open as many as you set)
3.3 Commands for switching between the front and the back of the console
4.Mining
Open one of the node consoles and enter the following commands in the console
personal.importRawKey("Your wallet private key","Your wallet password")
personal.unlockAccount("Your wallet address","Wallet Password",Unlock timeout period)
miner.setEtherbase("Your wallet address")
miner.start(1)
Supplementary description:
1. Only the node that produces the block needs to execute this command, and the account used must be the validator account you configured
2. Each node can only have one account for mining, and the number of nodes producing blocks must be greater than half of the number of validator accounts, otherwise the network will not be available and no one will process all transactions
5.Self-test
Use metamask to connect to any node. If it can be used normally, the deployment is successful.
6.Notice
Never use kill to directly kill the process
If you kill the geth process or it crashes, it will not write the latest state of the cache, and will force abandon the 'fast' synchronization state at the next startup and roll back to the last 'complete' 'Status. It will cause the balance to be lost
Elegantly shutdown options: SIGINT, SIGTERM, Ctrl+ D (if running on the console), Ctrl+ C1
Unsafe shutdown options: SIGQUIT, SIGKILL, Windows' [X] button
If there is a balance reset, you can try the following solutions
Stop the node and execute this command
./geth removedb
Delete the data directory corresponding to this node, and then restart the node
7.Links
[Console Operation Command] (https://www.jianshu.com/p/9fa31e4cdf4d)