Tag Archives: exported

Install containerd


title: “Install containerd”
date: 2019-03-26T14:00:39
slug: install-containerd


wget https://github.com/containerd/containerd/archive/v1.2.5.zip
unzip v1.2.5.zip
wget https://github.com/containerd/containerd/releases/download/v1.2.5/containerd-1.2.5.linux-amd64.tar.gz
containerd-1.2.5.linux-amd64.tar.gz
cp bin/\* /usr/local/bin
cp containerd.service /lib/systemd/system
systemctl enable containerd
mkdir /etc/containerd/
containerd config default > /etc/containerd/config.toml
systemctl start containerd

Add insecure registries to containerd /etc/containerd/config.toml (extract)

[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]
[plugins.cri.registry.mirrors."192.168.122.123:5000"]
endpoint = ["http://192.168.122.123:5000"]
[plugins.cri.registry.auths]
[plugins.cri.registry.auths."http://192.168.122.123:5000"]
username = "docker"
password = "docker"
[plugins.cri.x509\_key\_pair\_streaming]
tls\_cert\_file = ""

Foreman


title: “Foreman”
date: 2019-03-19T14:09:37
slug: foreman


yum -y update
yum -y install https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
yum -y install http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://yum.theforeman.org/releases/1.20/el7/x86\_64/foreman-release.rpm
yum -y install https://repo.saltstack.com/yum/redhat/salt-repo-latest.el7.noarch.rpm

yum -y install foreman-installer salt-master salt-api psmisc tcpdump mc

foreman-installer \
 --enable-foreman-plugin-salt \
 --enable-foreman-proxy-plugin-salt \
 --foreman-proxy-dhcp=true \
 --foreman-proxy-dhcp-interface=ens9 \
 --foreman-proxy-dhcp-gateway=10.0.0.1 \
 --foreman-proxy-dhcp-range="10.0.0.10 10.0.0.20" \
 --foreman-proxy-dhcp-nameservers="10.0.0.1" \
 --foreman-proxy-dns=true \
 --foreman-proxy-dns-interface=ens9 \
 --foreman-proxy-dns-forwarders=10.83.41.202

systemctl enable salt-master salt-api dhcpd

firewall-cmd --add-port=53/udp --permanent
firewall-cmd --add-port=53/tcp --permanent
firewall-cmd --add-port=67/udp --permanent
firewall-cmd --add-port=68/udp --permanent
firewall-cmd --add-port=69/tcp --permanent
firewall-cmd --add-port=69/udp --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=443/tcp --permanent
firewall-cmd --add-port=8140/tcp --permanent
firewall-cmd --add-port=8443/tcp --permanent

oder:
systemctl stop firewalld
systemctl disable firewalld
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
(reboot system)

Wenn Foreman als Gateway arbeiten soll:
vi /etc/sysctl.conf
net.ipv4.ip\_forward = 1

rspec


title: “rspec”
date: 2019-03-16T10:28:37
slug: rspec


ruby -v
gem install rspec

Gemfile:

gem 'rspec'
bundle

Install webhook on Centos7

yum -y install epel-release
yum -y install centos-release-scl-rh centos-release-scl rubygem-bundler
yum --enablerepo=centos-sclo-rh -y install rh-ruby23
scl enable rh-ruby23 bash
ruby -v
gem install rspec webmock

SSH Completation


title: “SSH Completation”
date: 2019-02-27T13:26:37
slug: ssh-completation


vi .bashrc
complete -W "$(<~/.ssh/hosts)" ssh
cat ~/.ssh/hosts

