Building an Ethereum Go geth RPM

in #ethereum7 years ago (edited)

Building an Ethereum geth RPM




Ethereum

For more information on Ethereum, visit ethereum.org


Description:


Ethereum is a decentralized platform that runs smart contracts using a custom built blockchain. The platform uses a cryptocurrency also called Ethereum (Ether/ETH). This tutorial will walk through all of the necessary steps, required to build an installable RPM that will allow an easy installation of Ethereum on any and all future worker nodes.


Pre-Requisites:


COMPATABILITY NOTICE:
These instructions are only compatible with RedHat 7 or newer   and CentOS 7 or newer. Although other OS's are supported, this tutorial is built on the RHEL/CentOS platform. The RPMs should be able to work however on any distribution based on RHEL 7 or later.


1.    Perform an update:

sudo yum update


2.   Install the Build Requirements:

sudo yum -y install rpm-build rpmrebuild rpm-sign redhat-rpm-config vim wget


3.   Make the required directory structure:

sudo mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}  || exit 1


Get Ethereum Source:


1.    Get the geth Source File:

cd /root/rpmbuild/SOURCES
sudo wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.6.5-cf87713d.tar.gz


2.    Untar the source files:

sudo tar --strip-components=1 -xzvf geth-linux-amd64-1.6.5-cf87713d.tar.gz
sudo rm -fr geth-linux-amd64-1.6.5-cf87713d.tar.gz 


3.    Verify the source files:

[root@tmprpmbuild SOURCES]# ls -lah 
total 28M
drwxr-xr-x 2 root root 4.0K Jun 12 15:45 .
drwxr-xr-x 7 root root 4.0K Jun 12 15:43 ..
-rw-rw-r-- 1 1000 1000  32K Jun  1 18:57 COPYING
-rwxrwxr-x 1 1000 1000  28M Jun  1 19:00 geth


Create Unit File:


1.    Create the geth unit file in the sources directory:

cd /root/rpmbuild/SOURCES
sudo vim geth.service


[Unit]
Description=Ethereum Application Platform
Documentation=https://geth.ethereum.org/

[Service]
ExecStart=/usr/local/bin/geth --rpc 2 > %h/.ethereum/geth.log
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity

[Install]
WantedBy=multi-user.target


Create RPM Spec File:


1.    Create the geth RPM spec file:

cd /root/rpmbuild/SPECS/
sudo vim geth.spec


# Prevent attemts to strip binaries as this is what we want to push.
%global __os_install_post %{nil}

Name:                   ethereum-go
Version:                1.6.5
Release:                1
Summary:                Ethereum Go Toolkit
Packager:               Richard Nason <[email protected]>
License:                Ethereum
Group:                  System/Base
Vendor:                 Ethereum
Url:                    https://geth.ethereum.org
# Source:               %{name}.tar.gz
BuildArch:              x86_64
BuildRoot:              %{_tmppath}/%{name}-%{version}-tmp
# BuildRequires:         
# Requires:               

%description
Ethereum is a decentralized platform that runs smart contracts, applications that run 
 exactly as programmed without possibility of downtime, censorship, fraud or third party interference.

%prep
# There is nothing to prep as we are dealing with pre-built binaries.

%build
# This section will remain empty as we are not compiling anything, just building the RPM

%install

# create directories where the files will be located
mkdir -p $RPM_BUILD_ROOT/usr/local/bin
mkdir -p $RPM_BUILD_ROOT/etc/systemd/system
mkdir -p $RPM_BUILD_ROOT/usr/local/share/info/ethereum

# Deploy the binary files (-m argument = permissions)
install -m 554 $RPM_SOURCE_DIR/geth $RPM_BUILD_ROOT/usr/local/bin/geth
install -m 554 $RPM_SOURCE_DIR/geth.service $RPM_BUILD_ROOT/etc/systemd/system/geth.service
install -m 554 $RPM_SOURCE_DIR/COPYING $RPM_BUILD_ROOT/usr/local/share/info/ethereum/LICENSE

%pre
# Pre install commands or scripts if any

if (( $(ps -ef | grep -v grep | grep geth | wc -l) > 0 ))
then
    echo -e "\n"
    echo -e "============================="
    echo -e "Stoping geth.service"
    echo -e "Initializing Installation..."
    echo -e "============================="
    echo -e "\n"

    # Set variables to check for running unit files
    GETH=`systemctl list-units | grep geth.service`

    # Check and stop geth.service
    if [ -z "$GETH" ]; then
        echo -e "geth.service is not running... "
    else
        sudo systemctl stop geth.service
    fi

