0G

  1. Clone the Repository:

    Copy

    codulgit clone https://github.com/0glabs/0g-storage-node.git
    cd 0g-storage-node
  2. Install Node.js and npm: If Node.js and npm are not installed, we need to install them. For Ubuntu:

    Copy

    codulsudo apt update
    sudo apt install -y nodejs npm
    node -v
    npm -v
  3. Install Project Dependencies:

    Copy

    codulnpm install
  4. Configure Environment Variables: Create a .env file in the project root:

    Copy

    codultouch .env
    nano .env

    Add the necessary environment variables:

    Copy

    codulNODE_ENV=production
    PORT=3000
    DATABASE_URL=mongodb://localhost:27017/0g_storage_node
    JWT_SECRET=your_secret_key
    API_KEY=your_api_key
  5. Database Setup: Install and start MongoDB:

    Copy

    codulsudo apt update
    sudo apt install -y mongodb
    sudo systemctl start mongodb
    sudo systemctl enable mongodb

    Check MongoDB status:

    Copy

    codulsudo systemctl status mongodb
  6. Build the Project:

    Copy

    codulnpm run build
  7. Run Database Migrations (if applicable):

    Copy

    codulnpm run migrate
  8. Seed the Database (if applicable):

    Copy

    codulnpm run seed
  9. Run the Node:

    Copy

    codulnpm start
  10. Verify Installation: Check the logs and ensure the application is running:

    Copy

    codultail -f logs/app.log

    Verify the application is accessible:

    Copy

    codulcurl http://localhost:3000
  11. Set Up Reverse Proxy with Nginx (Optional): Install Nginx:

    Copy

    codulsudo apt update
    sudo apt install -y nginx

    Configure Nginx:

    Copy

    codulsudo nano /etc/nginx/sites-available/your_domain.com

    Add the following configuration:

    Copy

    codulserver {
        listen 80;
        server_name your_domain.com;
    
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }

    Enable the configuration and restart Nginx:

    Copy

    codulsudo ln -s /etc/nginx/sites-available/your_domain.com /etc/nginx/sites-enabled/
    sudo systemctl restart nginx
  12. Setting Up SSL with Let's Encrypt (Optional): Install Certbot:

    Copy

    codulsudo apt update
    sudo apt install -y certbot python3-certbot-nginx

    Obtain and install the SSL certificate:

    Copy

    codulsudo certbot --nginx -d your_domain.com

    Follow the prompts to complete the SSL setup.

  13. Setting Up a Process Manager (Optional): To ensure the node application runs continuously, we can use a process manager like PM2: Install PM2:

    Copy

    codulnpm install -g pm2

    Start the application with PM2:

    Copy

    codulpm2 start npm --name "0g-storage-node" -- start

    Set PM2 to start on system boot:

    Copy

    codulpm2 startup
    pm2 save
  14. Additional Commands: Checking the status of the application with PM2:

    Copy

    codulpm2 status

    Viewing logs with PM2:

    Copy

    codulpm2 logs 0g-storage-node

    Restarting the application with PM2:

    Copy

    codulpm2 restart 0g-storage-node

By following these steps, including the additional detailed commands and configurations, the 0g-storage-node is thoroughly installed and configured for production use.

Last updated