20 Aralık 2020 Pazar

Cacti-Docker

 Merhabalar,

5 dk. Cacti kurup kullanmaya başlamak ister misiniz? Hemde bir kaç basit komut ile :)

Container dünyasına basit uygulamalı giriş yapmış oluyoruz. Docker container kullanımı bilmeniz şart değil. Belki öğrenmenize teşvik bile edebiliriz :)

Elimizde Linux bir sunucu olduğunu düşünün. Cacti kurmak için web-server ve db kurup ayarlarını yapmamız gerekecek. Biz ise bu yapımızda 2 container (cacti webserver ve db) ilişkili hazır cacti kurup ayağa kaldıracağız. Dilerseniz ilerde bu sunucu üzerindeki dockerda başka containerlarda çalıştırabilirsiniz. Mesala Network config yedeği alan rancid gibi...

Hazırlık:

Debian 10.7.0 versiyonunu kullanacağim. gnome ve xcfc gibi masa üstü servislerini kurmadan sadece ssh server özelliği kurdum.

Güncel tutmak için:

root@debian:/home/enes# apt update
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Hit:2 http://deb.debian.org/debian buster InRelease
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Fetched 117 kB in 1s (147 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

 
root@debian:/home/enes# apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@debian:/home/enes# apt install date
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package date

wget ve curl yazılımlarını kuralım.

root@debian:/home/enes# apt install wget curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.64.0-4+deb10u1).
wget is already the newest version (1.20.1-1.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Sunucumuzun timezone değirini kontrol edelim. Bozuksa düzeltelim.

Benim timezone hatalı

root@debian:/home/enes# date
Sun 20 Dec 2020 07:15:47 AM EST

 

root@debian:/home/enes# timedatectl
               Local time: Sun 2020-12-20 07:16:21 EST
           Universal time: Sun 2020-12-20 12:16:21 UTC
                 RTC time: Sun 2020-12-20 12:16:21
                Time zone: US/Eastern (EST, -0500)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no


root@debian:/home/enes# ls -l /etc/localtime
lrwxrwxrwx 1 root root 30 Dec 19 17:25 /etc/localtime -> /usr/share/zoneinfo/US/Eastern

Debian 10 için Timezone düzeltme komutumuz:

root@debian:/home/enes# timedatectl set-timezone Asia/Baghdad

Tekrar kontrol ettiğimizde düzeldiğini görüyoruz.

root@debian:/home/enes# ls -l /etc/localtime
lrwxrwxrwx 1 root root 34 Dec 20 15:17 /etc/localtime -> ../usr/share/zoneinfo/Asia/Baghdad
root@debian:/home/enes# timedatectl
               Local time: Sun 2020-12-20 15:17:52 +03
           Universal time: Sun 2020-12-20 12:17:52 UTC
                 RTC time: Sun 2020-12-20 12:17:52
                Time zone: Asia/Baghdad (+03, +0300)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no


Docker Kurulumu:

 Birçok docker kurulumu var internetten bakabilirsiniz. Hatta eğitim bile alabilirsiniz. Biz en kolay olanı yapacağız. Hangi linux sürünümü veya versiyonunu kullandığınızı algılayıp sizin yerinize kuruyor.

https://get.docker.com bu sayfayı açıyoruz. 

Bizden aşağıdaki 2 komut çalıştırmamızı istiyor :

# This script is meant for quick & easy install via:
#   $ curl -fsSL https://get.docker.com -o get-docker.sh 

# $ sh get-docker.sh 


root@debian:/home/enes# curl -fsSL https://get.docker.com -o get-docker.sh

 

root@debian:/home/enes# sh get-docker.sh
# Executing docker install script, commit: 3d8fe77c2c46c5b7571f94b42793905e5b3e42e4
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl gnupg >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/debian/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sh -c echo "deb [arch=amd64] https://download.docker.com/linux/debian buster stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
 Version:           20.10.1
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        831ebea
 Built:             Tue Dec 15 04:34:48 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Server: Docker Engine - Community
 Engine:
  Version:          20.10.1
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       f001486
  Built:            Tue Dec 15 04:32:45 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
  sudo usermod -aG docker your-user
Remember that you will have to log out and back in for this to take effect!
WARNING: Adding a user to the "docker" group will grant the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.
root@debian:/home/enes# docker -version
unknown shorthand flag: 'e' in -ersion
See 'docker --help'.
Usage:  docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker
                           context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit
Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Build with BuildKit (Docker Inc., v0.5.0-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes
Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

Kurulum bitti. Bende 2 dk sürmedi. Belki internet hızımdan kaynaklı şaşırdım.(20mbps). Kurulum başarılımı kontrol edelim. Docker versiyonu öğrenelim.

root@debian:/home/enes# docker --version
Docker version 20.10.1, build 831ebea

Evet , gerçekten docker kurulumu bitti. Şimdi Compose toolunu kuralım.

https://docs.docker.com/compose/install/

İlgili sayfa yukarıda.Güncel versiyonu çıkarsa yukarıdan komutu güncelleyin.

root@debian:/home/enes/iso# curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   651  100   651    0     0   1269      0 --:--:-- --:--:-- --:--:--  1269
100 11.6M  100 11.6M    0     0   662k      0  0:00:18  0:00:18 --:--:--  597k
root@debian:/home/enes/iso# chmod +x /usr/local/bin/docker-compose

Kontrol edelim: 

root@debian:/home/enes/iso# docker-compose --version
docker-compose version 1.27.4, build 40524192

Cacti-Docker kurulumu:

https://github.com/scline/docker-cacti

Yukarıdaki sayfadaki arkadaşımızın çalışmasını baz alacağız. Yukarıdaki sayfada çok fazla detay var. Okuyabilirsiniz. Benim amacım türkçe ve basit düzeyde size anlatmak. Arkadaşımız oturmuş uğraşmış cacti için güzel container hazırlamış. Kendisine teşekkür ederiz. Sizde buna benzer kendiniz de docker uzmanı olduğunuzda kendi uygulamalarınız için hazır containerlar hazırlayabilirsiniz.

Compose ise birbiri ile ilişkili containerların tüm değişken parametrelerin içinde bulunduğu conf. dosyası diyebilirsiniz. 

compose dosyamızı indiriyoruz.

Sayfamız: 

https://github.com/scline/docker-cacti/tree/master/docker-compose

https://github.com/scline/docker-cacti/blob/master/docker-compose/cacti_single_install.yml


İndirdiğimiz compose dosyamızı inceleyelim.

version: '3.5'
services:


  cacti:
    image: "smcline06/cacti"
    container_name: cacti
    domainname: example.com
    hostname: cacti
    ports:
      - "80:80"
      - "443:443"
    environment:
      - DB_NAME=cacti_master
      - DB_USER=cactiuser
      - DB_PASS=cactipassword
      - DB_HOST=db
      - DB_PORT=3306
      - DB_ROOT_PASS=rootpassword
      - INITIALIZE_DB=1
      - TZ=America/Los_Angeles
    volumes:
      - cacti-data:/cacti
      - cacti-spine:/spine
      - cacti-backups:/backups
    links:
      - db


  db:
    image: "mariadb:10.3"
    container_name: cacti_db
    domainname: example.com
    hostname: db
    ports:
      - "3306:3306"
    command:
      - mysqld
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --max_connections=200
      - --max_heap_table_size=128M
      - --max_allowed_packet=32M
      - --tmp_table_size=128M
      - --join_buffer_size=128M
      - --innodb_buffer_pool_size=1G
      - --innodb_doublewrite=ON
      - --innodb_flush_log_at_timeout=3
      - --innodb_read_io_threads=32
      - --innodb_write_io_threads=16
      - --innodb_buffer_pool_instances=9
      - --innodb_file_format=Barracuda
      - --innodb_large_prefix=1
      - --innodb_io_capacity=5000
      - --innodb_io_capacity_max=10000
    environment:
      - MYSQL_ROOT_PASSWORD=rootpassword
      - TZ=America/Los_Angeles
    volumes:
      - cacti-db:/var/lib/mysql


volumes:
  cacti-db:
  cacti-data:
  cacti-spine:
  cacti-backups:

Kırmızıya boyadığım kısımlardaki timezoneları düzeltmemiz lazım. 

" - TZ=Asia/Baghdad" 

Yerimiz belli olsun diye birde cacti isimli klasör açıyorum.

root@debian:/home/enes# mkdir /home/enes/cacti
root@debian:/home/enes# cd cacti/
vi editor ile girip yukarıdaki bilgileri düzgün timezone ile yapıştırdım.

root@debian:/home/enes/cacti# vi cacti_single_install.yml


root@debian:/home/enes/cacti# ls
cacti_single_install.yml

Hazırız. artık compose ayağa kaldıralım. -f dosya gösteriyoruz. -d arkaplanda çalış diyoruz.

root@debian:/home/enes/cacti# docker-compose -f cacti_single_install.yml up -d
Creating network "cacti_default" with the default driver
Creating volume "cacti_cacti-db" with default driver
Creating volume "cacti_cacti-data" with default driver
Creating volume "cacti_cacti-spine" with default driver
Creating volume "cacti_cacti-backups" with default driver
Pulling db (mariadb:10.3)...
10.3: Pulling from library/mariadb
da7391352a9b: Pull complete
14428a6d4bcd: Pull complete
2c2d948710f2: Pull complete
22776aa82430: Pull complete
90e64230d63d: Pull complete
f30861f14a10: Pull complete
e8e9e6a3da24: Pull complete
420a23f08c41: Pull complete
bd73f23de482: Pull complete
739c71d82551: Pull complete
65465f3a9066: Pull complete
1d96eca58ffe: Pull complete
13ddb412bd22: Pull complete
Digest: sha256:25d59d64013285f77db2e252c1b2cd390dc639773ae4f5132b90f539cfba27d4
Status: Downloaded newer image for mariadb:10.3
Creating cacti_db ... done
Creating cacti    ... done

2 dk sürmedi yine . Evet cacti kuruldu ve ayağa kalktı. Linux sunucumuzun ipsini öğrenelim.

root@debian:/home/enes/cacti# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:01:67:02 brd ff:ff:ff:ff:ff:ff
    inet 172.28.115.223/20 brd 172.28.127.255 scope global dynamic eth0
       valid_lft 79356sec preferred_lft 79356sec
    inet6 fe80::215:5dff:fe01:6702/64 scope link
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:88:36:d5:27 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
9: br-abd6962118d3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:8c:b8:b5:6a brd ff:ff:ff:ff:ff:ff
    inet 172.19.0.1/16 brd 172.19.255.255 scope global br-abd6962118d3
       valid_lft forever preferred_lft forever
    inet6 fe80::42:8cff:feb8:b56a/64 scope link
       valid_lft forever preferred_lft forever
11: veth8261430@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-abd6962118d3 state UP group default
    link/ether 8e:bd:9b:3d:22:e5 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::8cbd:9bff:fe3d:22e5/64 scope link
       valid_lft forever preferred_lft forever
13: veth48ca71d@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-abd6962118d3 state UP group default
    link/ether ea:88:d5:9b:4e:51 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::e888:d5ff:fe9b:4e51/64 scope link
       valid_lft forever preferred_lft forever

Cacti Web kurulum:

Sunucumuzun ipsi 172.28.115.223 miş. Şimdi kendi bilgisayarımızın browserdan bu ip  çağırarak 1 kez cacti bildiğimiz kurulum ekranı gelmesini sağlıyoruz.



Sayfamız geldi. admin/admin şeklinde ilk şifremizi giriyoruz.


Admin şifremizi değiştiriyoruz. Yeni şifremizde :en az 8 karakter, küçük harf,büyük harf, rakam ve karakter olacak. 


Dilimizi türkçe yapıp lisans anlaşmasını kabul ediyoruz.


Devam ediyoruz.


Devam ediyoruz.


Devam ediyoruz.


Hiç hata vermedi. Devam ediyoruz.


Kabul edip devam ediyoruz.


Devam ediyoruz.


Devam ediyoruz.


Kurmaya başlıyoruz.



Bitti:)

 Artık rahat bir şekilde son sürüm ve tüm tüm fonsiyonları tam cacti kullabilirsiniz.

Docker üzerindeki son durum nedir? 

Kontrol edelim.

root@debian:/home/enes/cacti# docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS          PORTS                                      NAMES
a2e3f08faee0   smcline06/cacti   "/start.sh"              19 minutes ago   Up 19 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   cacti
1bdeb602814b   mariadb:10.3      "docker-entrypoint.s…"   19 minutes ago   Up 19 minutes   0.0.0.0:3306->3306/tcp                     cacti_db

 

root@debian:/home/enes/cacti# docker volume ls
DRIVER    VOLUME NAME
local     cacti_cacti-backups
local     cacti_cacti-data
local     cacti_cacti-db
local     cacti_cacti-spine

containerler açılıp kapansada volume dediğimiz kalıcı yerlerde bizim datalarımız saklanacak.

Sonuç:

Bence başlangıç için bu kadar docker yeterli. Sizde 5 dk kurabilecek misiniz? Yorumlara yazarsanız sevinirim.