haproxy01.stg.fkb01.fti.int
haproxy02.prd.fkb01.fti.int
haproxy02.stg.fkb01.fti.int
hotelbeschreibung-db01.prd.fkb01.fti.int
hotelbeschreibung-db01.stg.fkb01.fti.int
hotelbeschreibung-web01.prd.fkb01.fti.int
hotelbeschreibung-web01.stg.fkb01.fti.int
hr-azubiblog-db01.prd.fkb01.fti.int
hr-azubiblog-db01.stg.fkb01.fti.int
hr-azubiblog-web01.prd.fkb01.fti.int
hr-azubiblog-web01.stg.fkb01.fti.int
i5-public-webservice-camper.prd.fkb01.fti.int
i5-public-webservice-camper.stg.fkb01.fti.int
i5-public-webservice-contact.prd.fkb01.fti.int

PHP mssql drivers


title: “PHP mssql drivers”
date: 2019-02-18T19:33:36
slug: php-mssql-drivers


Step 2.1 Install the PHP Driver for SQL Server

If using PHP 7.3, replace sqlsrv and pdo_sqlsrv in the following commands with sqlsrv-5.4.0preview and pdo_sqlsrv-5.4.0preview or later, as earlier versions are not compatible with PHP 7.3.

Terminal


sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT\_EULA=Y apt-get install msodbcsql17 mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash\_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install unixodbc-dev
sudo pecl install sqlsrv
sudo pecl install pdo\_sqlsrv
sudo su
echo extension=pdo\_sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.\*:\s\*||"`/30-pdo\_sqlsrv.ini
echo extension=sqlsrv.so >> `php --ini | grep "Scan for additional .ini files" | sed -e "s|.\*:\s\*||"`/20-sqlsrv.ini
exit

Copy

Step 2.2 Create a database for your application

Create the database using sqlcmd

Terminal


sqlcmd -S localhost -U sa -P your\_password -Q "CREATE DATABASE SampleDB;"

Copy

Step 2.3 Create a PHP app that connects to SQL Server and executes queries

Terminal


mkdir SqlServerSample
cd SqlServerSample

Copy

Using your favorite text editor, create a new file called connect.php in the SqlServerSample folder. Paste the code below inside into the new file.

PHP

<?php
 $serverName = "localhost";
 $connectionOptions = array(
 "Database" => "SampleDB",
 "Uid" => "sa",
 "PWD" => "your\_password"
 );
 //Establishes the connection
 $conn = sqlsrv\_connect($serverName, $connectionOptions);
 if($conn)
 echo "Connected!"
?>

Top 10 IP count


title: “Top 10 IP count”
date: 2019-02-13T10:10:02
slug: top-10-ip-count


POST /filebeat-2019.02.12/\_search?size=0
{
 "aggs" : {
 "hits" : {
 "terms" : { "field" : "haproxy.client\_ip"
 }
 }
 }
}

Configure PXE (Network Boot) installation Server on CentOS 7.x


title: “Configure PXE (Network Boot) installation Server on CentOS 7.x”
date: 2019-02-12T09:38:46
slug: configure-pxe-network-boot-installation-server-on-centos-7-x


yum install dhcp tftp tftp-server syslinux vsftpd xinetd
vi /etc/dhcp/dhcpd.conf

# DHCP Server Configuration file.

ddns-update-style interim;
ignore client-updates;
authoritative;
allow booting;
allow bootp;
allow unknown-clients;

# internal subnet for my DHCP Server
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.200 10.0.0.250;
option domain-name-servers 10.0.0.1;
option domain-name "openstack.local";
option routers 10.0.0.1;
option broadcast-address 10.0.0.255;
default-lease-time 600;
max-lease-time 7200;
next-server 10.0.0.5;
}

host controller.openstack.local {
 hardware ethernet 52:54:00:37:2a:4e;
 option host-name controller;
 fixed-address 10.0.0.11;
 filename "pxelinux.0";
}
vi /etc/xinetd.d/tftp
service tftp
{
 socket\_type = dgram
 protocol = udp
 wait = yes
 user = root
 server = /usr/sbin/in.tftpd
 server\_args = -s /var/lib/tftpboot
 disable = no
 per\_source = 11
 cps = 100 2
 flags = IPv4
}
cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot
cp -v /usr/share/syslinux/memdisk /var/lib/tftpboot
cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot
cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot
mkdir /var/lib/tftpboot/pxelinux.cfg
mkdir /var/lib/tftpboot/networkboot

