Setting Up SQL and Redis Proxy Servers - Pratiksha-Marane/duplo-docs GitHub Wiki
-
Create a Virtual Machine (VM):
- Launch a new Proxy VM instance within the same VPC where we have SQL instance.
-
SSH into the VM:
- Use SSH to connect to the created VM
-
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
- Update the package list:
-
Set Up the SQL Proxy as a Service
- Create a systemd service file for the SQL proxy:
Add the following content:
sudo nano /etc/systemd/system/cloud-sql-proxy.service
[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
- Create a systemd service file for the SQL proxy:
-
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
- Start the service:
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}
.
- Connect to perimeter81.
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.
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
-
Go to the "Firewall" section in your GCP console.
-
Click on "Create firewall rule".
-
Fill in the details:
-
Name:
proxy
-
Network:
select your vpc
-
Target Tags:
proxy-vm name
-
Source IPv4 Range:
<Your public IP>/32
orPerimeter81 IP
-
Protocol and Ports:
-
Select:
TCP
-
Port:
22,{Provide the port that you have assigned to run SQL locally}
-
Select:
-
Name:
-
Click on "CREATE" to save the firewall rule.