Common things we need as SysAdmins on Cloud

byGinkTue, 28 Nov 2023

Install dig on Alpine

We can install dig, nslookup and their dependencies by adding package bind-tools. These commands are very useful to check the IP address from the domain name.

apk update
apk add bind-tools
  • How to use it?
dig google.com

# ;; ANSWER SECTION:
# google.com.		39	IN	A	74.125.200.101
# google.com.		39	IN	A	74.125.200.102

Install telnet on Alpine

Telnet is a common way to verify the connection between your server to another one by testing connectivity to TCP ports. Can install telnet via this package busybox-extras.

apk update
apk add busybox-extras
  • How to use it?
telnet google.com 80
# Connected to google.com

# Press [Ctrl + $] to quit

Install SSH on Alpine

SSH is very useful when we need to allow different users access to the server via Linux account. Let's install OpenSSH

apk update
apk add openssh
  • How to use it?
# Generate host key if not existing
ssh-keygen -A

# Start SSH server
/usr/sbin/sshd -D -e "$@"
  • Note: to support SSH tunnel, may need to open /etc/ssh/sshd_config and modify these options:
AllowTcpForwarding yes
TCPKeepAlive yes
PermitTTY yes

Install hey or wrk to benchmark HTTP services

Tools like hey and wrk are used for performance testing and benchmarking of web servers or web applications. They simulate a large number of concurrent users or requests to assess the system's capacity, performance, and response times under different loads.

apk update
apk add hey
apk add wrk
  • How to use them?
hey -z 30s http://localhost

wrk -d 30s http://localhost

Install curl and jq to access REST apis

Sometimes, we need to access internal REST api from the shell and check the response as Json. curl and jq are created for that.

apk update
apk add curl
apk add jq

How to use them?

  • curl to access API in shell:
curl http://localhost:8080/api
# {"status":"success"}
  • If the response is in Json, we can pipe the result with jq for a better look:
curl http://localhost:8080/api | jq
{
  "status": "success"
}

jq is pretty useful when you need to read a part of the json response. For example, the api at http://localhost:8080/auth replies a json with this format:

{
  "data": {
    "access_token": "your-token-here"
  }
}

And what you really care about is the token. You can read it directly like this:

curl http://localhost:8080/auth | jq -r '.data.access_token'

Tips: Sometimes you may need to skip SSL verification due to self-signed certificate with internal services. Let's try:

curl -k https://localdomain.com/api

Install speedtest-cli for bandwidth checking

You might need to check how fast is your network where your container is running. speedtest will provide a quick look.

apk update
apk add speedtest-cli

How to use it?

  • Just simply trigger speed test command:
speedtest


© 2016-2024  GinkCode.com