Skip to content

Instantly share code, notes, and snippets.

@novy4
Last active February 21, 2021 08:20
Show Gist options
  • Save novy4/c11ec59065a88b6f62f917d4652a00e8 to your computer and use it in GitHub Desktop.
Save novy4/c11ec59065a88b6f62f917d4652a00e8 to your computer and use it in GitHub Desktop.
##########GRAPH-NODE########
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -; \
sudo bash -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'; \
sudo apt-get update && sudo apt-get upgrade -y; \
sudo apt-get install -y clang libpq-dev libssl-dev pkg-config; \
sudo apt-get install -y gnupg gnupg2 snapd git postgresql-12 postgresql-client-12 nodejs screen httpie ufw; \
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
sudo snap install ipfs
######DB-SERVER############
sudo -i -u postgres
createdb graph-node
psql
ALTER USER postgres PASSWORD 'xxx';
exit
exit
#####GRAPH-NODE############
git clone https://github.com/graphprotocol/graph-node
cd graph-node
cargo build
cargo run -p graph-node --release -- \
--postgres-url postgresql://postgres:xxx@ip:5432/graph-node \
--ethereum-rpc mainnet:https://gdomain/mainnet/secretc0de \
--ipfs https://testnet.thegraph.com/ipfs/
sudo bash -c 'cat <<EOF >> /etc/systemd/system/graph-node.service
[Unit]
Description=Graph Chain Indexer
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
User=$(id -u -n)
Restart=always
RestartSec=1
ExecStart=/$HOME/graph-node/target/release/graph-node --postgres-url 'postgresql://postgres:@ip:5432/graph-node-r1' --ethereum-rpc 'mainnet:https://po/' --ipfs 'https://testnet.thegraph.com/ipfs/'
[Install]
WantedBy=multi-user.target
EOF';
sudo systemctl start graph-node.service; \
sudo systemctl enable graph-node.service; \
sudo journalctl -u graph-node.service;
http post localhost:8020 jsonrpc="2.0" method="subgraph_create" params:='{"name": "molochventures/moloch" }' id=1
http post localhost:8020 jsonrpc="2.0" method="subgraph_deploy" params:='{"name": "molochventures/moloch", "ipfs_hash": "QmTXzATwNfgGVukV1fX2T6xw9f6LAYRVWpsdXyRWzUR2H9"}' id=2
http post localhost:8020 jsonrpc="2.0" method="subgraph_create" params:='{"name": "uniswap/uniswap-v2" }' id=3
http post localhost:8020 jsonrpc="2.0" method="subgraph_deploy" params:='{"name": "uniswap/uniswap-v2", "ipfs_hash": "QmXKwSEMirgWVn41nRzkT3hpUBw29cp619Gx58XW6mPhZP"}' id=4
http post localhost:8020 jsonrpc="2.0" method="subgraph_create" params:='{"name": "synthetixio-team/synthetix" }' id=5
http post localhost:8020 jsonrpc="2.0" method="subgraph_deploy" params:='{"name": "synthetixio-team/synthetix", "ipfs_hash": "Qme2hDXrkBpuXAYEuwGPAjr6zwiMZV4FHLLBa3BHzatBWx"}' id=6
sudo useradd --no-create-home --shell /bin/false node_exporter; \
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz; \
tar -xvzf node_exporter-1.0.1.linux-amd64.tar.gz; \
sudo cp node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin/; \
sudo bash -c 'cat <<EOF >> /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
After=network-online.target
[Service]
User=node_exporter
Group=node_exporter
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=default.target
EOF'
sudo systemctl daemon-reload; \
sudo systemctl start node_exporter; \
sudo systemctl enable node_exporter; \
sudo systemctl status node_exporter
curl 'localhost:9100/metrics'
sudo useradd --no-create-home --shell /bin/false prometheus; \
wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz; \
tar -xvzf prometheus-2.20.1.linux-amd64.tar.gz; \
sudo cp prometheus-2.20.1.linux-amd64/prometheus /usr/local/bin/; \
sudo cp prometheus-2.20.1.linux-amd64/promtool /usr/local/bin/; \
sudo mkdir /etc/prometheus; \
sudo cp -r prometheus-2.20.1.linux-amd64/consoles/ /etc/prometheus/consoles; \
sudo cp -r prometheus-2.20.1.linux-amd64/console_libraries/ /etc/prometheus/console_libraries; \
sudo cp prometheus-2.20.1.linux-amd64/prometheus.yml /etc/prometheus/; \
sudo chown -R prometheus:prometheus /etc/prometheus; \
sudo mkdir /var/lib/prometheus; \
sudo chown prometheus:prometheus /var/lib/prometheus; \
sudo bash -c 'cat <<EOF >> /etc/prometheus/prometheus.yml
- job_name: 'node_localhost'
static_configs:
- targets: ['localhost:9100']
- job_name: 'graph_node'
static_configs:
- targets: ['localhost:8040']
EOF'; \
sudo bash -c 'cat <<EOF >> /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=default.target
EOF'
sudo systemctl daemon-reload; \
sudo systemctl start prometheus; \
sudo systemctl enable prometheus; \
curl 'localhost:8040/metrics'; \
curl 'localhost:9090/metrics' | grep graph
sudo ufw disable; \
sudo ufw allow 22; \
sudo ufw allow 8000; \
sudo ufw allow 8001; \
sudo ufw allow 8020; \
sudo ufw allow 8030; \
sudo ufw allow 8040; \
sudo ufw allow 9100; \
sudo ufw allow 9090; \
sudo ufw allow 3000; \
sudo ufw enable;
### Заходим в браузере ###
:8030/graphql
вписываем команду и проверяем синхронизацию
{ indexingStatuses { subgraph synced fatalError chains { ... on EthereumIndexingStatus { latestBlock { number hash } chainHeadBlock { number hash } } } } }
пеерходим в браузере и смотрим. Должна быть цифра 3
ip:9090/graph?g0.range_input=1h&g0.expr=subgraph_count&g0.tab=1
если все ок,
https://airtable.com/shrCoDhJDYST0eMF5
Graph endpoint: IP:8000
Prometheus endpoint: IP:9090
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment