redhat test

1) command shows you critical packages that are ready to be installed?
Correct

Correct answer

yum updateinfo list --sec-severity=Critical

2) following is the common vulnerability and exposures website?
Correct

Correct answer

http://cve.mitre.org

3) command installs the yum security plugin?
Correct

Correct answer

yum install yum-plugin-security

4) command shows you critical packages that are ready to be installed?
Correct

Correct answer

yum updateinfo list --sec-severity=Critical

Explanation

The command to use for getting critical updates is the following: yum updateinfo list --sec-severity=Critical


s3-parallel-put for faster uploads

/var/www# /usr/local/bin/s3-parallel-put --bucket=mediatest.visualsociety.com --host=s3.amazonaws.com --processes=10 --put=stupid --secure --content-type=guess --log-filename=/var/log/s3upload.log  .

Tested for 600GB of data
start time: 9:00AM March14
End time:-xx
11 GB uploaded in 10 minutes so far...
digital ocean droplet (2vcpu,2GB memory) NYC region to aws-s3

github: s3-parallel-put

devstack and packstack

yum -y update
#to install packstack
yum install centos-release-qemu-ev
yum remove mariadb-libs
visudo
enable wheel by uncommenting

#disable selinux
vim /etc/selinux/config
selinux=disabled

#disable Networkmanager and firewalld
systemctl disable NetworkManager firewalld

yum search openstack  #look for latest at bottom here its ocata
yum install -y install centos-release-openstack-ocata
yum install -y openstack-packstack
packstack --gen-answer-file=/home/user1/answers.txt
edit the answers.txt
change password=config_default_password=openstack
config_magnum_install=y #for container orchestration
config_keystone_admin_pw=xxxxxx
config_keystone_demo_pw=xxxx
save file
#start packstack installation
packstack --answwer-file=/home/user1/answers.txt


# Devstack on ubuntu
adduser stack
add it to sudo user without password
echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
su stack
apt-get install git
git clone https://git.openstack.org/openstack-dev/devstack
cd devstack
vim local.conf
[[local|localrc]]
ADMMIN_PASSWORD=openstack
DATABASE_PASSWORD=openstack
RABBIT_PASSWORD=openstack
SERVICE_PASSWORD=openstack

tcpdump


# Type Qualifier

host, net, port, portrange

tcpdump -v net 12.12.12.0 mask 255.255.255.0 
tcpdump -v net 12.12.12.0/24  or tcpdump -v net 11.11.11   #capture from /24 network
tcpdump -v host 33.33.33.33

tcpdump -v port 80  - capture all traffic to-or-from port 80
tcpdump -v portrange 21-80


# Directional Qualifier
src, dst, src or dst, src and dst

tcpdump -v  src 1.1.1.1 . (show pkt COMING from 1.1.1.1 only)
tcpdump -v dst 1.1.1.1 (show pkt Going to 1.1.1.1)

#Protocol Qualifier(ip,ip6,tcp,udp,icmp,ether)
eg. arp - IP to MAC resolution

tcpdump -v arp  -  show arp
tcpdump -nv ether broadcast  - shows ethernet broadcast traffic(ipp, arp traffic)
/etc/services --ipp is used to convert port number to names

tcpdump -nnv udp
tcpdump -nnv icmp

tcpdump src host 192.168.75.1 and dst port 22   - reveals TCP:22 or UDP 22 sourced/Coming from  192.168.75.1

tcpdump dst host 1.1.2.2 and dst port 22
tcpdump -c 1      # count capture 1 packet and exit
tcpdump -n -r filename.dump not port 5901 . ##exclude packet to/from 5901 tcp/udp port


iostat -xnz 1

Force postfix to encrypt all traffic between mail server communication

Add below lines to postfix main.cf

smtpd_tls_security_level = may
smtp_tls_security_level = may
smtp_tls_loglevel = 1
smtpd_tls_loglevel = 1

docker volumes

# bind mount in container

docker run -it --name ctrName  -v ~/host/dir:/dataCtr ubuntu:latest /bin/bash
  usecase:- webserver mount directory

to debug run "docker inspect <containerId> and look for mounts to check if mounted or not

# docker volume
docker run -it --name ctrName2 -v volName:/dataCtrFolder ubuntu:latest /bin/bash

