Linux或者Mac环境安装Photon network

官方安装文档:
https://photonnetwork.readthedocs.io/en/latest/installation_guide/

下载源码:
https://github.com/SmartMeshFoundation/Spectrum
https://github.com/SmartMeshFoundation/Photon

流程是:
1,go安装及配置
2,安装运行spectrum
3,下载运行photon

GO安装及配置

  • 下载地址 https://golang.org/dl/

  • 进行安装

    步骤:打开终端  → 进入local目录 → 下载压缩包 → 
         解压到当前目录 → 删除压缩包 → 创建gopath(后续开发项目目录) → 
         进入gopath → 创建 bin src pkg
    
    #Linux执行
    注意: 必须安装在 /usr/local/ 目录下,因为GOROOT必须为/usr/local/go
    cd /usr/local
    wget https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gz   
    tar zxvf go go1.9.7.linux-amd64.tar.gz
    rm go1.9.7.linux-amd64.tar.gz   
    mkdir gopath
    cd gopath
    mkdir -p bin src pkg
    
    

GO环境变量配置

  • 配置环境

     vim ~/.bashrc
     vim /etc/profile
    #尾部添加,全是大写
    #根目录
    export GOROOT=/usr/local/go
    #bin目录
    export GOBIN=$GOROOT/bin
    #工作目录
    export GOPATH=/usr/local/gopath
    export PATH=$PATH:$GOPATH:$GOBIN:$GOPATH
    
    #退出保存,
    source ~/.bashrc生效
    #执行
    go env
    
    

安装运行Spectrum链

详细教程如下:
Spectrum链开发 -- Mac开发环境搭建
https://www.jianshu.com/p/078ccfcfb001

Spectrum链开发--Linux环境搭建
https://www.jianshu.com/p/92d067c44b3c

启动Spectrum链:

mkdir smclog testnetdata

 ls
Photon  smc  smc-linux-amd64  smc-linux-amd64-0.5.1.tar.gz  smclog  Spectrum  testnetdata

sudo ./smc-linux-amd64  --datadir=/home/ubuntu/testnetdata/ --testnet --ws --wsapi  "eth,admin,web3,net,debug,personal"   --rpc  --rpccorsdomain "*" --rpcapi "eth,admin,web3,net,debug,personal"   --wsaddr "0.0.0.0" --rpcaddr "0.0.0.0"   --wsorigins "*" console
INFO [10-30|18:29:47] Starting peer-to-peer node               instance=Smc/v0.5.1-release-f085b369/linux-amd64/go1.10.1
INFO [10-30|18:29:47] Allocated cache and file handles         database=/home/ubuntu/testnetdata/smc/chaindata cache=128 handles=1024
INFO [10-30|18:29:47] Initialised chain configuration          config="{ChainID: 3 Homestead: 0 DAO:  DAOSupport: true EIP150:  EIP155: 0 EIP158: 0 Byzantium: 62678 Engine: tribe}"
INFO [10-30|18:29:47] Initialising Ethereum protocol           versions="[63 62]" network=3
INFO [10-30|18:29:47] Loaded most recent local header          number=1207096 hash=5c7bd6…488789 td=3066556
INFO [10-30|18:29:47] Loaded most recent local full block      number=1207096 hash=5c7bd6…488789 td=3066556
INFO [10-30|18:29:47] Loaded most recent local fast block      number=1207096 hash=5c7bd6…488789 td=3066556
INFO [10-30|18:29:47] Loaded local transaction journal         transactions=0 dropped=0
INFO [10-30|18:29:47] Regenerated local transaction journal    transactions=0 accounts=0
WARN [10-30|18:29:47] Blockchain not empty, fast sync disabled 
INFO [10-30|18:29:47] Starting P2P networking 
INFO [10-30|18:29:49] UDP listener up                          self=enode://7d2541c024906b566e9399694a5e12c238d1733cf47c5adee60ec6fcc542d1d544d003c03c462b1aa850fc9b41c6627ae7e3f9285f6b28c7ef5b6053dcec25a9@[::]:60303
INFO [10-30|18:29:49] HTTP endpoint opened: http://0.0.0.0:18545 
INFO [10-30|18:29:49] WebSocket endpoint opened: ws://[::]:18546 
INFO [10-30|18:29:49] RLPx listener up                         self=enode://7d2541c024906b566e9399694a5e12c238d1733cf47c5adee60ec6fcc542d1d544d003c03c462b1aa850fc9b41c6627ae7e3f9285f6b28c7ef5b6053dcec25a9@[::]:60303
INFO [10-30|18:29:49] init tribe.status when chiefservice start end. getnodekey=true
INFO [10-30|18:29:49] IPC endpoint opened: /home/ubuntu/testnetdata/smc.ipc 
INFO [10-30|18:29:49] init tribe.status success. 
Welcome to the Geth JavaScript console!