Mount Centos  ISO and copy content to /var/ftp/pub/

mount /dev/cdrom /mnt
cd /mnt/
cp -av \* /var/ftp/pub/
cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot/networkboot/
cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/networkboot/

Generate Root Password

openssl passwd -1 Pxe@123#
$1$e2wrcGGX$tZPQKPsXVhNmbiGg53MN41

Create kickstart file (Replace Password and URLs)

vi /var/ftp/pub/centos7.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use FTP installation media
url --url="ftp://10.0.0.5/pub/"
# Root password
rootpw --iscrypted $1$B8PHMhWg$89J2kxGGtxIc/RdA9/3OI1
# System authorization information
auth useshadow passalgo=sha512
# Use graphical install
graphical
firstboot disable
# System keyboard
keyboard de
# System language
lang en\_US
# SELinux configuration
selinux disabled
# Installation logging level
logging level=info
# System timezone
timezone Europe/Amsterdam
# System bootloader configuration
bootloader location=mbr
ignoredisk --only-use=sda
clearpart --all --initlabel
part swap --asprimary --fstype="swap" --size=1024 --ondisk=sda
part /boot --fstype xfs --size=300 --ondisk=sda
part pv.01 --size=1 --grow --ondisk=sda
volgroup root\_vg01 pv.01
logvol / --fstype xfs --name=lv\_01 --vgname=root\_vg01 --size=1 --grow
%packages

@^minimal
@core
%end
network --device=eth0 --bootproto=dhcp
network --device=eth1 --bootproto=static
%addon com\_redhat\_kdump --disable --reserve-mb='auto'

%end
%post
rpm -Uvh https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm
yum -y install salt-minion
yum -y update
systemctl enable salt-minion
systemctl start salt-minion
echo "10.0.0.5 salt" >> /etc/hosts
sed -i -e 's/GRUB\_CMDLINE\_LINUX=.\*/GRUB\_CMDLINE\_LINUX="rd.lvm.lv=root\_vg01\/lv\_01 rhgb quiet net.ifnames=0 biosdevname=0"/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin" >> /var/spool/cron/root
echo "@reboot salt-call state.apply > /tmp/out 2>&1" >> /var/spool/cron/root
%end
reboot

Create a PXE menu file

vi /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 30
MENU TITLE LinuxTechi.com PXE Menu
LABEL centos7\_x64
MENU LABEL CentOS 7\_X64
KERNEL /networkboot/vmlinuz
APPEND initrd=/networkboot/initrd.img inst.repo=ftp://10.0.0.5/pub ks=ftp://10.0.0.5/pub/centos7.cfg net.ifnames=0 biosdevname=0

Start Services

systemctl start xinetd
systemctl enable xinetd
systemctl start dhcpd.service
systemctl enable dhcpd.service
systemctl start vsftpd
systemctl enable vsftpd

Allow FTP connection (selinux)

setsebool -P allow\_ftpd\_full\_access 1

Allow Connections (Firewall)

firewall-cmd --add-service=ftp --permanent
firewall-cmd --add-service=dhcp --permanent
firewall-cmd --add-port=69/tcp --permanent
firewall-cmd --add-port=69/udp --permanent
firewall-cmd --add-port=4011/udp --permanent
firewall-cmd --add-port=4506/tcp --permanent
firewall-cmd --reload

Salt installieren

rpm -Uvh https://repo.saltstack.com/yum/redhat/salt-repo-latest-2.el7.noarch.rpm
yum -y install salt-master epel-release git
yum install python-pip
pip install --upgrade pip

export VERSION=develop
for s in $(python -c "import site; print(' '.join(site.getsitepackages()))"); do
 pip install --install-option="--prefix=" --upgrade --force-reinstall -I \
 -t "$s" git+https://github.com/salt-formulas/reclass.git@${VERSION};
