How to find ulimit for www-data user ?


# su www-data --shell /bin/bash --command "ulimit -aH" 
#  ulimit -aS ->will give soft limit

core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 3900
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) unlimited
cpu time               (seconds, -t) unlimited
max user processes              (-u) 3900
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

system tuning for database servers

Virtual Memory

Dirty Ratio

Page cache on a Linux system is the area where filesystem based I/O is cached and that these settings affect how the cache is utilized by the kernel.
We can tune pdflush to determine how much RAM based cache to use for (dirty pages) data targeted to disk and how frequently to flush that cached data by writing the pages back to disk.
The “dirty_ratio” is the percentage of total system memory that can hold dirty pages. The default on most Linux hosts is between 20-30%. When you exceed the limit, the dirty pages are committed to disk, creating a small pause. To avoid this hard pause, there is a second ratio: “dirty_background_ratio” (default 10-15%), which tells the kernel to start flushing dirty pages to disk in the background without any pause.
20-30% is a good general default for “dirty_ratio,” but on large-memory database servers, this can be a lot of memory! For example, on a 128GB-memory host, this can allow up to 38.4GB of dirty pages. The background ratio won’t kick in until 12.8GB! We recommend that you lower this setting and monitor the impact to query performance and disk IO. The goal is reducing memory usage without impacting query performance negatively. Reducing caches sizes also guarantees data gets written to disk in smaller batches more frequently, which increases disk throughput (rather than huge bulk writes less often).
A recommended setting for dirty ratios on large-memory (64GB+ perhaps) database servers is: “vm.dirty_ratio = 15″ and “vm.dirty_background_ratio = 5″, or possibly less. (Red Hat recommends lower ratios of 10 and 3 for high-performance/large-memory servers.)
You can set this by adding the following lines to “/etc/sysctl.conf
vm.dirty_ratio=15
vm.dirty_background_ratio=5



zpool convert /dev/sdx to /dev/disk/by-id

zpool export my_pool 
zpool import -d /dev/disk/by-id/     my_pool 

Example of creating pool using by-path 

zfs create tank raidz1 pci-0000:03:00.0-scsi-0:0:21:0 pci-0000:03:00.0-scsi-0:0:19:0 pci-0000:02:00.0-scsi-0:0:9:0 pci-0000:02:00.0-scsi-0:0:11:0 pci-0000:03:00.0-scsi-0:0:22:0 pci-0000:03:00.0-scsi-0:0:18:0

ls -l /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root  9 Mar 23 14:01 pci-0000:00:07.1-ata-2 -> ../../sr0
lrwxrwxrwx 1 root root  9 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part5 -> ../../sda5
lrwxrwxrwx 1 root root 10 Mar 23 14:01 pci-0000:00:10.0-scsi-0:0:0:0-part9 -> ../../sda9

Drawbacks of /dev/sdx way:The names are not persistent and will change depending on what order they disks are detected in. Adding or removing hardware for your system can easily cause the names to change. You would then need to remove the zpool.cache file and re-import the pool using the new names.

https://ubuntuforums.org/archive/index.php/t-2087726.html
https://wiki.archlinux.org/index.php/Persistent_block_device_naming#by-id_and_by-path
https://unix.stackexchange.com/questions/86764/understanding-dev-disk-by-folders

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)