• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

curl

Windows Curl Command

January 11, 2023

If you have to download a file from the Internet on a Windows server, can certainly use the browser. But if the browser is rendering the file instead of downloading them, you may have to use the curl command which is already pre-installed on most Windows servers. Just open the command line. Here’s the the curl command to download a file.

curl.exe --output index.txt --url https://website.domain/index.txt

curl.exe --output index.txt --url https://website.domain/index.txt

Filed Under: Misc Tagged With: curl, download, server, windows

GCP Setup NLB

December 23, 2019

Here’s how to setup a Network Load Balancer in GCP.

Setup your instances.

# Instance 1
gcloud compute instances create www1 \
  --image-family debian-9 \
  --image-project debian-cloud \
  --zone us-central1-b \
  --tags network-lb-tag \
  --metadata startup-script="#! /bin/bash
    sudo apt-get update
    sudo apt-get install apache2 -y
    sudo service apache2 restart
    echo '<!doctype html><html><body><h1>www1</h1></body></html>' | tee /var/www/html/index.html
    EOF"
# Instance 2
gcloud compute instances create www2 \
  --image-family debian-9 \
  --image-project debian-cloud \
  --zone us-central1-b \
  --tags network-lb-tag \
  --metadata startup-script="#! /bin/bash
    sudo apt-get update
    sudo apt-get install apache2 -y
    sudo service apache2 restart
    echo '<!doctype html><html><body><h1>www2</h1></body></html>' | tee /var/www/html/index.html
    EOF"
# Instance 3
gcloud compute instances create www3 \
  --image-family debian-9 \
  --image-project debian-cloud \
  --zone us-central1-b \
  --tags network-lb-tag \
  --metadata startup-script="#! /bin/bash
    sudo apt-get update
    sudo apt-get install apache2 -y
    sudo service apache2 restart
    echo '<!doctype html><html><body><h1>www3</h1></body></html>' | tee /var/www/html/index.html
    EOF"

# Instance 1 gcloud compute instances create www1 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www1</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 2 gcloud compute instances create www2 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www2</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 3 gcloud compute instances create www3 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www3</h1></body></html>' | tee /var/www/html/index.html EOF"

Create a firewall to allow external traffic to reach port 80.

gcloud compute firewall-rules create www-firewall-network-lb \
    --target-tags network-lb-tag --allow tcp:80

gcloud compute firewall-rules create www-firewall-network-lb \ --target-tags network-lb-tag --allow tcp:80

Configure your network load balancer.

# Create an external IP address.
gcloud compute addresses create network-lb-ip-1 \
    --region us-central1
# Add a legacy HTTP health check.
gcloud compute http-health-checks create basic-check
# Add a target pool.
gcloud compute target-pools add-instances www-pool \
    --instances www1,www2,www3 \
    --instances-zone us-central1-b
# Add a forwarding rule.
gcloud compute forwarding-rules create www-rule \
    --region us-central1 \
    --ports 80 \
    --address network-lb-ip-1 \
    --target-pool www-pool
# Lookup external IP address.
gcloud compute forwarding-rules describe www-rule \
    --region us-central1

# Create an external IP address. gcloud compute addresses create network-lb-ip-1 \ --region us-central1 # Add a legacy HTTP health check. gcloud compute http-health-checks create basic-check # Add a target pool. gcloud compute target-pools add-instances www-pool \ --instances www1,www2,www3 \ --instances-zone us-central1-b # Add a forwarding rule. gcloud compute forwarding-rules create www-rule \ --region us-central1 \ --ports 80 \ --address network-lb-ip-1 \ --target-pool www-pool # Lookup external IP address. gcloud compute forwarding-rules describe www-rule \ --region us-central1

Finally, use the curl command to send traffic to the NLB external IP address.

while true; do curl -m1 [IP_ADDRESS]; done

while true; do curl -m1 [IP_ADDRESS]; done

Filed Under: Cloud Tagged With: curl, firewall, forwarding, gcp, health check, instances, load balancer, network, nlb, pool

Use Curl on Load Balancers

December 18, 2019

You can use the curl command to test if your load balancer is working as expected. The curl command will alternately and randomly access several instances in your load balancer. If you have 3 instances behind your load balancer, it will be cycled across all 3. The -m1 command means max time is set to 1 second.

while true; do curl -m1 [IP_ADDRESS]; done

while true; do curl -m1 [IP_ADDRESS]; done

Filed Under: Cloud Tagged With: aws, curl, gcp, load balancer, test

GCP Load Balancer Local Routing Table

July 29, 2019

Test if the GCP Load Balancer is working by sending a curl command from the backend VM.

Assume the load balancer IP address is 10.1.2.99, and the VM is called vm-a1.

curl http://10.1.2.99

curl http://10.1.2.99

The end result is …

Page served from: vm-a1

Page served from: vm-a1

Make sure there’s an entry in the local table that matches the IP of the load balancer.

ip route show table local | grep 10.1.2.99

ip route show table local | grep 10.1.2.99

If not, add it.

ip route add to local 10.1.2.99/32 dev eth0 proto 66

ip route add to local 10.1.2.99/32 dev eth0 proto 66

Documentation

Filed Under: Cloud, Linux Tagged With: curl, gcp, load balancer, local, route, table

CodeIgniter 2.1.3 on PHP7

March 18, 2019

If you’re still running older versions of CodeIgniter, here are a couple of tips to make it work with PHP7.

  1. Make sure to install all PHP tools and libraries that comes with PHP7. I was missing curl.
  2. Change your database driver from mysql to mysqli (application/config/config.php).
  3. Fix the /system/core/Common.php error or as some prefer, upgrade to a newer version.

Considering v2.1.3 is very old (currently 3.1.10) , I’m surprised it works with PHP7 with just a few modifications.

Filed Under: PHP Tagged With: codeigniter, curl, mysqli, php7

Weather Report from the Terminal

February 17, 2019

Get the weather report right from your terminal.

curl wttr.in

curl wttr.in

Here’s the output.

Filed Under: Linux Tagged With: curl, terminal, weather, wttr.in

Laravel: Curl and Mycrypt

August 8, 2014

I’ve installed Laravel at least a dozen times. Each time, there’s always something new that goes awry during the installation. If it’s not curl, it’s mcrypt, or maybe the app/storage permissions. I think it’s just the fact that I’m experimenting where to put the Laravel files each time I install. It’s either /var/www or /home/user/. I’m using the Ubuntu standard PHP5 install. You have to specifically install php5-curl in addition to the standard PHP package. I think mcrypt is already in the PHP5 package, but to be sure I added it to the install. Here’s the command.

PHP

sudo apt-get install php5 php5-curl php5-mcrypt

sudo apt-get install php5 php5-curl php5-mcrypt

App/storage

cd /home/user/laravel/app/
chmod -R o+x storage

cd /home/user/laravel/app/ chmod -R o+x storage

These two things seem to solve most of the Laravel installation issues.

Filed Under: PHP Tagged With: curl, laravel, mcrypt

  • Home
  • About
  • Archives

Copyright © 2023