instance: Smc/v0.5.1-release-f085b369/linux-amd64/go1.10.1
coinbase: 0xbcb48ef81630c6ca138eebbb8dabb938ec464ff9
at block: 1207096 (Tue, 30 Oct 2018 18:05:55 CST)
 datadir: /home/ubuntu/testnetdata
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 tribe:1.0 txpool:1.0 web3:1.0

> INFO [10-30|18:29:59] Block synchronisation started 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::: ORIGIN ::: origin= 1207096 height= 1207199
::: ORIGIN ::: d.syncStatsChainHeight= 1207199 current= 1207096
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
---- FullSync ---->
INFO [10-30|18:30:00] -> num=1207098 , diff=3 , hash=0x519146afa188bc868347f86fc5eefda47d27e07f2d020d75f504edee514d0f82 , miner=0x4110bD1fF0b73fa12C259acF39C950277f266787 
INFO [10-30|18:30:00] [ downloader ] ==> importBlockResults() 1207097 --> 1207098. 

安装运行Photon 光子网路

go get github.com/SmartMeshFoundation/Photon/
cd /usr/local/gopath/github.com/SmartMeshFoundation/Photon/

ubuntu@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon$ ls
accounts        encoding           mkdocs.yml    photonService.go  smoketest.sh
ackhelper.go    eventhandler.go    mobile        README.md         testdata
blockchain      feepolicy.go       models        req.go            transfer
channel         goclean.sh         network       rerr              utils
cmd             internal           notify        restful           vendor
codefortest     log                params        restore.go
codefortest.go  Makefile           pfsproxy      rungotest.sh
docs            messagehandler.go  photonapi.go  runpprof.sh


更新到最新的代码:
root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon# git pull
remote: Enumerating objects: 41, done.
remote: Counting objects: 100% (41/41), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 41 (delta 20), reused 40 (delta 20), pack-reused 0
Unpacking objects: 100% (41/41), done.
From https://github.com/SmartMeshFoundation/Photon
   9c0f89b..90602a9  master     -> origin/master
 * [new tag]         v0.91      -> v0.91
Updating 9c0f89b..90602a9
Fast-forward
 Makefile                    |  3 ++-
 cmd/photon/build.sh         |  9 +++++++++
 cmd/photon/buildall.sh      | 30 ++++++++++++++++++++++++++++++
 cmd/photon/mainimpl/impl.go |  7 +++++--
 docs/installation_guide.md  |  7 +++++--
 docs/mobile_api_zh.md       |  2 +-
 mobile/build.sh             | 19 +++++++------------
 mobile/build_android.sh     | 10 ++++------
 mobile/build_iOS.sh         |  8 ++------
 9 files changed, 65 insertions(+), 30 deletions(-)
 create mode 100755 cmd/photon/build.sh
 create mode 100755 cmd/photon/buildall.sh

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon# ls
accounts      cmd             encoding         internal           mkdocs.yml  notify        photonService.go  restful       smoketest.sh  vendor
ackhelper.go  codefortest     eventhandler.go  log                mobile      params        README.md         restore.go    testdata
blockchain    codefortest.go  feepolicy.go     Makefile           models      pfsproxy      req.go            rungotest.sh  transfer
channel       docs            goclean.sh       messagehandler.go  network     photonapi.go  rerr              runpprof.sh   utils

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon# cd cmd/photon/

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/cmd/photon# ls
buildall.sh  build.sh  main.go  mainimpl
root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/cmd/photon# ./build.sh 
90602a99958e25b71218784bb3ba9254de790675
root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/cmd/photon# ls
buildall.sh  build.sh  main.go  mainimpl  photon

photon即我们的可执行文件

或者
wget https://github.com/SmartMeshFoundation/Photon/releases 目录获得最新编译的程序
Linux或者Mac环境安装Photon network_第1张图片
屏幕快照 2018-10-31 上午11.06.01.png

编译生成iOS或者安卓的sdk

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/mobile# ls
api.go  build_android.sh  build_iOS.sh  build.sh  main.go  mobile_test.go  primitives.go
root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/mobile# ./build_iOS.sh 
90602a99958e25b71218784bb3ba9254de790675
goversiongo1.9.7linux/amd64
TueOct30145225CST2018

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/mobile# ./build_android.sh 
90602a99958e25b71218784bb3ba9254de790675
goversiongo1.9.7linux/amd64
TueOct30145238CST2018
0.91

运行Photon

在keystore创建密码登录密码,spectrum创建的用户名
cd /home/ubuntu/testnetdata/keystore
UTC--2018-10-30T07-26-23.224590191Z--9dabc8a16b179b9521c68243200492a5ca0e5630
输入spectrum创建的用户名密码
root@VM-0-16-ubuntu:/home/ubuntu/testnetdata/keystore# touch pass.txt
root@VM-0-16-ubuntu:/home/ubuntu/testnetdata/keystore# ls
pass.txt
UTC--2018-10-30T07-26-23.224590191Z--9dabc8a16b179b9521c68243200492a5ca0e5630
root@VM-0-16-ubuntu:/home/ubuntu/testnetdata/keystore# vi pass.txt 
root@VM-0-16-ubuntu:/home/ubuntu/testnetdata/keystore# ls
pass.txt
UTC--2018-10-30T07-26-23.224590191Z--9dabc8a16b179b9521c68243200492a5ca0e5630
root@VM-0-16-ubuntu:/home/ubuntu/testnetdata/keystore# ls
pass.txt
UTC--2018-10-30T07-26-23.224590191Z--9dabc8a16b179b9521c68243200492a5ca0e5630

启动命令详解:

root@VM-0-16-ubuntu:/usr/local/gopath/src/github.com/SmartMeshFoundation/Photon/cmd/photon# ./photon -help
GoVersion=goversiongo1.9.7linux/amd64
GitCommit=90602a99958e25b71218784bb3ba9254de790675
builddate=TueOct3014:49:49CST2018Version=0.91
os.args=["photon" "-help"]
photon [global options] command [command options] [arguments...]

VERSION:
   0.91

COMMANDS:
   help  Shows a list of commands or help for one command
   
