Deployment¶
Premise¶
Create a folder for fullnode.
Clone the latest master branch of https://github.com/stabilaprotocol/java-stabila and extract it to
/deploy/java-stabila
Make sure you have the proper dependencies.
- JDK 1.8 (JDK 1.9+ is not supported yet)
- On Linux Ubuntu system (e.g. Ubuntu 16.04.4 LTS), ensure that the machine has Oracle JDK 8, instead of having Open JDK 8 in the system. If you are building the source code by using Open JDK 8, you will get "Build Failed" result.
- Open UDP ports for connection to the network
- MINIMUM 2 CPU Cores
Deployment Guide¶
1. Build the java-stabila project
cd /deploy/java-stabila ./gradlew build
2. Copy the FullNode.jar along with configuration files into the respective directories
download your needed configuration file from https://github.com/stabilaprotocol/stabila-deployment. main_net_config.conf is the configuration for MainNet. please rename the configuration file to `config.conf` and use this config.conf to start FullNode. cp build/libs/FullNode.jar ../fullnode
3. You can now run your FullNode using the following command
java -jar FullNode.jar -c config.conf // make sure that your config.conf is downloaded from https://github.com/stabilaprotocol/stabila-deployment
4. Running a Governor Node for mainnet
java -jar FullNode.jar -p your private key --executive -c your config.conf(Example:/data/java-stabila/config.conf) Example: java -jar FullNode.jar -p 650950B193DDDDB35B6E48912DD28F7AB0E7140C1BFDEFD493348F02295BD812 --executive -c /data/java-stabila/config.conf
5. Running a Governor Node
You should modify the config.conf:
- Replace existing entry in genesis.block.executives with your address
- Replace existing entry in seed.node ip.list with your ip list
- The first Governor Node start, needSyncCheck should be set false
- Set p2pversion to 61
cd build/libs java -jar FullNode.jar -p your private key --executive -c your config.conf (Example:/data/java-stabila/config.conf) Example: java -jar FullNode.jar -p 650950B193DDDDB35B6E48912DD28F7AB0E7140C1BFDEFD493348F02295BD812 --executive -c /data/java-stabila/config.conf
Logging and Network Connection Verification¶
Logs for both nodes are located in /deploy/\*/logs/stabila.log
. Use tail -f /logs/stabila.log/
to follow along with the block syncing.
You should see something similar to this in your logs for block synchronization:
FullNode
12:00:57.658 INFO [pool-7-thread-1] [o.t.c.n.n.NodeImpl](NodeImpl.java:830) Success handle block Num:236610,ID:0000000000039c427569efa27cc2493c1fff243cc1515aa6665c617c45d2e1bf
Stop Node Gracefully¶
Create file stop.sh,use kill -15 to close FullNode.jar.
You need to modify pid=ps -ef |grep FullNode.jar |grep -v grep |awk '{print $2}'
to find the correct pid.
#!/bin/bash while true; do pid=`ps -ef |grep FullNode.jar |grep -v grep |awk '{print $2}'` if [ -n "$pid" ]; then kill -15 $pid echo "The java-stabila process is exiting, it may take some time, forcing the exit may cause damage to the database, please wait patiently..." sleep 1 else echo "java-stabila killed successfully!" break fi done
FullNode Fast Deployment¶
Download fast deployment script, run the script according to different types of node.
Scope of use
This script could be used on Linux/MacOS, but not on Windows. Supported just by FullNode.
Download and run script
wget https://github.com/stabilaprotocol/stabila-deployment/blob/master/deploy_stabila.sh -O deploy_stabila.sh
Parameter Illustration
bash deploy_stabila.sh --app [FullNode] --net [mainnet] --db [keep|remove|backup] --heap-size <heapsize> --app Optional, Running application. The default node is Fullnode. --net Optional, Connecting network. The default network is mainnet and it could be mainnet, testnet. --db Optional, The way of data processing could be keep, remove and backup. Default is keep. If you launch two different networks, like from mainnet to testnet or from testnet to mainnet, you need to delete database. --rpc-port Optional, Port of grpc. Default is 50051. --commit Optional, commitid of project. --branch Optional, branch of project. Mainnet default is latest release and Testnet default is master. --heap-size Optional, jvm option: Xmx. The default heap-size is 0.8 * memory size. --work_space Optional, default is current directory.
Deployment of FullNode on the one host
wget https://raw.githubusercontent.com/stabilaprotocol/StabilaDeployment/master/deploy_stabila.sh -O deploy_stabila.sh bash deploy_stabila.sh
Grpc Gateway Deployment¶
Summary
This script helps you download the code from https://github.com/stabilaprotocol/grpc-gateway and deploy the code on your environment.
Pre-requests
Please follow the guide on https://github.com/stabilaprotocol/grpc-gateway Install Golang, Protoc, and set $GOPATH environment variable according to your requirement.
Download and run script
wget https://github.com/stabilaprotocol/stabila-deployment/blob/master/deploy_grpc_gateway.sh -O deploy_grpc_gateway.sh
Parameter Illustration
bash deploy_grpc_gateway.sh --rpchost [rpc host ip] --rpcport [rpc port number] --httpport [http port number] --rpchost The fullnode IP where the grpc service is provided. Default value is "localhost". --rpcport The fullnode port number grpc service is consuming. Default value is 50051. --httpport The port intends to provide http service provided by grpc gateway. Default value is 18890.
Example
Use default configuration:
bash deploy_grpc_gateway.sh
Use customized configuration:
bash deploy_grpc_gateway.sh --rpchost 127.0.0.1 --rpcport 50052 --httpport 18891
Event Subscribe plugin Deployment¶
This is an implementation of Stabila eventsubscribe model.
- api module defines IPluginEventListener, a protocol between Java-stabila and event plugin.
- app module is an example for loading plugin, developers could use it for debugging.
- kafkaplugin module is the implementation for kafka, it implements IPluginEventListener, it receives events subscribed from Java-stabila and relay events to kafka server.
- mongodbplugin mongodbplugin module is the implementation for mongodb.
Setup/Build
- Clone the repo
git clone https://github.com/stabilaprotocol/event-plugin.git
- Go to eventplugin
cd event-plugin
-
run
./gradlew build
-
This will produce one plugin zip, named
plugin-kafka-1.0.0.zip
, located in theevent-plugin/build/plugins/
directory.
Edit **config.conf** of Java-stabila, add the following fileds:
event.subscribe = { path = "" // absolute path of plugin server = "" // target server address to receive event triggers dbconfig="" // dbname|username|password topics = [ { triggerName = "block" // block trigger, the value can't be modified enable = false topic = "block" // plugin topic, the value could be modified }, { triggerName = "transaction" enable = false topic = "transaction" }, { triggerName = "contractevent" enable = true topic = "contractevent" }, { triggerName = "contractlog" enable = true topic = "contractlog" } ] filter = { fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range contractAddress = [ "" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address. ] contractTopic = [ "" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic. ] } }
- path: is the absolute path of "plugin-kafka-1.0.0.zip"
- server: Kafka server address
- topics: each event type maps to one Kafka topic, we support four event types subscribing, block, transaction, contractlog and contractevent.
- dbconfig: db configuration information for mongodb, if using kafka, delete this one; if using Mongodb, add like that dbname|username|password
- triggerName: the trigger type, the value can't be modified.
- enable: plugin can receive nothing if the value is false.
- topic: the value is the kafka topic to receive events. Make sure it has been created and Kafka process is running
- filter: filter condition for process trigger. note: if the server is not 127.0.0.1, pls set some properties in config/server.properties file remove comment and set listeners=PLAINTEXT://:9092 remove comment and set advertised.listeners to PLAINTEXT://host_ip:9092
Install Kafka
On Mac:
brew install kafka
On Linux:
cd /usr/local wget http://archive.apache.org/dist/kafka/0.10.2.2/kafka_2.10-0.10.2.2.tgz tar -xzvf kafka_2.10-0.10.2.2.tgz mv kafka_2.10-0.10.2.2 kafka add "export PATH=$PATH:/usr/local/kafka/bin" to end of /etc/profile source /etc/profile kafka-server-start.sh /usr/local/kafka/config/server.properties &
Note: make sure the version of Kafka is the same as the version set in build.gradle of eventplugin project.(kafka_2.10-0.10.2.2 kafka)
Run Kafka
On Mac:
zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties & kafka-server-start /usr/local/etc/kafka/server.properties
On Linux:
zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties & Sleep about 3 seconds kafka-server-start.sh /usr/local/kafka/config/server.properties &
Create topics to receive events, the topic is defined in config.conf
On Mac:
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic block kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic transaction kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractlog kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractevent
On Linux:
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic block kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic transaction kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractlog kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic contractevent
Kafka consumer
On Mac:
kafka-console-consumer --bootstrap-server localhost:9092 --topic block kafka-console-consumer --bootstrap-server localhost:9092 --topic transaction kafka-console-consumer --bootstrap-server localhost:9092 --topic contractlog kafka-console-consumer --bootstrap-server localhost:9092 --topic contractevent
On Linux:
kafka-console-consumer.sh --zookeeper localhost:2181 --topic block kafka-console-consumer.sh --zookeeper localhost:2181 --topic transaction kafka-console-consumer.sh --zookeeper localhost:2181 --topic contractlog kafka-console-consumer.sh --zookeeper localhost:2181 --topic contractevent
Load plugin in Java-stabila
- add --es to command line, for example:
java -jar FullNode.jar -p privatekey -c config.conf --es
Event filter
which is defined in config.conf, path: event.subscribe
filter = { fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range contractAddress = [ "SVkNuE1BYxECWq85d8UR9zsv6WppBns9iH" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address. ] contractTopic = [ "f0f1e23ddce8a520eaa7502e02fa767cb24152e9a86a4bf02529637c4e57504b" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic. ] }
Download and install MongoDB
Suggested Configuration
- CPU/ RAM: 16Core / 32G
- DISK: 500G
- System: CentOS 64
The version of MongoDB is 4.0.4, below is the command:
- cd /home/java-stabila
- curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.4.tgz
- tar zxvf mongodb-linux-x86_64-4.0.4.tgz
- mv mongodb-linux-x86_64-4.0.4 mongodb
Set environment - export MONGOPATH=/home/java-stabila/mongodb/ - export PATH=$PATH:$MONGOPATH/bin
Create mongodb config The path is : /etc/mongodb/mgdb.conf
- cd /etc/mongodb
- touch mgdb.conf
Create data&log folder for mongodb Create data, log subfolder in mongodb directory, and add their absolute path to mgdb.conf
Example:
- dbpath=/home/java-stabila/mongodb/data
- logpath=/home/java-stabila/mongodb/log/mongodb.log
- port=27017
- logappend=true
- fork=true
- bind_ip=0.0.0.0
- auth=true
- wiredTigerCacheSizeGB=2
Note: - bind_ip must be configured to 0.0.0.0,otherwise remote connection will be refused. - wiredTigerCacheSizeGB, must be configured to prevent OOM
Launch MongoDB - mongod --config /etc/mongodb/mgdb.conf
Create admin account: - mongo - use admin - db.createUser({user:"root",pwd:"admin",roles:[{role:"root",db:"admin"}]})
Create eventlog and its owner account
- db.auth("root", "admin")
- use eventlog
- db.createUser({user:"stabila",pwd:"123456",roles:[{role:"dbOwner",db:"eventlog"}]})
database: eventlog, username: stabila, password: 123456
Firewall rule: - iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
Remote connection via mongo:
- mongo 47.90.245.68:27017
- use eventlog
- db.auth("stabila", "123456")
- show collections
- db.block.find()
Query block trigger data:
- db.block.find({blockNumber: {$lt: 1000}}); // return records whose blockNumber less than1000
Set database index to speedup query:
cd /{projectPath} sh insertIndex.sh
Advanced Configurations¶
Read the Advanced Configuration