一、postgersql安装配置
参考资料: https://www.postgresql.org/download/linux/ubuntu/
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-9.5
安装postgres完毕
#连接数据库
sudo -u postgres psql
#创建用户名和密码
create user stellar with password ‘wancloud’;
#创建stellar_core数据库和horizon数据库
create database stellar_core owner stellar;
create database horizon owner stellar;
#给用户赋予数据库权限
grant all privileges on database stellar_core to stellar;
grant all privileges on database horizon to stellar;
二、 stellar-core安装
#安装依赖包
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install git build-essential pkg-config autoconf automake libtool bison flex libpq-dev clang++-3.5 gcc-4.9 g++-4.9 cpp-4.9
#下载源代码(https://gitlab.wancloud.io/yuwd/stellar-core.git)
git clone https://github.com/stellar/stellar-core.git
cd stellar-core
#自动编译配置
git submodule init
git submodule update
./autogen.sh
./configure
#安装
make
make check
make install
#准备好配置文件,可以使用提供的样本stellar-core.cfg
stellar-core –genseed
#生成如下密钥对:
#Secret seed: SCFOO3QATON3DJDKTRAPGJDZGBEFVN6GV3KTB5Q6AEK5RTWNWX2RSB3M
#Public: GCWCZS5WH3HU4AEN7ABPTPDDRX5C6HMJIYCAYL43LL3J55VGGD6BVUZL
#修改配置文件,设置自己的种子秘钥
NODE_SEED="SCFOO3QATON3DJDKTRAPGJDZGBEFVN6GV3KTB5Q6AEK5RTWNWX2RSB3M"
NODE_IS_VALIDATOR=true
#设置数据配置
DATABASE="postgresql://dbname=stellar_core user=stellar password=wancloud host=localhost“
#配置数据存储路径
BUCKET_DIR_PATH="/home/ywd/stellar-core/buckets“
#设置http暴露接口
HTTP_PORT=11626
#设置和其他节点互联的端口
PEER_PORT=11625
#初始化数据库
stellar-core –newdb
#启动节点
stellar-core (后台启动:nohup stellar-core &)
三、horizon安装
#安装go,版本>1.6
sudo apt install golang-go
#安装gb
go get -u github.com/constabulary/gb/...
#下载horizon源文件(https://gitlab.wancloud.io/yuwd/horizon.git)
git clone https://github.com/stellar/horizon.git && cd horizon
#下载外部依赖(由于网络不稳定,可以直接把依赖horizon-vendor-src.zip解压到/horizon/src下,可以省掉下面步骤)
gb vendor restore
#构建二进制文件
gb build
cd bin && cp horizon /usr/local/bin
#$GOPATH配置环境变量为horizon的目录位置
#安装drienv读取配置文件至环境变量
mkdir -p $GOPATH/src/github.com/direnv
cd $GOPATH/src/github.com/direnv && git clone https://github.com/direnv/direnv.git
cd $GOPATH/src/github.com/direnv/direnv
make install
#安装redis
sudo apt-get install redis-server
#配置文件设置,参考提供的配置文件.envrc(备注有样板)
#horizon数据库配置
export DATABASE_URL="postgres://stellar:wancloud@localhost/horizon?sslmode=disable"
#stellar节点的数据库配置
export STELLAR_CORE_DATABASE_URL="postgres://stellar:wancloud@localhost/stellar_core?sslmode=disable"
#stellar mian-http
export STELLAR_CORE_URL="http://localhost:11626"
#redis端口配置
export REDIS_URL="redis://127.0.0.1:6379"
#日志级别配置("Debug", "Info", "Warn", "Error" or "Panic")
export LOG_LEVEL="debug"
#证书配置
export TLS_CERT=tls/public.crt
export TLS_KEY=tls/private.key
#端口配置
export PORT=8000
#加入配置项到环境变量
direnv allow
#初始化数据库
horizon db init
#启动
horizon (后台启动: nohup horizon &)
四、监控
#stellar-core节点启动查看状态
stellar-core –c ‘info’
显示如下,表示完成同步:
"info" : {
"UNSAFE_QUORUM" : "UNSAFE QUORUM ALLOWED",
"build" : "v0.6.2-78-gcc5ac0af",
"ledger" : {
"age" : 3,
"closeTime" : 1501236130,
"hash" : "89b6de83c6d75adce3f4338ba79f11f98dbc07f8444c8f47bcdd80b0e66314cc",
"num" : 2881151
},
"network" : "Test SDF Network ; September 2015",
"numPeers" : 4,
"protocol_version" : 8,
"quorum" : {
"2881150" : {
"agree" : 3,
"disagree" : 0,
"fail_at" : 2,
"hash" : "273af2",
"missing" : 0,
"phase" : "EXTERNALIZE"
}
},
"state" : "Synced!"
}
}
#horizon查看运行状态
https://192.168.191.185:8001/
显示如下:
{
"_links": {
"account": {
"href": "https://193.168.191.185:8001/accounts/{account_id}",
"templated": true
},
"account_transactions": {
"href": "https://193.168.191.185:8001/accounts/{account_id}/transactions{?cursor,limit,order}",
"templated": true
},
"friendbot": {
"href": "https://193.168.191.185:8001/friendbot{?addr}",
"templated": true
},
"metrics": {
"href": "https://193.168.191.185:8001/metrics"
},
"order_book": {
"href": "https://193.168.191.185:8001/order_book{?selling_asset_type,selling_asset_code,selling_issuer,buying_asset_type,buying_asset_code,buying_issuer}",
"templated": true
},
"self": {
"href": "https://193.168.191.185:8001/"
},
"transaction": {
"href": "https://193.168.191.185:8001/transactions/{hash}",
"templated": true
},
"transactions": {
"href": "https://193.168.191.185:8001/transactions{?cursor,limit,order}",
"templated": true
}
},
"horizon_version": "",
"core_version": "v0.6.2-78-gcc5ac0af",
"history_latest_ledger": 2880301,
"history_elder_ledger": 2797440,
"core_latest_ledger": 2880302,
"core_elder_ledger": 2797440,
"network_passphrase": "Test SDF Network ; September 2015",
"protocol_version": 8
}
五、端口介绍
Port Service Description
5432 postgresql database access port
8000 horizon main http port
11625 stellar-core main http port
11626 stellar-core peer node port
需要开放的是horizon http port