else
    echo -e "\n"
    echo -e "========================================="
    echo -e "Existing geth.service not detected.."
    echo -e "Initializing Installation..."
    echo -e "========================================="
    echo -e "\n"
fi

%post
# Post install commands or scripts if any.

FIREWALL=`systemctl list-units | grep firewalld.service`

# Check and amend firewalld.service
if [ -z "$FIREWALL" ]; then
    echo -e "\n"
    echo -e "Firewalld not found skipping step...:"
else
    # Open the ports ethereum needs in order to run
    echo -e "Opening ports 30301 and 30303 on Firewalld"
    firewall-cmd --permanent --add-port=30301/tcp
    firewall-cmd --permanent --add-port=30303/tcp
    firewall-cmd --reload
fi

# Reload the unit file cache
systemctl daemon-reload

echo -e "Enabling geth.service to start on boot:"
sudo systemctl enable geth.service
# sudo systemctl start geth.service

echo -e "\n"
echo -e "======================================================"
echo -e "Ethereum Installation has completed!                  "
echo -e "======================================================"
echo -e "\n"

%clean
rm -rf $RPM_BUILD_ROOT
rm -rf %{_tmppath}/%{name}
rm -rf $RPM_BUILD_ROOT/%{name}

# List files that are deployed to the server.
%files
%defattr(-,root,root)
/usr/local/bin/geth
/etc/systemd/system/geth.service
/usr/local/share/info/ethereum/LICENSE

%changelog
* Mon Jun 05 2017  Richard Nason <[email protected]>
- Initial build using ethereum 1.6.5


Build the RPM:


1.    Use RPMBuild to build the RPM:

cd /root/rpmbuild
sudo rpmbuild -bb SPECS/geth.spec


Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Su2yut
+ umask 022
+ cd /root/rpmbuild/BUILD
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.zRixTn
+ umask 022
+ cd /root/rpmbuild/BUILD
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.9nVPii
+ umask 022
+ cd /root/rpmbuild/BUILD
+ '[' /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64 '!=' / ']'
+ rm -rf /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64
++ dirname /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT
+ mkdir /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64
+ mkdir -p /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/usr/local/bin
+ mkdir -p /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/etc/systemd/system
+ mkdir -p /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/usr/local/share/info/ethereum
+ install -m 554 /root/rpmbuild/SOURCES/geth /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/usr/local/bin/geth
+ install -m 554 /root/rpmbuild/SOURCES/geth.service /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/etc/systemd/system/geth.service
+ install -m 554 /root/rpmbuild/SOURCES/COPYING /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/usr/local/share/info/ethereum/LICENSE
+ /usr/lib/rpm/check-buildroot
Processing files: ethereum-go-1.6.5-1.x86_64
Provides: ethereum-go = 1.6.5-1 ethereum-go(x86-64) = 1.6.5-1
Requires(interp): /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires(post): /bin/sh
Requires: libc.so.6()(64bit) libc.so.6(GLIBC_2.14)(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) libc.so.6(GLIBC_2.7)(64bit) libc.so.6(GLIBC_2.8)(64bit) libpthread.so.0()(64bit) libpthread.so.0(GLIBC_2.2.5)(64bit) libpthread.so.0(GLIBC_2.3.2)(64bit) libpthread.so.0(GLIBC_2.3.3)(64bit) librt.so.1()(64bit) librt.so.1(GLIBC_2.2.5)(64bit) rtld(GNU_HASH)
Checking for unpackaged file(s): /usr/lib/rpm/check-files /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64
Wrote: /root/rpmbuild/RPMS/x86_64/ethereum-go-1.6.5-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.g97Mnk
+ umask 022
+ cd /root/rpmbuild/BUILD
+ rm -rf /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64
+ rm -rf /var/tmp/ethereum-go
+ rm -rf /root/rpmbuild/BUILDROOT/ethereum-go-1.6.5-1.x86_64/ethereum-go
+ exit 0


2.    Verify the RPM was built:

sudo ls -lah /root/rpmbuild/RPMS/x86_64


total 7.0M
drwxr-xr-x 2 root root 4.0K Jun 12 16:03 .
drwxr-xr-x 3 root root 4.0K Jun 12 16:03 ..
-rw-r--r-- 1 root root 7.0M Jun 12 16:03 ethereum-go-1.6.5-1.x86_64.rpm


Installing the RPM:


1.    Install the new Ethereum RPM to test it out:

cd /root/rpmbuild/RPMS/x86_64
sudo yum install ./ethereum-go-1.6.5-1.x86_64.rpm


