1 numpy data science

 
a=[0,1,2,3,4,5] 
a[-1]    # last item in the array 
>>> a[-2]  # second last item in array it returns 4
 
a[-2:]   # last two items in the array
 
a[:-2]   # everything except the last two items
a[::-1]    # all items in the array, reversed
a[1::-1]   # the first two items, reversed
a[:-3:-1]  # the last two items, reversed
a[-3::-1]  # everything except the last two items, reversed
 
import numpy as np
array([0, 1, 2, 3, 4]) 
 
 

lacp bonding ubuntu


cat /etc/network/interfaces

# The primary network interface
# Interfaces bonding
auto eth4
iface eth4 inet manual
bond-master bond0

auto eth5
iface eth5 inet manual
bond-master bond0

auto bond0
iface bond0 inet static
address 10.233.193.23 
netmask 255.255.255.0
gateway 10.233.193.254
dns-nameservers 217.16.102.1
bond-mode 802.3ad
bond-miimon 100
bond-lacp-rate 1
bond-slaves none


# cat /proc/net/bonding/bond0 

Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

802.3ad info
LACP rate: fast
Min links: 0
Aggregator selection policy (ad_select): stable

Slave Interface: eth5
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: f8:f2:1e:09:18:c1
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0

Slave Interface: eth4
MII Status: up
Speed: 10000 Mbps
Duplex: full
Link Failure Count: 1
Permanent HW addr: f8:f2:1e:09:18:c0
Slave queue ID: 0
Aggregator ID: 1
Actor Churn State: none
Partner Churn State: none
Actor Churned Count: 0
Partner Churned Count: 0

Mode1 Activebackup
DEVICE=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=192.168.99.110
PREFIX=24
ONBOOT=yes
BOOTPROTO=static
BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"
DEVICE=bond0 TYPE=Bond BONDING_MASTER=yes IPADDR=192.168.99.110 PREFIX=24 ONBOOT=yes BOOTPROTO=static BONDING_OPTS="mode=1 miimon=100 fail_over_mac=1"

multipath ubuntu

# Single Path in multipath (not useful)
root@L0004906:~# cat /etc/multipath.conf | grep -v "#"
defaults {
    polling_interval    10
    selector        "round-robin 0"
    path_grouping_policy    multibus
    prio            const
    path_checker        directio
    failback        immediate
    no_path_retry       1
    features        "0"
}
blacklist {
}
blacklist_exceptions {
}
multipaths {
    multipath {
        alias           mpath0
    }
    multipath {
                wwid                    3600c0ff0001e54bae320f75401000000
                alias                   mpath1
        }
}

#Multiple path in multipath
root@L0004909:~# cat /etc/multipath.conf | grep -v "#"
defaults {
        polling_interval        10
        selector                "round-robin 0"
        path_grouping_policy    multibus
        prio                    const
        path_checker            directio
        failback                immediate
        no_path_retry           1
        features                "0"
}
blacklist {
}
blacklist_exceptions {
}
multipaths {
        multipath {
                alias                   mpath0
        }
        multipath {
                wwid                    3600c0ff0001e44ef1bd1fe5401000000
                alias                   mpath1
        }
    multipath {
                alias                   mpath2
        }
        multipath {
                wwid                    3600c0ff0001e44efd7cefe5401000000
                alias                   mpath3
        }
}
root@L0004909:~# multipath -ll
mpath2 (3600c0ff0001e6fd3d3cefe5401000000) dm-2 HP      ,MSA 2040 SAS   
size=3.3T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 4:0:0:11 sdh 8:112 active ready running
  `- 3:0:0:11 sdd 8:48  active ready running
mpath3 (3600c0ff0001e44efd7cefe5401000000) dm-3 HP      ,MSA 2040 SAS   
size=3.3T features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 4:0:0:12 sdi 8:128 active ready running
  `- 3:0:0:12 sde 8:64  active ready running



  /opt/immune/bin/envdo python /opt/immune/installed/idx/apps/NewMerger/util/requester.py --q "|chart count() by device_ip"

sudoer nopasswd


root@ip-172-31-29-138:/etc/sudoers.d# cat 90-cloud-init-users 
# Created by cloud-init v. 18.2 on Fri, 22 Jun 2018 11:43:26 +0000

# User rules for ubuntu
ubuntu ALL=(ALL) NOPASSWD:ALL

vsftpd and pam

We will be using PAM to deny access to the VSFTPD service to certain users.
  1. Install the VSFTPD FTP server.
yum install vsftpd
  1. Start the service and verify it is running.
