# 私链搭建（单机多节点）

## 最终创建两个生产节点的私链

## 开启钱包服务节点

```bash
#建议只在本地监听，因为密钥传输是不加密的
keosd --http-server-address 127.0.0.1:8899
#直接输出
2042116ms thread-0   wallet_plugin.cpp:41          plugin_initialize    ] initializing wallet plugin
2042120ms thread-0   http_plugin.cpp:141           plugin_initialize    ] host: 127.0.0.1 port: 8899
2042121ms thread-0   http_plugin.cpp:144           plugin_initialize    ] configured http to listen on 127.0.0.1:8899
2042122ms thread-0   http_plugin.cpp:213           plugin_startup       ] start listening for http requests
2042123ms thread-0   wallet_api_plugin.cpp:70      plugin_startup       ] starting wallet_api_plugin
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/create
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/get_public_keys
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/import_key
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/list_keys
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/list_wallets
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/lock
2042127ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/lock_all
2042128ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/open
2042128ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/set_timeout
2042128ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/sign_transaction
2042128ms thread-0   http_plugin.cpp:242           add_handler          ] add api url: /v1/wallet/unlock\
#后输出的
2167622ms thread-0   wallet.cpp:182                save_wallet_file     ] saving wallet to file /home/hiup/eosio-wallet/./default.wallet
3194752ms thread-0   wallet.cpp:182                save_wallet_file     ] saving wallet to file /home/hiup/eosio-wallet/./default.wallet
```

## 创建一个默认钱包

```bash
cleos --wallet-port 8899  wallet create

#记住输出的私钥
"PW5JMmtnJxaUiEwwSLVSrA9UTxSzypnxVkhRtKA1QeSAQm25LU8Dx"
```

## 创建第一个生产节点

```bash
#第一个节点叫eosio
nodeos --enable-stale-production --producer-name eosio --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin
#不停输出区块信息
eosio generated block 36cd7280... #7030 @ 2018-04-16T03:36:09.000 with 0 trxs, lib: 7029
eosio generated block a135dfcc... #7031 @ 2018-04-16T03:36:09.500 with 0 trxs, lib: 7030
eosio generated block 6b6e8f9d... #7032 @ 2018-04-16T03:36:10.000 with 0 trxs, lib: 7031
eosio generated block 26f1a273... #7033 @ 2018-04-16T03:36:10.500 with 0 trxs, lib: 7032
eosio generated block 797bdc13... #7034 @ 2018-04-16T03:36:11.000 with 0 trxs, lib: 7033
```

## 创建第二个生产节点

```bash
#加载智能合约
cleos --wallet-port 8899 set contract eosio ../eos/build/contracts/eosio.bios
Reading WAST/WASM from ../eos/build/contracts/eosio.bios/eosio.bios.wast...
Assembling WASM...
Publishing contract...
executed transaction: 684d83f376333d381841d79931b0c820698a3f2cadb11080169bc5504d1eff8b  3280 bytes  2200576 cycles
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001581060037f7e7f0060057f7e7e7e7e...
#         eosio <= eosio::setabi                {"account":"eosio","abi":{"types":[],"structs":[{"name":"set_account_limits","base":"","fields":[{"n...

#创建密钥对
cleos create key
Private key: 5JaN9LSpwuqY89KbtiJHQDdngQztDyB9XZHz2KC6QxP7xn9NUeN
Public key: EOS5BTsWP7hC7wAeUuoo6Q3LBTjiPLoEAM6hY51ujDEzsq7UNfex2

#导入密钥对到钱包
cleos --wallet-port 8899 wallet import 5JaN9LSpwuqY89KbtiJHQDdngQztDyB9XZHz2KC6QxP7xn9NUeN

#创建新用户test2
./cleos --wallet-port 8899 create account eosio test2 EOS5BTsWP7hC7wAeUuoo6Q3LBTjiPLoEAM6hY51ujDEzsq7UNfex2 EOS5BTsWP7hC7wAeUuoo6Q3LBTjiPLoEAM6hY51ujDEzsq7UNfex2
executed transaction: 431d872ad07764b912c1eca32e50e01bd0dac26113f6545054b453a1b5330daf  352 bytes  102400 cycles
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"test2","owner":{"threshold":1,"keys":[{"key":"EOS5BTsWP7hC7wAeUuoo6Q3LBTj...

#开启用户test2的生产
#避免了端口冲突
./nodeos --producer-name test2 --plugin eosio::chain_api_plugin --plugin eosio::net_api_plugin --http-server-address 127.0.0.1:8889 --p2p-listen-endpoint 127.0.0.1:9877 --p2p-peer-address 127.0.0.1:9876 --config-dir node2 --data-dir node2 --private-key [\"EOS5BTsWP7hC7wAeUuoo6Q3LBTjiPLoEAM6hY51ujDEzsq7UNfex2\",\"5JaN9LSpwuqY89KbtiJHQDdngQztDyB9XZHz2KC6QxP7xn9NUeN\"]
test2 generated block b6fe0ecd... #7978 @ 2018-04-16T03:44:03.000 with 0 trxs, lib: 7977
test2 generated block 85f9b073... #7979 @ 2018-04-16T03:44:03.500 with 0 trxs, lib: 7978
test2 generated block 36066d05... #7980 @ 2018-04-16T03:44:04.000 with 0 trxs, lib: 7979
test2 generated block 1d5314fa... #7981 @ 2018-04-16T03:44:04.500 with 0 trxs, lib: 7980
test2 generated block b5410853... #7982 @ 2018-04-16T03:44:05.000 with 0 trxs, lib: 7981
```

## 激活test2用户

```bash
./cleos --wallet-port 8899 push action eosio setprods "{ \"version\": 1, \"producers\": [{\"producer_name\": \"test2\",\"block_signing_key\": \"EOS5BTsWP7hC7wAeUuoo6Q3LBTjiPLoEAM6hY51ujDEzsq7UNfex2\"}]}" -p eosio@active
executed transaction: 8644f6707157ecceae7397000234e1725d2f18a39a53de27e1b375e6b5b85d1f  272 bytes  105472 cycles
#         eosio <= eosio::setprods              {"version":1,"producers":[{"producer_name":"test2","block_signing_key":"EOS5BTsWP7hC7wAeUuoo6Q3LBTji...

```

## 状态检查

```
#节点1
./cleos get info
{
  "server_version": "74a4c7a0",
  "head_block_num": 7715,
  "last_irreversible_block_num": 7714,
  "head_block_id": "00001e23e240c450f2bf1b747ea64eba97f8ffd784f6a8e63daae279a386ab9d",
  "head_block_time": "2018-04-16T03:41:51",
  "head_block_producer": "test2"
}


#节点2
./cleos --port 8889 get info
{
  "server_version": "74a4c7a0",
  "head_block_num": 7770,
  "last_irreversible_block_num": 7769,
  "head_block_id": "00001e5a78fd1fca6b21c823e51b50f0d7984d1ff5eb0e297a48d2bd1b610b52",
  "head_block_time": "2018-04-16T03:42:19",
  "head_block_producer": "test2"
```

## 完结


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://neochain.gitbook.io/project/eos/si-lian-da-jian-dan-ji-duo-jie-dian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