done

mkdir -p /srv/salt/inventory/{classes,hosts}
mkdir -p /srv/salt/pillar/{file\_tree,roots/base}
mkdir -p /srv/salt/state/base/basenode

[root@localhost ~]# tree /srv/salt/
/srv/salt/
├── inventory
│   ├── classes
│   └── hosts
│   └── controller.openstack.yml
├── pillar
│   ├── file\_tree
│   └── roots
│   └── base
└── state
 └── base
 └── basenode
 └── init.sls

10 directories, 2 files
vi /srv/salt/state/base/basenode/init.sls

mc:
 pkg.installed
vi /srv/salt/inventory/hosts/controller.openstack.yml

environment:
 base classes: {}
 applications:
 - basenode
vi /etc/salt/master.d/01-master.conf

keep\_jobs: 24
max\_open\_files: 16384
open\_mode: True
auto\_accept: True
state\_top: top.sls
reclass: &reclass
 storage\_type: yaml\_fs
 inventory\_base\_uri: /srv/salt/inventory
 nodes\_uri: hosts
 classes\_uri: classes
 class\_mappings: []
master\_tops:
 reclass: \*reclass
state\_output: changes
file\_roots:
 base:
 - /srv/salt/state/base
env\_order:
 - base
hash\_type: sha256
file\_ignore\_regex:
 - '/\.svn($|/)'
 - '/\.git($|/)'
file\_ignore\_glob:
 - '\*.pyc'
 - '\*/somefolder/\*.bak'
 - '\*.swp'
fileserver\_backend:
 - roots
pillar\_roots:
 base:
 - /srv/salt/pillar/roots/base
ext\_pillar:
 - reclass:
 storage\_type: yaml\_fs
 inventory\_base\_uri: /srv/salt/inventory
 nodes\_uri: hosts
 classes\_uri: classes
 class\_mappings: []
 - file\_tree:
 root\_dir: /srv/salt/pillar/file\_tree
 follow\_dir\_links: False
 keep\_newline: True
pillar\_source\_merging\_strategy: smart
log\_level: warning
systemctl enable salt-master
systemctl start salt-master

NFS Freigabe für Salt Scripte

yum -y install nfs-utils
#firewall-cmd --permanent --zone=public --add-service=ssh
firewall-cmd --permanent --zone=public --add-service=nfs
firewall-cmd --reload
systemctl enable nfs-server.service
systemctl start nfs-server.service
/etc/exports
/srv/salt/ 10.0.0.0/24(rw,sync,no\_subtree\_check)
exportfs -a

Am Client:

sudo mount -o soft -t nfs 10.0.0.5:/srv/salt/ /home/tay/openstack/salt

Install Vault

yum install unzip
curl https://releases.hashicorp.com/vault/1.0.3/vault\_1.0.3\_linux\_amd64.zip -o vault\_1.0.3\_linux\_amd64.zip
unzip vault\_1.0.3\_linux\_amd64.zip
mv vault /usr/bin/
export VAULT\_ADDR='http://10.0.0.5:8200'
vi /root/vault.hcl
backend "file" {
 path = "/var/lib/vault"
}
listener "tcp" {
 address = "0.0.0.0:8200"
 tls\_disable = 1
}
vault server -config=/root/vault.hcl &
vault operator init

Unseal Key 1: hiR5fSIEaS5NErWwmH/KGpwo1UDROL4nW5SyCwk6kMNm
Unseal Key 2: iYJrQ3UCIuuqwonQJWu4JoLj+/ElQfrKxtnEfd/H83rC
Unseal Key 3: 6+sPo592bAA9n5VCz9agyIW7Xrsb5dBsP7YEpK9gdP6c
Unseal Key 4: fxKfoRb6IWL5+07X25AmoHGbjwypX7592VydbBl3jpPU
Unseal Key 5: ItaavrSMOR8Qn3Q2wd7BDEVd76k2NDczstZnqWyWndKw