systemctl start vsftpdsystemctl status vsftpd
[OUTPUT]
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2017-02-24 13:39:42 CST; 5min ago
  Process: 17739 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
 Main PID: 17741 (vsftpd)
   Memory: 592.0K
   CGroup: /system.slice/vsftpd.service
           └─17741 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
  1. Install the FTP client utility.
yum install ftp
  1. Using the client, verify that the user account can log in to the server.
ftp localhost
[output]
Connected to localhost (127.0.0.1).
220 (vsFTPd 3.0.2)
Name (localhost:root):
  1. Display the contents of the PAM VSFTP module, note the file referred to for denying user access.
cat /etc/pam.d/vsftpd
[output]
#%PAM-1.0
session    optional     pam_keyinit.so    force revoke
auth       required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required pam_shells.so
auth       include password-auth
account    include password-auth
session    required     pam_loginuid.so
session    include password-auth
  1. Add the user account to the appropriate file noted from Step 5.
vim /etc/vsftpd/ftpusers
[contents with our setting on last line]
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
user
  1. Verify the user account is no longer permitted to log in.
ftp localhost
[output]
Connected to localhost (127.0.0.1).
220 (vsFTPd 3.0.2)
Name (localhost:root): user
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> quit
221 Goodbye.

parted extend the expanded disk

root@server:# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print free                                                  
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
    25.8GB  25.8GB 3584B   Free Space
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
    1100GB  2199GB 1100GB  Free Space

(parted) mkpart
Partition name?  []? <you can leave it blank>                                           
File system type?  [ext2]? zfs                                       
Start? 1100GiB                                                       
End? 100%                                                            
(parted) print                                                       
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start End Size File system  Name Flags
2   17.4kB  1049kB 1031kB                  bios_grub
1   1049kB  25.8GB 25.8GB  zfs
3   25.8GB  36.5GB 10.7GB  zfs
4   36.5GB  47.2GB 10.7GB  zfs
5   47.2GB  1100GB 1052GB  zfs
9   1100GB  1100GB 8392kB
6   1181GB  2199GB 1018GB  zfs # this is the new one created

(parted) quit
Information: You may need to update /etc/fstab.


UEFI/GPT examples

In every instance, a special bootable EFI System Partition is required.
If creating a new EFI System Partition, use the following commands (the recommended size is 512MiB):
(parted) mkpart ESP fat32 1MiB 513MiB
(parted) set 1 boot on
The remaining partition scheme is entirely up to you. For one other partition using 100% of remaining space:
(parted) mkpart primary ext4 513MiB 100%
For separate / (20GiB) and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary ext4 20.5GiB 100%
And for separate / (20GiB), swap (4GiB), and /home (all remaining space) partitions:
(parted) mkpart primary ext4 513MiB 20.5GiB
(parted) mkpart primary linux-swap 20.5GiB 24.5GiB
(parted) mkpart primary ext4 24.5GiB 100%

Case vmware expanded

There's a difference between rescanning for new disks at the adapter level and rescanning for update size information at the disk level.
echo "- - -" > /sys/class/scsi_host/host#/scan
Sending "- - -" to /sys/class/scsi_host/host[012]/scan is telling the SCSI host adapter to look for new disks on every channel "(-)", every target "(-)", and every lun "(-)". - this is the right thing to do if you add a new disk to the system while it's powered on.
echo “1” > /sys/class/block/sdc/device/rescan
Sending a "1" to /sys/class/block/sdc/device/rescan is telling the SCSI block device to refresh it's information about where it's ending boundary is (among other things) to give the kernel information about it's updated size. - this is the right thing to do if you change the size of an existing disk while it's powered on.



Came back to using parted again today and this is how to properly create a partition using parted and getting rid of the alignment error:

Code:
root@loadtest01:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mktable gpt                                                      
(parted) mkpart                                                           
Partition name?  []? primary                                        
File system type?  [ext2]? linux-swap                                    
Start? 0%                                                                 
End? 100%                                                                 
(parted) print                                                            
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start End     Size File system  Name Flags
1      1049kB 17.2GB  17.2GB     primary

(parted) align-check                                                      
alignment type(min/opt)  [optimal]/minimal? optimal                       
Partition number? 1                                                       
1 aligned

Increasing nofiles pam ulimit

cat /proc/{process_id}/limits:

$ cat /proc/1882/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max open files            4096                 4096                 files
Max locked memory         65536                65536                bytes

it looks like 4096 number is too low for elastic search , now checking if the limit is reached for this PID
 /proc/{process_id}/fd is a directory that holds a file for each open file the process has,
 ls /proc/1882/fd | wc -l


/etc/pam.d/common-session needs to have this line in it:
session required pam_limits.so

/etc/pam.d/common-session-noninteractive also needs to have this line in it:
session required pam_limits.so

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