EOS私有链搭建

参考文章https://www.jianshu.com/p/f5b90a82e969

源码下载

git clone https://github.com/EOSIO/eos.git --recursive

编译源码

cd eos
./eosio_install.sh
./eosio_build.sh

如果内存低于7G,需要修改配置

vim scripts/eosio_build_ubuntu.sh

if [ "${MEM_MEG}" -lt 7000 ]; then  

如果你的物理内存是4G ,可以把7000改成3000
如果磁盘过低,也需要修改磁盘配置

启动第一个节点

1.在源码外创建一个目录,并在目录里创建data目录和config目录,data用于存放eos运行过程中的数据,config目录用于存放config.ini和genesis.json文件。
2.修改config.ini文件和genesis.json文件

config.ini

#blocks-dir = "blocks"   区块目录,建议屏蔽,自己指定
http-server-address = 0.0.0.0:8888   #http服务器本地监听
p2p-server-address = 192.168.1.132:9898   #配置本地为p2p服务器
p2p-listen-endpoint = 0.0.0.0:9898    #本地节点监听
p2p-peer-address = 192.168.1.132:9898  #其他超级节点,可以配置多个   
agent-name = "EOS Test Agent"  #名称,可以随意修改
allowed-connection = any   #允许任意节点连接
enable-stale-production = true    #第一节点配置为true,允许直接出块,其他超级节点配置为false
max-transaction-time = 1000   #防止部署合约失败,此配置设置为1000
producer-name = eosio   #本节点的账户名称,eosio为创世节点名称,后面几个节点名称分别为inita,initb,initc由自己设定,这些账户在下面脚本中创建
#节点密钥对,eosio节点配置为genesis.json对应公钥即可
signature-provider = EOS5xXJ8LkHDhJWHC5HKz8y9nhq5UaZgxzDMdGbiufrrJXwcCHzH8=KEY:5KMmKcSh4cNWLvASoKqVzoKgC8Gn953byfZnzrVS2XeXirRrVWm  

#文件末尾加上相关插件
plugin = eosio::chain_api_plugin
plugin = eosio::history_api_plugin
plugin = eosio::chain_plugin
plugin = eosio::producer_plugin
plugin = eosio::http_plugin
plugin = eosio::net_plugin
plugin = eosio::net_api_plugin

genesis.json

创世文件,所有节点保存一致。https://github.com/EOSIO/eos/blob/master/tutorials/bios-boot-tutorial/genesis.json

#如果不能出块,可以先运行一次eosio节点,再回填
"initial_timestamp": "2018-12-13T02:02:13.066",    
 #创世区块节点的公钥,必须和源码里的地址一致(不过改了好像改了也可以)
"initial_key": "EOS5xXJ8LkHDhJWHC5HKz8y9nhq5UaZgxzDMdGbiufrrJXwcCHzH8",  
"initial_chain_id": 
"0000000000000000000345000000000000000000000000000000000000000000"    #随意填写

修改完配置文件后,可以启动节点了:

nodeos  --data-dir ./data --config-dir ./config  --genesis-json  ./config/genesis.json

节点启动后就会不断出块了,0.5S一个块。私有链就算是搭起来了,接下来就可以去创建自己的钱包、账户、发行系统代币了。