Initial Root Token: s.5qhccbKwytnpX5sEjLDBp3hg

3 Times: until Unseal Progress 2/3 is 3/3:
vault operator unseal
vault login <Initial Root Token>
vault write secret/openstack/RABBIT\_PASS password="abc123"

Create Salt Token (Read and List)
vi salt-policy.hcl
path "openstack/\*" {
 capabilities = ["read", "list"]
}
path "auth/\*" {
 capabilities = ["read", "list","sudo","create","update","delete"]
}

vault policy write salt-policy salt-policy.hcl
vault token create -policy=salt-policy

Key Value
token s.PCGMAcQTrN505EA8BIB3dLku
token\_accessor avIpcDUGvSTJMUmb910eXTUG
token\_duration 768h
token\_renewable true
token\_policies ["default" "salt-policy"]
identity\_policies []
policies ["default" "salt-policy"]

Create Entries

for NAME in ADMIN\_PASS CINDER\_DBPASS CINDER\_PASS DASH\_DBPASS DEMO\_PASS GLANCE\_DBPASS GLANCE\_PASS KEYSTONE\_DBPASS METADATA\_SECRET NEUTRON\_DBPASS NEUTRON\_PASS NOVA\_DBPASS NOVA\_PASS PLACEMENT\_PASS PLACEMENT\_DBPASS RABBIT\_PASS
do
 PW=`openssl rand -hex 10`
 vault write secret/openstack/${NAME} password=${PW}
done

vi /etc/salt/master.d/vault.conf (with token from 2nd step obove – vault token create -policy=salt-policy )

vault:
 url: http://10.0.0.5:8200
 auth:
 method: token
 token: s.mIeRDNYMeGhJv2W5e96DGr7z
 policies:
 - salt-policy

vi salt-policy.hcl

path "secret/\*" {
 capabilities = ["read", "list"]
}
path "auth/\*" {
 capabilities = ["read", "list","sudo","create","update","delete"]
}

NFS mount


title: “NFS mount”
date: 2019-01-29T09:37:12
slug: nfs-mount


1) Soft Mount

Suppose you have mounted a NFS filesystem using “soft mount”. When a program or application requests a file from the NFS filesystem, NFS client daemons will try to retrieve the data from the NFS server. But, if it doesn’t get any response from the NFS server (due to any crash or failure of NFS server), the NFS client will report an error to the process on the client machine requesting the file access. The advantage of this mechanism is “fast responsiveness” as it doesn’t wait for the NFS server to respond. But the main disadvantage of this method is data corruption or loss of data. So this is not a recommended option to use.

mount -o rw,soft host.nf\_server.com/home /techhome

2) Hard Mount

If you have mounted the NFS filesystem using hard mount, it will repeatedly retry to contact the server. Once the server is back online, the program will continue to execute undisturbed from the state where it was during server crash. We can use the mount option “intr” which allows NFS requests to be interrupted if the server goes down or cannot be reached. Hence the recommended settings are hard and intr options.

mount -o rw,hard,intr host.nf\_server.com/home /techhome

Selenium Headless mode (no display)


title: “Selenium Headless mode (no display)”
date: 2019-01-28T13:04:20
slug: selenium-headles-mode-no-display


Selenium Headless WebDriver requirements

apt-get install xvfb
pip install pyvirtualdisplay
pip install selenium

Samplescript:

#!/usr/bin/env python
import re
from pyvirtualdisplay import Display
from selenium import webdriver
# Set screen resolution to 1366 x 768 like most 15" laptops
display = Display(visible=0, size=(1366, 768))
display.start()
browser = webdriver.Firefox()
browser.get('http://localhost:8080/')
html = browser.find\_element\_by\_id("name").get\_attribute("innerHTML");
if not re.search('TOM', html):
browser.close()
print "TOM not found"
exit(1)
else:
print "TOM was found"
browser.close()
exit(0)
display.stop()