Sunday, May 25, 2014

How to set up Darkcoin p2pool server on Debian

Installing a DRK (or almost any other crypto-currency) p2pool on Debian Stable



Updated: Added darkcoind config step and installing drk python modules.


First up if you’re not bothered about making a p2pool, but would like to join a good one (0% fees for one month from today), scroll straight to the bottom for a link.

If on the other hand you find this guide useful or even profitable, I won’t stop you throwing a donation my way at XtnchkvpVveDGm4vJmeBt8nuRk2pR7hF8g

The reason we need more p2pool servers out there is to distribute the network hash rate better. Currently there are a couple of DRK pools that are rather getting in the way, and the way that p2pool works, there’s almost no chance of one member grabbing more than 50% of the hash rate and performing attacks against the network.

p2pool isn’t ideal for everybody – you need to be able to broadcast shares of a higher difficulty than the minimum share difficulty on p2pool for that coin. DRK is currently showing 0.145 on my node, meaning you probably need about 200kh/s at the moment to get regular payouts. That’s not very much at the moment, but the diff on DRK is skyrocketing so expect that to go up too.

This guide will assume that you are doing this on a remote machine via SSH, and are logged in as root. For anyone running as a less privileged user, you need to make sure that user has sudo access, and prefix any command run as root with “sudo “.


DISCLAIMER

This is only meant to be a basic guide for those already somewhat experienced in server admin. This is a slightly hardened, but definitely NOT the safest setup, and if your machine is compromised I cannot be held liable for any funds lost. If you really want to run it with maximum safely you need to understand chrooting and shell-less, unprivileged users, and perform regular checkups on your server to ensure that it has not been compromised. I also suggest that you try this entire tutorial in a virtual machine locally before trying to deploy an instance. This will mean you can work out any bugs in the process while you still have physical access to the system.


Caveat #1:

If libboost1.49-all-dev doesn’t exist on the Debian derivative you’re running, use apt-cache search libboost*chrono-dev to find which version you should substitute in.


Caveat #2:

There’s also an issue of portability. I have suggested you use libdb5.1, but many machines out there still only have libdb4.8 available. While wallets created by daemons built using 4.8 will be compatible with 5.1, the same cannot be said of daemons built using libdb5.1 running on a libdb4.8 system.

However, I don’t see this as being a huge issue, as I recommend you run an off-site wallet, which will send all fees to your own, preferably cold storage wallet, leaving the on-site wallet empty at all times minimising the risk of theft. If, though, you decide to throw caution to the wind and run an on-site wallet, I suggest you either have a system which you can guarantee can access libdb5.1, or find a way to make 4.8 available on your system and compile with that.

Ok, let’s get started.


GRAB DEPENDENCIES

aptitude install git build-essential curl libcurl4-openssl-dev libminiupnpc-dev \

libboost1.49-all-dev libncurses-dev libffi-dev python-twisted \

libdb5.1++-dev libdb5.1-dev screen mailutils


Build the client and p2pool

cd ~

git clone https://github.com/evan82/darkcoin

git clone https://github.com/chaeplin/p2pool-drk


First build the client

cd darkcoin/src

make -f makefile.unix darkcoind

Wait a while for the compile to finish, and fix any errors you come across. I’ve checked all the aptitude commands in my bash_history, so I shouldn’t have left anything out, but a quick search for the error using Google or DuckDuckGo (for you privacy enthusiasts) will quickly find a solution for you.

Now you can copy your finished binary into a globally accessible folder and stop unprivileged users from modifying the file. cp darkcoind /usr/local/bin && chmod 744 /usr/local/bin/darkcoind


Then build p2pool

cd ../p2pool-drk

make


Now install the python modules. Note, if you use sudo rather than su replace the commands as required:

NOTE: Since the latest update this does not work this easily on Debian Stable. In order to get it to work you have to install glibc-2.17 from the Debian Testing repositories.

apt-get install libboost1.48-all-dev python-dev

git clone https://github.com/chaeplin/SUBSIDY_FUNC.git

git clone https://github.com/evan82/xcoin-hash.git

cd SUBSIDY_FUNC/darkcoin-subsidy-python

python setup.py install

cd ../../xcoin-hash

python setup.py install


SET UP A USER TO CONTROL THE P2POOL/DRK SERVICE

Replace any occurrence of “chosenusername” in this section with a username of your choice. A naming convention makes sense here, so you can run multiple pools, each as their own user. Perhaps choose just “drk”, or “drk-admin”. adduser chosenusername


