Useful shortcuts for vi editor

Monday 16 December 2019

unzip vs gunzip

e.g. using unzip and gunzip tools for extracting the zip files

* example.txt file compressed into example.zip file

-> Listing contents of the zip file
$ unzip -l example.zip
gunzip -l example.zip

-> Extracting the zip file
$ unzip example.zip
gunzip -S .zip -c example.zip > example.txt

-> Extracting the zip file to specified directory
unzip example.zip -d /home/alper
gunzip -S .zip -c example.zip > /home/alper/example.txt

Wednesday 20 November 2019

How to reset mariadb root password on using Galera Cluster system?

e.g. reset root password
two machines in a cluster

1st step:

-> Activate "safe_to_bootstrap" parameter on first machine
# vi /var/lib/mysql/grastate.dat
safe_to_bootstrap: 1

2nd step on first/second machine:
# systemctl stop mariadb

3rd step:

-> Run database in safe mode on first machine
# /usr/bin/mysqld_safe --skip-grant-tables --wsrep-new-cluster "${@:2}" > /dev/null 2>&1 & 

4th step:

-> Note the process id of mysql service
# ps -ef | grep mysql

5th step:

-> Connect mysql terminal then run following commands on first machine
# mysql -u root
 use mysql;
 update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
 flush privileges;
 exit

6th step:

-> Try to connect with new password on first machine
# mysql -u root -ppassword

7th step:
-> kill the odd service on first machine
# kill -9 1111

8th step:
-> Start new cluster on first machine
# galera_new_cluster

9th step:

-> Start mariadb on second machine
systemctl start mariadb

Done...

Ref:

https://robbinespu.github.io/eng/2018/03/29/Reset_mariadb_root_password.html
https://blog.toonormal.com/2015/11/23/mariadb-cluster-install-notes/

Friday 18 October 2019

e.g. preparing multiple virtual machines in local network

Hostnames: VM node-A, VM node-B, VM node-C

Adapter 1: Host-only Adapter (VirtualBox-Host-Only Ethernet Adapter)
Type -> Paravirtualized network adapter (virtio-net) - Deny Mode

Adapter 2: Bridged Adapter (Intel Ethernet Connection)
Type -> Paravirtualized network adapter (virtio-net) - Deny Mode

Test
Try to connect one of VMs such as "node-A" by SSH

Monday 30 September 2019

How to solve git merge conflict?

e.g. git merge conflict issue
source: private branch
target: develop branch

1st step:
$ git clone http://blabla --branch private

2nd step:
$ cd <working folder>

3rd step:
$ git checkout private
-> if not specified branch by default while cloning branch

4th step:
$ git merge develop

Error occurred in here
Auto-merging my_new_file.yml
CONFLICT (content): Merge conflict in my_new_file.yml
Auto-merging my_new_file.yml
Automatic merge failed; fix conflicts and then commit the result.

5th step:
-> make necessary changes on my_new_file.yml

6th step:
$ git status
-> check the file

7th step:
$ git branch
-> check the branch before commit

8th step:
$ git add --all

9th step:
$ git commit -m "blabla"

10th step:
$ git push

Tuesday 27 August 2019

Ansible Commands Book

-> valid syntax of the playbook
$ ansible-playbook -i myhosts example.yml -v 
--syntax-check

-> show elapsed time of the playbook

$ time ansible-playbook -i myhosts example.yml -v

-> maintain output verbosity (-v, -vv, -vvv, -vvv)
$ time ansible-playbook -i myhosts example.yml -vvvv

-> list tags/tasks of the playbook
$ ansible-playbook -i myhosts example.yml --list-tags
$ ansible-playbook -i myhosts example.yml --list-tasks

-> run the playbook by getting vault password/sudo password from user
$ ansible-playbook -i myhosts example.yml --ask-vault-pass
$ ansible-playbook -i myhosts example.yml --ask-sudo-pass

-> run the playbook with sudo password 
$ ansible-playbook -i myhosts example.yml -e "ansible_sudo_pass=alper"
(-e, --extra-vars)

How to drop database/user on logical replicated database?

1st step
on 2nd node:
$ echo "DROP SUBSCRIPTION exampledb_node_2" | psql

on 1st node:
$ echo "DROP PUBLICATION exampledb_node_1" | psql

2nd step
on 1st node:
$ echo -e "DROP DATABASE exampledb \n" | psql
$ echo "DROP USER \"user-example\"" | psql

on 2nd node:
$ echo -e "DROP DATABASE exampledb \n" | psql
$ echo "DROP USER \"user-example\"" | psql

Saturday 29 June 2019

Kubernetes label usage

e.g. namespace; kube-system

-> List labels
# kubectl get pods --all-namespaces --show-labels
# kubectl get pods -n kube-system --show-labels

-> List pods via labels
# kubectl get pods -n kube-system -l tier=control-plane

-> Describe pod/pods via labels

# kubectl describe pod -n kube-system -l component=kube-scheduler
# kubectl describe pod -n kube-system -l tier=control-plane

-> Get logs via labels
# kubectl logs -n kube-system -l component=kube-scheduler
kubectl logs -n kube-system -l tier=control-plane

-> Delete pods via labels
kubectl delete pods -n kube-system -l component=example
kubectl delete pods -n kube-system -l 'component in (example,example2)'
# kubectl delete pods -n kube-system -l 'component notin (example3, example4)'

Sunday 19 May 2019

Examples of "escape sequences" usage on echo command

To use interpretation of backslash escapes, just need to put "-e" parameters afterward echo command.

Info: "-e" means enable escape sequences

Examples of backslash escapes:
New line;
$ echo -e "Hello World\n"
-> Hello World

Form feed;
$ echo -e "Hello World\fWhat a lovely day\fI like this\f"
-> Hello World
            What a lovely day
                              I like this

Carriage return;
$ echo -e "Hello World\rWorld"
-> World World

Horizontal tab;
$ echo -e "Hello World\tWhat a lovely day"
-> Hello World     What a lovely day

Vertical tab;
$ echo -e "Hello World\vWhat a lovely day"
-> Hello World
           What a lovely day

Null;
$ echo -e "Hello World\0 What a lovely day"
-> Hello World What a lovely day

Clear after all;
$ echo -e "Hello World\c What a lovely day"
-> Hello World

Escape character;
$ echo -e "Go to \\home directory"
-> Go to \home directory

$ echo -e "Go to \"home\" directory"
-> Go to "home" directory

Unicode usage;
$ echo -e "This is turkish lira symbol-> \u20ba"
-> This is turkish lira symbol-> ₺

Friday 22 February 2019

Linux Terminal Commands Book

chage (manage user password settings)
hostnamectl (show hostname settings)
date (manage system date and time)
* rpm (means RedHat Package Manager)
timedatectl (show timezone settings)
tcpdump (analyze network packages)
* tar (compress the files for archiving)
* tree (see the files as tree format)
* wc (means word count)
* yum (manage RPM packages on RedHat distro)

Thursday 3 January 2019

How to fix "connection refused" error?

Error
e.g.
The connection to the server 10.10.10.10:6443 was refused - did you specify the right host or port?

Solution
On kubernetes control nodes, try to "stop/start" docker service
# service docker restart
or
# systemctl restart docker