Set Permanant hostname on AWS EC2 CentOS 7 server

On AWS EC2 when you boot, hostname set something like ip-172-31-41-172.eu-central-1.compute.internal

To chaneg this, run

Example

To disable change of hostname, run

Now reboot your server with

Resize Amazon EC2 Boot Disk

Once you resize disk in Amazon AWS console, it get auto resized on reboot. Some times this won’t happen, you have to manually resize the disk.

To resize disk, do the following.

1) Take a snapshot of the disk
2) Create a new server in same availability zone as current server. Lets call it tmpServer.
3) Shutdown tmpServer.
4) Shutdown the server that need disk resized. Lets call it mainServer. Make sure you have Elastic IP, if not shutting down changes IP of the server.
5) Detach the disk.
6) Attack the disk in tmpServer as /dev/xvdf
7) Start tmpServer.

Login to tempServer and do the following.

Resize Partition

Firt find the devices

In this cause /dev/xvdf is the disk that need to be resized. Current Size is approx 107 GB.

To see free disk space on this disk, run

There is 21.5GB free space on the disk.

To grow partition 1 to use up remaining disk space, run command

Verify free disk space after. Now you see there is not much free disk space left after partition 1.

Resize FileSystem

Resize file system depends on the type of file system you are using. For ext4, do the folllowing.

Check disk using e2fsck

If any errors found, you will be asked to press “y” to fix the errors. After e2fsck run, you can reszie filesystem with command

You have completed resizeing the disk. All you need to do now is

8) Shutdown tmpServer
9) Detact the disk from tmpServer (/dev/xvdf)
10) Attach the disk on original server mainServer as /dev/sda1.

11) start the mainServer.

VMWare esxcli

To list all running VM, run

To list all installed software

Example

Amazon Route 53 DKIM error

DKIM keys failed to validate on a mail server. The domain used Amazon ROute 53 DNS server.

amavisd-new showkeys command print out following public key for this domain.

When you cut and paste this in Amazon ROute 53, it get treadted as 4 seperate TXT records.

When i test with

It shows syntax error.

To fix this, make the DKIM key into 1 line and paste into Amazon Route 53.

Now the nslookup response look like

Once DNS record updated, testkeys command passed.

kubectl

kubectl command is used to manage Kubernetes Clusters.

To install kubectl on Linux, run

On Ubuntu, you can install from snap using

or with apt

To get help, run

Check if Kubernetes environment is ready

Run nginx container

Connect to a pod

Execute a command in pod

Change image used by a pod

Scale a deployment

Expose a port

Port forward

Some useful commands

kubectl get no
kubectl get nodes
List all available nodes
kubectl get po
kubectl get pods
List all available pods
kubectl get services
kubectl get svc
List all available services
kubectl config current-context Shows with cluster kubectl is connected to.
kubectl cluster-info Shows info on current cluster.
kubectl scale deployment DEPLOYMENT_NAME –replicas 4 Scale a deployment to 4 replicas.
kubectl create ns production Create namespace “production”
kubectl -n kube-system create sa tiller Create tiller account for helm

See Kubernetes

Install LetsEncrypt SSL on Bitnami

To install LetsEncrypt SSL on bitnami wordpress server, install letsencrypt with

Stop apache web server with

Now get SSL certificate using certbot

Now you have SSL certficate, lets copy it to bitnami folder

Start the web server with

Auto Renew LetsEncrypt

Create file

Add following to the file

make the script executable

Set a cronjob to execute it every month

See bitnami