8 Haziran 2020 Pazartesi

/etc/fstab Dosyası - Mount İçin Gerekli Dosyadır

Giriş
İşletim sistemi açılırken fstab dosyasını okur. fstab sabit diskinizdeki bölümleri sisteminize bağlama (mount) işleminin yapılabilmesi için gerekli bir ayar dosyasıdır. Açıklaması şöyle.
For an embarrassingly long time, I thought /etc/fstab is used to override the default mounting options so the drives are only mounted once. But now it looks wrong: the drive is mounted using its default mount options, then /etc/fstab is picked up to remount it.
Açıklaması şöyle.
/etc/fstab resides on the root filesystem, but it can't be read until after the filesytem has been mounted
Path - 2. Sütun
Örnek
Şöyle yaparız.
$ sudo vim /etc/fstab

...
# tmpfs in RAM
tmpfs         /tmp         tmpfs         defaults,noatime,mode=1777      0 0
...
Şöyle yaparız.
$ sudo mount /tmp
$ mount | grep tmp # Check /tmp is in RAM
tmpfs on /tmp type tmpfs (rw,noatime)
File System Type - 3. Sütun
Örnek - auto
Açıklaması şöyle
If  no  -t  option  is  given, or if the auto type is specified, mount will try to guess the desired type.
Örnek - ext4
Şöyle yaparız.
UUID=<UUID> / ext4 errors=remount-ro 0 1
Örnek - swap
swap diski şöyledir
UUID=21618415-7989-46aa-8e49-881efa488132    none    swap     sw      0  0
veya şöyledir
/dev/sdb    none    swap     sw      0  0
Herşeyi RAM'a almak için şöyle yaparız
tmpfs /var/tmp tmpfs nodev,nosuid,size=50M 0 0
Mount Options - 4. Sütun
Bu sütunda kullanılabilecek bazı seçenekler şöyle
rw, suid, dev, exec, auto, nouser, async
Bu sütun ve File System Type yani 3. sütunda da auto seçeneği mevcut olduğu için bazen karışıklık olabiliyor. Açıklaması şöyle
... the auto keyword may be used as both a filesystem type and a mount option
auto seçeneği
Açıklaması şöyle
auto   Can be mounted with the -a option.
Örnek
Şöyle yaparız
UUID=[UUID] [mount pount] auto nosuid,nodev,nofail,x-gvfs-show 0 0
noauto seçeneği
Belirtilen bölümlemenin otomatik olarak mount edilmesini engeller.

noexec seçeneği

user seçeneği
Açıklaması şöyle. exec seçeneği user seçeneğinden sonra gelmeli.
user   Allow an ordinary user to mount the filesystem.  The name of the
          mounting user is written to the mtab file  (or  to  the  private
          libmount  file  in /run/mount on systems without a regular mtab)
          so that this same user can unmount the filesystem  again.   This
          option  implies  the  options  noexec, nosuid, and nodev (unless
          overridden  by  subsequent  options,  as  in  the  option   line
          user,exec,dev,suid).
Açıklaması şöyle
You must put the exec, suid and dev options after the user option, because user implies noexec, nosuid and nodev.


7 Haziran 2020 Pazar

Kubernetes - Container Orchestration İçindir

Giriş
Kubernetes, Google tarafından geliştirildi. Container Orchestration içindir. 

Kubernetes Borg'dan Türetildi
Açıklaması şöyle
It's a direct descendant of Borg, Google’s long-rumored internal container-based cluster-management solution.
Kubernetes Alternatifleri
Alternatif listesi şöyle
- Red Hat OpenShift
- Apache Mesos
- Mirantis Kubernetes Engine
- Helios
- Amazon Elastic Container Service (Amazon ECS)
- Google Kubernetes Engine (GKE)
- Azure Service Fabric
- Amazon Elastic Kubernetes Service (EKS)
- Docker Swarm. Rakiplerinden bir tanesi Docker Swarm kullanılmıyor deniyor

Container Orchestration Ne Demek
Açıklaması şöyle.
With such unprecedented usage of containers, there has been an increase in demand for container orchestration and management tools like Kubernetes and Docker Swarm. These tools ease our job to manage the containers with a lot of features including:

