Skip to content

Instantly share code, notes, and snippets.

@wakiyamap
Last active April 1, 2023 07:25
Show Gist options
  • Save wakiyamap/a9062193f3af254487f36f4a33b5aafa to your computer and use it in GitHub Desktop.
Save wakiyamap/a9062193f3af254487f36f4a33b5aafa to your computer and use it in GitHub Desktop.
## monacoin.confの内容
rpcuser=wakiyamatamamichankawaii
rpcpassword=[適当にパスワードどうぞ]
daemon=1
txindex=1
addressindex=1
spentindex=1
server=1
## ライブラリ等追加
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update && sudo apt-get install python3.7 python3.7-dev
sudo apt-get install git python3.7-distutils libleveldb-dev
wget https://bootstrap.pypa.io/get-pip.py
python3.7 get-pip.py
sudo pip3 install setuptools --upgrade
## electrumxユーザー追加
sudo adduser electrumx --disabled-password
## electrumxをgitで持ってくる
git clone https://github.com/kyuupichan/electrumx.git
## electrumxインストール (python3 setup.py installでやると3.5でインストールされるのでアウト)
cd ~/electrumx
sudo python3.7 setup.py install
## electrumx設定ファイル設置用フォルダ作成 & 権限追加
sudo mkdir /var/electrumx
sudo chown electrumx /var/electrumx
## systemdの設定ファイル
cd contrib/systemd
sudo cp electrumx.service /etc/systemd/system/
## SSLの設定 5個目のコマンドで出てくるのは俺俺証明書なら何でもいい。
cd /etc
sudo openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
sudo openssl rsa -passin pass:x -in server.pass.key -out server.key
sudo rm server.pass.key
sudo openssl req -new -key server.key -out server.csr
sudo openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt
## /etc/electrumx.confで作成
## electrumx.confの設定 めんどくさいなら中身コピペでもOK。ただしDAEMON_URLとREPORT_SERVICESは変えること。DONATION_ADDRESSは変えてもそのままでも良いぞ!
# electrumx.conf設定ここから下
DB_DIRECTORY = /var/electrumx
USERNAME = electrumx
ELECTRUMX = /usr/local/bin/electrumx_server
#Bitcoin Node RPC Credentials
DAEMON_URL = http://user:pass@IPaddress:port/
#port is optional, defaults to COIN RPC default
#
#REQUIRED FOR PUBLIC VISIBILITY
#
#Requires
SSL_CERTFILE = /etc/server.crt
SSL_KEYFILE = /etc/server.key
#
#OPTIONAL VISIBILITY
#
BANNER_FILE = /etc/electrumx.banner
DONATION_ADDRESS = MEmGfo7cgRNM3kAHqVkcbesWVrBo7DoEbU
SERVICES = tcp://:50001,ssl://:50002,wss://:50004,rpc://
# sv.usebsv.comを書き換えてelectrumxネットワークにreportしたいドメイン、IPアドレスに書き換える
REPORT_SERVICES = tcp://sv.usebsv.com:50001,ssl://sv.usebsv.com:50002,wss://sv.usebsv.com:50004
LOG_SESSIONS = 0
#
#MISC
#
COIN = Monacoin
#NETWORK = mainnet
#DB_ENGINE = leveldb
#leveldb, rocksdb, lmdb (You'll need to install appropriate python packages)
#REORG_LIMIT = 200
#maximum number of blocks to be able to handle in a chain
#reorganisation. ElectrumX retains some fairly compact
#undo information for this many blocks in levelDB.
#ANON_LOGS =
#Set to anything non-empty to remove IP addresses from logs.
#These following environment variables are to help limit server
#resource consumption and to prevent simple DoS. Address subscriptions
#in ElectrumX are very cheap - they consume about 100 bytes of memory
#each and are processed efficiently. I feel the defaults are low and
#encourage you to raise them.
MAX_SEND = 5000000
SESSION_TIMEOUT = 1800
MAX_SESSIONS = 2000
#If synchronizing from the Genesis block your performance might change
#by tweaking the following cache variables. Cache size is only checked
#roughly every minute, so the caches can grow beyond the specified
#size. Also the Python process is often quite a bit fatter than the
#combined cache size, because of Python overhead and also because
#leveldb consumes a lot of memory during UTXO flushing. So I recommend
#you set the sum of these to nothing over half your available physical
#RAM:
#HIST_MB = 300
#amount of history cache, in MB, to retain before flushing to
#disk. Default is 300; probably no benefit being much larger
#as history is append-only and not searched.
#UTXO_MB = 1000
#amount of UTXO and history cache, in MB, to retain before
#flushing to disk. Default is 1000. This may be too large
#for small boxes or too small for machines with lots of RAM.
#Larger caches generally perform better as there is
#significant searching of the UTXO cache during indexing.
#However, I don't see much benefit in my tests pushing this
#too high, and in fact performance begins to fall. My
#machine has 24GB RAM; the slow down is probably because of
#leveldb caching and Python GC effects. However this may be
#very dependent on hardware and you may have different
#results.
######
# electrumx.conf設定ここから上まで
## electumxのバナー作成、中身はお好きに(electrumクライアントのコンソールで接続時に出るやつ)
sudo nano /etc/electrumx.banner
## ここから運用編
## systemd起動関係コマンド
sudo systemctl start electrumx #起動
sudo systemctl stop electrumx #終了
sudo systemctl restart electrumx #再起動
## ログ確認 ctrl+Cで終了
journalctl -u electrumx -f
## システムアップデート方法
systemd使用時
設定ファイルは/var/electrumx,/etc/electrumxにあるので最悪ホームディレクトリ内にあるであろうelectrumxディレクトリは削除してもOK
daemontools使用時
/contrib/daemontools/env/配下に設定ファイルがあるので注意。バックアップを取っておくこと
基本的にはelectrumxディレクトリ内でgit pullで事足りる。
先にコミットしろ云々言われた際には最悪electrumxディレクトリ削除後、git cloneし直しでもOK。なお上記の点に注意せよ。
## let's encryptで証明書を取得する場合
## 80,443を使っているソフトはする前にkillせよ
## firewallは80,443を開ける
sudo apt-get install letsencrypt
sudo letsencrypt certonly --standalone -d www.example.com #www.example.comは自分のelectrumxサーバのURL
##更新時
sudo /usr/bin/letsencrypt renew --force-renew
## electrumx_compact_historyの時々実行
## スクリプトを動かすroot権限が実行できる場所に置く
## from https://denariustalk.org/index.php?/profile/1583-manosv/content/&type=forums_topic_post&change_section=1
sudo nano /root/compact_electrum_database.sh
## compact_electrum_database.sh の内容ここから
#!/bin/bash
service electrumx stop
export DB_DIRECTORY='/var/electrumx'
export COIN=Monacoin
export DB_ENGINE=leveldb
electrumx_compact_history
chown -R electrumx:electrumx /var/electrumx
service electrumx start
## compact_electrum_database.sh の内容ここまで
sudo chmod +x /root/compact_electrum_database.sh
sudo crontab -u root -e
## crontabで出てきた内容の一番下に設置 1か月に1回/12日に1回
0 1 */12 * * /root/compact_electrum_database.sh >/dev/null 2>&1
## python3.6 からpython3.7に上げるユーザーへ
sudo apt remove python3.6-dev
sudo apt remove python3.6
sudo add-apt-repository --remove ppa:jonathonf/python-3.6
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7 python3.7-dev python3.7-distutils
wget https://bootstrap.pypa.io/get-pip.py
sudo python3.7 get-pip.py
## これを完了した後にgit cloneで落としてきたファイルでsetup.py installするとpython3.6の残り物がエラー吐くので
## electrumx/buildを消すか、もうめんどうなのでelectrumxディレクトリを消した後に再度electrumxをgit cloneするのがおすすめ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment