Useful shortcuts for vi editor

Monday 30 July 2018

How to know last login info on the system?

-> show all records
$ last

-> show all records page by page
$ last | more

-> show first 10 records
$ last | head

-> show first 100 records
$ last | head -100

-> show last 10 records
$ last | tail -10

-> show last 100 records
$ last | tail -100

Wednesday 18 July 2018

How to change service name?

e.g.
current service name: postgresql.service
desired service name: postgresql-9.1.service

Run following commands to change service name;

Step 1: Stop current service
# systemctl stop postgresql.service
# systemctl daemon-reload

Step 2: Change service name
# cd /usr/lib/systemd/system
# mv postgresql.service postgresql-9.1.service

Step 3: Start and enable new service
# systemctl start postgresql-9.1.service
# systemctl enable postgresql-9.1.service

Step 4: Check service status:
# systemctl status postgresql-9.1.service

Step 5: Make sure that service runs properly
# journalctl -u postgresql-9.1.service

Friday 13 July 2018

How to solve remote connection error cause of iptables/firewalld service?

Case
Machine A(192.168.1.2) wants to connect on Machine B(192.168.1.5) by database port.

Action
In Machine A;
# su - postgres
$ psql -h 192.168.1.5 -d alper -U alper -p 5433

Error
psql: could not connect to server: No route to host
        Is the server running on host "192.168.1.5" and accepting
        TCP/IP connections on port 5433?

Solution
In Machine B;
For iptables service:
# iptables -I INPUT -p tcp --dport 5433 -j ACCEPT
# iptables-save

For firewalld service:
# firewall-cmd --zone=public --add-port=5433/tcp --permanent
# firewall-cmd --reload

Check
In Machine A;
nc -vz 192.168.1.5 5433
Ncat: Connected to 192.168.1.5:5433

How to solve database module error?

Action
# ansible-playbook -i myhosts example.yml -v

Error
TASK [example role : example task] *******************
fatal: [local]: FAILED! => {"changed": false, "msg": "The MySQL-python module is required."} 

Solution
# yum install MySQL-python

The other solutions related to database tasks:
# yum install python-redis (Redisdb)
# yum install python-psycopg2 (PostgreSQL)

Check it for up to date list of database modules:
https://docs.ansible.com/ansible/latest/modules/list_of_database_modules.html

Friday 6 July 2018

How to prevent sleep mode on laptop when lid closes?

Press Window Key then type "Power Options" and click on it -> Click "Choose what closing the lid does" -> Set "When I close the lid" to "Do nothing" -> Click "Save changes" -> Done!