Useful shortcuts for vi editor

Wednesday, 31 October 2018

How to connect into local VM via SSH?

* Set a new Port Forwarding Rule in Network Settings

Step 1: Settings -> Network -> Adapter 1 -> Advanced -> Adapter Type -> "Paravirtualized network adapter (virtio-net)" -> OK

Step 2: Settings -> Network -> Adapter 1 -> Advanced -> Keep it as "NAT" -> Click "Port Forwarding" -> Define a Rule -> OK
e.g.
Name Protocol Host Port Guest Port
SSH TCP      1022 22

SSH Connection Host/Port Settings:
Host: 127.0.0.1
Port: 1022

WSREP "Failed to open channel" solution

Error
ERROR WSREP "Failed to open channel 'my_mariadb_cluster'"

Detailed Error
WSREP: gcs/src/gcs.cpp:gcs_open():1458: Failed to open channel 'my_mariadb_cluster' at 'gcomm://10.10.10.10,10.10.10.11': -110 (Connection timed out)

Solution
On the first node: (e.g. node-1)
-> Stop mariadb service if it hangs
# systemctl stop mariadb.service

-> Make sure "safe_to_bootstrap" value is "1"
# cat /var/lib/mysql/grastate.dat
safe_to_bootstrap: 1

-> Run following command for starting cluster as new
# galera_new_cluster

-> mariadb service should be started automatically
# systemctl status mariadb.service

-> note wsrep_last_committed number by looking system table
# mysql -u root -p
> show status like 'wsrep_%';

-> note uuid number
# cat /var/lib/mysql/grastate.dat

On the second node: (e.g. node-2)
-> Stop mariadb service if it hangs
# systemctl stop mariadb.service

-> uuid and seqno (wsrep_last_committed) should be same with node-1
# vi /var/lib/mysql/grastate.dat
uuid: 0000
seqno: 100

-> start mariadb service
# systemctl start mariadb.service

Monday, 8 October 2018

How to find/follow postgresql server logs?

-> Check log level from config file
# cat /var/lib/pgsql/data/postgresql.conf
e.g.
log_min_messages= 'ERROR' (default value)
(options; DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, and PANIC)

-> Determine log directory name (via postgres user)
$ psql
postgres=# show log_directory;
e.g. pg_log

-> Determine data directory name (via postgres user)
$ psql
postgres=# show data_directory;
e.g. /var/lib/pgsql/data

-> Determine log file name (via postgres user)
$ psql
postgres=# show log_filename;
e.g. postgresql-%a.log (%a will be "day" of the week)
e.g. postgresql-%a-%H.log (%H will be "hour" of the day)

-> Check log rotation age of the log files
postgres=# show log_rotation_age;
e.g. 1d (1d means one day)
* The database system generate log files daily
e.g. 1h (1h means one hour)
* The database system generate log files hourly

Eventually, the log path could be like this;
e.g. 
# ls /var/lib/pgsql/data/pg_log/postgresql-Mon.log
# ls /var/lib/pgsql/data/pg_log/postgresql-Mon-07.log

-> To follow the logs by tail
e.g.
# tail -100f /var/lib/pgsql/data/pg_log/postgresql-Mon.log
# tail -100f /var/lib/pgsql/data/pg_log/postgresql-Mon-07.log

Ref: https://www.postgresql.org/docs/9.5/static/runtime-config-logging.html

Thursday, 4 October 2018

How to setup/configure/use mailx for Office365 account?

-> Update the OS
# yum -y update
or (y -> yes)
# yum update

-> Install mailx
# yum install -y mailx

-> Define soft link to use "email" the command
# ln -s /bin/mailx /bin/email

-> Prepare config file
# vi /etc/mail.rc
set smtp=outlook.office365.com
set smtp-auth-user=alper@alper.com
set smtp-auth-password=alper123
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
set smtp-use-starttls
set from="alper@alper.com(Alper Ozsoyler)"

-> Try to send an email to yourself
# echo "Your message is my message!" | email -v -s "Message Subject is Bla Bla" alper@alper.com

Ref: https://gist.github.com/ilkereroglu/aa6c868153d1c5d57cd8

How to solve "restarting/pending pod repeatedly" problem?

-> Check the pods status
e.g.
# kubectl get pods --all-namespaces
NAMESPACE     NAME                            READY     STATUS
kube-system   coredns-78fcdf6894-6ggkk        0/1       Pending
kube-system   coredns-78fcdf6894-tm52r        0/1       Pending 

-> Check the deployments
# kubectl get deployment --all-namespaces
NAMESPACE     NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE
kube-system   coredns   2         2         2            0

-> Needs to remove the deployments related to pod and service
e.g.
# kubectl delete deployment coredns -n kube-system
deployment.extensions "coredns" deleted

Tuesday, 2 October 2018

How to enable Hyper-V in Windows 10?

Press Windows key -> Type "Turn Windows features on or off" then click it -> Select "Hyper-V" check box then click "OK" -> Restart PC -> Done!