Sia storage farm

Материал из poiuty wiki
Перейти к: навигация, поиск

Действия выполняются на операционной системе Debian 8.
Устанавливаем пакеты и supervisor

apt-get update
apt-get upgrade
apt-get install curl zip supervisor

Создаем пользователя.

adduser --disabled-login sia

Скачиваем готовые бинарники.

wget https://github.com/NebulousLabs/Sia/releases/download/v1.2.2/Sia-v1.2.2-linux-amd64.zip
unzip Sia-v1.2.2-linux-amd64.zip
mkdir /home/sia/bin
mkdir /home/sia/host
cp Sia-v1.2.2-linux-amd64/siad /home/sia/bin/
cp Sia-v1.2.2-linux-amd64/siac /home/sia/bin/
ln -s /home/sia/bin/siad /usr/bin/siad
ln -s /home/sia/bin/siac /usr/bin/siac
chown -R sia:sia /home/sia/bin/
chown -R sia:sia /home/sia/host/

Создаем конфиг /etc/supervisor/conf.d/siad.conf

[program:siad]
command=/home/sia/bin/siad -M gctwh --rpc-addr :9981 --host-addr :9982
directory=/home/sia/host
user=sia
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/siad.err.log
stdout_logfile=/var/log/supervisor/siad.out.log

Запускаем sia.

# supervisorctl reload
# supervisorctl start siad
# cat /var/log/supervisor/siad.out.log
Loading...
(0/6) Loading siad...
(1/6) Loading gateway...
(2/6) Loading consensus...
(3/6) Loading transaction pool...
(4/6) Loading wallet...
(5/6) Loading host...
(6/6) Loading renter...
Finished loading in 0.705183109 seconds

Подождем пока siad синхронизируется. Проверить состояние можно с помощью curl.
Текущий height можно посмотреть на сайте https://explore.sia.tech

# curl -s -X GET http://localhost:9980/consensus -A "Sia-Agent"
{"synced":true,"height":94179,"currentblock":"00000000000002bd87e59c5216bc27885800599b2551e92c8ca4554565fc7a6a","target":[0,0,0,0,0,0,3,144,138,27,23,42,193,109,68,203,188,190,127,202,181,210,130,109,205,239,167,224,5,139,19,104]}

Теперь все действия выполняются под пользователем sia.

su sia

Создадим создадим адрес. Обязательно сохраните Recovery seed, Wallet encrypted with password и Created new address.

# siac wallet init
# siac wallet unlock
# siac wallet address
Created new address: 74a8cb4c431cad100e7da8fe7002d6fc0006cb35e77922db2f3b9afad06091d988adcf5c88df

Купите 1k~50k sia на любой бирже и переведите их на свой адрес.

# siac wallet balance
Wallet status:
Encrypted, Unlocked
Confirmed Balance:   49.99 KS
Unconfirmed Delta:  +0 H
Exact:               49990967874342694250048651264 H
Siafunds:            0 SF
Siafund Claims:      0 H

Добавим storage и запустим host.

# mkdir /home/sia/storage
# siac host folder add /home/sia/storage 5000GB
# siac host announce IP:PORT
# siac host
Host info:
	Estimated Competitive Price: 2.393 KS

	Storage:      5.0000 TB (0 B used)
	Price:        750 SC / TB / Month
	Max Duration: 25 Weeks

	Accepting Contracts: Yes
	Anticipated Revenue: 20 SC
	Locked Collateral:   1.532 SC
	Revenue:             0 H

Storage Folders:
    Used    Capacity     % Used    Path
    0 B     5.0000 TB    0.00      /home/sia/storage

Через несколько часов - проверьте свою ноду на сайте https://siahub.info

NAT

internet <===> server (real ip) <===> lan (192.168.0.1/24) <===> sia (192.168.0.119)

iptables -t nat -A PREROUTING -p tcp -i eth0 -m multiport --dports 9981,9982 -j DNAT --to-destination 192.168.0.119
iptables -A FORWARD -p tcp -d 1192.168.0.119 -m multiport --dports 9981,9982 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

Проверить с помощью telnet. Зайдите на удаленный сервер/vps.

telnet IP 9981
telnet IP 9982

Auto unlock wallet

Create file /home/sia/unlock.txt

Wallet encrypted with password in one line

Create file /etc/cron.d/sia

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=""
HOME=/

*/10 * * * * sia echo $(cat /home/sia/unlock.txt) | siac wallet unlock >/dev/null 2>&1

Restart cron.

/etc/init.d/crond restart

Auto update sia

Create file /home/sia/bin/update.bash

#!/bin/bash
x=$(/home/sia/bin/siac update)

if [[ $x == *"Updated to version"* ]]; then
	/home/sia/bin/siac stop
fi

Add new task in file /etc/cron.d/sia

25 8 * * * sia /home/sia/bin/update.bash >/dev/null 2>&1

Restart cron.

/etc/init.d/crond restart

Auto update price

Install php.

apt-get install php5-cli

Create file /home/sia/bin/price.php

#!/usr/bin/php5
<?php
$arr = array_slice(json_decode(file_get_contents("https://siahub.info/api/network"), true), -1);
$price = round($arr[0]["avg_storageprice"]);
if(!is_numeric($price) || $price > 1000 || $price < 1) die;
shell_exec(escapeshellcmd("siac host config minstorageprice {$price}SC\n"));

Add new task in file /etc/cron.d/sia

0 8 */7 * * sia /home/sia/bin/price.php >/dev/null 2>&1

Restart cron.

/etc/init.d/crond restart

Fast download consensus.db

You can download consensus.db from https://consensus.siahub.info/

supervisorctl stop siad
su sia
cd ~/host/consensus/
rm consensus.db
wget https://consensus.siahub.info/consensus.db # check current link on site

Links

http://sia.tech/
https://siawiki.tech/
https://github.com/NebulousLabs/Sia
https://en.wikipedia.org/wiki/Cooperative_storage_cloud