Guest User

Untitled

a guest
Sep 14th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.63 KB | None | 0 0
  1. # Update
  2.  
  3. Consider updating the versions in `WalletWasabi.Helpers.Constants`. If the versions are updated, make sure the Client Release is already available before updating the backend.
  4.  
  5. ```sh
  6. sudo apt-get update && cd ~/WalletWasabi && git pull && cd ~/WalletWasabi/WalletWasabi.Backend && dotnet restore && cd ~
  7.  
  8. # Check if rounds are not in critical phase
  9.  
  10. https://wasabiwallet.io/api/v4/btc/ChaumianCoinJoin/states
  11.  
  12. # Stop
  13. sudo service nginx stop
  14. sudo systemctl stop walletwasabi.service
  15. sudo killall tor
  16. bitcoin-cli stop
  17.  
  18. # Status checks
  19. echo -n 'Tor: '; systemctl is-active tor; echo -n 'Wasabi: '; systemctl is-active walletwasabi; echo -n 'Bitcoind: '; ps -C bitcoind >/dev/null && echo "active" || echo "incative";
  20.  
  21. # Upgrade and reboot
  22. sudo apt-get upgrade -y && sudo apt-get autoremove -y
  23. sudo reboot
  24. set DOTNET_CLI_TELEMETRY_OPTOUT=1
  25.  
  26. # Start Bitcoind
  27. bitcoind
  28. bitcoin-cli getblockchaininfo
  29.  
  30. # Start Tor
  31. tor
  32.  
  33. # Start Nginx
  34. sudo service nginx start
  35.  
  36. # Start Wasabi
  37. rm -rf WalletWasabi/WalletWasabi.Backend/bin && dotnet publish ~/WalletWasabi/WalletWasabi.Backend --configuration Release --self-contained false
  38. sudo systemctl start walletwasabi.service
  39. echo -n 'Tor: '; systemctl is-active tor; echo -n 'Wasabi: '; systemctl is-active walletwasabi; echo -n 'Bitcoind: '; ps -C bitcoind >/dev/null && echo "active" || echo "incative";
  40. tail -200 /home/user/.walletwasabi/backend/Logs.txt
  41.  
  42. # Advanced status checks
  43. systemctl status nginx
  44. systemctl status walletwasabi
  45. systemctl status tor
  46. pgrep -ilfa bitcoin
  47.  
  48. ```
  49.  
  50. # 1. Create Remote Server
  51.  
  52. ## Name
  53. WalletWasabi.Backend.[TestNet/Main]
  54.  
  55. ## Image
  56. Ubuntu 20.04 x64
  57.  
  58. ## Region
  59. Mostly anywhere is fine, except the US or China.
  60.  
  61. ## Size
  62.  
  63. https://bitcoin.org/en/full-node#minimum-requirements
  64.  
  65. [4GB Standard/32GB Standard]
  66.  
  67. # 2. Setup Server
  68.  
  69. https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-20-04
  70.  
  71. ## SSH in as Root
  72.  
  73. Putty (Copypaste with Ctrl+Insert and Shift+Insert)
  74. https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users
  75.  
  76. Make sure the new user's SSH pubkey added to ~/.ssh/authorized_keys on the server as well.
  77.  
  78. ### Create a New User and Grant Administrative Privileges
  79.  
  80. ```sh
  81. adduser user
  82. usermod -aG sudo user
  83. ```
  84.  
  85. ### Increase the number of files limit
  86.  
  87. By default a process can keep open up to 4096 files. Increase that limit for the `user` user as follows:
  88.  
  89. ```sh
  90. pico /etc/security/limits.conf
  91. ```
  92.  
  93. ```
  94. # Wasabi backend
  95. # Wasabi runs with the user called user
  96. user soft nofile 16384
  97. user hard nofile 16384
  98. # End of Wasabi backend
  99. ```
  100.  
  101. # Setup Firewall
  102.  
  103. https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-14-04
  104.  
  105. ```sh
  106. ufw allow OpenSSH
  107. ufw enable
  108. ```
  109.  
  110. > As the firewall is currently blocking all connections except for SSH, if you install and configure additional services, you will need to adjust the firewall settings to allow acceptable traffic in. You can learn some common UFW operations in this guide.
  111. > https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands
  112. ## Enable External Access for User
  113.  
  114. ```sh
  115. rsync --archive --chown=user:user ~/.ssh /home/user
  116. ```
  117.  
  118. ## Update Ubuntu
  119.  
  120. ```sh
  121. sudo apt-get update && sudo apt-get dist-upgrade -y
  122. ```
  123.  
  124. # 3. Install .NET SDK
  125.  
  126. https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu
  127.  
  128. Opt out of the telemetry:
  129.  
  130. ```sh
  131. export DOTNET_CLI_TELEMETRY_OPTOUT=1
  132. ```
  133.  
  134. # 4. Install Tor
  135.  
  136. ```sh
  137. sudo apt-get install tor
  138. pgrep -ilfa tor
  139. sudo killall tor
  140. ```
  141.  
  142. ### Update Tor
  143.  
  144. ```sh
  145. sudo apt update
  146. apt list --upgradable | grep tor
  147. sudo apt install --only-upgrade tor
  148. ```
  149.  
  150.  
  151. Create torrc:
  152.  
  153. ```sh
  154. mkdir ~/.walletwasabi
  155. sudo pico /etc/tor/torrc
  156. ```
  157.  
  158. ```sh
  159. Log notice file /home/user/.walletwasabi/notices.log
  160.  
  161. HiddenServiceDir /home/user/.hidden_service_v3
  162. HiddenServiceVersion 3
  163. HiddenServicePort 80 127.0.0.1:37127
  164.  
  165. RunAsDaemon 1
  166.  
  167. # ---MAKE TOR FASTER---
  168.  
  169. # Need to disable for HiddenServiceNonAnonymousMode
  170. SOCKSPort 0
  171. # Need to enable for HiddenServiceSingleHopMode
  172. HiddenServiceNonAnonymousMode 1
  173. # This option makes every hidden service instance hosted by a tor
  174. # instance a Single Onion Service. One-hop circuits make Single Onion
  175. # servers easily locatable, but clients remain location-anonymous.
  176. HiddenServiceSingleHopMode 1
  177. ```
  178.  
  179. Enable firewall:
  180. ```sh
  181. sudo ufw allow 80
  182. ```
  183.  
  184. Start Tor and verify it is properly running:
  185. ```sh
  186. tor
  187. pgrep -ilfa tor
  188. ```
  189.  
  190. **Backup the generated private key!**
  191.  
  192. # 5. Install, Configure and Synchronize bitcoind (Bitcoin Knots)
  193.  
  194. https://bitcoinknots.org/
  195.  
  196. ```sh
  197. sudo add-apt-repository ppa:luke-jr/bitcoinknots
  198. sudo apt-get update
  199. sudo apt-get install bitcoind
  200. mkdir ~/.bitcoin
  201. pico ~/.bitcoin/bitcoin.conf
  202. ```
  203.  
  204. ```sh
  205. testnet=[0/1]
  206.  
  207. [main/test].rpcworkqueue=256
  208. [main/test].rpcthreads=8
  209.  
  210. [main/test].txindex=1
  211.  
  212. [main/test].daemon=1
  213. [main/test].server=1
  214. [main/test].rpcuser=bitcoinuser
  215. [main/test].rpcpassword=password
  216. [main/test].whitebind=127.0.0.1:[8333/18333]
  217. [main/test].mempoolreplacement=fee,optin # Only valid for Bitcoin Knots - https://github.com/MetacoSA/NBitcoin/pull/884#issuecomment-663620290
  218. #[main/test].debug=rpc # in some cases it could be good to uncomment this line.
  219. ```
  220. https://bitcoincore.org/en/releases/0.17.0/
  221. https://medium.com/@loopring/how-to-run-lighting-btc-node-and-start-mining-b55c4bab8ad
  222. https://github.com/MrChrisJ/fullnode/issues/18
  223.  
  224. ```sh
  225. sudo ufw allow ssh
  226. sudo ufw allow [8333/18333]
  227. bitcoind
  228. bitcoin-cli getblockcount
  229. bitcoin-cli stop
  230. bitcoind
  231. ```
  232.  
  233. ### Upgrade Knots
  234.  
  235. ```sh
  236. bitcoin-cli stop
  237. sudo apt-get update && sudo apt install --only-upgrade bitcoind
  238. bitcoind --version
  239. bitcoin-cli getblockchaininfo
  240. ```
  241.  
  242. # 6. Publish, Configure and Run WalletWasabi.Backend
  243.  
  244. ```sh
  245. git clone https://github.com/zkSNACKs/WalletWasabi.git
  246. cd WalletWasabi
  247. dotnet restore
  248. dotnet build
  249. dotnet publish WalletWasabi.Backend --configuration Release --self-contained false
  250. cd ..
  251. ```
  252.  
  253. https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.0&tabs=aspnetcore2x
  254.  
  255. ```sh
  256. sudo pico /etc/systemd/system/walletwasabi.service
  257. ```
  258.  
  259. ```sh
  260. [Unit]
  261. Description=WalletWasabi Backend API
  262.  
  263. [Service]
  264. WorkingDirectory=/home/user/WalletWasabi/WalletWasabi.Backend/bin/Release/net6.0/publish
  265. ExecStart=/usr/bin/dotnet /home/user/WalletWasabi/WalletWasabi.Backend/bin/Release/net6.0/publish/WalletWasabi.Backend.dll
  266. Restart=always
  267. RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
  268. SyslogIdentifier=walletwasabi-backend
  269. User=user
  270. Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
  271.  
  272. [Install]
  273. WantedBy=multi-user.target
  274. ```
  275.  
  276. ```sh
  277. sudo systemctl enable walletwasabi.service
  278. sudo systemctl start walletwasabi.service
  279. systemctl status walletwasabi.service
  280. tail -10000 .walletwasabi/backend/Logs.txt
  281.  
  282. pico .walletwasabi/backend/Config.json
  283. pico .walletwasabi/backend/CcjRoundConfig.json
  284. sudo systemctl start walletwasabi.service
  285. tail -10000 .walletwasabi/backend/Logs.txt
  286. ```
  287.  
  288. ## Tor
  289.  
  290. ```sh
  291. tor
  292. pgrep -ilfa tor
  293. ```
  294.  
  295. Review the tor activity using the logs stored in the linux journal:
  296.  
  297. ```sh
  298. sudo journalctl -u tor@default
  299. ```
  300.  
  301. ## Load balance and server performance
  302.  
  303. Check load avarages
  304. ```sh
  305. uptime
  306. ```
  307. Check the number of CPU-s
  308. ```sh
  309. nproc
  310. ```
  311.  
  312. Load average numbers are in order according to the average time-window in the last - 1, 5, 15 minutes. Zero means no load, 1 means 100% load - however, average loads are added up among the number of CPUs. So as far as the load average is not bigger than the number of CPUs, there shouldn't be any performance issues.
  313.  
  314. For interactive monitoring you can use:
  315. ```sh
  316. htop
  317. ```
  318.  
  319. # 8. Setup Nginx
  320.  
  321. https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.0&tabs=aspnetcore2x#install-nginx
  322. Only setup Nginx if you want to expose the autogenerated website to the clearnet.
  323.  
  324. Enable firewall:
  325. ```sh
  326. sudo ufw allow http
  327. sudo ufw allow https
  328. ```
  329.  
  330. ```sh
  331. sudo apt-get install nginx -y
  332. sudo service nginx start
  333. ```
  334. Verify the browser displays the default landing page for Nginx.
  335. The landing page is reachable at `http://<server_IP_address>/index.nginx-debian.html`
  336.  
  337. ```sh
  338. sudo pico /etc/nginx/sites-available/default
  339. ```
  340.  
  341. Fill out the first server's name with the server's IP and domain, and remove the unneeded domains and the second server. (Note that I use `wasabiwallet.co` for testnet.)
  342.  
  343. ```
  344. server {
  345. listen 80;
  346. listen [::]:80;
  347. listen 443 ssl;
  348. listen [::]:443 ssl;
  349. server_name [InsertServerIPHere] wasabiwallet.net www.wasabiwallet.net wasabiwallet.org www.wasabiwallet.org wasabiwallet.info www.wasabiwallet.info wasabiwallet.co www.wasabiwallet.co zerolink.info www.zerolink.info hiddenwallet.org www.hiddenwallet.org;
  350. location / {
  351. sub_filter '<head>' '<head><meta name="robots" content="noindex, nofollow" />';
  352. sub_filter_once on;
  353. proxy_pass http://localhost:37127;
  354. }
  355. }
  356. server {
  357. listen 80;
  358. listen [::]:80;
  359. listen 443 ssl;
  360. listen [::]:443 ssl;
  361. server_name wasabiwallet.io www.wasabiwallet.io;
  362. location / {
  363. proxy_pass http://localhost:37127;
  364. }
  365. }
  366. ```
  367.  
  368. ```sh
  369. sudo nginx -t
  370. sudo nginx -s reload
  371. ```
  372.  
  373. Setup https, redirect to https when asks. This will modify the above config file, but oh well.
  374.  
  375. ```sh
  376. sudo certbot -d wasabiwallet.io -d www.wasabiwallet.io -d wasabiwallet.net -d www.wasabiwallet.net -d wasabiwallet.org -d www.wasabiwallet.org -d wasabiwallet.info -d www.wasabiwallet.info -d wasabiwallet.co -d www.wasabiwallet.co -d zerolink.info -d www.zerolink.info -d hiddenwallet.org -d www.hiddenwallet.org
  377. ```
  378.  
  379. certbot will not properly redirect www, so it must be setup by hand, one by one.
  380. Duplicate all entries like this by adding a `www.`:
  381. ```
  382. server {
  383. if ($host = wasabiwallet.co) {
  384. return 301 https://$host$request_uri;
  385. }
  386. }
  387. ```
  388.  
  389. Add `add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;` and `server_tokens off;` to every HTTPS `server` block.
  390.  
  391. ```sh
  392. sudo nginx -t
  393. sudo nginx -s reload
  394. ```
  395.  
  396. After accessing the website finalize preload in https://hstspreload.org/
  397.  
  398. # Check If Everything Works
  399.  
  400. TestNet: http://testwnp3fugjln6vh5vpj7mvq3lkqqwjj3c2aafyu7laxz42kgwh2rad.onion/swagger/
  401. Main: http://wasabiukrxmkdgve5kynjztuovbg43uxcbcxn6y2okcrsg7gb6jdmbad.onion/swagger/
  402. GET fees
  403.  
  404. http://www.wasabiwallet.io/
  405.  
  406. # Check Statuses
  407.  
  408. ```sh
  409. tail -f ~/.bitcoin/debug.log
  410. tail -10000 .walletwasabi/backend/Logs.txt
  411. du -bsh .walletwasabi/backend/IndexBuilderService/*
  412. ```
  413. # Specify Your ExtPubKey
  414.  
  415. Take your ExtPubKey from Wasabi. Never receive money to that wallet's external keypath.
  416.  
  417. ```sh
  418. pico ~/.walletwasabi/backend/CcjRoundConfig.json
  419. ```
  420.  
  421. Add your extpub to the `CoordinatorExtPubKey`.
  422.  
  423. # Additional (optional) Settings
  424.  
  425. ## Rolling Bitcoin Knots node debug logs
  426.  
  427. The following command line adds a configuration file to let logrotate service know
  428. how to rotate the bitcoin debug logs.
  429.  
  430. ```sh
  431. sudo tee -a /etc/logrotate.d/bitcoin <<EOS
  432. /home/user/.bitcoin/debug.log
  433. {
  434. su user user
  435. rotate 5
  436. copytruncate
  437. daily
  438. missingok
  439. notifempty
  440. compress
  441. delaycompress
  442. sharedscripts
  443. }
  444. EOS
  445. ```
  446.  
  447. **Note:** In test server replace the first line by the following one `/home/user/.bitcoin/testnet3/debug.log`
  448.  
  449. ## Welcome Banner
  450.  
  451. The following command line adds a welcome banner indicating the ssh logged user that he is in the production server.
  452.  
  453. ```sh
  454. sudo pico /etc/motd
  455. ```
  456.  
  457. ```
  458. ****************************************************************************
  459. *** Attention! Wasabi PRODUCTION server ***
  460. ****************************************************************************
  461. ```
  462.  
  463. ## Prompt
  464.  
  465. Additionally to the welcome banner it could be good to know in which server we are all the time and to see clearly which branch is checked out, in this case update the prompt as follow:
  466.  
  467. ```sh
  468. pico ~/.bashrc
  469. ```
  470.  
  471. Replace the line:
  472.  
  473. ```sh
  474. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  475. ```
  476.  
  477. by this one:
  478.  
  479. ```sh
  480. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:(PROD):\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
  481. ```
  482.  
  483. Additionally add the following function before:
  484.  
  485. ```sh
  486. parse_git_branch() {
  487. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
  488. }
  489. ```
  490.  
  491. **Note:** In the test server replace the word **PROD** by **TEST**
  492.  
  493. ## Let's Encrypt
  494.  
  495. [Let’s Encrypt](https://letsencrypt.org/about/) is a free, automated, and open certificate authority (CA), run for the public’s benefit.
  496. It is renewed automatically by certbot which is an agent software installed on both backends. A newly created or renewed certificates are valid for 90 days and the renewal process should start automatically (`cronjob`) if the certificate will expire in less than 30 days.
  497.  
  498. You can list the certificates with:
  499.  
  500. `sudo certbot certificates`
  501.  
  502. Check all of the certificates that you’ve obtained and tries to renew any that will expire in less than 30 days (this should be automatic):
  503.  
  504. `sudo certbot renew`
  505.  
  506. !Be aware that after 5 failures you will be suspended for an hour - for debugging use `certbot renew --dry-run`.
  507.  
  508. Detailed instuctions about configuration [here](https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx).
  509.  
  510. ## Accessing Software Logs
  511.  
  512. You can read the log file with the `tail -1000 ~/.walletwasabi/backend/Logs.txt`. However these logs aren't kept around forever. In order to access a longer timeframe use `sudo tail -1000 /var/log/syslog | grep "walletwasabi-backend"` and `sudo tail -1000 /var/log/syslog.1 | grep "walletwasabi-backend"`.
  513.  
  514. ## Setup Cloudflare Anti-DDoS for clearnet website
  515.  
  516. Properly implemented DDoS mitigation is what keeps websites online during an attack.
  517. We use Cloudflare to mitigate a DDoS attack by detecting, responding, routing and adapting to it.
  518.  
  519. ### Create a Cloudflare account
  520.  
  521. 1. Visit https://dash.cloudflare.com/sign-up
  522. 2. Enter Email address and Password
  523. 3. Click `Create Account`
  524.  
  525. ### Add a domain to Cloudflare
  526.  
  527. 1. Log in to your Cloudflare account
  528. 2. Click on `Add site` from the top navigation bar
  529. 3. Enter your website’s root domain and then click `Add Site`.
  530. For example, if your website is `https://www.wasabiwallet.co`, type `wasabiwallet.co`
  531. 4. Cloudflare will automatically identify your DNS records
  532. 5. Click `Next`
  533. 6. Select a plan level (the `Free` package is enough, as it contains DDoS attack mitigation and Global Content Delivery Network services)
  534. 7. Click `Confirm` in the Confirm Plan window that appears
  535. 8. Review whether all DNS records were identified in the DNS query results window
  536. 9. Click `Continue`
  537. 10. Copy the 2 Cloudflare nameservers displayed and click `Continue`
  538.  
  539. ### Replace default nameservers with Cloudflare ones
  540.  
  541. 1. Log in to your registrar (eg. Godaddy)
  542. 2. Make sure your registrar has disabled DNSSEC for your domain
  543. 3. Replace the current/default nameserver records in your registrar account with the information you copied from Cloudflare
  544. 4. Wait some hours (max 24) while your registrar updates your nameservers and the DNS propagates
  545. You will receive an email when your site is active on Cloudflare
  546.  
  547. ## DEBUG
  548.  
  549. - Find PID `ps aufx | grep 'WalletWasabi.Backend`
  550. - Creating a core dump: `dotnet dump collect -p 21600`
  551. - Cound threads for dotnet process `pstree -tpl 21600 | wc -l` usually around 109
  552.  
  553.  
Add Comment
Please, Sign In to add comment