Setting Up SQL and Redis Proxy Servers - Pratiksha-Marane/duplo-docs GitHub Wiki

Setting Up SQL and Redis Proxy Servers

SQL Proxy Server Setup

Steps:

  1. Create a Virtual Machine (VM):

    • Launch a new Proxy VM instance within the same VPC where we have SQL instance.
  2. SSH into the VM:

    • Use SSH to connect to the created VM
  3. Install a SQL Proxy Tool

    • Update the package list:
      sudo apt-get update
    • Install the SQL proxy tool (e.g., Cloud SQL Proxy):
      sudo apt-get install google-cloud-sdk-cloud-sql-proxy -y
  4. Set Up the SQL Proxy as a Service

    • Create a systemd service file for the SQL proxy:
      sudo nano /etc/systemd/system/cloud-sql-proxy.service
      Add the following content:
        [Install]
        WantedBy-multi-user.target
        Description Google Cloud Compute Engine SQL Proxy
        Requires-network.target
        After-network.target
      
        [Service]
        User=root
        Type-simple
        Working Directory=/usr/local/bin
        ExecStart=/usr/local/bin/cloud-sql-proxy {Sql-server endpoint} -p {Provide the port on which it should run locally} --private-ip 
        address {private ip of vm instance}
        Restart always
        StandardOutput-journal
  5. Start and Enable the SQL Proxy Service

    • Start the service:
      sudo systemctl start cloud-sql-proxy
    • Enable the service to start on boot:
      sudo systemctl enable cloud-sql-proxy

Redis Proxy Server Setup

Steps to Set Up

1. Set the Correct Project

Run the following command on your local to set your project in gcloud:

gcloud config set project {project-id}

Verify the project configuration by running:

gcloud config get-value project

Ensure the output matches your intended project ID: {project-id}.


2. Connect to OpenVPN

  • Connect to perimeter81.

3. Create SSH Tunnel to Proxy Server

Run the following command to create an SSH tunnel from your local machine to the proxy server:

gcloud compute ssh {vm instance-name} --zone=us-west2-b --ssh-flag="-N -L 6379:<redis-ip>:6379"

Replace <redis-ip> with the actual private IP address of the Redis instance.


4. Access Redis

After setting up the SSH tunnel, you can access the Redis instance using the following command on your local machine:

redis-cli -h localhost -p 6379

Configuring Firewall Rules

  1. Go to the "Firewall" section in your GCP console.

  2. Click on "Create firewall rule".

  3. Fill in the details:

    • Name: proxy
    • Network: select your vpc
    • Target Tags: proxy-vm name
    • Source IPv4 Range: <Your public IP>/32 or Perimeter81 IP
    • Protocol and Ports:
      • Select: TCP
      • Port: 22,{Provide the port that you have assigned to run SQL locally}
  4. Click on "CREATE" to save the firewall rule.

⚠️ **GitHub.com Fallback** ⚠️