Setting up Rubykube ==> Crypto currency exchange

in rails •  6 years ago  (edited)

17 steps guide to deploy production, crypto currency exchange.

Supporting, Bitcoin, Bitcoin Cash, Litecoin, Xrp, Ether, Dash, all their forks

  1. Setup deploy user
  2. Install Ruby
  3. Install MySQL
  4. Install Redis
  5. Install RabbitMQ
  6. Install Bitcoind
  7. Install Nginx with Passenger
  8. Install JavaScript Runtime
  9. Install ImageMagick
  10. Configure Peatio
  11. Setup Pusher
  12. Setup Bitcoin RPC
  13. Run Daemons
  14. Setup Google authentication
  15. Setup Auth0
  16. Run Peatio
  17. Setup nginx

1) Setup deploy user

Create (if it doesn’t exist) deploy user, and assign it to the sudo group
sudo adduser deploy
sudo usermod -a -G sudo deploy

Re-login as deploy user

su deploy
cd

2) Install Ruby

Make sure your system is up-to-date.

         sudo apt-get upgrade
    Installing dependencies
         sudo apt-get install git curl zlib1g-dev build-essential \
           libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 \
           libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev
    Installing rvm
         gpg --keyserver hkp://keys.gnupg.net \
             --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \
                         7D2BAF1CF37B13E2069D6956105BD0E739499BDB

         \curl -sSL https://get.rvm.io | bash -s stable --ruby=2.5.0 --gems=rails
    If you want to skip fetching documentation when installing gems, do the following:
         echo "gem: --no-ri --no-rdoc" > ~/.gemrc
    Source rvm
         source /home/deploy/.rvm/scripts/rvm
         rvm use 2.5.0

3) Install MySQL

     sudo apt-get install mysql-server mysql-client libmysqlclient-dev
    setup a password for root while its installing

    Create environment variables for database
        cd
        sudo nano .bashrc
    ## Add following lines. at the end of .bashrc file
    ## Insert your password for mysql
        export DATABASE_HOST=localhost         
        export DATABASE_USER=root                       
        export DATABASE_PASS=Bilal-IS-Awesome
    Source the bashrc file
        source ~/.bashrc

4) Install Redis

Be sure to install the latest stable Redis, as the package in the distro may be a bit old:

         sudo add-apt-repository ppa:chris-lea/redis-server
         sudo apt-get update
         sudo apt-get install redis-server

5) Install RabbitMQ

    Download Erlang
        wget http://packages.erlang-solutions.com/site/esl/esl-erlang/FLAVOUR_1_general/esl-erlang_20.1-1~ubuntu~xenial_amd64.deb
    Install using gdebi
        sudo apt install gdebi
        sudo gdebi esl-erlang_20.1-1~ubuntu~xenial_amd64.deb
    Install RabbitMQ
        echo "deb https://dl.bintray.com/rabbitmq/debian xenial main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list
        wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -

        sudo apt-get update
        sudo apt-get install rabbitmq-server

        sudo rabbitmq-plugins enable rabbitmq_management
        sudo service rabbitmq-server restart
        wget http://localhost:15672/cli/rabbitmqadmin
        chmod +x rabbitmqadmin
        sudo mv rabbitmqadmin /usr/local/sbin

6) Install Bitcoind

     sudo add-apt-repository ppa:bitcoin/bitcoin
     sudo apt-get update
     sudo apt-get install bitcoind
 Configure

    Prepare config files:
           mkdir -p ~/.bitcoin
           touch ~/.bitcoin/bitcoin.conf
           sudo nano ~/.bitcoin/bitcoin.conf
    Insert the following lines into bitcoin.conf, and replce with your username and password.
           server=1
           daemon=1

           # If run on the test network instead of the real bitcoin network
           # testnet=1

           # You must set rpcuser and rpcpassword to secure the JSON-RPC api
           # Please make rpcpassword to something secure, `5gKAgrJv8CQr2CGUhjVbBFLSj29HnE6YGXvfykHJzS3k` for example.
           # Listen for JSON-RPC connections on <port> (default: 8332 or testnet: 18332)
           rpcuser=deployuser
           rpcpassword=deploypass
           rpcport=8332

           # Notify when receiving coins
           walletnotify=/usr/local/sbin/rabbitmqadmin publish routing_key=peatio.deposit.coin payload='{"txid":"%s", "currency":"btc"}'
   Start bitcoin daemon:
           bitcoind

7) Installing Nginx & Passenger

    Install Phusion's PGP key to verify packages
         sudo apt-get install -y dirmngr gnupg
         sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
    Add HTTPS support to APT
         sudo apt-get install apt-transport-https ca-certificates
    Add the passenger repository. Note that this only works for Ubuntu 16.04. For other versions of Ubuntu, you have to add the appropriate repository according to Section 2.3.1 of this link.
         sudo add-apt-repository 'deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main'
         sudo apt-get update
    Install nginx and passenger
         sudo apt-get install nginx-extras passenger
    Next, we need to update the Nginx configuration to point Passenger to the version of Ruby that we're using. You'll want to open up /etc/nginx/nginx.conf in your favorite editor,
         sudo nano /etc/nginx/passenger.conf
    find the following lines, and update them with these:
         passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
         passenger_ruby /home/.rvm/rubies/ruby-2.5.0/bin/ruby;
    Enable to include this file in nginx
         sudo nano /etc/nginx/nginx.conf 
    find this line and uncomment it :)
         include /etc/nginx/passenger.conf;