GLOBAL OPTIONS:
   --address value                             The ethereum address you would like photon to use and for which a keystore file exists in your local system.
   --keystore-path "/root/.ethereum/keystore"  If you have a non-standard path for the ethereum keystore directory provide it using this argument. 
   --eth-rpc-endpoint value                    "host:port" address of ethereum JSON-RPC server.\n'
                                                          'Also accepts a protocol prefix (ws:// or ipc channel) with optional port', (default: "/root/.ethereum/geth.ipc")
   --registry-contract-address value           hex encoded address of the registry contract.
   --listen-address value                      "host:port" for the photon service to listen on. (default: "0.0.0.0:40001")
   --api-address value                         host:port" for the RPC server to listen on. (default: "127.0.0.1:5001")
   --datadir "/root/.photon"                   Directory for storing photon data.
   --password-file value                       Text file containing password for provided account
   --debugcrash                                enable debug crash feature
   --conditionquit value                       quit at specified point for test
   --nonetwork                                 disable network, for example ,when we want to settle all channels
   --fee                                       enable mediation fee
   --xmpp                                      use xmpp as transport
   --xmpp-server value                         use another xmpp server  (default: "193.112.248.133:5222")
   --ignore-mediatednode-request               this node doesn't work as a mediated node, only work as sender or receiver
   --enable-health-check                       enable health check
   --matrix-server value                       use another matrix server
   --matrix                                    use matrix as transport
   --reveal-timeout value                      channels' reveal timeout, default 10 (default: 10)
   --pfs value                                 pathfinder service host
   --verbosity value                           Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=trace (default: 3)
   --vmodule value                             Per-module verbosity: comma-separated list of = (e.g. eth/*=5,p2p=4)
   --backtrace value                           Request a stack trace at a specific logging statement (e.g. "block.go:271")
   --debug                                     Prepends log messages with call-site location (file and line number)
   --pprof                                     Enable the pprof HTTP server
   --pprofaddr value                           pprof HTTP server listening interface (default: "127.0.0.1")
   --pprofport value                           pprof HTTP server listening port (default: 6060)
   --memprofilerate value                      Turn on memory profiling with the given rate (default: 524288)
   --blockprofilerate value                    Turn on block profiling with the given rate (default: 0)
   --cpuprofile value                          Write CPU profile to the given file
   --trace value                               Write execution trace to the given file
   --logfile value                             redirect log to this the given file
   --help, -h                                  show help
   --version, -v                               print the version

sudo ./photon --datadir=.photon --api-address=0.0.0.0:5001 --listen-address=0.0.0.0:40001 --address=9dabc8a16b179b9521c68243200492a5ca0e5630 --keystore-path /home/ubuntu/testnetdata/keystore --registry-contract-address 0xb3aE919aB595f5844cba80499ee6423688E06F89 --password-file jianghua --eth-rpc-endpoint ws://0.0.0.0:18546

--datadir 缓存目录
--eth-rpc-endpoint 这个参数是是smc节点的ip,如果是本地节点ws://0.0.0.0:18546是可以的,如果部署在服务器上,缓存运行smc的ip既可。


sudo ./photon --datadir=.photon --api-address=0.0.0.0:5001 --listen-address=192.168.0.145:40001 --address=9dabc8a16b179b9521c68243200492a5ca0e5630 --keystore-path /home/ubuntu/testnetdata/keystore --registry-contract-address 0xb3aE919aB595f5844cba80499ee6423688E06F89 --password-file jianghua --eth-rpc-endpoint ws://0.0.0.0:18546
GoVersion=goversiongo1.9.7linux/amd64
GitCommit=90602a99958e25b71218784bb3ba9254de790675
builddate=TueOct3014:49:49CST2018Version=0.91
os.args=["photon" "--datadir=.photon" "--api-address=0.0.0.0:5001" "--listen-address=192.168.0.145:40001" "--address=9dabc8a16b179b9521c68243200492a5ca0e5630" "--keystore-path" "/home/ubuntu/testnetdata/keystore" "--registry-contract-address" "0xb3aE919aB595f5844cba80499ee6423688E06F89" "--password-file" "jianghua" "--eth-rpc-endpoint" "ws://0.0.0.0:18546"]
INFO [10-30|17:37:50.303] Welcome to photon,version 0.91
 
INFO [10-30|17:37:50.303] os.args=["photon" "--datadir=.photon" "--api-address=0.0.0.0:5001" "--listen-address=192.168.0.145:40001" "--address=9dabc8a16b179b9521c68243200492a5ca0e5630" "--keystore-path" "/home/ubuntu/testnetdata/keystore" "--registry-contract-address" "0xb3aE919aB595f5844cba80499ee6423688E06F89" "--password-file" "jianghua" "--eth-rpc-endpoint" "ws://0.0.0.0:18546"] 
INFO [10-30|17:37:51.384] Start with account 0x9DAbC8A16B179B9521c68243200492A5ca0e5630 
2018/10/30 17:37:51 [impl.go:198] [I] ethclient connection status changed from 0 to 1
INFO [10-30|17:37:51.419] create photon service registry=0xb3aE919aB595f5844cba80499ee6423688E06F89,node=0x9DAbC8A16B179B9521c68243200492A5ca0e5630 
ERROR[10-30|17:37:51.422] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
INFO [10-30|17:37:51.668] changeStatus from 0 to 1                 matrix=9dab
ERROR[10-30|17:37:52.422] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
INFO [10-30|17:37:53.331] get state change since 0 
WARN [10-30|17:37:53.337] AlarmTask missed 1206974 blocks 
ERROR[10-30|17:37:53.423] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
ERROR[10-30|17:37:54.423] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
INFO [10-30|17:37:55.403] NewTokenAdd token=0xF0123C3267Af5CbBFAB985d39171f5F5758C0900,tokennetwork=0x3b5AdD6F9164B51DB2Ee0126D43Df06207d91f5d 
INFO [10-30|17:37:55.403] Photon Startup complete and history events process complete. 
INFO [10-30|17:37:55.409] NewChannel tokenNetwork=3b5a,token=f012,participant1=e011,participant2=8330 
INFO [10-30|17:37:55.415] NewChannel tokenNetwork=3b5a,token=f012,participant1=e011,participant2=d8d7 
INFO [10-30|17:37:55.423] NewChannel tokenNetwork=3b5a,token=f012,participant1=fb07,participant2=e011 
ERROR[10-30|17:37:55.423] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
INFO [10-30|17:37:55.426] NewChannel tokenNetwork=3b5a,token=f012,participant1=70ae,participant2=810a 
INFO [10-30|17:37:55.432] NewChannel tokenNetwork=3b5a,token=f012,participant1=fb07,participant2=e5a8 
INFO [10-30|17:37:55.437] NewChannel tokenNetwork=3b5a,token=f012,participant1=fb07,participant2=e011 
INFO [10-30|17:37:55.441] NewChannel tokenNetwork=3b5a,token=f012,participant1=e5a8,participant2=e011 
INFO [10-30|17:37:55.453] NewChannel tokenNetwork=3b5a,token=f012,participant1=fb07,participant2=d8d7 
INFO [10-30|17:37:55.456] NewChannel tokenNetwork=3b5a,token=f012,participant1=e5a8,participant2=d8d7 
ERROR[10-30|17:37:56.424] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
ERROR[10-30|17:37:57.424] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 
ERROR[10-30|17:37:58.424] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address 

错误总结

1,tyring to reconnect geth

Linux或者Mac环境安装Photon network_第2张图片
image.png

解决方案:查看启动spectrum的时候,没有启动HTTP endpoint opened的18545和webSocket的服务。

Linux或者Mac环境安装Photon network_第3张图片
image

2,启动smartRaiden时候,cannot create or open db,makesure you have write permission
Linux或者Mac环境安装Photon network_第4张图片
image

解决方案:1,清空spectrum的节点datadir缓存数据,2,关闭terminal,3,重新启动spectrum和smartRaiden。

3,spectrum一直卡着没动
Linux或者Mac环境安装Photon network_第5张图片
image

解决方案:情况的spectrum节点缓存datadir里面的数据,每次启动spectrum他都会同步节点数据。

4,没有链上公链

Linux或者Mac环境安装Photon network_第6张图片
image.png

解决方案:查看spectrum公链运行情况。

5,ERROR[10-30|17:39:50.463] listen udp 192.168.0.145:40001 error listen udp 192.168.0.145:40001: bind: cannot assign requested address

屏幕快照 2018-10-31 下午12.01.52.png

解决方案:
--listen-address=192.168.0.145:40001换成0.0.0.0:40001
--eth-rpc-endpoint 这个参数是是smc节点的ip,如果是本地节点ws://0.0.0.0:18546是可以的,如果部署在服务器上,缓存运行smc的ip既可。

你可能感兴趣的:(Linux或者Mac环境安装Photon network)