Loaded plugins: fastestmirror
Examining ./ethereum-go-1.6.5-1.x86_64.rpm: ethereum-go-1.6.5-1.x86_64
Marking ./ethereum-go-1.6.5-1.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package ethereum-go.x86_64 0:1.6.5-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package             Arch                 Version            Repository                      Size
=================================================================================================
Installing:
 ethereum-go        x86_64                1.6.5-1            /ethereum-go-1.6.5-1.x86_64     28 M

Transaction Summary
=================================================================================================
Install  1 Package

Total size: 28 M
Installed size: 28 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction


=========================================
Existing geth.service not detected..
Initializing Installation...
=========================================


  Installing : ethereum-go-1.6.5-1.x86_64                                                                                                                                                                                          1/1 


Firewalld not found skipping step...:
Enabling geth.service to start on boot:
Created symlink from /etc/systemd/system/multi-user.target.wants/geth.service to /etc/systemd/system/geth.service.


======================================================
Ethereum Installation has completed!                  
======================================================


  Verifying  : ethereum-go-1.6.5-1.x86_64                                                                                                                                                                                          1/1 

Installed:
  ethereum-go.x86_64 0:1.6.5-1                                                                                                                                                                                                         

Complete!


Run geth:


Running the geth.service file will allow us to run geth without having to worry about using a screen session. geth will run as a system background service and automatically start syncing the block chain.


NOTICE:
This will start the blockchain synchronization. Depending on the size of the blockchain, this could take up to a few hours to complete.


1.    Run the geth service:

systemctl start geth.service


2.    Check the status of the geth service:

systemctl status geth.service -l


● geth.service - Ethereum Application Platform
   Loaded: loaded (/etc/systemd/system/geth.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-06-12 16:17:57 UTC; 18s ago
     Docs: https://geth.ethereum.org/
 Main PID: 8473 (geth)
   CGroup: /system.slice/geth.service
           └─8473 /usr/local/bin/geth --rpc 2 > /root/.ethereum/geth.log

Jun 12 16:17:58 tmprpmbuild geth[8473]: INFO [06-12|16:17:58] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
Jun 12 16:17:58 tmprpmbuild geth[8473]: INFO [06-12|16:17:58] Starting P2P networking
Jun 12 16:18:00 tmprpmbuild geth[8473]: INFO [06-12|16:18:00] UDP listener up                          self=enode://dc6735453645c2ba340fa1263cbe41807c6df6483a215dffdf0b22b461a0d616f98f962955f022864f70c1da138d922850fe33bc8bfda6b166adff7ec1fa0167@[::]:30303
Jun 12 16:18:00 tmprpmbuild geth[8473]: INFO [06-12|16:18:00] HTTP endpoint opened: http://127.0.0.1:8545
Jun 12 16:18:00 tmprpmbuild geth[8473]: INFO [06-12|16:18:00] RLPx listener up                         self=enode://dc6735453645c2ba340fa1263cbe41807c6df6483a215dffdf0b22b461a0d616f98f962955f022864f70c1da138d922850fe33bc8bfda6b166adff7ec1fa0167@[::]:30303
Jun 12 16:18:00 tmprpmbuild geth[8473]: INFO [06-12|16:18:00] IPC endpoint opened: /root/.ethereum/geth.ipc
Jun 12 16:18:10 tmprpmbuild geth[8473]: INFO [06-12|16:18:10] Block synchronisation started
Jun 12 16:18:15 tmprpmbuild geth[8473]: INFO [06-12|16:18:15] Imported new block headers               count=384 elapsed=2.024s   number=384 hash=d3d5d5…c79cf3 ignored=0
Jun 12 16:18:15 tmprpmbuild geth[8473]: INFO [06-12|16:18:15] Imported new block receipts              count=2   elapsed=303.806µs number=2   hash=b495a1…4698c9 ignored=0
Jun 12 16:18:15 tmprpmbuild geth[8473]: INFO [06-12|16:18:15] Imported new block headers               count=192 elapsed=66.304ms  number=576 hash=41a746…6a8b38 ignored=0
Jun 12 16:18:56 tmprpmbuild geth[8473]: INFO [06-12|16:18:56] Imported new block headers               count=2048 elapsed=1.032s    number=12864 hash=3c1d00…2f62e2 ignored=0


3.    Set the service to run on boot:

systemctl enable geth.service


We can tell that the synchronization is complete when the number= field in the geth output, matches the LAST BLOCK value found on etherscan.io


geth


geth    etherscan


Post Requisites:


None, You can sit back, relax, and let the blockchain sync !!


References:


Clusterfrak

Etherscan.io

Sort:  

Congratulations @rnason! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published 4 posts in one day

Click on any badge to view your own Board of Honnor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60445.30
ETH 2331.01
USDT 1.00
SBD 2.52