Docu changes for switch to leveldb with limit, abe deprecated
[electrum-server.git] / HOWTO.md
1 How to run your own Electrum server
2 ===================================
3
4 Abstract
5 --------
6
7 This document is an easy to follow guide to installing and running your own
8 Electrum server on Linux. It is structured as a series of steps you need to
9 follow, ordered in the most logical way. The next two sections describe some
10 conventions we use in this document and hardware, software and expertise
11 requirements.
12
13 The most up-to date version of this document is available at:
14
15     https://github.com/spesmilo/electrum-server/blob/master/HOWTO.md
16
17 Conventions
18 -----------
19
20 In this document, lines starting with a hash sign (#) or a dollar sign ($)
21 contain commands. Commands starting with a hash should be run as root,
22 commands starting with a dollar should be run as a normal user (in this
23 document, we assume that user is called 'bitcoin'). We also assume the
24 bitcoin user has sudo rights, so we use '$ sudo command' when we need to.
25
26 Strings that are surrounded by "lower than" and "greater than" ( < and > )
27 should be replaced by the user with something appropriate. For example,
28 <password> should be replaced by a user chosen password. Do not confuse this
29 notation with shell redirection ('command < file' or 'command > file')!
30
31 Lines that lack hash or dollar signs are pastes from config files. They
32 should be copied verbatim or adapted, without the indentation tab.
33
34 Prerequisites
35 -------------
36
37 **Expertise.** You should be familiar with Linux command line and
38 standard Linux commands. You should have basic understanding of git,
39 Python packages. You should have knowledge about how to install and
40 configure software on your Linux distribution. You should be able to
41 add commands to your distribution's startup scripts. If one of the
42 commands included in this document is not available or does not
43 perform the operation described here, you are expected to fix the
44 issue so you can continue following this howto.
45
46 **Software.** A recent Linux distribution with the following software
47 installed: `python`, `easy_install`, `git`, standard C/C++
48 build chain. You will need root access in order to install other software or
49 Python libraries. 
50
51 **Hardware.** The lightest setup is a pruning server with diskspace 
52 requirements well under 1 GB growing very moderately and less taxing 
53 on I/O and CPU once it's up and running. If you have more ressources to spare
54 you can run the server with a higher limit of historic transactions per address.
55 CPU speed is also important, mostly for the initial block chain import, but 
56 also if you plan to run a public Electrum server, which could serve tens 
57 of concurrent requests. 
58
59 Instructions
60 ------------
61
62 ### Step 1. Create a user for running bitcoind and Electrum server
63
64 This step is optional, but for better security and resource separation I
65 suggest you create a separate user just for running `bitcoind` and Electrum.
66 We will also use the `~/bin` directory to keep locally installed files
67 (others might want to use `/usr/local/bin` instead). We will download source
68 code files to the `~/src` directory.
69
70     # sudo adduser bitcoin
71     # su - bitcoin
72     $ mkdir ~/bin ~/src
73     $ echo $PATH
74
75 If you don't see `/home/bitcoin/bin` in the output, you should add this line
76 to your `.bashrc`, `.profile` or `.bash_profile`, then logout and relogin:
77
78     PATH="$HOME/bin:$PATH"
79
80 ### Step 2. Download and install Electrum
81
82 We will download the latest git snapshot for Electrum and 'install' it in
83 our ~/bin directory:
84
85     $ mkdir -p ~/src/electrum
86     $ cd ~/src/electrum
87     $ git clone https://github.com/spesmilo/electrum-server.git server
88     $ chmod +x ~/src/electrum/server/server.py
89     $ ln -s ~/src/electrum/server/server.py ~/bin/electrum
90
91 ### Step 2. Download Bitcoind from git & patch it
92
93 In order for the latest versions of Electrum to work properly we will need to use the latest 
94 build from Git and also patch it with an electrum specific patch.
95 Please make sure you run a version of bitcoind from git from at least December 2012 or newer:
96
97     $ cd src && git clone git://github.com/bitcoin/bitcoin.git
98     $ cd bitcoin 
99     $ patch -p1 < ~/src/electrum/server/patch/patch
100     $ cd src && make -f makefile.unix
101
102 ### Step 3. Configure and start bitcoind
103
104 In order to allow Electrum to "talk" to `bitcoind`, we need to set up a RPC
105 username and password for `bitcoind`. We will then start `bitcoind` and
106 wait for it to complete downloading the blockchain.
107
108     $ mkdir ~/.bitcoin
109     $ $EDITOR ~/.bitcoin/bitcoin.conf
110
111 Write this in `bitcoin.conf`:
112
113     rpcuser=<rpc-username>
114     rpcpassword=<rpc-password>
115     daemon=1
116
117 Restart `bitcoind`:
118
119     $ bitcoind
120
121 Allow some time to pass, so `bitcoind` connects to the network and starts
122 downloading blocks. You can check its progress by running:
123
124     $ bitcoind getinfo
125
126 You should also set up your system to automatically start bitcoind at boot
127 time, running as the 'bitcoin' user. Check your system documentation to
128 find out the best way to do this.
129
130 ### Step 5. Install Electrum dependencies and leveldb
131
132 Electrum server depends on various standard Python libraries. These will be
133 already installed on your distribution, or can be installed with your
134 package manager. Electrum also depends on two Python libraries which we will
135 need to install "by hand": `JSONRPClib`.
136
137     $ sudo easy_install jsonrpclib
138
139
140 Then carry out the steps in README.leveldb to get your system ready for
141 leveldb setups.
142
143 ### Step 6. Select your limit
144
145 Electrum server uses leveldb to store transactions. You can choose
146 how many spent transactions per address you want to store on the server.
147 The default is 100, but there are also servers with 1000 or even 10000.
148 Very few addresses have more than 10000 transactions. A limit this high
149 can be considered to be equivalent to a "full" server. Full servers previously
150 used abe to store the blockchain. The use of abe for electrum servers is now
151 deprecated.
152
153 The pruning server uses leveldb and keeps a smaller and
154 faster database by pruning spent transactions. It's a lot quicker to get up
155 and running and requires less maintenance and diskspace than abe.
156
157 The section in the configuration file looks like this:
158
159 [leveldb]
160 path = /path/to/your/database
161 # for each address, history will be pruned if it is longer than this limit
162 pruning_limit = 100
163
164 ### Step 7. Import blockchain into the database or download it
165
166 As of April 2013 it takes between 12-24 to import 230k of blocks, depending
167 on CPU speed, I/O speed and selected pruning limit.
168
169 It's considerably faster to index in memory. You can use /dev/shm or indexing in RAM
170 or create a tmpfs which will also use swap if you run out of memory:
171
172     $ sudo mount -t tmpfs -o rw,nodev,nosuid,noatime,size=6000M,mode=0777 none /tmpfs
173
174 At limit 10000 the database comes to 3,5 GB with 230k blocks.
175
176 Alternatively you can fetch a pre-processed leveldb from the net
177
178 You can fetch recent copies of electrum leveldb databases and further instructions 
179 from the Electrum full archival server foundry at:
180 http://electrum-foundry.no-ip.org/ 
181
182 ### Step 8. Configure Electrum server
183
184 Electrum reads a config file (/etc/electrum.conf) when starting up. This
185 file includes the database setup, bitcoind RPC setup, and a few other
186 options.
187
188     $ sudo cp ~/src/electrum/server/electrum.conf.sample /etc/electrum.conf
189     $ sudo $EDITOR /etc/electrum.conf
190
191 Go through the sample config options and set them to your liking.
192 If you intend to run the server publicly have a look at README-IRC.md 
193
194 If you're looking to run SSL / HTTPS you need to generate a self-signed certificate
195 using openssl. Otherwise you can just comment out the SSL / HTTPS ports and run 
196 without.
197
198 ### Step 9. (Finally!) Run Electrum server
199
200 The magic moment has come: you can now start your Electrum server:
201
202     $ server
203
204 You should see this on the screen:
205
206     starting Electrum server
207     cache: yes
208
209 If you want to stop Electrum server, open another shell and run:
210
211     $ electrum-server stop
212
213 You should also take a look at the 'start' and 'stop' scripts in
214 `~/src/electrum/server`. You can use them as a starting point to create a
215 init script for your system.
216
217 ### Step 10. Test the Electrum server
218
219 We will assume you have a working Electrum client, a wallet and some
220 transactions history. You should start the client and click on the green
221 checkmark (last button on the right of the status bar) to open the Server
222 selection window. If your server is public, you should see it in the list
223 and you can select it. If you server is private, you need to enter its IP
224 or hostname and the port. Press Ok, the client will disconnect from the
225 current server and connect to your new Electrum server. You should see your
226 addresses and transactions history. You can see the number of blocks and
227 response time in the Server selection window. You should send/receive some
228 bitcoins to confirm that everything is working properly.
229
230 ### Step 11. Join us on IRC, subscribe to the server thread
231
232 Say hi to the dev crew, other server operators and fans on 
233 irc.freenode.net #electrum and we'll try to congratulate you
234 on supporting the community by running an Electrum node
235
236 If you're operating a public Electrum server please subscribe
237 to or regulary check the following thread:
238 https://bitcointalk.org/index.php?topic=85475.0
239 It'll contain announcements about important updates to Electrum
240 server required for a smooth user experience.