the volume will be mounted to  /dataCtrFolder  directory of the container "ctrName2"

docker volume

usecase: persisting data/share between containers eg. mysql

# mount volumes from another container eg. volume from master1 to slave1

docker run -it --name master1 -v backup:/backup -v logs:/logs ubuntu:latest /bin/bash

docker run -it --name slave1 --volumes-from master1 ubuntu:latest /bin/bash

docker volume inspect volName  # see json details


# persisting data
to export key-value env variables to container
#docker run -it -e DOC_ROOT=/var/www/html -e SHELL=/bin/bash ubuntu bash

if there are lots of env variables
 create file with valiables eg. env.list
MODE=test
DOC_ROOT=/var/www

docker run -it --env-file /path/env.list ubuntu bash

  # echo $MODE
        test
 # echo $DOC_ROOT
      /var/www

# To override the value in env.list use  -e option again
docker run -it --env-file /path/env.list -e MODE=dev ubuntu bash


regex part1 positive and negative look behind

Negative look behind:

(?<!spam)@.*

# select all the email where userpart in email doesNOT contain the word spam

Positive look behind:

(?<=spam)@[^;,]+  # this matches below domain part only eg. "zohomail.com"

input:-

spam@zohomail.com; spam@google.com; spam@hotmail.com; ram@klsd.com
spam@gmail.com; spam@jira-ya.com,

Non capturing group
(?RegexHere)

NFS client mount options

usernfs1@visualsociety:~$ cat /etc/exports

#webserver 2
/var/www/visualmetrics.com 192.241.148.65(rw,fsid=0,async,no_root_squash,no_subtree_check)
/var/www/visualmetrics.com 10.136.48.14(rw,fsid=0,async,no_root_squash,no_subtree_check)

#webserver 1
/var/www/visualmetrics.com 67.205.184.188(rw,fsid=0,async,no_root_squash,no_subtree_check)
/var/www/visualmetrics.com 10.136.51.5(rw,fsid=0,async,no_root_squash,no_subtree_check)

#webserver 3
/var/www/visualmetrics.com 67.207.90.11(rw,fsid=0,async,no_root_squash,no_subtree_check)
/var/www/visualmetrics.com 10.10.0.12(rw,fsid=0,async,no_root_squash,no_subtree_check)



userweb1@visualsociety:~$ cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
162.243.174.83:/var/www/visualmetrics.com /var/www/visualmetrics.com/htdocs nfs auto,noatime,nolock,bg,intr,tcp,actimeo=1 0 0

django iterating over the querydict

stack link
https://stackoverflow.com/questions/39565023/django-querydict-only-returns-the-last-value-of-a-list

view file

def save_state(request):
    print '##from SAVESTATE view##'    print request.POST
    print '#######################'    if request.method =='POST':
        for item in request.POST.getlist("task[]"):
            todo = Todo(title=item,completed=True,author=request.session.get('uname'))
            todo.save()
        print "##############"    return HttpResponseRedirect('/todos')



Template file

<form method="post" action="{% url 'save_state'%}">
{% csrf_token %}
<!--list task list items -->{% for todo in todos %}

<input type="checkbox" name="task[]" value="{{ todo.title }}"        {% if todo.completed is True %}
            checked = "checked"        {% endif %} ><label>{{ todo.title }} : {{ todo.author }} </label><br>
{% endfor %}

 <input type="submit" name="submit" value="Submit">
</form>

wordpress migration

make sure in the wp-config.php

$table_prefix  = 'wp_';     # the table prefix (eg. here 'wp_' )is same  on both old and new 

take mysqldump of wordpress databaes from old server and import it into the new server
and make changes to wp-config.php accordingly

In wordpress database

in eg. wp_options table
set the new values accordingly using phpmyadmin of migrating to another domain

siteurl  http://example.com

home     http://example.com


Due to permalinks , object not found error may come. To overcome that select the error item post and mark it as draft and again mark it as post and error will go away

in wp-admin --> posts


select post with error -->
status-- draft (update)

select post with error -->
status-- Published (update)

this error wont come if migration is within same domain name
example.com ---> example.com

but may arise if migration is done from 
example.com --> example.org