本文中采用具体环境linux
若是机器上已经安装过Golang,则能够跳过此步骤。git
下载地址为:https://storage.googleapis.com/golang/go1.7.5.linux-amd64.tar.gzgithub
传送门golang
假定golang安装包的名称没有改过(名称为go1.7.5.linux-amd64.tar.gz)sql
打开Terminal,进入root用户模式,cd到安装包所在路径数据库
# 解压 tar zxf go1.7.5.linux-amd64.tar.gz # 移动解压后的go目录 mv go /usr/local/go # 配置环境变量 vim /etc/profile
在 /etc/profile 后面追加配置:vim
export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin
环境变量添加成功后,有两种方式使环境变量生效api
对于第二种方式,命令以下浏览器
source /etc/profile
上述步骤完成后,能够使用 go version 命令检查go环境时候安装成功bash
若是已经安装PostgreSQL,能够跳过此步骤
对于PostgresSQL的安装,咱们能够用最简单的方式安装,即 apt-get install 方式
apt-get install postgresql-9.5
命令执行结束后,能够使用以下命令查看安装PostgreSQL数据库的版本号
psql --version
为了稍后ChainCore使用数据库,咱们须要对数据库进行建立以及配置
打开Terminal,进入root用户模式
# 切换到postgres帐号 su postgres # 打开sql交互器 psql
在打开的sql交互器中,输入修改帐号密码的sql语句:
alter user postgres with password 'postgres';
修改为功后,会输出 ALTER ROLE
输入 Ctrl + D 组合键退出sql交互器
打开Terminal,进入root用户模式
# 切换到postgres帐号 su postgres # 建立一个名为core的数据库 createdb core
此步骤对于ChainCore源码方式安装不是必须的
打开Terminal,进入root用户模式
# 编辑postgresql配置文件 vim /etc/postgresql/9.5/main/postgresql.conf
在配置文件的 CONNECTIONS AND AUTHENTICATION 部分中,将注释的 #listen_addresses = 'localhost' 修改成以下配置:
listen_addresses = '*'
注意,#符号被删除,localhost改成*
接下来修改 pg_hba.conf 配置文件
vim /etc/postgresql/9.5/main/pg_hba.conf
在pg_hba.conf 配置文件添加一条配置,以下:
host all all 0.0.0.0/0 md5
完成后,重启postgres服务
# 重启 postgresql 服务 service postgresql restart
对于ProtoBuf的安装,只须要一条命令便可:
apt-get install protobuf-compiler
源码能够在ChainCore的GitHub上下载,转送门
目前ChainCore的最新release版本为1.0.2,下载传送门
假定咱们下载的ChainCore压缩包文件名为 chain-cmd.cored-1.0.2.tar.gz
# 解压源码压缩包 zxf chain-cmd.cored-1.0.2.tar.gz # 修改解压目录名称 mv chain-cmd.cored-1.0.2 chain # 建立目录来存放ChainCore源码 mkdir -p ~/chaincore/src # 移动解压的源码目录 mv chain ~/chaincore/src
完成后,确保你的ChainCore源码放在了 $HOME/chaincore/src/chain 目录下
使用以下命令配置用户环境变量
vim ~/.profile
在用户环境变量中,加入以下环境变量
# go 项目路径 export GOPATH=$HOME/chaincore # ChainCore 数据库链接URL export DATABASE_URL=postgres://postgres:postgres@localhost/core?sslmode=disable # Chain 路径 export CHAIN=$(go env GOPATH)/src/chain export PATH=$PATH:$(go env GOPATH)/bin:$CHAIN/bin
cd $CHAIN go install ./cmd/...
若是没有任何错误输出,则ChainCore编译成功
运行ChainCore很是简单,只须要用以下命令便可启动:
cored
当看到 Chain Core online and listening at :1999 时,ChainCore就已经启动成功了
打开数据库管理工具,能够看到 core 数据库中已经建立了几张数据表
咱们能够打开浏览器,访问 http://localhost:1999,便可以访问ChainCore提供的开发者看板工具。