8) Install JavaScript Runtime

    A JavaScript Runtime is needed for Asset Pipeline to work. Any runtime will do but Node.js is recommended.
        curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
        sudo apt-get install nodejs
    Then install and run yarn:
        sudo apt-get install gcc g++ make
          
        curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
        echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
        sudo apt-get update && sudo apt-get install yarn    

9) Install ImageMagick

     sudo apt-get install imagemagick  

10) Configure Peatio

Setup production environment variable

    Setting up production environment
             echo "export RAILS_ENV=production" >> ~/.bashrc
    Clone the project:
         git clone https://github.com/berycoin-project/Beryxchange.git peatio
         cd peatio
         git checkout 1-8-stable  // Choose your version, but make sure you'll install the same version for peatio-trading-ui
         bundle install
         bin/init_config
    Creating and Sourcing Secret_key_base
         bundle exec rake secret
         echo "export SECRET_KEY_BASE=YOUR-SECRET" >> ~/.bashrc
         source ~/.bashrc
    Install ruby-dev
         sudo apt-add-repository ppa:brightbox/ruby-ng
         sudo apt update
         sudo apt-get install ruby2.5 ruby2.5-dev
         sudo apt upgrade
    Run setup
         bin/setup

11) Setup Pusher

Peatio depends on pusher. A development key/secret pair for development/test is provided in config/application.yml. PLEASE USE IT IN DEVELOPMENT/TEST ENVIRONMENT ONLY!

    Create an account on www.pusher.com

    Create an app

    Set pusher-related settings
        sudo nano config/application.yml

12) Setup bitcoind rpc endpoint

      sudo nano config/seed/currencies.yml
Replace username:pass and port
      json_rpc_endpoint: http://deployuser:[email protected]:8332

13) Run daemons

Make sure you are in /peatio directory
    god -c lib/daemons/daemons.god
This will start all the daemons :)

14) Setup the Google Authentication

    By default, it ask for Google Authentication. This parameter can be changed in /config/application.yml ->
           OAUTH2_SIGN_IN_PROVIDER: google
    Setup a new Web application on https://console.developers.google.com Configure the Google Id, Secret and callback in
           sudo nano config/application.yml
    Note: Make sure your host ISN'T an IP in the callback config. Looks like Google auth expect a callback to a DNS only
           GOOGLE_CLIENT_ID: <Google id>
           GOOGLE_CLIENT_SECRET: <Google secret>
           GOOGLE_OAUTH2_REDIRECT_URL: https://yourAwesome-exchange.com:3000/auth/google_oauth2/callback

15) Setup Auth0

    Change OAUTH2. This parameter can be changed in /config/application.yml ->
           OAUTH2_SIGN_IN_PROVIDER: auth0
    Setup a new Web application on https://manage.auth0.com/
           sudo nano config/application.yml
    Insert values
           AUTH0_OAUTH2_DOMAIN: DOMAIN
           AUTH0_OAUTH2_CLIENT_ID: CLIENTID
           AUTH0_OAUTH2_CLIENT_SECRET: CLIENTSECRET
           AUTH0_OAUTH2_REDIRECT_URL: REDIRECTURI-IN-HTTPS 

16) Run Peatio

    Finalize the config; open /config/application.yml Set the DNS of your host (IP won't work if you use Google Authentication)
        sudo nano config/application.yml
        URL_HOST: yourAwesome-exchange.com:3000
    Start the server:
        bundle exec rails server
OR Make sure the port 3000 is open your server Start the server by passing the ip in parameter
       bundle exec rails server -b 0.0.0.0
OR

You can also provide a port
    bundle exec rails server -p 3000
Validate the server is working:

17) Install nginx to setup a reverse proxy

    sudo apt-get update
    sudo apt-get install nginx
    sudo ufw allow 'Nginx HTTP'
    systemctl status nginx
At this point you should see nginx running

But you need to edit the default config to setup the reverse proxy. Open /etc/nginx/sites-available/default in your favorite editor

Replace the content of the file by the following
    server {
      server_name http://YOUR-AWESOME-WEBSITE.com;
      listen      80 default_server;

      location ~ ^/(?:trading|trading-ui-assets)\/ {
        proxy_pass http://127.0.0.1:4000;
      }

      location / {
        proxy_pass http://127.0.0.1:3000;
      }
    }

Generate JWT key-pair

      ruby -e "require 'openssl'; require 'base64'; OpenSSL::PKey::RSA.generate(2048).tap { |p| puts '', 'PRIVATE RSA KEY (URL-safe Base64 encoded, PEM):', '', Base64.urlsafe_encode64(p.to_pem), '', 'PUBLIC RSA KEY (URL-safe Base64 encoded, PEM):', '', Base64.urlsafe_encode64(p.public_key.to_pem) }"
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thanks for the information

I am the Great Cornholio! I'm a gringo!

You got a 7.75% upvote from @upme thanks to @bilal-haider! Send at least 3 SBD or 3 STEEM to get upvote for next round. Delegate STEEM POWER and start earning 100% daily payouts ( no commission ).

This is really helpful. thanks sir😊

Are you setting up your exchange?

  ·  5 years ago (edited)

I need help setting up an
"exchange" but really I am more interested in using it for market analysis. Are you available for hire to set up the basics? I have a market.yml file that I want to add. I also have a coin list of for the currency.yml. I have a current install but its broke with gems that just want to talk with each other nicely.

not yet 😊

how do you add cryptonote? nice work by the way

am getting berycoin