KVM Bridging and Bonding

[root@MTEST ~]# cat /etc/sysconfig/network-scripts/ifcfg-
ifcfg-bond0 ifcfg-br0 ifcfg-enP1p1s0f2 ifcfg-enP2p1s0f2 ifcfg-lo
[root@MTEST ~]# ls -l /etc/sysconfig/network-scripts/ifcfg-bond0
-rw-r–r–. 1 root root 85 Nov 7 2016 /etc/sysconfig/network-scripts/ifcfg-bond0
[root@MTEST ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
ONBOOT=yes
BONDING_OPTS=’mode=1 miimon=100′
BRIDGE=br0
NM_CONTROLLED=no

[root@MTEST ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
ONBOOT=yes
TYPE=Bridge
IPADDR=10.81.189.51
NETMASK=255.255.255.192
GATEWAY=10.81.189.1
NM_CONTROLLED=no

[root@MTEST ~]# cat /etc/sysconfig/network-scripts/ifcfg-enP1p1s0f2
TYPE=Ethernet
BOOTPROTO=no
NAME=enP1p1s0f2
UUID=22a0a65e-1212-48f5-ae4e-d5491a867657
DEVICE=enP1p1s0f2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
HWADDR=98:be:94:68:9e:a2

 

[root@MTEST ~]# cat /etc/sysconfig/network-scripts/ifcfg-enP2p1s0f2
TYPE=Ethernet
BOOTPROTO=no
NAME=enP2p1s0f2
UUID=bcd70f87-19d8-4f3d-914c-b08250866d69
DEVICE=enP2p1s0f2
ONBOOT=yes
MASTER=bond0
SLAVE=yes
HWADDR=98:be:94:68:8f:7e
https://docs.fedoraproject.org/en-US/Fedora/24/html/Networking_Guide/sec-Network_Bridge_with_Bond.html
https://docs.solusvm.com/display/DOCS/KVM+Bridge+Setup

 

 

Advertisements

netfilter-persistent error while installing

Error

Failed to insert ‘ipmi_si’: No such device

 

#systemctl status systemd-modules-load.service
#/usr/lib/modules-load.d/ipmievd.conf

comment ipmi_si in above file
ls /lib/systemd/system/systemd-modules-load.service

cat /etc/modules

service netfilter-persistent save

service netfilter-persistent reload

bash loop through files

Loop Through Files

for FILE in *; do
# do something with $FILE
echo “File: $FILE”
done
For more control, use /usr/bin/file

for FILE in $(find ./ -name *.html -type f); do
# do something with $FILE
echo “HTML File: $FILE”
done
Loop Through Lines in a File

while read LINE; do
# do something with $LINE
echo “Line: $LINE”
done < /etc/hosts
Loop Through Words in a File

for WORD in $(cat /etc/hosts); do
# do something with $WORD
echo "Word: $WORD"
done
Loop Through Characters in a File

while read -n1 CHAR; do
# do something with $CHAR
echo "Character: $CHAR"
done < /etc/hosts

Linux Tips

https://perso.crans.org/~raffo/docs/linux-lpic-guide-3ed.pdf

Linux LPIC

# file -s /dev/sda2
/dev/sda2: Linux/i386 swap file (new style) 1 (4K pages) size 140031 pages

# file -s /dev/sda
/dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x11cb38, GRUB version 0.94; partition 1: ID=0x83, active, starthead 32, startsector 2048, 3072000 sectors; partition 2: ID=0x82, starthead 89, startsector 3074048, 1120256 sectors, code offset 0x48

If file -s doesn’t show a valid file system inside a disk partition, then you can’t mount the file system

#vi +11 ~/.ssh/known_hosts

mount -o loop rhel-server-7.2-x86_64-dvd.iso /mnt/
mount -t tmpfs -o size=1G tmpfs /ramdisk/

# fuser -m /media/cdrom
/media/cdrom: 1793 2013 2022 2435 10532c 10672c

Extract a single file
$ tar xvf test.tar -C anotherDirectory/ testfile1

find the largefiles on your system
du -ahx / | sort -rh | head -20

dig mx in alias

echo ‘alias mxdig=”dig mx +short”‘ >> ~/.bashrc
source ~/.bashrc

—————-

list only directories

ls -d */
ls -l | egrep ‘^d’
find / -type d -ls (include sub directories)

find /var/qmail/alias/ -iname “*zaicheng*” -exec cat {} \;

 

sysctl -p
lsof -i

 

Find total hard disk space – fdisk -l | grep Disk

Find the highest file size –
du -hs * | sort -rh | head -10
find /path/to/dir/ -printf ‘%s %p\n’| sort -nr | head -10

show files above certain size
find . -type f -size +1000000 -ls

show files less certain size (1,000,000 bytes = 1 M)
find . -type f -size -1000000 -ls

https://www.ibm.com/developerworks/community/blogs/58e72888-6340-46ac-b488-d31aa4058e9c/entry/linux_netstat_command_explained_with_10_examples?lang=en

http://www.linux.com/learn/tutorials/428331-ipv6-crash-course-for-linux

http://www.linux.com/learn/tutorials/432537-another-ipv6-crash-course-for-linux-real-ipv6-addresses-routing-name-services

 

less
-N – view line no
100g – goto line no 100
100G – goto line no 100 from end of file

 

ps -A | grep —thunderbirddos

nohup cmd &
———————————————————————
—Skype—
In Linux I have in folder /home/Johtd/.Skype/myacc#/ many files with “dbb” extension, call256.dbb, chat564.dbb and chatmsg654.dbb, etc.

 


 

recursively add file extension to all files
find /path -type f -not -name “*.*” -exec mv “{}” “{}”.jpg \;
____________________________________________________________

Mount on same file system


[root@localhost ~]# mount --bind /opt/mountpoint/ /var/www/html/bseclab.com/
[root@localhost ~]# cat /proc/mounts | grep bsec
/dev/mapper/rhel-root /var/www/html/bseclab.com xfs rw,relatime,attr2,inode64,noquota 0 0
[root@localhost ~]# findmnt -n -o SOURCE --target /var/www/html/bseclab.com
/dev/mapper/rhel-root[/opt/mountpoint]

Add in fstab (example below)

/proc /chroot/mysql/proc none defaults,bind 0 0

 

 

 

 


 

for d in ccm_hard certmanager_auscert comodo_esmlanding comodocoin; do echo ${d}; pg_dump93 -h 192.168.236.57 -Fc -c -C ${d} | pg_restore93 -c -C -j=32 -d postgres; done
psql93

pg_dump93 -h /run/postgresql/9.3/ comodo_sasp | gzip > /var/lib/postgresql/comodo_sasp_$(date +%F).sql.gz

pg_dump93 MLB-768-80079 | gzip – > /var/tmp/ccm_hard-MLB-768-80079.gz

pg_ctl reload -D /var/lib/postgresql/9.3/data/

postgres@csdbase1 /var/tmp $ pg_dump92 -h /run/postgresql/9.2/ -Fc -Z6 dbSas | gzip > /var/tmp/dbSas.dump$(date +$Y-%m-%d).sql.gz
dbSas.dump-03-26.sql.gz

 

Mysql

mysqldump blogscomodocom | gzip > blogscomodocom_dump_2015-02-04.sql.gz

mysql kayako_wl 4_tables_dump_2015-01-09.sql
mysql -u root blogcomodocom < 4_table_dump_2015-01-09.sql

 

mcsql2 ~ # sed -re 's/(.*)\s(10.34.*)/\1 \2\n\1 10.1.75.0\/24 md5\n\1 10.32.75.0\/24 md5/g' -i.nodc /var/lib/postgresql/9.3/data/pg_hba.conf

Replace ".*10.34.*" with ".*10.34.*" and ".*10.1.75.0/24.*" and ".*10.32.75.0/24.*"

Linux Remote Desktop using tigervnc minimal

[root@testvm11 ~]# rpm -qa | grep tigervnc
tigervnc-license-1.3.1-3.el7.noarch
tigervnc-server-minimal-1.3.1-3.el7.x86_64

[root@testvm11 ~]# file /usr/bin/vncserver
/usr/bin/vncserver: Perl script, ASCII text executable

you need this perl scrip vncserver download it

Start a vnc server

[root@testvm11 ~]# vncserver :1
New ‘testvm11.project360.com:1 (root)’ desktop is slicinfchnd11.project360.com:1
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/slicinfchnd11.project360.com:1.log

Stop a vnc server
[root@testvm11 ~]# vncserver -kill :1
Killing Xvnc process ID 3493
Xvnc process ID 3493 already killed
Xvnc did not appear to shut down cleanly. Removing /tmp/.X11-unix/X1

Change Port number in vnc
[root@testvm11 ~]# grep -i vncport /usr/bin/vncserver
$vncPort = 5900 + $displayNumber;

Learn Cron

Cron provides only this environment by default :

MAILTO=”a@b.com,b@b.com”
PATH=”/usr/bin:/sbin:/bin” (get it from echo $PATH in the user login)
HOME=”/path/to/app/root”
SHELL=”/bin/bash”
LOGNAME user’s login

By default cron runs in sh shell

Export environment variables to file

30 08 * * * env > /tmp/cronenv

—————————–
Only /etc/crontab and the files in /etc/cron.d/ have a username field. In that file you can do this:

1 1 * * * username /path/to/your/script.sh
From root’s crontab sudo crontab -e you can use:

1 1 * * * su username -c “/path/to/your/script.sh”
Or you can use the user’s actual crontab like this:

sudo crontab -u username -e
—————————————————————
The following is an example on how to run a Django management command as the deploy user. You might notice that cron is run as root and then uses sudo to run as the deploy user with the argument -i. This is because we need to “simulate initial login” so that the source command works.:

0/5 * * * * root sudo -u deploy -i source /usr/local/virtualenvs/mysite/bin/activate && export DJANGO_SETTINGS_MODULE=config.settings && /usr/local/virtualenvs/mysite/bin/django-admin.py my_management_command

———————————————————————-

Schedule a script with error and output messages to a single file
* * * /bin/execute/this/script.sh >> /var/log/script_output.log 2>&1

 

—–
BASH_ENV=”/root/.bashrc

 

Cron tricks

https://blog.hazrulnizam.com/understanding-cron-environment-variables/
https://raymii.org/s/tutorials/Better_cron_env_and_shell_control_with_the_SHELL_variale.html
http://dev-notes.eu/2017/10/access-user-environment-variable-in-a-cron-triggered-script-in-ubuntu/
https://stackoverflow.com/questions/2135478/how-to-simulate-the-environment-cron-executes-a-script-with/2546509#2546509

https://www.endpoint.com/blog/2015/02/06/cron-wrapper-keep-your-cron-jobs

https://www.endpoint.com/blog/2013/05/28/login-shells-in-scripts-called-from-cron
https://bash.cyberciti.biz/guide/Source_command