<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zekiye AYDEMİR on Medium]]></title>
        <description><![CDATA[Stories by Zekiye AYDEMİR on Medium]]></description>
        <link>https://medium.com/@aydemirzekiye?source=rss-cb21cd23cff8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jUdHmRWWSjqpyuNOk9IQkw@2x.jpeg</url>
            <title>Stories by Zekiye AYDEMİR on Medium</title>
            <link>https://medium.com/@aydemirzekiye?source=rss-cb21cd23cff8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 06:17:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aydemirzekiye/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Terraform ile PostgreSQL Yönetimi]]></title>
            <link>https://aydemirzekiye.medium.com/terraform-ile-postgresql-y%C3%B6netimi-2e1456d4b800?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e1456d4b800</guid>
            <category><![CDATA[terraform-provider]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Mon, 12 Sep 2022 20:02:20 GMT</pubDate>
            <atom:updated>2022-09-13T06:09:23.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*KOTrrE3nJkjylxArTfAwZA.png" /></figure><p>Terraform, AWS, Google Cloud ve Azure bulut ortamları başta olmak üzere birden çok bulut platformunda altyapıyı düzenlenmemizi ve otomatikleştirmemizi mümkün kılar. Terraform konfigürasyon otomasyonu ve güvenilir orkestrasyon sağlar. Bu özelliğiyle Terraform, veritabanı işlemlerinde de kullanılabilir.</p><p>PostgreSQL sağlayıcısı(provider), kaynakları bir PostgreSQL sunucusunda dağıtma ve yapılandırma imkanı verir. Terraform ile PostgreSQL veritabanına bağlanarak yeni veritabanı ve kullanıcılar oluşturabiliriz.</p><p>Bu yazımda, PostgreSQL veritabanı ve kullanıcıları oluştururken değişkenleri kullanarak Terraform konfigürasyonunu nasıl daha dinamik hale getireceğimizi öğreneceğiz.</p><p>Terraform kurulumunu anlattığım yazıma <a href="https://www.linkedin.com/pulse/installing-terraform-centos-zekiye-aydemi%CC%87r/">linkten</a> ulaşabilirsiniz.</p><p>Terraformda en çok karşılaştığımız komutlar için hazırladığım <a href="https://aydemirzekiye.medium.com/the-most-used-terraform-commands-f3be6472b34d">Terraform Cheatsheet’e linkten </a>ulaşabilirsiniz.</p><h4>Terraform-PostgreSQL İşlemleri</h4><p>Öncelikle, projemizin dizinlerini oluşturuyoruz:</p><pre>mkdir pgterraform<br>cd pgterraform</pre><p>Dosyaların yönetimi ve üzerinde değişiklik yapmamızı kolaylaştıracak şekilde ayrı <strong>.tf</strong> dosyaları oluşturacağız.</p><p>Tüm bu adımların sonunda aşağıdaki dizin yapısını elde edeceğiz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*rYIYGxz_jRZj3xuovF5o9g.png" /></figure><p>Öncelikle, temel bir Terraform konfigürasyonu içeren main.tf dosyası üzerinde çalışacağız. <strong>main.tf</strong> dosyasını aşağıdaki gibi oluşturup içeriği ekliyoruz:</p><pre>vim main.tf</pre><pre>terraform {<br>  required_providers {<br>    postgresql = {<br>      source  = &quot;cyrilgdn/postgresql&quot;<br>      version = &quot;1.17.1&quot;<br>    }<br>  }<br>}</pre><pre>provider &quot;postgresql&quot; {<br>  host            = var.db_host<br>  port            = 5432<br>  username        = &quot;postgres&quot;<br>  sslmode         = &quot;disable&quot;<br>  connect_timeout = 30<br>}</pre><pre>resource &quot;postgresql_role&quot; &quot;create_role&quot; {<br>  name     = var.db_owner<br>  login    = true<br>  password = var.db_owner_password<br>}</pre><pre>resource &quot;postgresql_database&quot; &quot;create_tf_db&quot; {<br>  name              = var.db_name<br>  owner             = postgresql_role.create_role.name<br>  lc_collate        = &quot;C&quot;<br>  connection_limit  = -1<br>  allow_connections = true<br>}</pre><pre>resource &quot;postgresql_role&quot; &quot;create_tf_dba&quot; {<br>  name     = var.dba_name<br>  login    = true<br>  password = var.dba_password<br>}</pre><pre>resource &quot;postgresql_schema&quot; &quot;terraform_schema&quot; {<br>  name     = var.schema_name<br>  owner    = &quot;postgres&quot;<br>  database = postgresql_database.create_tf_db.name<br>}</pre><p>Ardından değişkenleri tanımladığımız <strong>variables.tf</strong> dosyasını oluşturuyoruz;</p><pre>vim variables.tf</pre><pre>variable &quot;db_host&quot; {<br>  description = &quot;The host of postgresql&quot;<br>  default     = &quot;127.0.0.1&quot;<br>}<br>variable &quot;db_owner&quot; {<br>  description = &quot;the user of db owner&quot;<br>  default     = &quot;pgElephant&quot;<br>}</pre><pre>variable &quot;db_owner_password&quot; {<br>  description = &quot; user password&quot;<br>  default     = &quot;pgElephant&quot;<br>  sensitive   = true<br>}<br>variable &quot;db_name&quot; {<br>  description = &quot;new database name&quot;<br>  default     = &quot;tftestdb&quot;<br>}<br>variable &quot;dba_name&quot; {<br>  description = &quot;dba name&quot;<br>  default     = &quot;pineapple&quot;<br>}</pre><pre>variable &quot;dba_password&quot; {<br>  description = &quot;dba password&quot;<br>  default     = &quot;Lifeisbeautiful&quot;<br>  sensitive   = true<br>}<br>variable &quot;schema_name&quot; {<br>  description = &quot;your schema name&quot;<br>  default     = &quot;fruit&quot;<br>}</pre><p><strong>description:</strong> Değişkeni tanımlarken açıklama girebiliriz. Bu isteğe bağlıdır.<br><strong>default</strong>: Değişkene varsayılan bir değer atamak için kullanılır. Bu isteğe bağlıdır.</p><p><strong>sensitive</strong>: Değişkene atanan değerin <strong>terraform plan</strong> ve <strong>terraform apply</strong> komutlarının çıktısında açıkca görünmemesini sağlar. Parola gibi değişkenlerde kullanabiliriz.</p><p>Son olarak, <strong>main.tf</strong> ve <strong>variable.tf</strong> dosyası ile aynı klasörde <strong>terraform.tfvars</strong> adında yeni bir dosya oluşturuyoruz. Oluşturduğumuz değişkenlere <strong>terraform.tfvars</strong> dosyasında değer atayalım;</p><pre>vim terraform.tfvars </pre><pre>db_host           = &quot;192.168.195.240&quot;<br>db_owner          = &quot;zaydemir&quot;<br>db_owner_password = &quot;123&quot;<br>db_name           = &quot;buket&quot;<br>dba_name          = &quot;pgElephant&quot;<br>dba_password      = &quot;papatya&quot;<br>schema_name       = &quot;sepet&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*iopOv-RLAzl3yrU_Ecx8Lw.png" /></figure><p>Değişkenleri <strong>variable.tf</strong> dosyasında tanımlarken varsayılan bir değer belirlediğimizden, <strong>terraform.tfvars</strong> dosyasında değişkende bir değer ayarlamak isteğe bağlıdır.</p><p><strong>terraform apply</strong> komutunu çalıştırıyoruz, çıktısı aşağıdaki gibi;</p><pre>[zekiye@zaydemir pgterraform]$ terraform apply</pre><pre>Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:<br>  + create</pre><pre>Terraform will perform the following actions:</pre><pre># postgresql_database.create_tf_db will be created<br>  + resource &quot;postgresql_database&quot; &quot;create_tf_db&quot; {<br>      + allow_connections = true<br>      + connection_limit  = -1<br>      + encoding          = (known after apply)<br>      + id                = (known after apply)<br>      + is_template       = (known after apply)<br>      + lc_collate        = &quot;C&quot;<br>      + lc_ctype          = (known after apply)<br>      + name              = &quot;buket&quot;<br>      + owner             = &quot;zaydemir&quot;<br>      + tablespace_name   = (known after apply)<br>      + template          = (known after apply)<br>    }</pre><pre># postgresql_role.create_role will be created<br>  + resource &quot;postgresql_role&quot; &quot;create_role&quot; {<br>      + bypass_row_level_security = false<br>      + connection_limit          = -1<br>      + create_database           = false<br>      + create_role               = false<br>      + encrypted_password        = true<br>      + id                        = (known after apply)<br>      + inherit                   = true<br>      + login                     = true<br>      + name                      = &quot;zaydemir&quot;<br>      + password                  = (sensitive value)<br>      + replication               = false<br>      + skip_drop_role            = false<br>      + skip_reassign_owned       = false<br>      + superuser                 = false<br>      + valid_until               = &quot;infinity&quot;<br>    }</pre><pre># postgresql_role.create_tf_dba will be created<br>  + resource &quot;postgresql_role&quot; &quot;create_tf_dba&quot; {<br>      + bypass_row_level_security = false<br>      + connection_limit          = -1<br>      + create_database           = false<br>      + create_role               = false<br>      + encrypted_password        = true<br>      + id                        = (known after apply)<br>      + inherit                   = true<br>      + login                     = true<br>      + name                      = &quot;pgElephant&quot;<br>      + password                  = (sensitive value)<br>      + replication               = false<br>      + skip_drop_role            = false<br>      + skip_reassign_owned       = false<br>      + superuser                 = false<br>      + valid_until               = &quot;infinity&quot;<br>    }</pre><pre># postgresql_schema.terraform_schema will be created<br>  + resource &quot;postgresql_schema&quot; &quot;terraform_schema&quot; {<br>      + database      = &quot;buket&quot;<br>      + drop_cascade  = false<br>      + id            = (known after apply)<br>      + if_not_exists = true<br>      + name          = &quot;sepet&quot;<br>      + owner         = &quot;postgres&quot;</pre><pre>+ policy {<br>          + create            = (known after apply)<br>          + create_with_grant = (known after apply)<br>          + role              = (known after apply)<br>          + usage             = (known after apply)<br>          + usage_with_grant  = (known after apply)<br>        }<br>    }</pre><pre>Plan: 4 to add, 0 to change, 0 to destroy.</pre><pre>Do you want to perform these actions?<br>  Terraform will perform the actions described above.<br>  Only &#39;yes&#39; will be accepted to approve.</pre><pre>Enter a value: yes</pre><pre>postgresql_role.create_tf_dba: Creating...<br>postgresql_role.create_role: Creating...<br>postgresql_role.create_tf_dba: Creation complete after 0s [id=pgElephant]<br>postgresql_role.create_role: Creation complete after 0s [id=zaydemir]<br>postgresql_database.create_tf_db: Creating...<br>postgresql_database.create_tf_db: Creation complete after 0s [id=buket]<br>postgresql_schema.terraform_schema: Creating...<br>postgresql_schema.terraform_schema: Creation complete after 0s [id=buket.sepet]</pre><pre>Apply complete! Resources: 4 added, 0 changed, 0 destroyed.<br>[zekiye@zaydemir pgterraform]$</pre><p>psql ile bağlanarak veritabanı ve kullanıcıları kontrol edebiliriz;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*u5WqQEGxwazTb__FChBeSw.png" /></figure><p>Terraform ile PostgreSQL’de yaptığımız tüm işlemleri terraform destroy komutu ile geri alabiliriz.</p><pre>terraform destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*_6aJX4uhNfWi6RvDkeOYNw.png" /></figure><p>Terraformda PostgreSQL sağlayıcı(provider) ile veritabanı ve kullanıcı oluşturma işlemlerinden kısaca bahsettim. Daha detaylı bilgiye <a href="https://registry.terraform.io/providers/cyrilgdn/postgresql">terraformun kendi sayfasından</a> ulaşabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e1456d4b800" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Modülü ve EC2 Instance Oluşturma]]></title>
            <link>https://aydemirzekiye.medium.com/terraform-modul%C3%BC-ve-ec2-instance-olu%C5%9Fturma-dbe3ee18b8cb?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbe3ee18b8cb</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[terraform-provider]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[ec2-instance]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 14:18:55 GMT</pubDate>
            <atom:updated>2022-08-21T16:25:10.516Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*0EJYXt5NJDOGabnVGasawQ.png" /></figure><p><a href="https://www.linkedin.com/pulse/terraform-modul%2525C3%2525BC-ve-ec2-olu%2525C5%25259Fturma-zekiye-aydemi%2525CC%252587r%3FtrackingId=XicShXndSg20WAMxgHSCqw%253D%253D/?trackingId=XicShXndSg20WAMxgHSCqw%3D%3D">Linkedin profilimde</a> paylaştığım bu yazımı burada da paylaşıyorum.</p><p>Terraform kurulumunu anlattığım yazıma <a href="https://www.linkedin.com/pulse/installing-terraform-centos-zekiye-aydemi%CC%87r/">linkten</a> ulaşabilirsiniz.</p><p>Terraform modülleri, tekrarlanan kod parçalarını diğer Terraform projeleri ve konfigürasyonlarında yeniden kullanılabilir hale getirir. Terraform modülü, bir veya daha fazla .tf uzantılı dosya içeren bir Terraform konfigürasyonudur.</p><p>Bir modül oluşturma ve onu yerel olarak kullanma adımlarını içeren bir Terraform modülünün temellerine bakacağız.</p><h3>VPC Modulü Oluşturma</h3><p>Öncelikle, projemizin dizinlerini oluşturuyoruz:</p><pre>mkdir -p terraform_project/modules/vpc</pre><p><strong>main.tf</strong> dosyasını aşağıdaki gibi oluşturup içeriği ekliyoruz:</p><pre>vim main.tf</pre><pre>provider &quot;aws&quot; {<br>  region = var.region<br>}<br></pre><pre>resource &quot;aws_vpc&quot; &quot;this&quot; {<br>  cidr_block = &quot;10.0.0.0/16&quot;<br>}<br></pre><pre>resource &quot;aws_subnet&quot; &quot;this&quot; {<br>  vpc_id     = aws_vpc.this.id<br>  cidr_block = &quot;10.0.1.0/24&quot;<br>}<br></pre><pre>data &quot;aws_ssm_parameter&quot; &quot;this&quot; {<br>  name = &quot;/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2&quot;<br>}</pre><p><strong>variables.tf</strong> dosyasını aşağıdaki gibi oluşturup içeriği ekliyoruz:</p><pre>vim variables.tf</pre><pre>variable &quot;region&quot; {<br>  type    = string<br>  default = &quot;us-east-1&quot;<br>}</pre><p><strong>subnet_id</strong> ve <strong>ami_id</strong> değerlerinin ana projeye aktarılabilmesi için aşağıdaki gibi outputs.tf doyasında tanımlıyoruz;</p><pre>vim outputs.tf </pre><pre>output &quot;subnet_id&quot; {<br>  value = aws_subnet.this.id<br>}<br></pre><pre>output &quot;ami_id&quot; {<br>  value = data.aws_ssm_parameter.this.value<br>}</pre><p><strong>main.tf</strong>: Bu dosya, modülün sağlayacağı(provider) kaynaklarının kodunu içerir.</p><p><strong>variables.tf</strong>: Bu dosya, modülün ihtiyaç duyduğu input değişkenlerini içerir.</p><p><strong>outputs.tf</strong>: Bu dosya, modül kod bloğunun ürettiği çıktıların ana projede kullanılabilmesi için referans verir.</p><p>Buraya kadar olan kısımda VPC modulü kodlarını yazdık. Şimdi Modulü kullanacağımız asıl projeye geçiyoruz;</p><h4>Terraform ile EC2 Oluşturma</h4><p>VPC modülünü kullanarak bu networkte EC2 instance oluşturacağız.</p><p>Öncelikle proje için yazının ilk başında oluşturduğumuz <strong>terraform_project</strong> dizinine gidiyoruz. Ardından EC2 instance’ı oluşturacağımız <strong>main.tf</strong> dosyasını aşağıdaki içerikle oluşturuyoruz:</p><pre>cd ~/terraform_project<br>vim main.tf</pre><pre>variable &quot;main_region&quot; {<br>  type    = string<br>  default = &quot;us-east-1&quot;<br>}<br></pre><pre>provider &quot;aws&quot; {<br>  region = var.main_region<br>}<br></pre><pre>module &quot;vpc&quot; {<br>  source = &quot;./modules/vpc&quot;<br>  region = var.main_region<br>}<br></pre><pre>resource &quot;aws_instance&quot; &quot;my-instance&quot; {<br>  ami           = module.vpc.ami_id<br>  subnet_id     = module.vpc.subnet_id<br>  instance_type = &quot;t2.micro&quot;<br>}</pre><p><strong>main.tf</strong>’deki kod, daha önce oluşturduğunuz VPC modülünü çağırır. Terraform’un modül kodunun nerede olduğunu bilmesini sağlamak için modül dizinini kaynak olarak giriyoruz.</p><p>EC2 instance’ı oluşturulduğunda private ip’sinin komut çıktısında ekrana yazılması için outputs.tf dosyasını aşağıdaki gibi oluşturuyoruz:</p><pre>vim outputs.tf</pre><pre>output &quot;PrivateIP&quot; {<br>  description = &quot;Private IP of EC2 instance&quot;<br>  value       = aws_instance.my-instance.private_ip<br>}</pre><p>Alt dizinlerdeki dosyalar da dahil olmak üzere tüm dosyalardaki kodları biçimlendirmek için<strong> terraform fmt -recursive</strong> komutunu çalıştırıyoruz.</p><p>Gerekli sağlayıcıları(provider) almak ve vpc modulündeki kodu almak için <strong>terraform init</strong> komutunu çalıştırıyoruz:</p><pre>terraform fmt -recursive<br>terraform init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*1Fa5akaEWKDQNrh_ECvJXQ.png" /></figure><p>Terraform kodlarında herhangi bir hata var mı onu kontrol edebilmek için de <strong>terraform validate</strong> komutunu çalıştırıyoruz.</p><p><strong>terraform plan</strong> ve sonrasında <strong>terraform apply — auto-approve</strong> komutunu çalıştırıyoruz:</p><pre>terraform plan<br>terraform apply --auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*hUHxWxMCJjcu0Wb4dP5Cng.png" /></figure><p>Vpc modulünde tanımladığım vpc, subnet ve aynı network ağında EC2 instance’ı oluşturduk.</p><p>Tüm bu adımların sonunda aşağıdaki dizin yapısını elde ederiz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*k9fJdWK5QHSE4TVsrQyqbQ.png" /></figure><p>Bu yazımda, bir Terraform modülünün oluşturulmasının temellerini ve yerel kullanımını gösterdim. Daha detaylı bilgi için <a href="https://www.terraform.io/language/modules/develop">Terrafom dökümantasyonuna</a> bakabilirsiniz.</p><p>Kaynakça: A Cloud Guru</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbe3ee18b8cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Most-Used Terraform Commands]]></title>
            <link>https://aydemirzekiye.medium.com/the-most-used-terraform-commands-f3be6472b34d?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3be6472b34d</guid>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Sun, 17 Jul 2022 20:35:23 GMT</pubDate>
            <atom:updated>2022-07-17T20:36:40.684Z</atom:updated>
            <content:encoded><![CDATA[<p>Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. You can refer to my article for terraform installation. <a href="https://lnkd.in/dtxF6pRP">https://lnkd.in/dtxF6pRP</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JDrJT46UvlZ-Z-nqArcG_g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3be6472b34d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Elasticsearch]]></title>
            <link>https://aydemirzekiye.medium.com/installing-elasticsearch-32c72f321da?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/32c72f321da</guid>
            <category><![CDATA[install]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[elastic-stack]]></category>
            <category><![CDATA[elastic]]></category>
            <category><![CDATA[full-text-search]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Fri, 08 Jul 2022 13:35:44 GMT</pubDate>
            <atom:updated>2022-07-08T13:42:07.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZjVSSG6d0NQZbUrZmVJRuQ.png" /></figure><h3>What is Elasticsearch ?</h3><p>Elasticsearch is a highly scalable open source search engine. Elasticsearch supports multi-tenancy, meaning it can store multiple indices on a server, and information can be retrieved from multiple indices using a single query. It uses documents with JSON format; for requests, responses, and during transfer, they are automatically indexed. Elasticsearch has three main uses: <strong>web search</strong>,<strong> log analysis</strong>, and <strong>big data analytics</strong>.</p><p>If you are familiar with relational databases, the table below shows equivalent terms in Elasticsearch:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOxoAX6A7zS8Zhygks94qw.png" /></figure><p><strong>Index</strong>: A collection of documents that contain similar characteristics is called an index. An index is similar to a database. The term index should not be confused with a database index, as someone familiar with traditional SQL might assume. There is no limit on how many indices there can be in a cluster. The word indexing means <strong>inserting/updating</strong> the documents into an Elasticsearch index. The name of the index must be unique and typed in all lowercase letters.</p><p><strong>Type</strong>: A type is similar to a database table, an index can have one or more types. Type is a logical separation of different kinds of data.</p><p><strong>Document</strong>: A document is a JSON object that contains the actual data in key value pairs. A row contains columns; similarly, a document contains fields. Elasticsearch documents are very <strong>flexible</strong> and support storing <strong>nested</strong> objects.</p><h4>Installing Elasticsearch on RedHat 8</h4><p>We need to download Elasticsearch, take the following steps:</p><ol><li>Install the rpm package manually using the following steps.</li></ol><p>We can download the rpm package for Elasticsearch v8.3.2 from the website using the following command:</p><pre><strong>sudo wget </strong><a href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.2-x86_64.rpm"><strong>https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.2-x86_64.rpm</strong></a></pre><p>2. After downloading the rpm package we can compare the SHA of the downloaded <strong>rpm</strong> using the following command:</p><pre><strong>sudo wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.3.2-x86_64.rpm.sha512<br>shasum -a 512 -c elasticsearch-8.3.2-x86_64.rpm.sha512</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*1SN3hj8zQmtPA7kDabSQZQ.png" /></figure><p>3. Once the <strong>rpm</strong> package is downloaded, we can install it using the following command:</p><pre><strong>sudo rpm --install elasticsearch-8.3.2-x86_64.rpm</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*HO0eFJKvowyKY2vHFAFNVg.png" /></figure><p>As seen in the above command output, security features are enabled and configured by default in Elasticsearch installation. <strong>elastic</strong> user’s password is also created at installation.</p><p>4. This way we can manually install the rpm package. After installing Elasticsearch, we can run the service using the systemd method.</p><p>We can configure Elasticsearch to start automatically every time the system boots up by running the following commands:</p><pre><strong>sudo systemctl daemon-reload<br>sudo systemctl enable elasticsearch.service<br></strong></pre><p>5.Using the below command we can start Elasticsearch and check its status:</p><pre><strong>sudo systemctl start elasticsearch.service<br>sudo systemctl status elasticsearch.service</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*DHJBNLFvDJXH0CW_uyTbVw.png" /></figure><p>6. We can check whether Elasticsearch is running by sending an HTTP request on the Elasticsearch host and port. For example, if Elasticsearch is installed on the local machine, we can test by hitting the following command in the command line:</p><pre><strong>curl -X GET &quot;</strong><a href="https://localhost:9200/_cluster/health?wait_for_status=yellow&amp;timeout=50s&amp;pretty"><strong>https://localhost:9200/_cluster/health?wait_for_status=yellow&amp;timeout=50s&amp;pretty</strong></a><strong>&quot; --key certificates/elasticsearch-ca.pem  -k -u elastic</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*eWFfxOKFKT2TiqU2fiQ8Zg.png" /></figure><p>Elasticsearch uses port 9200 by default. You can check <strong>/etc/elasticsearch/elasticsearch.yml</strong> file for port and host settings.</p><p>I briefly talked about elasticsearch installation. For more detailed information, you can check <a href="https://www.elastic.co/guide/index.html">elasticsearch’s website</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32c72f321da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Installing Terraform on CentOS]]></title>
            <link>https://aydemirzekiye.medium.com/installing-terraform-on-centos-765f9243d633?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/765f9243d633</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[terraform-installation]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[terraforming]]></category>
            <category><![CDATA[terraform-cloud]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Thu, 21 Apr 2022 14:07:14 GMT</pubDate>
            <atom:updated>2022-04-21T14:36:51.440Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*f8nN4Ka8kF5FB-mDennytw.png" /></figure><h4>What is Terraform?</h4><p>Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform is an open source tool written in the Go programing language. Terraform can provision infrastructure across many different types of cloud providers, including Amazon Web Services(AWS), Azure, Google Cloud and many others. Testing and Production environments can easily be spun up and destroyed if necessary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*HprJwxA99fV56sr344jeGg.png" /></figure><ul><li><strong><em>terraform init,</em></strong> basically initializes the working directory that contains your Terraform code. <strong><em>terraform init</em></strong> does is to download the supporting or ancillary components required for your code to work. These are things like the providers, which provide the libraries and code for your resources to be able to make API calls to whatever infrastructure you’re deploying into, and also modules. Terraform code is written in the HashiCorp Configuration Language (HCL) in files with the extension <strong><em>.tf</em></strong>. You can write Terraform code in just about any text editors.</li><li><strong><em>terraform plan</em></strong> creates and shows you an execution plan for your infrastucture. By default, <strong><em>terraform plan</em></strong> looks within your current directory for config files and state files to refresh. Using <strong><em>terraform plan</em></strong> can allow you to see if your execution plan matches your expectations. You can do this without making any changes. This command does not deploy anything.</li><li><strong><em>terraform apply</em></strong>, you are able to apply the changes to your infrastructure that is generated by the execution plan from <strong><em>terraform plan</em></strong>. By default, the first time you run terraform, terraform creates the <strong><em>terraform.tfstate</em></strong> file in the current directory. Every time you run Terraform, it saves information about what infrastructure it created in a <strong><em>terraform.tfstate</em></strong> file.</li></ul><h4>Installing Terraform</h4><p>For CentOS/RHEL 7 :</p><pre>yum install -y yum-utils<br>yum-config-manager --add-repo <a href="https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo">https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*wOwFVZKi4Gj8pru__0cu4A.png" /></figure><p>Then, install terraform:</p><pre>yum install -y terraform</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*ATnesoD0Pc_9K3hNR8diLQ.png" /></figure><p>Check the Terraform version information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*orGYUMQXnAkmhR0YCPTB9Q.png" /></figure><h4>Download And Manually Install the Terraform Binary</h4><p>You can also download the terraform binary and execute it on your machine. The examples below are done on Linux Mint (Ubuntu flavour) for example.</p><p>Download the appropriate Terraform binary package for the Linux 64-bit using the wget command:</p><pre>wget -c <a href="https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_linux_amd64.zip">https://releases.hashicorp.com/terraform/1.1.9/terraform_1.1.9_linux_amd64.zip</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*_C7q-lRzws9cafU6U66_8Q.png" /></figure><p>Unzip the downloaded file:</p><pre>unzip terraform_1.1.9_linux_amd64.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*TcZQgItaS6ihZjrwKK4nCA.png" /></figure><p>Place the Terraform binary in the PATH of the operating system so the binary is accessible system-wide to all users, then check the Terraform version information:</p><pre>mv terraform /usr/local/bin/<br>terraform -v</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*5-i6zS5KpBbV6gYi0FN5lQ.png" /></figure><p>In this article, I talked about terraform installation. For more detailed information, you can check the <a href="https://www.terraform.io/">https://terraform.io</a> website for up-to-date information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=765f9243d633" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Oracle_fdw ile Oracle’dan PostgreSQL’e Veri Transferi]]></title>
            <link>https://aydemirzekiye.medium.com/oracle-fdw-ile-oracledan-postgresql-e-veri-transferi-7733003b9844?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/7733003b9844</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[fdw]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 22:30:18 GMT</pubDate>
            <atom:updated>2020-11-11T07:20:13.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*QcR0CdP6V96a2Tm_HKBRpQ.png" /></figure><p>oracle_fdw eklentisi (extension), Oracle veri tabanındaki bir tabloyu PostgreSQL veri tabanında bir tablo olarak göstermenizi sağlayan açık kaynak bir Foreign Data Wrapper’dır(FDW). Böylece PostgreSQL üzerinden Oracle veri tabanı üzerinde bulunan tablomuza SELECT, INSERT, UPDATE ve DELETE işlemleri yapabiliriz, aşağıda örneklerini yapacağız.</p><h4>Oracle Client Kurulumu</h4><p>Oracle_fdw eklentisini kullanarak Oracle ile bağlantı kurabilmek için Oracle istemci(client) paketlerinin kurulması gerekir.</p><p>CentOS 7 üzerinde PostgreSQL 12 versiyonunun bulunduğu sunucuda <a href="http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/index.html">http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/index.html</a> adresinden gerekli olan Oracle Instant Client paketini yüklüyoruz:</p><pre>yum install <a href="http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm">http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm</a></pre><p>Oracle veri tabanına sunucudan erişimi kontrol etmek için sqlplus paketini aşağıdaki komutla kuruyoruz:</p><pre>yum install <a href="http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm">http://yum.oracle.com/repo/OracleLinux/OL7/oracle/instantclient/x86_64/getPackage/oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm</a></pre><p>Erişeceğimiz Oracle veri tabanı sunucusunun IP ve hostname bilgilerini <strong>/etc/hosts</strong> dosyasına aşağıdaki gibi ekliyoruz:</p><pre>echo &quot;192.168.195.191 ol7-19.localdomain  ol7-19&quot; &gt;&gt; /etc/hosts</pre><p>Sunucu üzerinden erişimi aşağıdaki aşağıdaki gibi test edebiliriz:</p><pre>/usr/lib/oracle/19.8/client64/bin/sqlplus \<br>zekiye/password@ol7-19.localdomain:1521/cdb1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*xHxk9fUASBKIJyQMDJ_eCw.png" /></figure><p>Oracle veri tabanı kullanıcısı olan “zekiye”, parolası “password”, Oracle veri tabanı sunucu hostname’i “ol7–19.localdomain”, Oracle veri tabanı portu 1521 ve cdb1 servisine erişiyor.</p><p>Erişim testinin başarılı olmasının ardından PostgreSQL işlemlerine geçebiliriz.</p><h4>Oracle_fdw Extension Kurulumu</h4><p>Oracle_fdw kurulumu için PostgreSQL 12 versiyonuna uygun olan PostgreSQL NonFree repoyu aşağıdaki gibi ekliyoruz:</p><pre>yum install <a href="https://download.postgresql.org/pub/repos/yum/reporpms/non-free/EL-7-x86_64/pgdg-redhat-nonfree-repo-latest.noarch.rpm">https://download.postgresql.org/pub/repos/yum/reporpms/non-free/EL-7-x86_64/pgdg-redhat-nonfree-repo-latest.noarch.rpm</a></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*PY6d76t2FKctCBrcZOcNrA.png" /></figure><p>oracle_fdw paketinin kurulumunu aşağıdaki gibi yapıyoruz:</p><pre>yum install oracle_fdw12.x86_64</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*sXviZcBFowJWjDfCqfFZqQ.png" /></figure><p>oracle_fdw eklentisini, <strong>superuser</strong> haklarına sahip bir kullanıcıyla veri tabanına bağlanarak aşağıdaki gibi oluşturuyoruz. Veri tabanındaki eklentilerin listesini <strong>\dx</strong> komutunu kullanarak görebiliriz:</p><pre>su - postgres<br>psql -d &lt;veritabanı&gt; -U &lt;kullanıcı&gt;<br>CREATE EXTENSION oracle_fdw;<br>\dx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*TBTz8nTfeiV-7KfHa8WoPA.png" /></figure><p>Oracle veri tabanına erişim için oradb adıyla foreign server’ı aşağıdaki gibi oluşturuyoruz. PostgreSQL kullanıcısı zaydemirpg ile Oracle veri tabanı kullanıcısı için eşleştirme (mapping) oluşturuyoruz. PostgreSQL veri tabanında cdb1pg adında yeni bir şema yaratıp Oracle veri tabanındaki “ZEKIYE” şemasındaki tablo yapısını bu şemaya aktarıyoruz.</p><pre>CREATE SERVER oradb FOREIGN DATA WRAPPER oracle_fdw OPTIONS (dbserver &#39;//ol7-19.localdomain:1521/cdb1&#39;);<br>CREATE USER MAPPING FOR zaydemirpg SERVER oradb OPTIONS (USER &#39;zekiye&#39;, PASSWORD &#39;password&#39;);<br>CREATE SCHEMA cdb1pg;<br>IMPORT FOREIGN SCHEMA &quot;ZEKIYE&quot; FROM SERVER oradb INTO cdb1pg;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*QbTT1Ls6T3Ajt2BRu-nj3w.png" /></figure><p>Oracle veri tabanındaki “ZEKIYE” şemasının PostgreSQL veri tabanındaki cdb1pg şemasına aktarımın ardından Oracle erişim testinde sorguladığımız my_table ve people tablolarına PostgreSQL’de cdb1pg şemasında erişebiliyoruz.</p><p>Oracle veri tabanındaki tablolar üzerinde SELECT, UPDATE, DELETE ve INSERT işlemlerini aşağıdaki gibi gerçekleştirebiliriz. Foreign tabloların listesini <strong>\det+</strong> komutu ile aşağıdaki gibi görebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*d3t4_xD8xJW7UyZUHT6CMg.png" /></figure><p>Son olarak, cdb1pg şemasındaki my_table tablosunu public.my_table adında yeni oluşturarak aşağıdaki gibi aktarabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*PWWX2v3iKgZdCck22XikPQ.png" /></figure><p>Bu yazımda oracle_fdw kurulumu ve kullanımından temel olarak bahsettim. Daha ayrıntılı bilgiyi projenin kendi sayfası olan <a href="https://github.com/laurenz/oracle_fdw">https://github.com/laurenz/oracle_fdw</a> sayfasında bulabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7733003b9844" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pg_stat_statements ile PostgreSQL’de Yavaş Sorguları Bulma]]></title>
            <link>https://aydemirzekiye.medium.com/pg-stat-statements-ile-postgresqlde-yava%C5%9F-sorgular%C4%B1-bulma-313efbe92975?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/313efbe92975</guid>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Sun, 05 Jul 2020 13:13:26 GMT</pubDate>
            <atom:updated>2020-07-05T14:26:18.287Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*Nk9ha2II6-K9AxPKcEnt2w.png" /></figure><h3>pg_stat_statements ile PostgreSQL’de Yavaş Sorguları Bulma</h3><p>PostgreSQL’de yavaş olan sorguları bulabilmek için <strong>postgresql.conf </strong>dosyasındaki <strong>log_min_duration_statement</strong> parametresini belirli bir eşik değerine ayarlayarak bu eşiği geçen sorguların log dosyasına yazılmasını sağlayabiliriz. Bu konfigürasyon bize uzun süren sorguları verse de belirttiğimiz eşikten daha kısa süren ve veritabanına yük oluşturan sorgular bizim için görünmezdir.</p><p>pg_stat_statements extension’ı, veritabanında çalıştırılan tüm SQL sorgularının istatistiklerini kaydeder. Performans sorunlarını tespit etmek için kullanılabilecek en önemli extension’lardan biridir. Oluşturulduğu veritabanında çalıştırılan her sorguya ait toplam çalışma süresi, sorguyla getirilen satır sayısı, sorgunun kaç kez çağırıldığı gibi bir çok bilgiyi elde etmemizi sağlar.</p><h3>pg_stat_statements Kurulumu</h3><p>Mevcut PostgreSQL Cluster’ımızın versiyonundaki <strong>contrib</strong> paketini yüklüyoruz:</p><p>CentOS/Redhat dağıtımları için:</p><pre>sudo yum install postgresql12-contrib</pre><p>Debian tabanlı dağıtımlar için:</p><pre>sudo apt-get install postgresql-contrib-12</pre><p>postgresql.conf dosyası içindeki <strong>shared_preload_libraries</strong> parametresini pg_stat_statements modülünü içerecek şekilde aşağıdaki gibi düzenliyoruz:</p><pre>vim /var/lib/pgsql/12/data/postgresql.conf<br>&gt;<br>shared_preload_libraries = &#39;pg_stat_statements&#39;</pre><p>Ya da PostgreSQL’e bağlanarak aşağıdaki gibi ALTER SYSTEM SET komutunu kullanarak ayarlayabiliriz:</p><pre>ALTER SYSTEM SET shared_preload_libraries TO &#39;pg_stat_statements&#39;;</pre><p><strong>shared_preload_libraries</strong> parametresinde yapılan değişikliğin etkin olabilmesi için PostgreSQL servisinin yeniden başlatılmasını gereklidir, aşağıdaki gibi servisi yeniden başlatıyoruz:</p><p>CentOS/Redhat dağıtımları için:</p><pre>sudo systemctl restart postgresql-12</pre><p>Debian tabanlı dağıtımlar için:</p><pre>sudo systemctl restart postgresql@main-12</pre><p>Sorgu istatistikleri izlemek istediğimiz veritabanına, superuser haklarına sahip bir kullanıcı ile bağlanarak extension’ı oluşturuyoruz:</p><pre>CREATE EXTENSION pg_stat_statements;</pre><p>Oluşturduğumuz pg_stat_statements extension’ını <strong>\dx</strong> ile aşağıdaki gibi görüntüleyebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*spKdyYk5xARjYYGnK6ErTg.png" /></figure><p>Veritabanında ortalama çalışma zamanı en yüksek olan sorguyu aşağıdaki gibi görebiliriz:</p><pre>SELECT total_time, min_time, max_time, mean_time, calls, rows, query<br>FROM pg_stat_statements<br>ORDER BY mean_time DESC<br>LIMIT 1;</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*G9-BO913doPYE03qdMXQBQ.png" /></figure><p><strong>total_time</strong>: Sorgu çalıştırıldığında harcanan toplam süreyi milisaniye cinsinden verir.<br><strong>min_time</strong> &amp; <strong>max_time</strong> : Sorgunun minimum ve maksimum çalışma zamanlarını verirler.<br><strong>mean_time</strong>: total_time/calls ile sorgunun ortalama çalışma süresini milisaniye cinsinden verir.<br><strong>calls</strong>: Sorgunun toplam kaç kez çalıştırıldığını verir.<br><strong>rows</strong>: Sorgu sonucunda alınan veya etkilenen toplam satır sayısını verir.<br><strong>query</strong>: Çalıştırılan sorguyu verir. Varsayılan olarak sorgunun en fazla 1024 byte karakteri görüntüler. Bu değeri <strong>track_activity_query_size</strong> parametresi ile değiştirebilirsiniz.</p><p>Varsayılan olarak, pg_stat_statements extension’ı karşılaştığı ilk 5.000 sorguya ait istatistikleri saklar. pg_stat_statements.max, parametresini düzenleyerek bu sayıyı değiştirebiliriz. Parametrede yapılan değişikliğin etkin olabilmesi için PostgreSQL servisinin yeniden başlatılması gereklidir.</p><p>Örnek olarak aşağıdaki gibi 10000 olarak ayarlayabiliriz:</p><pre>ALTER SYSTEM SET pg_stat_statements.max TO 10000;</pre><h4>İstatistikleri Sıfırlama</h4><p>pg_stat_statements tarafından elde edilen istatistikler, sıfırlanana kadar birikir. İstatistik verilerini sıfırlamak için superuser haklarına sahip bir kullanıcı ile veritabanına bağlanarak aşağıdaki fonksiyonu çalıştırabilirsiniz:</p><pre>SELECT pg_stat_statements_reset();</pre><p>Bu yazımda temel olarak pg_stat_statements kullanımından bahsettim. Daha ayrıntılı bilgi için <a href="https://www.postgresql.org/docs/12/pgstatstatements.html">kendi sayfasına</a> bakabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=313efbe92975" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CentOS-8 Üzerinde MongoDB Kurulumu]]></title>
            <link>https://aydemirzekiye.medium.com/centos-8-%C3%BCzerinde-mongodb-kurulumu-a2284c188df0?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2284c188df0</guid>
            <category><![CDATA[centos-8]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[mongo]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Tue, 21 Apr 2020 12:29:42 GMT</pubDate>
            <atom:updated>2020-04-21T22:24:28.221Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*OhiTQ-2xiYzwaT9_fEW9Zg.png" /></figure><p>MongoDB büyük miktarda veriyi verimli bir şekilde işlemek üzere tasarlanan açık kaynaklı ve belge tabanlı NoSQL bir veritabanıdır. Verileri Binary JSON belgeleri (BSON) olarak depolar. MongoDB 4.0 ve sonrasındaki sürümlerinde ACID desteği sağlar.</p><p>MongoDB’yi yüksek performans ve hızlı hale getirmek için RDBMS sistemlerinde yaygın olarak bulunan bazı özellikler mevcut değildir. Tablo, satır ve sütun kavramlarına sahip değildir. Dinamik şema yapısına sahiptir böylece belgeler farklı şemalara sahip olabilir, bu da uygulama geliştikçe şemanın değişebileceği anlamına gelir.</p><p>Tek bir MongoDB instance’ı birden çok veritabanı barındırabilir. Her veritabanı bir koleksiyon kümesidir. Koleksiyonlar ilişkisel veritabanındaki tablo kavramına benzer; ancak, bunlar şematiktir. Bir koleksiyonda birden fazla belge olabilir, belgeyi ilişkisel veritabanındaki satır(row) gibi düşünebiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/0*267a14uAS-7yDX7J" /></figure><p>CentOS 8 sunucusu üzerinde MongoDB kurulumunu ele alacağız.</p><h3>MongoDB Kurulumu</h3><p>Kurulum için <em>/etc/yum.repos.d/mongodb-org-4.2.repo</em> repo dosyasını vim komutu ile oluşturuyoruz ve dosya içerisine aşağıdaki satırları ekliyoruz, kaydedip çıkıyoruz:</p><pre>vim /etc/yum.repos.d/mongodb-org-4.2.repo</pre><pre>[mongodb-org-4.2]<br>name=MongoDB Repository<br>baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/<br>gpgcheck=1<br>enabled=1<br>gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc</pre><p>MongoDB’nin mongodb-org paketini kuruyoruz:</p><pre>dnf install mongodb-org</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*i0NcsdaUzVMgqZecdVmVNw.png" /></figure><p>Kurulumunu gerçekleştirdiğimiz <em>mongodb-org</em> paketi mongos, server, shell ve tools paketlerinin toplamını oluşturur.</p><p><strong>mongodb-org-server</strong> : Mongod programını ve init komutunu içerir.</p><p><strong>mongodb-org-mongos</strong> : Mongos programını içerir.</p><p><strong>mongodb-org-shell</strong> :Mongo kabuk programını içerir.</p><p><strong>mongodb-org-tools</strong> :Mongo komutlarını içerir; mongodump, mongorestore, mongoexport, mongoimport, mongostat, mongotop vb.</p><p>MongoDB servisi olan mongod’u başlatıyoruz ve sunucu açılışlarında otomatik olarak başlaması için enable ediyoruz:</p><pre>systemctl start mongod<br>systemctl enable mongod</pre><p>Mongod servisinin çalışmasını aşağıdaki gibi kontrol edebiliriz:</p><pre>systemctl status mongod</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*lneDd7nJJsojBG-TqRDX_w.png" /></figure><p>MongoDB konfigürasyon dosyası varsayılan olarak<em> /etc/mongod.conf</em> dosyasıdır. Varsayılan ayarlarla 127.0.0.1 adresinde 27017 portunda çalışır.</p><p><em>mongo</em> komutu ile veritabanına bağlanıyoruz:</p><pre>mongo</pre><p><em>show dbs</em> komutuyla mevcut veritabanlarını görüntüleyebiliriz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*LJ_YtwvM54VjqxwcY9oTVw.png" /></figure><p>MongoDB kurulumunda varsayılan olarak admin, local ve config veritabanlarına sahiptir.</p><p><strong>admin</strong> :Yönetim işlemleri için kök(root) veritabanıdır. Admin veritabanına bir kullanıcı eklenirse, kullanıcı tüm veritabanlarının izinlerini otomatik olarak devralır. Ayrıca, tüm veritabanlarını listeleme veya servisi kapatma işlemleri gibi yalnızca admin veritabanından çalıştırılabilen servis genelinde bazı komutlar da vardır.</p><p><strong>local </strong>: MongoDB servisinin replikasyon işlemlerindeki bilgilerini ve kendine özgü bilgileri barındırdığı veritabanıdır. Replikasyon işlemleri sırasında da kopyalanmaz.</p><p><strong>config </strong>:<strong> </strong>Sharded cluster bilgilerinin depolandığı veritabanıdır.</p><p>MongoDB kurulduğunda varsayılan olarak kimlik doğrulama (authotentication) ayarı disable olarak ayarlanmıştır. Örnek komut çıktısında yer alan “<strong><em>WARNING: Access control is not enabled for the database.</em></strong>” uyarısının sebebi bu ayardır. Veritabanında yetkili bir kullanıcı oluşturduktan sonra varsayılan konfigürasyon dosyası olan <em>/etc/mongod.conf</em> dosyasında kimlik doğrulama ayarını aktif edip servisi yeniden başlattığımızda bu uyarıyı almayacağız.</p><p>MongoDB daha iyi bir performansla çalışabilmek için Transparent HugePages’in devre dışı bırakılmasını önerir . Bu ayar çoğu Linux dağıtımında varsayılan olarak aktiftir. Örnek komut çıktısında “<strong>WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always’.</strong>” uyarısını almamızın sebebi bu ayardır. Veritabanında kullanıcı oluşturma işlemlerinin ardından bu ayarı önerildiği şekilde değiştireceğiz.</p><h3>MongoDB Kullanıcı Oluşturma ve Veritabanı İşlemleri</h3><p>Aşağıdaki komutla admin veritabanına bağlanarak tüm cluster’da yetkili bir kullanıcı oluşturuyoruz:</p><pre>use admin<br>db.createUser(<br>  {<br>    user: &quot;zaydemir&quot;,<br>    pwd: &quot;mypassword&quot;,<br>    roles: [ { role: &quot;userAdminAnyDatabase&quot;, db: &quot;admin&quot; }, &quot;readWriteAnyDatabase&quot; ]<br>  }<br>)</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*REDruiEy4o2RWNm8" /></figure><p><strong>exit</strong> komutuyla veritabanından çıkıp <em>/etc/mongod.conf</em> dosyasına aşağıdaki satırı ekliyoruz:</p><pre>security:<br>  authorization: enabled</pre><p><em>/etc/mongod.conf</em> dosyasının son hali aşağıdaki gibidir:</p><pre>cat /etc/mongod.conf</pre><pre>systemLog:<br>  destination: file<br>  logAppend: true<br>  path: /var/log/mongodb/mongod.log<br>storage:<br>  dbPath: /var/lib/mongo<br>  journal:<br>    enabled: true<br># how the process runs<br>processManagement:<br>  fork: true  # fork and run in background<br>  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile<br>  timeZoneInfo: /usr/share/zoneinfo<br># network interfaces<br>net:<br>  port: 27017<br>  bindIp: 127.0.0.1<br>security:<br>  authorization: enabled</pre><p>Mongod servisini yeniden başlatıyoruz:</p><pre>systemctl restart mongod</pre><p>Aşağıdaki komut ile veritabanına bağlandığımızda <em>authentication</em> uyarısını artık almadığımızı göreceğiz:</p><pre>mongo --port 27017 --host 127.0.0.1  --authenticationDatabase &quot;admin&quot; -u zaydemir -p &#39;mypassword&#39;</pre><p>Yeni bir veritabanı ve collection oluşturarak aşağıdaki komutlar ile kayıt ekleyelim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*bJ1-vaN1Zsm6C2jWCmyOvg.png" /></figure><p><strong>use customer </strong>: <em>customer</em> adında bir veritabanına bağlanır, bu isimde bir veritabanı yoksa oluşturur. Veritabanında bir nesne oluşturmadan çıkarsak veritabanı silinecektir.</p><p><strong>db</strong> : Bağlı olduğumuz veritabanını gösterir.</p><p><strong>db.people.insert()</strong> : <em>customer</em> veritabanında <em>people</em> adındaki collection’a kayıt ekler, collection yoksa oluşturur.</p><p><strong>db.people.find()</strong> : <em>people</em> collection’ında yer alan tüm kayıtları getirir.</p><p><strong>show dbs</strong> : Mevcut veritabanı listesini verir.</p><p><strong>show collections</strong> : Bağlandığımız veritabanındaki collection’ların listesini verir.</p><h3>Transparent HugePages’i Devre Dışı Bırakma (THP)</h3><p>Transparent HugePages(THP), çoğu Linux işletim sisteminde varsayılan olarak etkinleştirilen bir bellek yönetim sistemidir. MongoDB’nin Linux üzerinde daha performanslı çalışması için THP devre dışı bırakılmalıdır.</p><p>Bir servis dosyası oluşturup sunucunun her açılışında mongodb servisi başlamadan önce THP’yi devre dışı bırakacak şekilde ayarlayalım:</p><pre>vim /etc/systemd/system/disable-transparent-huge-pages.service<br></pre><pre>[Unit]<br>Description=Disable Transparent Huge Pages (THP)<br>DefaultDependencies=no<br>After=sysinit.target local-fs.target<br>Before=mongod.service<br></pre><pre>[Service]<br>Type=oneshot<br>ExecStart=/bin/sh -c &#39;echo never | tee /sys/kernel/mm/transparent_hugepage/enabled &gt; /dev/null&#39;<br></pre><pre>[Install]<br>WantedBy=basic.target</pre><p>Oluşturduğumuz <em>disable-transparent-huge-pages.service</em> servisini kullanabilir hale getirmek için systemd’yi reload ediyoruz:</p><pre>systemctl daemon-reload</pre><p>Servisi başlatıyoruz ve sunucu her açıldığında servisin aktif olabilmesi için enable ediyoruz:</p><pre>systemctl start disable-transparent-huge-pages<br>systemctl enable disable-transparent-huge-pages</pre><p>Aşağıdaki komutla THP ayarının [never] olduğunu görebiliriz:</p><pre>cat /sys/kernel/mm/transparent_hugepage/enabled</pre><p>Örnek çıktı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*h4MPVRnER3Ex-kXvx_-z9g.png" /></figure><p>Transparent HugePages’i devre dışı bırakırmanın servis dosyası oluşturmak dışında daha farklı yöntemleri de mevcut, MongoDB <a href="https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/">sayfasında</a> bulabilirsiniz.</p><p>Bu yazımda temel seviyede MongoDB kurulumuna değindim. Fiziksel, sanal ve cloud ortamlara kurulum yaparken daha detaylı yapılandırma işlemleri gerekecektir. MongoDB kurulumu hakkında resmi web sayfası olan <a href="https://docs.mongodb.com/manual/">https://docs.mongodb.com/manual/</a> adresinde çok daha detaylı ve kapsamlı anlatım mevcuttur.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2284c188df0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL 12 Barman ile Streaming Yedekleme]]></title>
            <link>https://aydemirzekiye.medium.com/postgresql-12-barman-ile-streaming-yedekleme-9d61b717515b?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d61b717515b</guid>
            <category><![CDATA[restore]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[disaster-recovery]]></category>
            <category><![CDATA[barman]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Tue, 14 Jan 2020 06:29:22 GMT</pubDate>
            <atom:updated>2020-10-13T10:14:50.166Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*IHTWG7TpnzkENrlwzP-ixA.png" /></figure><p>Barman, PostgreSQL’de açık kaynaklı bir backup/restore yönetim aracıdır.</p><h4>Barman ile neler yapabilirsiniz?</h4><p>Aynı sunucu üzerinde yedek alabilirsiniz.</p><p>Farklı bir backup sunucusuna yedek alabilirsiniz.</p><p>Birden fazla PostgreSQL cluster yedeği alabilirsiniz.</p><p>PostgreSQL’in farklı ana sürümlerinde çalışan birden fazla PostgreSQL Cluster’ından yedekleme yaparak verilerinizi merkezi bir backup sunucusunda toplayabilirsiniz.</p><p>Barman ile 2 farklı şekilde yedekleme yapabilirsiniz:</p><ul><li>rsync/ssh</li><li>streaming</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*uzdbRSujsztgCYSa3jHbTg.jpeg" /></figure><p>Barman ile streaming backup alırken backup sunucusu ile veritabanı arasında 3 bağlantı kurulur. Bunlardan <strong>1.PostgreSQL connection</strong>’ı yönetim işlemleri için kurulur, <strong>2. Streaming Backup</strong> bağlantısı pg_basebackup ile full yedek alımı için kurulur, <strong>3.WAL Streaming</strong> bağlantısı pg_receivewal ile veritabanındaki WAL dosyalarının alımı için kurulur.</p><p>Burada PostgreSQL sunucusu üzerinde /pg_backup dizinine yedekleme senaryosunu ele alacağız:</p><h3>Barman Kurulumu</h3><p>Debian ve türevleri için:</p><pre>sudo apt update<br>sudo apt install barman</pre><p>RedHat ve türevleri için:</p><pre>sudo yum update <br>sudo yum install barman</pre><h4>PostgreSQL Ayarları</h4><p>PostgreSQL’de yedekleme işlemleri için <strong>superuser</strong> hakkına sahip barman kullanıcısı ve streaming işlemleri için <strong>replication</strong> hakkına sahip streaming_barman kullanıcısını oluşturuyoruz:</p><pre>createuser --superuser barman<br>createuser --replication streaming_barman</pre><p>Ya da psql ile bağlanarak aşağıdaki gibi oluşturabiliriz:</p><pre>CREATE USER barman SUPERUSER;<br>CREATE USER streaming_barman REPLICATION;</pre><p>Kullanıcının veritabanına bağlanabilmesi için pg_hba.conf dosyasını düzenliyoruz:</p><pre>vim /var/lib/pgsql/12/data/pg_hba.conf<br>&gt;&gt;<br>local   all             barman                       trust <br>local   replication     streaming_barman             trust</pre><p>Burada PostgreSQL cluster’ı ile Barman <strong>aynı</strong> sunucu üzerinde ve sunucu üzerinde tek bir PostgreSQL cluster’ı olduğu için local’den bağlanacak şekilde ayarladım.</p><p>Not: Yukarıdaki gibi pg_hba.conf dosyasında trust ile barman kullanıcıları parola gerekmeden bağlanabilecekler, parola ile bağlanmaları durumunda trust yerine md5 yazıp barman kullanıcısı için ~barman/.pgpass dosyası oluşturarak bağlanabilirsiniz.</p><p>pg_hba.conf dosyasında yapılan bir değişikliğin etkin olabilmesi için PostgreSQL servisi reload işlemine ihtiyaç duyar. psql ile bağlanarak aşağıdaki komutla yapabiliriz:</p><pre>SELECT pg_reload_conf();</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*uq36fawGIVQj5gg2r1W_LQ.png" /></figure><p>Oluşturduğumuz barman kullanıcısının erişimini aşağıdaki komut ile kontrol edebiliriz:</p><pre>su - barman <br>psql -c &#39;SELECT version()&#39; -U barman -d postgres</pre><p>Örnek çıktı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*JHNOumErvZ2cZm5g2TgxuQ.png" /></figure><p>Streaming işlemleri için replication haklarına sahip streaming_barman kullanıcısının bağlantısını aşağıdaki gibi kontrol edebiliriz:</p><pre>su - barman <br>psql -U streaming_barman -c &quot;IDENTIFY_SYSTEM&quot; replication=1</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*r2UuJeVPwQcCVCO4IjKVFQ.png" /></figure><h3>Barman Ayarları</h3><p>Barman 2 tip konfigürasyon dosyasına sahiptir:</p><p><strong>/etc/barman.conf </strong>-&gt; Global konfigürasyon dosyasıdır. Log dosyası, backup kullanıcısı, backup dizini gibi genel yedekleme konfigürasyonlarını barındırır.</p><p>barman.conf dosyasını aşağıdaki gibi düzenliyoruz:</p><pre>vim /etc/barman.conf<br>&gt;&gt;<br>[barman]<br>active = true<br>barman_user = barman<br>barman_home = Backup_Dizini<br>log_file = Backup_Log_Dosyası<br>log_level = INFO<br>compression = gzip<br>retention_policy = REDUNDANCY 3<br>immediate_checkpoint = true<br>last_backup_maximum_age = 4 DAYS<br>minimum_redundancy = 1</pre><p><strong>/etc/barman.d</strong> -&gt; Server konfigürasyon dosyaları varsayılan olarak /etc/barman.d dizini altındadır. Barman ile alabileceğimiz streaming ve rsync her iki tip yedekleme için bu dizin altında template konfigürasyon dosyaları mevcuttur. Barman ile backup almak istediğiniz her bir PostgreSQL cluster’ı için bir konfigürasyon dosyasını bu template dosyalarını kullanarak oluşturabilirsiniz.</p><p>Öncelikle cluster data dizini adıyla template dosyalardan streaming-server.conf-template dosyasını kopyalıyoruz ve dosyayı düzenliyoruz:</p><pre>cp /etc/barman.d/streaming-server.conf-template \ /etc/barman.d/12_data.conf</pre><p>Tek bir barman ile birden fazla PostgreSQL cluster’ının yedeğini alabilirsiniz demiştim. Yedeğini almak istediğiniz her bir PostgreSQL cluster’ı için /etc/barman.d/ dizini altında bir backup server dosyası oluşturulmalıdır.</p><p>Dosya içinde aşağıdaki parametreleri düzenliyoruz:</p><pre>vim /etc/barman.d/12_data.conf<br>&gt;&gt;<br>[12_data] <br>description =  &quot;Cluster 12/data (Streaming-Only)&quot;<br>conninfo = user=barman dbname=postgres host=localhost port=5432 <br>streaming_conninfo =  user=streaming_barman host=localhost port=5432<br>streaming_archiver = on<br>slot_name = barman</pre><p><strong>12_data</strong> : Backup server adı belirliyoruz. İlerleyen kısımlarda backup işlemlerinde bu server adı ile işlem yapacağız.</p><p><strong>conninfo</strong> : Barman’in PostgreSQL’e yapacağı bağlantının bilgileri veriyoruz.</p><p><strong>streaming_conninfo</strong> : Streaming işlemler için yapılacak bağlantının bilgilerini veriyoruz.</p><p><strong>streaming_archiver</strong> : WAL archive alımını aktif ediyoruz.</p><p><strong>slot_name</strong> : Barman ile PostgreSQL’de oluşturacağımız slot’un adını veriyoruz.</p><p>Barman kullancısına bağlanarak slot oluşturuyoruz:</p><pre>su - barman<br>barman receive-wal --create-slot 12_data</pre><p>Örnek çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*oQbsmIQECQbaGFiceXeS3Q.png" /></figure><p>Konfigürasyon dosyasında belirttiğimiz slot_name ile bir slot oluşturur.</p><p>Oluşturulan slot’u aşağıdaki gibi kontrol edebilirsiniz:</p><pre>psql -c &quot;Select slot_name,slot_type, active from pg_replication_slots&quot; -U barman -d postgres</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*LTb2JbZY-_Ag9gUCsF9Pzw.png" /></figure><p>WAL dosyalarının streaming ayarlarının kontrolü için;</p><pre>su - barman<br>barman switch-wal --force --archive 12_data</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*amxwdhP3BaUhp2wTs4D93g.png" /></figure><p>Barman yapılandırmasının doğruluğunu aşağıdaki gibi kontrol edebilirsiniz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*9COc0Q5dYCHo8oPRlppP7g.png" /></figure><p>İlk yedeği aşağıdaki komutla alabilirsiniz:</p><pre>barman backup 12_data --wait</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*VCi4-JPUMkGoezl4ax4WcA.png" /></figure><p>Server’ın genel durumunu aşağıdaki gibi kontrol edebilirsiniz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*_QqJu-QO2yDMd4aU6rS3iw.png" /></figure><h4>Barman ile Yedekten Geri Dönme</h4><p>Sunucu üzerinde barman kullanıcısının erişebildiği bir dizine aşağıdaki gibi recovery yapabilirsiniz:</p><pre>barman recover &lt;Server_Name&gt; &lt;Backup_ID&gt; &lt;Recovery_Directory&gt;</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*ijs225IjDE_BmsiJ0QiXRA.png" /></figure><p>Belirli bir zamana geri dönmek için target-time parametresi ile zaman belirtebiliriz:</p><pre>barman recover 12_data 20200113T230114 /db/pg_data/12/data --target-time &quot;Mon Jan 13 23:20:29 +03 2020&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*_KofVx4Odo5-jOxrwIZyJg.png" /></figure><p>Bu yazımda temel seviyedeki konfigürasyonlarla yedeklemeye değindim. Daha detaylı bilgi için barman’in web sayfası olan <a href="https://www.pgbarman.org/">https://www.pgbarman.org/</a> adresinden yararlanabilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d61b717515b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL 12'de Streaming Replication İşlemleri]]></title>
            <link>https://aydemirzekiye.medium.com/postgresql-12de-streaming-replication-i%CC%87%C5%9Flemleri-40f792a8141b?source=rss-cb21cd23cff8------2</link>
            <guid isPermaLink="false">https://medium.com/p/40f792a8141b</guid>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[backup]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Zekiye AYDEMİR]]></dc:creator>
            <pubDate>Fri, 13 Dec 2019 17:57:51 GMT</pubDate>
            <atom:updated>2020-01-04T13:12:39.517Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/0*MwRxsyqoiiK6KU2H" /></figure><p>Daha önce <a href="https://www.linkedin.com/in/zekiye-aydemir-132844ba/">Linkedin profilimde</a> paylaştığım <a href="https://www.linkedin.com/pulse/postgresql-12de-streaming-replication-i%C5%9Flemleri-zekiye-aydemi%CC%87r/">yazımı</a> burada da paylaşıyorum.</p><p>PostgreSQL 12 ile birlikte bir çok heyecan verici yeni özellik hayatımıza girmiş oldu. Bu yeni yeteneklere ek olarak, replikasyon sürecinde oluşturulan yapılandırma işlemlerinde ciddi bir değişiklik yapıldı. PostgreSQL 8.0 sürümünden bu yana var olan recovery.conf yapılandırma dosyası artık hayatımızda yok.</p><p>Peki recovery.conf dosyasına yazdığımız parametreleri artık nereye yazıyoruz? Bu dosyada yer alan parametreler postgresql.conf dosyasına eklendi. Böylece, diğer postgresql.conf parametreleri gibi ALTER SYSTEM komutuyla yönetilmeleri mümkün hale getirildi. Ayrıca önceden recovery.conf dosyasında yapılan en ufak bir değişiklik için PostgreSQL servisini yeniden başlatmak gerekmekteyken, artık bazı parametre değişimleri için sunucuya reload işlemini yaptırmak yeterli. Örnek olarak artık aşağıdaki parametrelerdeki bir değişiklik için reload işlemi yeterli oluyor:</p><p>archive_cleanup_command</p><p>promote_trigger_file</p><p>recovery_end_command</p><p>recovery_min_apply_delay</p><p>recovery.conf dosyasındaki “standby_mode” parametresi tamamen kaldırıldı, onun yerine “standby.signal” ve “recovery.signal” adlarında sinyal dosyaları getirildi. Yine, recovery.conf dosyasındaki “trigger_file” parametresinin adı “promote_trigger_file“ olarak değiştirildi.</p><h4>PostgreSQL 12 Kurulumu</h4><p>Master ve Replica olmak üzere iki ayrı CentOS 7 sunucusunda PostgreSQL 12 kuralım:</p><pre>yum install <a href="https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm">https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm</a></pre><pre>yum install postgresql12 postgresql12-server postgresql12-contrib -y</pre><p>Sadece Master Sunucu üzerinde aşağıdaki gibi initdb yapalım ve PostgreSQL servisini başlatalım:</p><pre>/usr/pgsql-12/bin/postgresql-12-setup initdb<br>systemctl enable postgresql-12<br>systemctl start postgresql-12</pre><h3>Replikasyon Kurulumu</h3><h4>Master Sunucu İşlemleri</h4><p>PostgreSQL varsayılan olarak localhost adresini dinler. Replica sunucunun erişimi için master PostgreSQL servisini dışarıdan gelen tüm bağlantıları dinleyecek şekilde ayarlayalım ve replica sunucunun master sunucu üzerinde bağlanacağı replikasyon kullanıcısını oluşturalım:</p><pre>ALTER SYSTEM SET listen_addresses TO &#39;*&#39;;</pre><pre>CREATE ROLE replica_user WITH REPLICATION LOGIN;</pre><p>Kullanıcının oluşturulduğunu psql içinde \du ile kontrol edebilirsiniz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/0*zu2Mz1iFAvEUr-By" /></figure><p>listen_addresses parametresinde yapılan değişikliğin etkin olabilmesi için PostgreSQL servisini aşağıdaki gibi yeniden başlatalım:</p><pre>systemctl restart postgresql-12</pre><p>Oluşturduğumuz replica_user kullanıcısının erişimi için pg_hba.conf dosyasını düzenlememiz gerekiyor:</p><pre>echo &quot;host    replication     replica_user    Replica_Sunucu_IP/32      trust&quot;&gt;&gt;/var/lib/pgsql/12/data/pg_hba.conf</pre><p>pg_hba.conf dosyasında yapılan bir değişikliğin etkin olabilmesi için Postgres sunucusu reload işlemine ihtiyaç duyar. psql ile bağlanarak aşağıdaki komutla yapabiliriz:</p><pre>SELECT pg_reload_conf();</pre><p>Ya da PostgreSQL servisini reload edebiliriz:</p><pre>systemctl reload postgresql-12</pre><h4>Replica Sunucu İşlemleri</h4><p>pg_basebackup komutunu kullanarak master sunucu üzerinde bulunan PostgreSQL data dizininin bir kopyasını replica sunucuya alalım:</p><pre>/usr/pgsql-12/bin/pg_basebackup --host=Master_Sunucu_IP --pgdata=/var/lib/pgsql/12/data/ --username=replica_user --verbose --progress --wal-method=stream --write-recovery-conf --checkpoint=fast --create-slot --slot=Slot_name</pre><p>Örnek komut çıktısı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/0*Tr6TiRswmD7KsHVK" /></figure><p>Aktarım tamamlandığında replica sunucudaki data dizinini inceleyelim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*58e9Xxk3A0wr1Iq-" /></figure><p>recovery.conf dosyasında yer alan “standby_mode” parametresi yerine replikasyondaki /var/lib/pgsql/12/data dizini içinde standby.signal dosyası getirildi.</p><p>pg_basebackup komutunda yer alan — write-recovery-conf parametresi ile eskiden recovery.conf dosyasına yazılan recovery ayarları artık postgresql-auto.conf dosyasına yazılır:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/0*XI5g5Qbwr8VBnFbZ" /></figure><p>Master sunucu üzerinde listen_addresses parametresini değiştirmeyi ALTER SYSTEM komutu ile yapmıştık. Burada ufak bir hatırlatma yapayım ki kafalar karışmasın; ALTER SYSTEM ile değiştirdiğimiz parametreler postgresql.auto.conf içine yazılmakta (dosyanın ilk satırlarında da yazdığı gibi lütfen bu dosyaya elle müdahele etmeyin). Dolayısıyla yukarıdaki çıktıda gözüken listen_addresses parametresi master sunucuda yaptığımız yapılandırma işleminden gelmekte. Tam bu noktada master sunucudaki dosya içeriğini incelerseniz sadece bu parametrenin olduğunu göreceksiniz. pg_basebackup ile master data dizininin bir kopyasını replica sunucusu üzerine kopyaladık, ek olarak da bu dosyaya diğer satırları otomatik olarak yazdırmış olduk. Bu ayrımın netleşmesi önemli. :)</p><p>Replica sunucu üzerinde PostgreSQL servisini başlatıp replikasyonu aktif hale getirebiliriz:</p><pre>systemctl start postgresql-12</pre><p>Replica sunucu üzerinde veritabanına psql ile bağlanarak replikasyonun çalıştığını aşağıdaki gibi kontrol edebilirsiniz:</p><pre>SELECT * FROM pg_stat_wal_receiver;</pre><p>Sorgu çıktısını aşağıdaki gibi düzenli bir görünümle alabilmek için güzel psql özelliklerinden biri olan \x komutunu kullanabilirsiniz:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*56oB5uUnv4buGGnj" /></figure><p>Master sunucu üzerinden replikasyonu kontrol edelim:</p><pre>SELECT * FROM pg_stat_replication;</pre><p>Örnek çıktı aşağıdaki gibidir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/0*me_1BKbNdlHcSuj1" /></figure><p>Böylece PostgreSQL 12 ile iki sunucu arasında replikasyon kurulumunu tamamlamış ve önceki Postgres sürümlerine kıyasla değişen yapılandırma sürecini de görmüş olduk.</p><p>PostgreSQL 12 üzerinde replikasyon işlemlerine ait daha ayrıntılı bilgiye Postgres’in resmi sitesindeki <a href="https://www.postgresql.org/docs/12/runtime-config-replication.html">ilgili adresten</a> erişebilirsiniz.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40f792a8141b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>