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

virtualmin migration and email issue

email login format in virtualmin by default is not user friendly, heres the screenshot to change it to user@domain.com format



On CentOS, to get saslauthd running with the -r flag, you can log into your server over SSH as root, and edit:
/etc/sysconfig/saslauthd
At the bottom where it says "FLAGS=", change that line to read:
FLAGS=-r
the file should read like below:-
[root@server postfix]# cat /etc/sysconfig/saslauthd | grep -v "#"
SOCKETDIR=/run/saslauthd
MECH=pam
FLAGS="-r"
Then, restart saslauthd with:
service saslauthd restart
At that point, it should allow you to login with user@domain username formats.

Measuring IOPS of the disk

Running the typical web+database server on your VPS, the number is meaningless because typical services do not do long-running sequential writes.
Random reads, random writes, or a combination of both. Databases in particular will pull data from all over your disk - known as random access.
4 kilobyte blocks. Again, databases and many other programs will read very small chunks of data - 4 kilobytes is a good working estimate.
Multiple threads. If your website has multiple visitors, your website will serve them all at the same time. We want our benchmark to simulate this behaviour of multiple things accessing the disk at once


# fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75

digital ocean 1gb memory 1 cpu

# fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
test: (g=0): rw=randrw, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=64
fio-2.1.3
Starting 1 process
test: Laying out IO file(s) (1 file(s) / 4096MB)
Jobs: 1 (f=1): [m] [100.0% done] [98470KB/32733KB/0KB /s] [24.7K/8183/0 iops] [eta 00m:00s]
test: (groupid=0, jobs=1): err= 0: pid=21312: Wed Sep 13 17:24:42 2017
  read : io=3071.7MB, bw=89447KB/s, iops=22361, runt= 35165msec
  write: io=1024.4MB, bw=29828KB/s, iops=7457, runt= 35165msec
  cpu          : usr=8.87%, sys=30.80%, ctx=83527, majf=0, minf=6
  IO depths    : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0%
     issued    : total=r=786347/w=262229/d=0, short=r=0/w=0/d=0

Run status group 0 (all jobs):
   READ: io=3071.7MB, aggrb=89446KB/s, minb=89446KB/s, maxb=89446KB/s, mint=35165msec, maxt=35165msec
  WRITE: io=1024.4MB, aggrb=29828KB/s, minb=29828KB/s, maxb=29828KB/s, mint=35165msec, maxt=35165msec

Disk stats (read/write):
  vda: ios=782267/260753, merge=0/8, ticks=473648/1540456, in_queue=2014136, util=99.65%

Extract to email from mail log file

awk -v FS="(<|>)" '{ print $2; }'   maillogfile

echo "[hello]" | awk -F"[\\\[\\\]]" '{ print $2; }'

>>> hello

# echo "P(G1,G3) foobar" | awk -F"[()]" '{print $2}'
G1,G3
# echo "P<G1,G3>" | awk -F"[<>]" '{print $2}'
G1,G3

the -F lets you chose what character(s) awk will use to split the line into fields. Here, I am giving it a character class ([]) consisting of opening and closing parentheses. So it will split the line on ( and on ). As a result, the 2nd field will be the contents of the parentheses.
 E.g, with the string G8 = P(G1,G3)foo, 
$1 will be G8 = P  and
$2 will be G1,G3 and 
$3 will be foo

Use awk to print values larger than certain number


Quick how to on using awk to filter results if a certain value (column) is larger than a set value.
For example, if you have a file (servers.txt) with lines in this format
a_datacenter, servers 20
 error, servers xyz
 b_datacenter, servers 21
 c_datacenter, servers 50
and you want to show only the lines that have server value larger than 20, you can do this in awk by running
grep datacenter servers.txt | awk '$3 > 20  {print ;}'

openvpn on ubuntu 16.04

Open vpn server ip = 54.202.195.232
apt-get update && apt-get upgrade
apt-get install openvpn

vim /etc/default/openvpn,
    uncomment AUTOSTART="all"
sudo systemctl daemon-reload
sudo service openvpn restart

cd /usr/share/doc/openvpn/examples/sample-config-files/
gunzip -c server.conf.gz > /etc/openvpn/server.conf

vim /etc/openvpn/server.conf

push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"

user nobody
group nogroup

echo 1 > /proc/sys/net/ipv4/ip_forward

vim /etc/sysctl.conf
net.ipv4.ip_forward=1

iptables -t NAT -A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE

cd /usr/share/easy-rsa/
mkdir -p /etc/openvpn/easy-rsa/keys
cp -r /usr/share/easy-rsa/ /etc/openvpn/
mkdir /etc/openvpn/easy-rsa/keys
vim /etc/openvpn/easy-rsa/vars
  # change the export KEY_EMAIL ..
  export KEY_NAME="server"    # keep this in reference

openssl dhparam -out /etc/openvpn/dh2048.pem 2048

cd /etc/openvpn/easy-rsa/
. ./vars
./clean-all
./build-ca

    # let the defaults be same and no passwords
./build-key-server server
    sign the certificate = y

cd keys

cp server.crt server.key ca.crt /etc/openvpn
service openvpn start

## Create client keys
[CLIENT MACHINE]

/etc/openvpn/easy-rsa/build-key client
    ..writing a new private key to 'client.key'
sign the certificate y/n : select y

ls /etc/openvpn/easy-rsa/keys
-rw-r--r-- 1 root  root  1.7K Sep  3 02:13 client.key
-rw-r--r-- 1 root  root  5.4K Sep  3 02:13 client.crt
-rw-r--r-- 1 root  root  1.8K Sep  3 02:13 ca.crt

create client.ovpn file eg.
# vim urgen.ovpn
client
;dev tap
dev tun
;dev-node MyTap
;proto tcp
proto udp
remote 54.202.195.232 1194
;remote my-server-2 1194
;remote-random
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
;mute-replay-warnings
remote-cert-tls server
;tls-auth ta.key 1
;cipher x
comp-lzo
verb 3
;mute 20
####
Now append certificate and key file to urgen.ovpn file

echo "<ca>" >> urgen.ovpn
cat ca.crt >> urgen.ovpn
echo "</ca>" >> urgen.ovpn

echo "<cert>" >> urgen.ovpn
cat client.crt >> urgen.ovpn
echo "</cert>" >> urgen.ovpn

echo "<key>" >> urgen.ovpn
cat client.key >> urgen.ovpn
echo "</key>" >> urgen.ovpn

sudo openvpn urgen.ovpn

....now check your changed public ip addr

mysql GTID based replication

http://www.fromdual.ch/things-you-should-consider-before-using-gtid
https://www.percona.com/doc/percona-xtrabackup/2.4/backup_scenarios/incremental_backup.html


[mysqld]
datadir=/datadir/mysql
user=mysql
transaction_isolation = READ-COMMITTED
max_connections=1000
skip-name-resolve
wsrep_provider=/usr/lib/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://10.136.47.127,10.136.47.139,10.136.47.141
binlog_format=ROW

default_storage_engine=InnoDB

innodb_autoinc_lock_mode=2

wsrep_node_address=10.136.47.141

wsrep_sst_method=xtrabackup-v2

wsrep_cluster_name=gp_db_cluster

wsrep_sst_auth="sstuser:T3sTx344ehxDxZ"

log_error=/var/log/mysql/error.log