SYNC THE DRK BLOCKCHAIN

Now we’ll start the darkcoin daemon, so it can sync up the DRK blockchain before we get started. Run the following commands: su – chosenusername

If you are root, this will be automatic. If you are not, you will have to enter the user’s password as you set it up just above.


CONFIGURE AND START DARKCOIND

First you need to set up darkcoind as a server, so run /usr/local/bin/darkcoind, and it’ll output an example configuration, which should be placed in /home/username/.darkcoin/darkcoin.conf

Also add the following lines to the file using an editor (nano is usually available):

alertnotify=echo %s | mail -s “DarkCoin Alert” your@email-address.com

server=1

The alertnotify line will send automatic emails to the address you specify if problems occur with the daemon.

Now run the daemon, while logged in as “chosenusername” with /usr/local/bin/darkcoind -daemon

If you want to follow the progress of the blockchain download, use “tail -f /home/chosenusername/.darkcoin/debug.log”. Press Ctrl+C to close the file when you’re done looking.

Meanwhile, change back to root (or your original user) by typing the command “exit”.


USE AN OFF-SITE WALLET

Edit ~/p2pool-drk/run_darkpool.sh file in order to use an offsite wallet.

Change the line that starts “screen -d -m -S P2P_DRK_DIFF” to read as follows:

screen -d -m -S P2P_DRK_DIFF python ./run_p2pool.py –net darkcoin –give-author 0 \

–disable-upnp -f 0 -a YOUROFFSITEDARKCOINADDRESS

If you wish to charge a fee, make sure you set -f to the default percentage fee to miners. This will be displayed on the main interface along with all the other pool statistics.

Now you want to copy the p2pool source to your service user’s home folder and allow them access to it:

cp -r ~/p2pool-drk /home/chosenusername/ && chown -R chosenusername:chosenusername /home/chosenusername/


HARDENING

Hardening any public facing server is important, but even more so when dealing with mining as it can be so profitable to crack.

Step one is to disable root SSH login and only allow one unprivileged user to log in via SSH.

To disable root logins for SSH, edit /etc/ssh/sshd_config and change the PermitRootLogin value to false. It will read: PermitRootLogin no

A simple thing we can do to help harden the server is disable SSH access for the user controlling the p2pool instance. To do this, we’ll create another user who is only ever used to log into the machine, after which you will have to use sudo or su to perform any activities. I will use the name “pooladminuser”, but please choose your own. Using default credentials from any tutorial is a potential huge security risk.

As root run adduser pooladminuser

Fill out the fields as you wish. Now we’ll tell SSH to only allow access from this particular user. To do this, simply edit /etc/ssh/sshd_config and add the following line to the end: AllowUsers pooladminuser

Then run (still as root) service ssh restart

Make sure at this point that you have taken note of the password you set for “pooladminuser”. If you find that you haven’t, use the following command to change it before logging out and trying to get back in: passwd pooladminuser

Now nobody but “pooladminuser” can log in via SSH, and then would need to put a lot more work into breaking into the system. Having all this been said, running the entire thing inside a chroot jail would be even better, but that’s a huge job and outside the scope of this tutorial.


Start the server!!!

Now change to “chosenusername” with su – chosenusername

And start the p2pool server: cd p2pool-drk ./run_darkpool.sh

This will most likely now come straight back to the screen you started on. If it says the daemon is still downloading blocks, watch the log until it says it’s 0.99 complete or more and try again.

This process is now controlled by its very own dedicated terminal. To see it, use the command “screen -r”. Be careful not to press Ctrl+C while watching its output, or you’ll quit the p2pool instance. To exit the screen interface, press Ctrl+A then Ctrl+D. Anything else risks bringing your server uptime back to 0, so my advice is to only look at the output if you feel like something isn’t working right.

Ok, you should now have a working server. Visit “ip.add.res.ss:7903/static”, then point your miner there. I’m not going to go into how to connect a miner, because if you’re new enough to this that you don’t know that, you should probably avoid p2pool.



source: http://www.reddit.com/r/DRKCoin/comments/1zg2c8/tutorial_how_to_set_up_a_darkcoin_p2pool_server/



How to set up Darkcoin p2pool server on Debian

1 comment:

  1. If you're looking for the highest paying Bitcoin advertising network, try MellowAds.

    ReplyDelete