Skip to content

Instantly share code, notes, and snippets.

@tgerring
Last active August 18, 2021 07:55
Show Gist options
  • Save tgerring/6f274a999cab1d58a617 to your computer and use it in GitHub Desktop.
Save tgerring/6f274a999cab1d58a617 to your computer and use it in GitHub Desktop.
Geth installation Ubuntu
#!/bin/bash
#######################################################################
# Install base dependencies (required)
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y git build-essential
# Install Go binaries
GOVERSION="1.7.3"
[[ `uname -m` = "x86_64" ]] && GOARCH="amd64" || GOARCH="386"
wget https://storage.googleapis.com/golang/go$GOVERSION.linux-$GOARCH.tar.gz
sudo rm -rf /usr/local/go/ && sudo tar -C /usr/local -xzf go$GOVERSION*.tar.gz
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc && go version
#######################################################################
# Install Geth (required)
GETHTAG="v1.5.1"
mkdir -p $GOPATH/bin
git clone https://github.com/ethereum/go-ethereum.git $GOPATH/src/github.com/ethereum/go-ethereum
cd $GOPATH/src/github.com/ethereum/go-ethereum && git checkout $GETHTAG
make
cp build/bin/geth $GOPATH/bin/geth && geth version
mkdir -p $HOME/.ethereum
#######################################################################
# make separate disk for chaindata (optional)
DISKSIZE="24G"
DISKTYPE="tmpfs"
sudo mkdir -p /media/chaindata
sudo mount -t $DISKTYPE -o size=$DISKSIZE $DISKTYPE /media/chaindata
grep /media/chaindata /etc/mtab | sudo tee -a /etc/fstab
ln -s /media/chaindata $HOME/.ethereum/chaindata
#######################################################################
# copy settings from another server (optional)
OLDSERVER="1.1.1.1"
scp -r -i ~/.ssh/bootnode ubuntu@$OLDSERVER:$HOME/.ethereum/keystore $HOME/.ethereum/keystore
scp -i ~/.ssh/bootnode ubuntu@$OLDSERVER:$HOME/.ethereum/nodekey $HOME/.ethereum/nodekey
scp -i ~/.ssh/bootnode ubuntu@$OLDSERVER:$HOME/.ethereum/static-nodes.json $HOME/.ethereum/static-nodes.json
ln -s $HOME/.ethereum/static-nodes.json $HOME/.ethereum/trusted-nodes.json
#######################################################################
# Start on boot
# Set Upstart script
cat > $HOME/geth.conf <<EOF
description "geth bootnode"
start on runlevel [2345]
stop on shutdown
respawn
respawn limit 10 5
setuid ubuntu
setgid ubuntu
script
exec bash -c '/home/ubuntu/go/bin/geth --cache 1024 --fast --maxpeers 256'
end script
EOF
sudo mv $HOME/geth.conf /etc/init/
# start service
sudo service geth start
#######################################################################
# ethstats installation (optional)
sudo apt-get install -y unzip wget nodejs npm ntp cloud-utils
[[ ! -f /usr/bin/node ]] && sudo ln -s /usr/bin/nodejs /usr/bin/node
cd $HOME && git clone https://github.com/cubedro/eth-net-intelligence-api
cd eth-net-intelligence-api && git pull
npm install
sudo npm install pm2 -g
nano app.json
pm2 start app.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment