本文讲述在ubuntu16.04虚拟机下面安装最新的eos的过程,感觉比以太坊要复杂一些。eos现在只能从源代码编译安装,而不能用apt-get的方式进行安装。需要注意的一点是需要修改内存限制。默认的最低内存是7G,虚拟机只分配了5G内存。
git clone https://github.com/EOSIO/eos --recursive
打开eos/scripts/eosio_build_ubuntu.sh,有这句话
if [ "${MEM_MEG}" -lt 7000 ]; then
这句里面的7000改成4000。
OS_VER=$( grep VERSION_ID /etc/os-release | cut -d'=' -f2 | sed 's/[^0-9\.]//gI' )
OS_MAJ=$(echo "${OS_VER}" | cut -d'.' -f1)
OS_MIN=$(echo "${OS_VER}" | cut -d'.' -f2)
MEM_MEG=$( free -m | sed -n 2p | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 )
CPU_SPEED=$( lscpu | grep -m1 "MHz" | tr -s ' ' | cut -d\ -f3 || cut -d' ' -f3 | cut -d'.' -f1 )
CPU_CORE=$( lscpu | grep "^CPU(s)" | tr -s ' ' | cut -d\ -f2 || cut -d' ' -f2 )
MEM_GIG=$(( ((MEM_MEG / 1000) / 2) ))
JOBS=$(( MEM_GIG > CPU_CORE ? CPU_CORE : MEM_GIG ))
DISK_INSTALL=$(df -h . | tail -1 | tr -s ' ' | cut -d\ -f1 || cut -d' ' -f1)
DISK_TOTAL_KB=$(df . | tail -1 | awk '{print $2}')
DISK_AVAIL_KB=$(df . | tail -1 | awk '{print $4}')
DISK_TOTAL=$(( DISK_TOTAL_KB / 1048576 ))
DISK_AVAIL=$(( DISK_AVAIL_KB / 1048576 ))
printf "\\n\\tOS name: %s\\n" "${OS_NAME}"
printf "\\tOS Version: %s\\n" "${OS_VER}"
printf "\\tCPU speed: %sMhz\\n" "${CPU_SPEED}"
printf "\\tCPU cores: %s\\n" "${CPU_CORE}"
printf "\\tPhysical Memory: %s Mgb\\n" "${MEM_MEG}"
printf "\\tDisk install: %s\\n" "${DISK_INSTALL}"
printf "\\tDisk space total: %sG\\n" "${DISK_TOTAL%.*}"
printf "\\tDisk space available: %sG\\n" "${DISK_AVAIL%.*}"
if [ "${MEM_MEG}" -lt 7000 ]; then
printf "\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"
printf "\\tExiting now.\\n"
exit 1
fi
case "${OS_NAME}" in
~/eos$ sudo ./eosio_build.sh
这个过程会下载大量的依赖库,用时要俩个小时左右。成功后会显示界面:
_______ _______ _______ _________ _______
( ____ \( ___ )( ____ \\__ __/( ___ )
| ( \/| ( ) || ( \/ ) ( | ( ) |
| (__ | | | || (_____ | | | | | |
| __) | | | |(_____ ) | | | | | |
| ( | | | | ) | | | | | | |
| (____/\| (___) |/\____) |___) (___| (___) |
(_______/(_______)\_______)\_______/(_______)
EOS.IO has been successfully built. 0:32:57
To verify your installation run the following commands:
/home/liuwenbin/opt/mongodb/bin/mongod -f /home/liuwenbin/opt/mongodb/mongod.conf &
cd /home/liuwenbin/eos/build; make test
For more information:
EOS.IO website: https://eos.io
EOS.IO Telegram channel @ https://t.me/EOSProject
EOS.IO resources: https://eos.io/resources/
EOS.IO wiki: https://github.com/EOSIO/eos/wiki
进入build目录,执行下面命令
~/eos/build$ sudo make install
安装完成后会在 /usr/local/eosio/bin下生成 cleos、kesod、nodeos等可执行文件。
/usr/local/eosio/bin$ ls
cleos eosio-abigen eosiocpp eosio-launcher eosio-s2wasm eosio-wast2wasm keosd nodeos
上面步骤会在 /usr/local下面生成 eosio 文件夹。打开 /etc/profile 文件,添加 ./usr/local/eosio/bin 目录到PATH变量中
export PATH=/usr/local/eosio/bin:$PATH
首先准备一个genesis.json,文件就保存在eos目录下,文件内容我用的是:
{
"initial_timestamp": "2018-03-01T12:00:00.000",
"initial_key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"initial_configuration": {
"base_per_transaction_net_usage": 100,
"base_per_transaction_cpu_usage": 500,
"base_per_action_cpu_usage": 1000,
"base_setcode_cpu_usage": 2097152,
"per_signature_cpu_usage": 100000,
"per_lock_net_usage": 32,
"context_free_discount_cpu_usage_num": 20,
"context_free_discount_cpu_usage_den": 100,
"max_transaction_cpu_usage": 10485760,
"max_transaction_net_usage": 104857,
"max_block_cpu_usage": 104857600,
"target_block_cpu_usage_pct": 1000,
"max_block_net_usage": 1048576,
"target_block_net_usage_pct": 1000,
"max_transaction_lifetime": 3600,
"max_transaction_exec_time": 0,
"max_authority_depth": 6,
"max_inline_depth": 4,
"max_inline_action_size": 4096,
"max_generated_transaction_count": 16
},
"initial_chain_id": "0000000000000000000000000000000000000000000000000000000000000000"
}
然后执行命令启动nodeos节点:
nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --genesis-json genesis.json
运行界面如下:
可以看到这个节点在不停的产生区块,周期是0.5s左右。
区块数据保存在目录 ~/.local/share/eosio/nodeos/data下面。
只有第一次启动时需要用--genesis-json选项,以后启动时不要再带这个选项,否则会报错。
除了上面的用命令行来出块的方式,还可以通过配置config.ini文件的方式来启动nodeos节点。新建一个文件夹,创建一个genesis.json,内容和上节的一样。然后再创建一个config.ini文件,文件内容如下:
genesis-json = genesis.json
block-log-dir = blocks
readonly = 0
send-whole-blocks = true
shared-file-dir = blockchain
shared-file-size = 8192
unlock-timeout = 90000
bnet-endpoint = 0.0.0.0:4321
http-server-address = 0.0.0.0:8888
p2p-listen-endpoint = 0.0.0.0:9876
p2p-server-address = localhost:9876
allowed-connection = any
#p2p-peer-address = localhost:9877
required-participation = true
signature-provider = EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
producer-name = eosio
plugin = eosio::producer_plugin
plugin = eosio::chain_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::wallet_api_plugin
plugin = eosio::http_plugin
enable-stale-production = true
基本上命令行中可用的命令,都可以去掉前缀的--后然后直接用到config.ini中。比如命令行中的 -e,对应配置文件中的
enable-stale-production = true,即允许出块;命令行中的 -p eosio,在配置文件里可以写成 producer-name = eosio;命令行中的--plugin eosio::wallet_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin,在配置文件中可以写成:
plugin = eosio::chain_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::wallet_api_plugin
此外配置文件还可以配置
创建好genesis.json和config.ini后的文件夹:
~/eostest1$ ls
config.ini genesis.json
然后启动nodeos节点:
~/eostest1$ sudo nodeos --data-dir ./ --config-dir ./
节点启动起来了:
~/eostest1$ sudo nodeos --data-dir ./ --config-dir ./
2018-08-02T07:05:46.108 thread-0 chain_plugin.cpp:271 plugin_initialize ] initializing chain plugin
2018-08-02T07:05:46.150 thread-0 block_log.cpp:124 open ] Log is nonempty
2018-08-02T07:05:46.151 thread-0 block_log.cpp:142 open ] Index is nonempty
2018-08-02T07:05:46.172 thread-0 http_plugin.cpp:344 plugin_initialize ] configured http to listen on 0.0.0.0:8888
2018-08-02T07:05:46.172 thread-0 wallet_plugin.cpp:42 plugin_initialize ] initializing wallet plugin
2018-08-02T07:05:46.172 thread-0 wallet_api_plugin.cpp:123 plugin_initialize ]
2018-08-02T07:05:46.172 thread-0 net_plugin.cpp:2919 plugin_initialize ] Initialize net plugin
2018-08-02T07:05:46.172 thread-0 net_plugin.cpp:2944 plugin_initialize ] host: 0.0.0.0 port: 9876
2018-08-02T07:05:46.173 thread-0 net_plugin.cpp:3014 plugin_initialize ] my node_id is 2eeb56eff4165c28fe8a5e6e94113d3f066094d533606384e6758ecaef713cd3
2018-08-02T07:05:46.173 thread-0 main.cpp:105 main ] nodeos version 40a20769
2018-08-02T07:05:46.173 thread-0 main.cpp:106 main ] eosio root is /home/lzj/.local/share
2018-08-02T07:05:46.173 thread-0 chain_plugin.cpp:596 plugin_startup ] starting chain in read/write mode
2018-08-02T07:05:46.173 thread-0 chain_plugin.cpp:600 plugin_startup ] Blockchain started; head block is #3, genesis timestamp is 2018-06-01T12:00:00.000
2018-08-02T07:05:46.173 thread-0 producer_plugin.cpp:640 plugin_startup ] producer plugin: plugin_startup() begin
2018-08-02T07:05:46.173 thread-0 producer_plugin.cpp:658 plugin_startup ] Launching block production for 1 producers at 2018-08-02T07:05:46.173.
2018-08-02T07:05:46.173 thread-0 producer_plugin.cpp:670 plugin_startup ] producer plugin: plugin_startup() end
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:401 plugin_startup ] start listening for http requests
2018-08-02T07:05:46.173 thread-0 chain_api_plugin.cpp:75 plugin_startup ] starting chain_api_plugin
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/abi_bin_to_json
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/abi_json_to_bin
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_abi
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_account
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_block
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_block_header_state
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_code
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_currency_balance
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_currency_stats
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_info
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_producer_schedule
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_producers
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_raw_code_and_abi
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_required_keys
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_scheduled_transactions
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/get_table_rows
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/push_block
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/push_transaction
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/chain/push_transactions
2018-08-02T07:05:46.173 thread-0 history_api_plugin.cpp:38 plugin_startup ] starting history_api_plugin
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/history/get_actions
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/history/get_controlled_accounts
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/history/get_key_accounts
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/history/get_transaction
2018-08-02T07:05:46.173 thread-0 wallet_api_plugin.cpp:73 plugin_startup ] starting wallet_api_plugin
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/create
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/create_key
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/get_public_keys
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/import_key
2018-08-02T07:05:46.173 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/list_keys
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/list_wallets
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/lock
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/lock_all
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/open
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/remove_key
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/set_timeout
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/sign_digest
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/sign_transaction
2018-08-02T07:05:46.174 thread-0 http_plugin.cpp:447 add_handler ] add api url: /v1/wallet/unlock
2018-08-02T07:05:46.174 thread-0 net_plugin.cpp:3027 plugin_startup ] starting listener, max clients is 25
2018-08-02T07:05:46.502 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 00000004141690fd... #4 @ 2018-08-02T07:05:46.500 signed by eosio [trxs: 0, lib: 3, confirmed: 0]
2018-08-02T07:05:47.002 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 00000005c6ea9393... #5 @ 2018-08-02T07:05:47.000 signed by eosio [trxs: 0, lib: 4, confirmed: 0]
2018-08-02T07:05:47.502 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 00000006331daf2d... #6 @ 2018-08-02T07:05:47.500 signed by eosio [trxs: 0, lib: 5, confirmed: 0]
2018-08-02T07:05:48.002 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 00000007a97091c1... #7 @ 2018-08-02T07:05:48.000 signed by eosio [trxs: 0, lib: 6, confirmed: 0]
2018-08-02T07:05:48.501 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 0000000833bd7cff... #8 @ 2018-08-02T07:05:48.500 signed by eosio [trxs: 0, lib: 7, confirmed: 0]
2018-08-02T07:05:49.004 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 00000009615fae7f... #9 @ 2018-08-02T07:05:49.000 signed by eosio [trxs: 0, lib: 8, confirmed: 0]
2018-08-02T07:05:49.534 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 0000000a09f88d83... #10 @ 2018-08-02T07:05:49.500 signed by eosio [trxs: 0, lib: 9, confirmed: 0]
2018-08-02T07:05:50.001 thread-0 producer_plugin.cpp:1196 produce_block ] Produced block 0000000bba286721... #11 @ 2018-08-02T07:05:50.000 signed by eosio [trxs: 0, lib: 10, confirmed: 0]