Some config files or commands

Mysql REMOVE all tables

SET FOREIGN_KEY_CHECKS = 0; 
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
  FROM information_schema.tables 
  WHERE table_schema = 'common'; -- specify DB name here.

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;

mDNS avahi custom address advertisement

# avahi-deamon and avahi-utils have to be installed, avahi-deamon have to be running
# uncomment and set to no in /etc/avahi/avahi-daemon.conf
publish-addresses=no
# run all the time on both machines
avahi-publish-address test.local 10.10.10.10

Backup MongoDB on Docker

docker exec -ti db /usr/bin/mongodump
docker cp db:dump ./db_backup/`date +%F`-dump

Failover server configuration

# FILE: /etc/keepalived/keepalived.conf
vrrp_script chk_ports {
  script       "/usr/local/sbin/chk_ports-keepalived.sh"
  interval 2   # check every 2 seconds
  #fall 2       # require 2 failures for KO
  #rise 2       # require 2 successes for OK
}

vrrp_instance VI_1 {
        interface ens160
        state MASTER
        virtual_router_id 51
        priority 101

        notify /usr/local/sbin/notify-keepalived.sh

        authentication {
            auth_type PASS
            auth_pass Password!@#
        }
        track_script {
            chk_ports
        }
        virtual_ipaddress {
                192.168.0.10/24 dev ens160
        }
}
# FILE: /usr/local/sbin/chk_ports-keepalived.sh
#! /bin/bash

nc -z localhost 80
if [ $? -ne 0 ]; then
    logger "port 80 not responding..."
    exit 1
fi

exit 0
# FILE: /usr/local/sbin/notify-keepalived.sh
#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
case $STATE in
        "MASTER")
                /usr/bin/logger ">>> Master"
                 su -c - ycadmin "cd /home/admin/docker; ./docker.sh start"                  ;;
        "BACKUP") /usr/bin/logger ">>> Backup"
                 su -c - ycadmin "cd /home/admin/docker; ./docker.sh stop"                  ;;
        "FAULT")  /usr/bin/logger ">>> Fault"
                 su -c - ycadmin "cd /home/admin/docker; ./docker.sh stop"                  
                 exit 0
                  ;;
        *)        /usr/bin/logger "ipsec unknown state"
                  exit 1
                  ;;
esac

LVM extend

pated
	- resizepart
fdisk
	- new partition, type LVM
pvcreate /dev/sdb2
vgextend docker_data_vg /dev/sdb2
lvextend -l +30718 /dev/docker_data_vg/docker_data_lv (from vgdisplay  Free  PE / Size       30718 / 119.99 GiB)
resize2fs /dev/docker_data_vg/docker_data_lv

https://sites.google.com/site/rhelworldexperience/home/rhel-disk-management---tips-and-tricks/resizinganextendedpartition-nolvminuse
https://www.tecmint.com/extend-and-reduce-lvms-in-linux/

Linux MTU change (if the connection hangs on bigger data transferred over ssh)

ifconfig tun0 mtu 500 up
ifconfig tun0| grep MTU

nginx proxy timeout

in server brakets in sites-enabled/confluence:

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

From <https://www.scalescale.com/tips/nginx/504-gateway-time-out-using-nginx/>

Reboot linux if reboot or shutdown -r now not working

echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger

Mongo remove replica set member

config = rs.conf();
config.members = [config.members[0]];
rs.reconfig(config, {force: true});

Mongo shutdown server

use admin
db.shutdownServer({force: true})

Git preserve your changes before pull

git stash
#git checkout master or development
git pull
git stash pop

Mongo add host

#replica set add member (priority and votes should be > 0!!!
rs.add( { host: "host:port", priority: 1, votes: 1 } )

#replica set add arbiter
rs.addArb("host:port")

Mongo check oplog size

use local	
db.oplog.rs.stats().maxSize

Mongo change oplog size

### Change size of oplog!!!! ####
use admin
db.shutdownServer({force: true})

# start database without replication
mongod --port 37017 --dbpath /data/db/ &

#dump the local database and collection containing oplog
mongodump --db local --collection 'oplog.rs' --port 37017

#use local database
use local
#set db object to database local
db = db.getSiblingDB('local')
#drop temp collection
db.temp.drop()
# re-create temp collection with only 1 record
db.temp.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
#check
db.temp.find()

#remove current oplog
db = db.getSiblingDB('local')
db.oplog.rs.drop()
#create new oplog - 20GB
db.runCommand( { create: "oplog.rs", capped: true, size: (20 * 1024 * 1024 * 1024) } )
#copy data from temp 
db.oplog.rs.save( db.temp.findOne() )
#confirm
db.oplog.rs.find()

#stop and start with replica set
db.shutdownServer()
mongod -f /etc/mongod.conf

#mongod --replSet rs0 --dbpath /srv/mongodb

SSH tunnels from console (works also from cygwin)

# remote service to localhost
ssh -L local_port:remote_address:remote_port username@server.com

# local service to remote
ssh -R remote_port:local_address:local_port username@server.com

Samba example configuration

apt-get install samba

# /etc/samba/smb.conf
[Global]
        server string = SMB host
        netbios name = SMB_host
        interfaces = ens160 tun0
        security = user
        passdb backend = tdbsam
        load printers = no
        cups options = raw

[Omniyon]
        read only = No
        create mask = 0666
        directory mask = 0777
        browseable = Yes
        path = /opt/shared
        force user = mariusz
        force group = mariusz

NTP and timezone check

timedatectl set-ntp no
timedatectl
apt-get install ntp
ntpq -p

# check timezone
cd /usr/share/zoneinfo
find * -type f -exec sh -c "diff -q /etc/localtime '{}' > /dev/null && echo {}" \;