- Container grouping
- Self-healing
- Auto-scalability
- DNS management
- Load balancing
- Rolling update or rollback
- Resource monitoring and logging
Yani cloud'da çalışan yazılımlarda şu işleri yapmayı kolaylaştırıyor
Kubernetes solves real problems in the enterprises. Kubernetes provides an entire ecosystem of tools that you need; Networking, Compute & Memory Allocation, Load Balancing, Object Storage, and Scheduling, etc.
Kubernetes Nodları
Temelde iki çeşit nod var.
1. Kubernetes Master
2. Kubernetes Node
Şeklen şöyle
Şeklen şöyle



Master Nod Bileşenleri Nedir?
Kubernetes Master yazısına taşıdım

Kubernetes Nod Bileşenleri Nedir?
Kubernetes Node yazısına taşıdım



5 Haziran 2020 Cuma

bash Filename Expansion

Giriş
Açıklaması şöyle.
bash scans each word for the characters *, ?, and [. If one of these characters appears, then the word is regarded as a pattern, and replaced with an alphabetically sorted list of filenames matching the pattern. If no matching filenames are found, and the shell option nullglob is not enabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed.
glob altta ne yapar
Açıklaması şöyle
Using a feature of your shell called globbing or filename generation (pathname expansion in POSIX), not of the Linux system nor of any filesystem used on Linux.

te* is expanded by the shell to the list of files that match that pattern.

To do that, the shell requests the list of entries in the current directory from the system (typically using the readdir() function of the C library, which underneath will use a system-specific system call (getdents() on Linux)), and then match each name against the pattern.
Örnek
Şöyle yaparız. Burada elimize bir array geçer.
TXT=(*.txt)
Açıklaması şöyle.
will expand the *.txt pattern to the list filenames in the current directory that matches that pattern. The shell would do this at the time of the assignment.
Örnek
Şöyle yaparız.
echo ./*.txt
nullglob etkin değilse çıktı olarak şunu alırız
./*.txt
nullglob Etkinse
Açıklaması şöyle. Çıktı olarak sadece komut ve komut seçeneklerini alırız. Dizin ve dosya isimleri silinirler.
This makes ls * in an empty directory turn into plain ls, and rm -rf somepath/* where that subdirectory is empty turn into rm -rf.

4 Haziran 2020 Perşembe

xrandr komutu

Screen Satırı
Çıktı olarak şuna benzer bir şey alırız
Screen 0: minimum 320 x 320, current 1920 x 1080, maximum 8192 x 8192
Açıklaması şöyle.
minimum 320 x 320 - shows you the minimum,
current 1920 x 1080 - shows your current screen resolution.
maximum 8192 x 8192 - the maximum resolution that your gpu supports.
--output seçeneği
Örnek
Şöyle yaparız
#Activate TV
xrandr --output HDMI-0 --auto --right-of DVI-0;
#Turn off TV
xrandr --output HDMI-0 --off;

3 Haziran 2020 Çarşamba

bash kodlama - $IFS Değişkeni

Giriş
$IFS input field separator anlamına gelir. Açıklaması şöyle
$IFS is only used for word splitting after unquoted expansions.
...
The IFS variable is also used for splitting the input to the read utility.
Örnek - read komutu
Şöyle yaparız.
while IFS=, read -a words; do 
  printf '%s\n' "${words[@]}" | sort -u
done < file.csv | sort | uniq -c | sort -rn
  2 red
  2 green
  2 blue
  1 yellow
  1 brown

2 Haziran 2020 Salı

grep komutu

Giriş
grep komutundaki seçenekler
- Matcher Selection
- Matching Control
- General Output Control
- Output Line Prefix Control
- Context Line Control
- File and Directory Selection
- Other Options

başlıkları altına toplanmış.

Exit Status
Örnek
Şöyle yaparız. Dosya yoksa  2 değeri döner
grep "i am here" real-file

# Returns: 0 (via: echo $?)

grep "i am not here" real-file

# Returns: 1

grep "i am not here" not-a-file

# Returns: 2 (No such file or directory)
General Output Control
General Output Control yazısına taşıdım

Matching Control
Matching Control yazısına taşıdım

Matcher Selection
-E seçeneği
Extended regex kullan. Şöyle yaparız.
$ str='25 results [22 valid, 2 invalid, 1 undefined]'
grep -E -o '[0-9]+' <<<"$str"
Other Options
--line-buffered seçeneği
Normalde grep kendi içindeki buffer dolduktan sonra çıktı verir. Bunu satır seviyesine düşürmek için şöyle yaparız.
( echo "LINE 1" ; sleep 1 ; echo "LINE 2" ; ) | grep --line-buffered LINE | cat
-U
Treat the file as binary
Örnek
Şöyle yaparız
echo "[INFO] Checking if ddl sources have UPPERCASE file names..."
/bin/ls -1 -I *svn* src/main/resources/ddl | grep -U -e "[a-z]"
if [ $? -eq 0 ]; then
  echo "[ERROR] The above files have lowecase letters in their names!"
  exit 1
else
  echo "[INFO] ...done."
fi
-z, --null-data
Açıklaması şöyle
  -z, --null-data
          Treat  input  and  output  data  as  sequences  of  lines,  each
          terminated by a zero byte (the ASCII NUL character) instead of a
          newline. 
Açıklaması şöyle. Dolayısıyla normal kullanımda linefeed karakterini grep'lemek mümkün değil
Since grep is (by default) line-based, the linefeed characters are stripped out before pattern matching takes place.
Örnek
Elimizde şöyle iki dosya olsun
$ cat file1
this is a test:
test1

test2
and another one

$ cat file2
this is a test:

test1

test2

and another one
Şöyle yaparız. Burada sanki tüm dosya tek satır gibi düşünülebilir. İlk dosya eşleşmiyor çünkü test2'den sonra 2 tane \n karakteri yok.
$ grep -Pz '\n\ntest1\n\ntest2\n\n' file1
$ 

$ grep -Pz '\n\ntest1\n\ntest2\n\n' file2
this is a test:

test1

test2

and another one
File and Directory Selection
-a seçeneği
Açıklaması şöyle
-a, --text
Process  a  binary  file  as  if  it  were  text;  this  is  equivalent to the --binary-files=text option.

Output Line Prefix Control

-A seçeçeneği
After anlamına gelir. Eşleşen satırdan sonraki satırları da gösterir.
Örnek
Şöyle yaparız. -m1 ile ilk eşleme seçilir. Bu eşleşmeden sonra gelen 10 satırı görmek için -A10 kullanılır
grep -m1 -A10 PATTERN filename
-B seçeçeneği
Before anlamına gelir. Eşleşen satırdan önceki satırları da gösterir.
Örnek
Eşleşen satırdan önceki 5'inci satırı da çıktıda görmek için şöyle yaparız.
grep -r -i -B 5 -A 5 "match" 
Örnek
Elimizde şöyle bir veri olsun.
cat db_systems.txt

  "db-unique-name": "p00z5bj_iad2bj",
  "db-workload": "OLTP",
  "defined-tags": {},
  "freeform-tags": {},
  "id": "dfadfasfsadfasdfasdf",
  "lifecycle-details": null,
  "lifecycle-state": "AVAILABLE",
  ...
Burada lifecycle-state alanı AVAILABLE olan ve db-unique-name aradığımı değer olan kayıtları bulmak isteyelim. Şöyle yaparız. lifecycle-state alanına göre arama yapar ve çıktıya 6 satır öncesini de dahil ederiz. Daha sonra bu çıktı üzerinde bir daha grep yaparız.
grep -B6 AVAILABLE file | grep db-unique-name
 "db-unique-name": "p00z5bj_iad2bj",
Diğer
grep çıktısının renkleri GREP_COLORS ortam değişkeni ile atanır. Renkler şöyledir
Red:  ms=01;31
Green:  ms=01;32
Yellow:  ms=01;33
Blue:  ms=01;34
Çıktıyı kırmızı yapmak için şöyle yaparız.
export GREP_COLORS='ms=01;31'
Sarı için şöyle yaparız.
export GREP_COLORS='ms=01;33:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36'