#创建10对密钥 cleos create key --to-console
#创建钱包 cleos wallet create -n eosio.wallet --to-console   密钥未:"PW5KJ9Jsw4v9qZz4LbD68YUr922Ro9wT1YQdj7MUDbEUr9nDPaptt"  要记住钱包密码
#解锁钱包
echo "wallet unlock ..."
cleos wallet unlock -n eosio.wallet --password PW5KBgBrHyoqY8KiYiAR3NvCDPhfq7LCeYTUAhKHzFo9z1B5TJAxc
#导入私钥
echo "wallet import ..."
cleos wallet import -n eosio.wallet --private-key 5JzEdUHZ57jPdTNPpAANnzLQpBf6cv26qV3SJe66QreD4GxEKfD
cleos wallet import -n eosio.wallet --private-key 5KDj65fFcTuQTDDrFomyWb19QoSjEaJJjrJdswmz4VLZkai8ZuT
cleos wallet import -n eosio.wallet --private-key 5JWVi9KdZ273tFyNFxiogUnKMnncxaFdMcYTyb3FFaQEYpMGwbV
cleos wallet import -n eosio.wallet --private-key 5Hpoeryo4brkpBc5utR1bdTubLBhANreEDbXQiDsJaBhcPPuMzV
cleos wallet import -n eosio.wallet --private-key 5J4hmSkbGPHW6CK9i3Y8pb7tzxvoM19T2g5fdNtY7TdpHS4yXX4
cleos wallet import -n eosio.wallet --private-key 5HsEdJM6meYM2guGJrSDkMGLfJcCyEvBseuqChNfGepcFncZWKQ
cleos wallet import -n eosio.wallet --private-key 5KPhYWxhicE8QjsumzHcqpw29B1LchjDHWUZPP9WLiHG94hJBDp
cleos wallet import -n eosio.wallet --private-key 5HqyxVv5tJ2Kjug6owA1CwrhDxMSwNVF3kEh7FHUzfSfEWBRygK
cleos wallet import -n eosio.wallet --private-key 5JbE3wT7o8Dj8crE8gL9eCE7XzXdNeV5NpLba1UjQhmv6gY5btv
cleos wallet import -n eosio.wallet --private-key 5Jdvw42rZg2JTdMxm2ZFATKuw9cq26LYn7Ek2aGywkuW99ZSxQN
cleos wallet import -n eosio.wallet --private-key 5KaJVpBPA89THFz3cpyxGRVgUadf31BdLwWVVrPYtah2z5PoP8c
cleos wallet import -n eosio.wallet --private-key 5JsNaoqmkuMWz6KPqNJkBnAw5ZdtW5iTdzzdgbn3Z8B72Gne3ML
cleos wallet import -n eosio.wallet --private-key 5JSEBVXW6wHX87p8BYbAJDpH7gXJ4C2AXMyXUyPXhCBkTDeVwi6
cleos wallet import -n eosio.wallet --private-key 5Kk5vAvANhp4QWghAQfeos5qoB7GHwxfq8iTii15UxHzCjiZMcz
cleos wallet import -n eosio.wallet --private-key 5JL9bpLQ74VvoxqRGHXP9TRQpJ3TutAR4jxJq8vQJTbEkQ75Zps
cleos wallet import -n eosio.wallet --private-key 5JKkLotKioZWb2vLYxaWjcQZRGYggWCFJbPjP47oeHcYztoATFc
cleos wallet import -n eosio.wallet --private-key 5HuMZmdxEX8Gokwsp6pYEzfaxyVgaZZJcw4zmSvCHYAXZ3vGtFU
cleos wallet import -n eosio.wallet --private-key 5JZu7FKANH5BJKTzzEMKYRUPpFfnpQRQDZpGWJtmapyXguEGRCo
cleos wallet import -n eosio.wallet --private-key 5JL2fQo4eZKJrJCis791yCr2gvLzhJbw3kfD7iJSD1p6zG25sHj
cleos wallet import -n eosio.wallet --private-key 5KTsJSfMCtPjKw4J8fL2xYV3eP5eL6Hgz4h5YoQTfrkg2zuiVTU
cleos wallet import -n eosio.wallet --private-key 5KMwpdSHUAZT3MnwHKeH3fNHua8VokgWjgiincg6ixdnpLyXWW5
cleos wallet import -n eosio.wallet --private-key 5Jhs8DJzEXm9YkFYWhU6SkthLNiYsv1A3RWLJnu5XMF32fRVuAP
cleos wallet import -n eosio.wallet --private-key 5JPn51WyR63aHTZ5mnr3aY5aSjn4azvRnohWY6MvDpzFcaSnBwK
cleos wallet import -n eosio.wallet --private-key 5J9cGrc72NoEbSYoVEQCqvYDiv3fG8MN23BeEoWPbHPGJ5vRe2A
#创建系统代币
echo "create eosio.token ..."
sleep 2
#通过eosio账户创建eosio.token系统代币账户。(创建之前需要往钱包中插入eosio账户的私钥,这里的eosio账户私钥在config.ini文件中有。没有插入会没有权限而报错)
cleos create account eosio eosio.token EOS52VT7jeKKP71RWaEcLEhaoSfT86tnVYkrRERXAAuqCZmNjfJke EOS6mnRRwZ26qUe6SbCtJs6ch6aJTvY8X26vKypP4qkHcDmP5BjYU
sleep 2
cleos set contract eosio.token /root/eos-src/eos/build/contracts/eosio.token/
sleep 2
cleos  push action eosio.token create '["eosio","1000000000.0000 SYS",0,0,0]' -p eosio.token
sleep 2
cleos  push action eosio.token issue '["eosio","1000000000.0000 SYS","issue"]' -p eosio
创建9个系统账户
echo "create 9 eosio..."
cleos create account eosio eosio.bpay EOS8PMqhqJVm9G3nqYiNtYsP3x2Kvx955Yaz3idrhe5mSVVE6WAcy EOS5H7z2jKMmLbk9Q1LGLivn88PHXBGEpw6a3m9VVeZa15sW8Aanp
cleos create account eosio eosio.msig EOS6UZGR6MYYbMtpsPuF586XGnvbnUnLTrmFZrsacBVMNTTXf3DBh EOS8JBkp1oRqmbGBFs1wVUJUizGrWP93Cceo5aLmCpUvdqH7aXMmv
cleos create account eosio eosio.name EOS8G79TGTBpDPE5ZNbQLvRQJzLcXFSb4991aw8UJTEjFRTWfecry EOS59dYuDA4KiyecJ5eBNeq43X7GmXKSuJuZtDHgRDhG5y6Nu9Evb
cleos create account eosio eosio.names EOS7TfjDo7fTi5TLwWhzvKJjRwoSo8CYuj9mi8YwmFoDLBE5GHYs7 EOS5PZKeR3sGhyimNiXaRcn1xY9SzE3br78E8fz1uARcmvWoWvWry
cleos create account eosio eosio.ram EOS7UpH4rB1mkdZP43B3wHxKyrcQfB1Q674yhcTT1XJ3peyw7kH3i EOS5UgoMbihFgJ8RJyGEJhjm8gvZrH1uuvGWmyEXZWEwmt1VENC1e
cleos create account eosio eosio.ramfee EOS71wtJJMLfm5hnxTK3KJTSAZfrCHtk1awCgXxdGjL6ethSrHVrx EOS61fbgGb1nacyGNUUUkH8QBszNNRpPJoNhANdK74o5r5Uy9Q89M
cleos create account eosio eosio.saving EOS7ThT49aqseDtwjaJrTXbcsLn7Cmv2vXCzLKF65yaoDxjHSd5Jq EOS4ycHTjez57nhEa6Rg2TgD2gJLjKbXs2mVhuR1dEYCY8VoevF2D
cleos create account eosio eosio.stake EOS6BEiHYDUQeu3sGcqnYPajHQZRR6pjyyzoq8puHt32eJYfpCNcr EOS7sCv7XwXTGpYiat3TUWSk6cb66xfi1CcGhMrBsPQGraXgW3UEj
cleos create account eosio eosio.upay EOS5YQE9AEJXVRaddFrS1GBFEUeNStGoHGKnTQmyxaHSgVmav16J1 EOS7PsM6TqNER2QiRHsBnCHC3QS4uWCkjCicoatHvZzgoUGVZ7srN
#创建合约
echo "set contract ..."
sleep 6
cleos set contract eosio.msig  /root/eos-src/eos/build/contracts/eosio.msig/
sleep 6
cleos set contract eosio /root/eos-src/eos/build/contracts/eosio.system/
sleep 6
cleos  push action eosio setpriv '["eosio.msig", 1]' -p eosio@active
#创建3个超级节点账户
echo "new inita initb initc ..."
sleep 4
cleos system newaccount eosio inita EOS5VJv4YxPkv9asb5BfSHoDKSVnbuKfay3cNy2kcciELsCdDeqYB EOS6DyXgyTCTydr3GMxg34w7vmCErcWLjzYtvCeNFUyZR9YXCf1Gv --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
cleos system newaccount eosio initb EOS7P4K4wsKaDAkES6VSyFb6tAMRE5afkniB9jE4Sq9tqTy6yddHb EOS8N3kNs4eUrvFAnKCkjpzL4aou4mmcxJDZ9uoZpTFcvh7WhUxLm --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8 
cleos system newaccount eosio initc EOS534ZY8Qk6HCAKubu2prUGxbnsq7NqVq6gK8GWnbUh74w6fD7pG EOS7nNUJ9Nibw5uDYzjgKJ618YrD7yLBbAcxQXGmqJk4XjGRicDeg --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 8
#转账给超级节点系统币
echo "transfer SYS ..."
sleep 2
cleos  push action eosio.token transfer '["eosio", "inita","300000000.0000 SYS","vote"]' -p eosio
cleos  push action eosio.token transfer '["eosio", "initb","100000000.0000 SYS","vote"]' -p eosio
cleos  push action eosio.token transfer '["eosio", "initc","100000000.0000 SYS","vote"]' -p eosio
#echo "voteproducer ..."
#sleep 2
#cleos system delegatebw eosio inita  '300000000.0000 SYS' '300000000.0000 SYS'
#sleep 2
#cleos system delegatebw eosio initb  '100000000.0000 SYS' '100000000.0000 SYS'
#sleep 2
#cleos system delegatebw eosio initc  '100000000.0000 SYS' '100000000.0000 SYS'
#sleep 2
#cleos system voteproducer prods  eosio inita
#sleep 2
#cleos system voteproducer prods  eosio initb
#sleep 2
#cleos system voteproducer prods  eosio initc

你可能感兴趣的:(EOS私有链搭建)