Tuesday, April 8, 2014

Install Official Bitcoin Wallet On AWS EC2 Linux AMI (or RedHat / CentOS)





This article is now obsolete.
Please refer to the newer version:



Update 2014-04-09: Using bitcoin-0.9.1 with Heartbleed patch.

You should know that RedHat, CentOS or Amazon Linux AMI are not the best choice when it comes to use Bitcoin wallet or other Bitcoin related activities. If you are looking for the easy path you should use Ubuntu Linux or Microsoft Windows as platform. The community is much bigger there.

But if you are determined like me to have your Bitcoin Wallet in the Cloud here you have some instructions. They apply to RedHat and its branches like AWS Linux AMI and CentOS.

Launch a EC2 Instance using Amazon Linux AMI HVM. In this example is ami-b521dfc2 (Ireland). I suggest to use the HVM version to maintain compatibility among different EC2 Instance Types.

All command are executed using ec2-user


Update & Reboot


sudo yum update
sudo reboot



PU_IAS6 Repository & Berkeley DB4.8

We will need Berkeley DB 4.8 but our OS comes with 4.7. Let's use PUIAS repository to get the RPMs with need.
Create the repository config file /etc/yum.repos.d/puias-computational.repo and paste into it the repository definition.


sudo vim /etc/yum.repos.d/puias-computational.repo


[puias-computational]
name=PUIAS Computational
baseurl=http://puias.math.ias.edu/data/puias/computational/6/x86_64/
enabled=1
gpgcheck=0


sudo yum install db48 db48-devel



Boost-Devel


sudo yum install boost-devel



OpenSSL

We need Elliptic Curve Encryption for Bitcoin to work. For some reason it is missing in RHEL distributions. We have to patch around that.

Download & Install OpenSSL source


wget https://www.openssl.org/source/openssl-1.0.1f.tar.gz
tar xvfz openssl-1.0.1f.tar.gz
cd openssl-1.0.1f
export CFLAGS="-fPIC"
./config shared


Disable man pages


vim Makefile


Locate a line with this content "install: all install_docs install_sw" (Line #543) and remove "install_docs" command from it.
The final result should look like this:

...
...
...
        @$(MAKE) TAR='$(TAR)' TARFLAGS='$(TARFLAGS)' tar

dist_pem_h:
        (cd crypto/pem; $(MAKE) -e $(BUILDENV) pem.h; $(MAKE) clean)

install: all install_sw

install_sw:
        @$(PERL) $(TOP)/util/mkdir-p.pl $(INSTALL_PREFIX)$(INSTALLTOP)/bin \
                $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR) \
...
...
...

Make & Install


make depend
make all
sudo -E make install


If we are errors free, continue copying the following files:


sudo cp /usr/local/ssl/lib/pkgconfig/libssl.pc /usr/lib64/pkgconfig/
sudo cp /usr/local/ssl/lib/pkgconfig/libcrypto.pc /usr/lib64/pkgconfig/

sudo cp /usr/local/ssl/lib/libssl.so.1.0.0 /usr/lib64/
sudo cp /usr/local/ssl/lib/libcrypto.so.1.0.0 /usr/lib64/

cd



Bitcoin

Official Bitcoin download source & Install



cd
wget https://bitcoin.org/bin/0.9.1/bitcoin-0.9.1-linux.tar.gz
tar xvfz bitcoin-0.9.0-linux.tar.gz
cd bitcoin-0.9.0-linux/src/
tar xvfz bitcoin-0.9.0.tar.gz
cd bitcoin-0.9.0/
./configure


If everything goes well you should have and output like this one:

$ ./configure 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... yes
checking whether make supports nested variables... yes
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking how to run the C++ preprocessor... g++ -E
checking for gcc... gcc
checking whether we are using the GNU Objective C compiler... no
checking whether gcc accepts -g... no
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU Objective C++ compiler... no
checking whether g++ accepts -g... no
checking for a sed that does not truncate output... /bin/sed
checking for ar... /usr/bin/ar
checking for ranlib... /usr/bin/ranlib
checking for strip... /usr/bin/strip
checking for gcov... /usr/bin/gcov
checking for lcov... no
checking for java... /usr/bin/java
checking for genhtml... no
checking for git... no
checking for ccache... no
checking for xgettext... no
checking for hexdump... /usr/bin/hexdump
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking if compiler needs -Werror to reject unknown flags... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking whether the linker accepts -Wl,--large-address-aware... no
checking whether C++ compiler accepts -Wstack-protector... yes
checking whether C++ compiler accepts -fstack-protector-all... yes
checking whether C++ compiler accepts -fPIE... yes
checking whether C++ preprocessor accepts -D_FORTIFY_SOURCE=2... yes
checking whether C++ preprocessor accepts -U_FORTIFY_SOURCE... yes
checking whether the linker accepts -Wl,--dynamicbase... no
checking whether the linker accepts -Wl,--nxcompat... no
checking whether the linker accepts -Wl,-z,relro... yes
checking whether the linker accepts -Wl,-z,now... yes
checking whether the linker accepts -pie... yes
checking stdio.h usability... yes
checking stdio.h presence... yes
checking for stdio.h... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for strings.h... (cached) yes
checking for sys/types.h... (cached) yes
checking for sys/stat.h... (cached) yes
checking for MSG_NOSIGNAL... yes
checking for Berkeley DB C++ headers... /usr/include/db4/
checking for main in -ldb_cxx-4.8... yes
checking miniupnpc/miniwget.h usability... no
checking miniupnpc/miniwget.h presence... no
checking for miniupnpc/miniwget.h... no
checking miniupnpc/miniupnpc.h usability... no
checking miniupnpc/miniupnpc.h presence... no
checking for miniupnpc/miniupnpc.h... no
checking miniupnpc/upnpcommands.h usability... no
checking miniupnpc/upnpcommands.h presence... no
checking for miniupnpc/upnpcommands.h... no
checking miniupnpc/upnperrors.h usability... no
checking miniupnpc/upnperrors.h presence... no
checking for miniupnpc/upnperrors.h... no
checking for boostlib >= 1.20.0... yes
checking whether the Boost::System library is available... yes
checking for exit in -lboost_system... yes
checking whether the Boost::Filesystem library is available... yes
checking for exit in -lboost_filesystem... yes
checking whether the Boost::Program_Options library is available... yes
checking for exit in -lboost_program_options-mt... yes
checking whether the Boost::Thread library is available... yes
checking for exit in -lboost_thread... yes
checking whether the Boost::Chrono library is available... yes
checking for exit in -lboost_chrono-mt... yes
checking whether the Boost::Unit_Test_Framework library is available... yes
checking for dynamic linked boost test... yes
checking for SSL... yes
checking for CRYPTO... yes
checking for PROTOBUF... no
configure: WARNING: libprotobuf not found; bitcoin-qt frontend will not be built
checking whether to build bitcoind... yes
checking whether to build bitcoin-cli... yes
checking whether to build Bitcoin Core GUI... no (Qt)
checking for operating system IPv6 support... yes
checking if ccache should be used... no
checking if wallet should be enabled... yes
checking whether to build with support for IPv6... yes
checking whether to build with support for UPnP... no
checking whether to build test_bitcoin... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating src/test/Makefile
config.status: creating src/qt/Makefile
config.status: creating src/qt/test/Makefile
config.status: creating share/setup.nsi
config.status: creating share/qt/Info.plist
config.status: creating qa/pull-tester/run-bitcoind-for-test.sh
config.status: creating qa/pull-tester/build-tests.sh
config.status: creating src/bitcoin-config.h
config.status: executing depfiles commands
$

If it does not, review all the previous steps and repeat.

Make, Install & Execute (Note "d" after bitcoin. We use Bitcoin wallet as daemon)


make
sudo make install
bitcoind


Expected output:

$ bitcoind
Error: To use the "-server" option, you must set a rpcpassword in the configuration file:
/home/ec2-user/.bitcoin/bitcoin.conf
It is recommended you use the following random password:
rpcuser=bitcoinrpc
rpcpassword=abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd
(you do not need to remember this password)
The username and password MUST NOT be the same.
If the file does not exist, create it with owner-readable-only file permissions.
It is also recommended to set alertnotify so you are notified of problems;
for example: alertnotify=echo %s | mail -s "Bitcoin Alert" admin@foo.com
$

Bitcoind is telling us that we need a minimal configuration file to start with. With the first execution the .bitcoin folder is automatically created under our user directory.


cd
cd .bitcoin

vim bitcoin.conf


You can begin with this basic configuration file (Manual page).

server=1
daemon=1
rpcuser=<A LONG & UNIQUE USERNAME HERE>
rpcpassword=<A VERY GOOD PASSWORD HERE>

Let's try again:


bitcoind


And the expected result on console:

Bitcoin server starting


and now the debug.log file should be moving. We can see the initialization process and messages like these:

2014-04-08 18:34:33 Pre-allocating up to position 0x100000 in rev00000.dat
2014-04-08 18:34:33 UpdateTip: new best=00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048  height=1  log2_work=33.000022  tx=2  da
te=2009-01-09 02:54:25 progress=0.000000
2014-04-08 18:34:33 ProcessBlock: ACCEPTED
2014-04-08 18:34:33 UpdateTip: new best=000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd  height=2  log2_work=33.584985  tx=3  da
te=2009-01-09 02:55:44 progress=0.000000
2014-04-08 18:34:33 ProcessBlock: ACCEPTED
2014-04-08 18:34:33 UpdateTip: new best=0000000082b5015589a3fdf2d4baff403e6f0be035a5d9742c1cae6295464449  height=3  log2_work=34.000022  tx=4  da
te=2009-01-09 03:02:53 progress=0.000000
2014-04-08 18:34:33 ProcessBlock: ACCEPTED

This is our wallet loading and verifying all the Bitcoin blockchain. When the process is complete your wallet will become a node of the Bitcoin network and will help validating Bitcoin transactions. It could take more than 24 hours for the process to complete. You can learn more about this here.
There is a way to speed up this process by downloading a Torrent file. More details at the end of this post.

You can issue commands to interact with the daemon. For instance:


bitcoind getblockcount


to get the number of blocks imported so far. Type bitcoind help for the whole list.


Initializing Blockchain database using Torrent


bitcoind stop
sudo yum install transmission-cli
cd ~/.bitcoin
transmission-cli https://bitcoin.org/bin/blockchain/bootstrap.dat.torrent
bitcoind -loadblock=~/.bitcoin/bootstrap.dat


Torrent File ReadMe.txt




This article is now obsolete.
Please refer to the newer version:



3 comments:

  1. Comparebrokers.co investment broker review and comparison website. FXPrimus review and comparison. fxprimus.com review

    ReplyDelete
  2. Find the best UAE brokers on comparebrokers.co. Comparebrokers.co is a review and comparison website. United Arab Emirates trading account

    ReplyDelete
  3. Bruc Bond endeavor to lead the financial sector with sustainability, customizable product offering, and open communication. At Bruc Bond we aim to make 21st century banking straightforward, simple, and transparent.

    ReplyDelete