<?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 Humza Arshad Khan on Medium]]></title>
        <description><![CDATA[Stories by Humza Arshad Khan on Medium]]></description>
        <link>https://medium.com/@humzaarshadkhan?source=rss-dc8d8e6c4f3a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*846z-xD_q7H6y2xD</url>
            <title>Stories by Humza Arshad Khan on Medium</title>
            <link>https://medium.com/@humzaarshadkhan?source=rss-dc8d8e6c4f3a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:24:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@humzaarshadkhan/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[what is Cloud Computing ? with iaas saas paas]]></title>
            <link>https://medium.com/@humzaarshadkhan/what-is-cloud-computing-with-iaas-saas-paas-b0f49efd4a52?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0f49efd4a52</guid>
            <category><![CDATA[paas]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[iaas]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 09:34:43 GMT</pubDate>
            <atom:updated>2026-02-17T09:34:43.384Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*7uOCNgP7xEr49EoG4PTofA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*4iVliM5JLxZEflg0vmGkWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*DM_npJYN1i-ErpCLp7msRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*UpLULkqyI7Vutq3sIMtamA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*OS6nW-KWyTQ1ArByLXZq_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*hzky5hKYhzhUx3gci5jvkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*Rt1_eilXmstvAL1lfK_pKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*ikxYAhgtpmRn7-8bjp2t6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/909/1*negrMgxEuRMRP8avFBRcwA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qYqF2cRN5V4hor7MjfKa3w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0f49efd4a52" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Postgresql Data Replication on primary and standby node on ec2 instance.]]></title>
            <link>https://medium.com/@humzaarshadkhan/postgresql-data-replication-on-primary-and-standby-node-2eb8d3dedd42?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eb8d3dedd42</guid>
            <category><![CDATA[postgresql-database]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[postgresql-replication]]></category>
            <category><![CDATA[replication]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 21 Dec 2023 14:54:06 GMT</pubDate>
            <atom:updated>2026-01-08T06:14:36.220Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*klWmIBWKqvtTRWKZ3aYZew.jpeg" /></figure><p>Database replication is the process of copying data from a central or primary server to multiple servers known as replicas. The primary server accepts read and write operations whereas the replicas serve read-only transactions. The primary server and replicas collectively form a database cluster.</p><p>The goal of database replication is to ensure redundancy, consistency, high availability, and accessibility of data, especially in high-traffic, mission-critical applications.</p><p>PostgreSQL offers two methods for replications: physical (i.e. streaming) and logical replication. Both are ideal for different use cases, and a user may choose one over the other depending on the end goal.</p><h3>Physical PostgreSQL Replication</h3><p>This is the most common type of replication in PostgreSQL. Physical replication maintains a full copy of the entire data of a cluster. It uses exact block addresses and employs byte-by-byte replication. In simpler terms, the entire set of data on the primary server is copied to the replica which acts as a standby node.</p><p>Physical replication does not replicate a specific object of the primary database cluster such as a single row of data in a table. Instead, it works on a disk block level and mirrors all data to replica nodes; including all the tables in each database. This replication requires all replicas to be identical.</p><h3>Setup Physical PostgreSQL Replication on Ubuntu 22.04</h3><blockquote>To demonstrate the replication process, you need a primary node and a replica node on which the replication will occur. Below is our lab setup and we are going to use Ubuntu 22.04 as the preferred operating system.</blockquote><blockquote>Primary node: IP: 194.195.208.82 OS: Ubuntu 22.04 server</blockquote><blockquote>Replica node: IP: 139.144.169.79 OS: Ubuntu 22.04 server</blockquote><h3>Step 1: Install PostgreSQL Server</h3><blockquote>The first step is to <a href="https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04">install PostgreSQL</a> on both Primary and Replica nodes. Take note that you need to install the same version of PostgreSQL on both nodes for logical replication to take place.</blockquote><blockquote>At the time of writing this guide, the latest version of PostgreSQL is PostgreSQL 14.</blockquote><blockquote>First, log in to your server via SSH and refresh the repositories.</blockquote><blockquote>sudo apt update</blockquote><blockquote>Next, install the PostgreSQL database server as follows.</blockquote><blockquote>sudo apt install postgresql postgresql-contrib -y</blockquote><blockquote>By default, the PostgreSQL daemon automatically runs once installed. You can verify this by using the command:</blockquote><blockquote>sudo systemctl status postgresql</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*Pfn3m_gPYqxw6qK8" /></figure><blockquote>The output below confirms that the PostgreSQL service is up and running.</blockquote><blockquote>In addition, consider enabling the service to start on system startup as follows.</blockquote><blockquote>sudo systemctl enable postgresql</blockquote><h3>Step 2: Configure Primary Node</h3><blockquote>Next, log in to the primary node (194.195.208.82) as postgres <a href="https://www.cherryservers.com/blog/postgresql-create-user">user</a> which is the default user that is created with every new PostgreSQL installation.</blockquote><blockquote>sudo -u postgres psql</blockquote><blockquote>You need to create a replication user that will be used to initiate the replication process from the primary node.</blockquote><blockquote>Therefore, run the following command to create the replication user and assign replication privileges. In this command, replica_user is the replication user while P@ssword321 is the user’s password. Be sure to provide a strong password unlike the one we have used which is purely for demo purposes.</blockquote><blockquote>CREATE ROLE replica_user WITH REPLICATION LOGIN PASSWORD ‘P@ssword321’;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*B-LXajG_IVWmbqsk" /></figure><blockquote>Then log out from the PostgreSQL prompt</blockquote><blockquote>postgres-# \q</blockquote><blockquote>Next, you need to make a few tweaks to the main configuration file. Use your preferred text editor to access the following configuration file:</blockquote><blockquote>sudo nano /etc/postgresql/14/main/postgresql.conf</blockquote><blockquote>With the file open, scroll down and locate the listen_addresses directive. The directive specifies the host under which the PostgreSQL database server listens for connections.</blockquote><blockquote>Uncomment the directive by removing the # symbol and replace localhost with your server’s IP address enclosed in single quotation marks as shown:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*-TBEWqEwLg4LVxGI" /></figure><blockquote>Next, locate the wal_level directive. The setting specifies the amount of information to be written to the Write Ahead Log (WAL) file.</blockquote><blockquote>Uncomment the line and set it to logical as shown.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*0dmBuwET-av7F6CA" /></figure><blockquote>Next, locate the wal_log_hints directive. By default, it is set to off.</blockquote><blockquote>When set to on the value allows the PostgreSQL server to write the entire content of each disk page to the WAL file during the first modification of the page.</blockquote><blockquote>Uncomment it and set it to on.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*WfVE8WQVbgfTdyzj" /></figure><blockquote>That’s all for the changes needed in this configuration file. Save the changes and exit.</blockquote><blockquote>Next, access the /etc/postgresql/14/main/pg_hba.conf configuration file.</blockquote><blockquote>sudo nano /etc/postgresql/14/main/pg_hba.conf</blockquote><blockquote>Append this line at the end of the configuration file. This allows the replica ( 139.144.169.79 ) to connect with the master node using the replica_user.</blockquote><blockquote>host replication replica_user 139.144.169.79/24 md5</blockquote><blockquote>Save the changes and close the file. The restart PostgreSQL service.</blockquote><blockquote>sudo systemctl restart postgresql</blockquote><h3>Step 3: Configure Replica Node</h3><blockquote>Before the replica node can start replicating data from the master node, you need to create a copy of the primary node’s data directory to the replica’s data directory. To achieve this, first, stop the PostgreSQL service on the replica node.</blockquote><blockquote>sudo systemctl stop postgresql</blockquote><blockquote>Next, remove all files in the replica’s data directory in order to start on a clean slate and make room for the primary node data directory.</blockquote><blockquote>sudo rm -rv /var/lib/postgresql/14/main/</blockquote><blockquote>Now run the pg_basebackup utility as shown to copy data from the primary node to the replica node.</blockquote><blockquote>sudo pg_basebackup -h 194.195.208.82 -U replica_user -X stream -C -S replica_1 -v -R -W -D /var/lib/postgresql/14/main/</blockquote><blockquote>Let’s take a look at the options used in the command:</blockquote><blockquote>-h: This option specifies the host, in this case, the IP address of the master node.-U: The option specifies the replication user. This is the user that was configured on the primary node and which will be used by the replica node to connect to it. In our case, the replication user is called replica_user.</blockquote><blockquote>-X: The option along with the stream value instructs the pg_basebackup utility to stream and include the WAL files in the backup.</blockquote><blockquote>-C: The option allows you to create a replication slot before the backup gets underway. The option is used along with the -S option to specify the slot name. In this case, our replication slot is called replica_1.</blockquote><blockquote>-v: This prints out verbose output that indicates the progress of the backup process from the primary node to the replica.</blockquote><blockquote>-R: The option creates two files; an empty recovery configuration file called standby.signal and a primary node connection settings file called postgresql.auto.conf. The standby.signal file contains connection information about the primary node and the postgresql.auto.conf file informs your replica cluster that it should operate as a standby server.</blockquote><blockquote>-W: This prompts you to provide a password for the replica_user replication user.</blockquote><blockquote>-D: Lastly, the -D option allows you to include the directory that you want to export the backup files. In this example, we are placing the data under the/var/lib/postgresql/14/main/ directory in the replica node.</blockquote><blockquote>Here is the output from running the replication command.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*cLsbFjGZU6Ke1Hvs" /></figure><blockquote>Afterward, execute the following command on the replica to grant ownership of the data directory to the postgres user.</blockquote><blockquote>sudo chown postgres -R /var/lib/postgresql/14/main/</blockquote><blockquote>Now, start the PostgreSQL server. The replica will now be running in hot standby mode.</blockquote><blockquote>sudo systemctl start postgresql</blockquote><blockquote>Now check that both primary and standby have same max-connections if postgresql cluster service is getting a failed error.</blockquote><blockquote>Also change the configuration in the pg_hba.conf file.</blockquote><blockquote># IPv4 local connections:</blockquote><blockquote>host all all 0.0.0.0/0 scram-sha-256</blockquote><h3>Step 4: Test The Replication Setup</h3><blockquote>At this juncture, the primary node’s data directory has successfully been backed up on the replica and the replica started in a hot standby mode.</blockquote><blockquote>The remaining part is to test out if the replication is working as intended. If the replica is successfully running in hot standby mode, then it should be connected to the primary database cluster on the primary server.</blockquote><blockquote>To verify that the replica is connected to the primary node and that the primary is streaming, log into the primary server and switch to the postgres user.</blockquote><blockquote>sudo -u postgres psql</blockquote><blockquote>Next, query the pg_stat_replication table which contains vital information about the replication. In this command, we are retrieving information about the replica’s IP address and the state of the primary server.</blockquote><blockquote>SELECT client_addr, state</blockquote><blockquote>FROM pg_stat_replication;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*nsftlUoDUgnEUdKd" /></figure><blockquote>You should get the following output confirmation that your setup is working.</blockquote><blockquote>To corroborate this, we are going to create a test database and add a table with a few records and then verify if the database has been replicated on the replica.</blockquote><blockquote>we will create a sample database called students.</blockquote><blockquote>CREATE DATABASE students_db;</blockquote><blockquote>Next, switch to the database.</blockquote><blockquote>\c students_db;</blockquote><blockquote>Output</blockquote><blockquote>You are now connected to database “students_db” as user “postgres”.</blockquote><blockquote>Once in the database, create a table called student_details with the following schema.</blockquote><blockquote>CREATE TABLE student_details (first_name VARCHAR(15), last_name VARCHAR(15) , email VARCHAR(40) );</blockquote><blockquote>Then insert the following record into the table.</blockquote><blockquote>INSERT INTO student_details (first_name, last_name, email)</blockquote><blockquote>VALUES (‘Arthur’, ‘Spencer’, ‘arthurspencer@gmail.com’);</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*HIx6I7atuWoNJ2lE" /></figure><blockquote>You can query the table to confirm the inserted records as shown.</blockquote><blockquote>SELECT *</blockquote><blockquote>FROM student_details;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*vHI4XJLUQD-QxO55" /></figure><blockquote>Now head over to the replica node and switch to the postgres user.</blockquote><blockquote>sudo -u postgres psql</blockquote><blockquote>On the shell, verify the existence of the database that was created in the primary node moments ago.</blockquote><blockquote>postgres=# \l</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*60DsKlRAVS9KK0Vh" /></figure><blockquote>Now, switch to the database.</blockquote><blockquote>\c students_db;</blockquote><blockquote>Query the table for all the records stored.</blockquote><blockquote>SELECT *</blockquote><blockquote>FROM student_details;</blockquote><blockquote>You should get exactly the same record as you created in the master node as shown below.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*qdidJzd15_f743T7" /></figure><blockquote>This confirms that replication was successful! You can continue adding more records on the primary server which will then be copied or replicated to the replica node.</blockquote><p><strong>Conclusion</strong></p><blockquote>In this tutorial, we have looked at the two replication methods provided by PostgreSQL alongside their pros and cons. We went a step further and created a replication cluster using the PostgreSQL logical model and demonstrated the replication of data from the master to the replica node. Head over to the <a href="https://www.postgresql.org/docs/current/runtime-config-replication.html">official documentation</a> for a more comprehensive look at replication in PostgreSQL.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eb8d3dedd42" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install Elastic Stack on Ubuntu 20.04 LTS]]></title>
            <link>https://medium.com/@humzaarshadkhan/how-to-install-elastic-stack-on-ubuntu-20-04-lts-529705418a4b?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/529705418a4b</guid>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 02 Nov 2023 08:21:43 GMT</pubDate>
            <atom:updated>2023-11-02T08:21:43.463Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Install Elastic Stack on Ubuntu 20.04 LTS</h3><p>n this article we are going to perform How to Install Elastic Stack on Ubuntu 20.04 LTS or any Cloud Instance like Amazon EC2, Azure VM, Google Compute Engine,etc.</p><p>Install Configure ElasticSearch on Ubuntu, Install and Configure Kibana on Ubuntu, Install and Configure Logstash on Ubuntu, Install and Configure Filebeat on Ubuntu and Access Kibana Web Interface.</p><h3>Prerequisites</h3><ul><li>Ubuntu Server with 20.04 LTS</li><li>JDK</li><li>2 CPU and 4 GB RAM</li><li>Open Ports 9200, 5601, 5044</li></ul><p>update the system packages</p><p>sudo apt-get update</p><h3>Install JDK on Ubuntu</h3><p>Install openjdk and other dependencies before installing elastic stack</p><p>sudo apt-get install openjdk-11-jdk wget apt-transport-https curl gnupg2 -y</p><p>To check java version</p><p>java -version</p><p><strong>Output:</strong></p><p>openjdk version “11.0.10” 2021–01–19</p><p>OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)</p><p>OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)</p><h3>#1: Install and Configure ElasticSearch on Ubuntu</h3><p>First we will have to add a signing key and will have to add repositories to our system because Elasticsearch is not pre-installed in Ubuntu, we will have to do it manually.</p><p>Follow the below command to add elasticsearch signing key</p><p>wget -qO — <a href="https://artifacts.elastic.co/GPG-KEY-elasticsearch">https://artifacts.elastic.co/GPG-KEY-elasticsearch</a> — no-check-certificate | sudo apt-key add -</p><p>Next add the repository in <strong>/etc/apt/sources.list.d/elastic-7.x.list</strong> using below command.</p><p>echo “deb <a href="https://artifacts.elastic.co/packages/7.x/apt">https://artifacts.elastic.co/packages/7.x/apt</a> stable main” | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list</p><p>update the system packages</p><p>sudo apt-get update</p><p>Install elasticsearch on Ubuntu using below command</p><p>sudo apt-get install elasticsearch -y</p><p>Let’s make changes in below elesticsearch configuration file</p><p>sudo nano /etc/elasticsearch/elasticsearch.yml</p><p>Go to Network section and uncommnet network.host and replace your <strong>system IP</strong> or <strong>localhost</strong></p><p>network.host: localhost</p><p>Add the below line in <strong>Discovery</strong> section also.</p><p>discovery.type: single-node</p><p>you can change http port if you don’t want to use default port at<strong> (http.port:9200)</strong>.</p><p>If you have installing Elastic Stack on Single system, Open Elasticsearch configuration , navigate to Discovery section and change below as shown below</p><p>/etc/elasticsearch/elasticsearch.yml</p><p># — — — — — — — — — — — — — — — — — Network — — — — — — — — — — — — — — — — — -</p><p>#</p><p># By default Elasticsearch is only accessible on localhost. Set a different</p><p># address here to expose this node on the network:</p><p>#</p><p><strong>network.host:</strong> <strong>localhost</strong></p><p>#</p><p># By default Elasticsearch listens for HTTP traffic on the first free port it</p><p># finds starting at 9200. Set a specific HTTP port here:</p><p>#</p><p>#http.port: 9200</p><p>#</p><p># For more information, consult the network module documentation.</p><p>#</p><p># — — — — — — — — — — — — — — — — — Discovery — — — — — — — — — — — — — — — — —</p><p>#</p><p># Pass an initial list of hosts to perform discovery when this node is started:</p><p># The default list of hosts is [“127.0.0.1”, “[::1]”]</p><p>#</p><p>#discovery.seed_hosts: [“host1”, “host2”]</p><p>#</p><p># Bootstrap the cluster using an initial set of master-eligible nodes:</p><p>#</p><p>#cluster.initial_master_nodes: [“node-1”, “node-2”]</p><p><strong>discovery.type: single-node</strong></p><p>#</p><p># For more information, consult the discovery and cluster formation module documentation.</p><p>#</p><p>start the elacticsearch service</p><p>sudo systemctl start elasticsearch</p><p>To enable elacticsearch at system startup</p><p>sudo systemctl enable elasticsearch</p><p>To check the status of elasticsearch</p><p>sudo systemctl status elasticsearch</p><p>To stop elasticsearch service</p><p>sudo systemctl stop elasticsearch</p><p>To check elasticsearch service pid using command line</p><p>sudo ss -antpl | sudo grep 9200</p><p><strong>Output:</strong></p><p>sudo ss -antpl | sudo grep 9200</p><p>LISTEN 0 4096 *:9200 *:* users:((“java”,pid=17313,fd=283))</p><p>Enter below command to check elasticsearch is running by sending HTTP request.</p><p>curl -X GET “localhost:9200”</p><p><strong>Output:</strong></p><p>curl -X GET “localhost:9200”</p><p>{</p><p>“name” : “ip-172–31–0–235”,</p><p>“cluster_name” : “elasticsearch”,</p><p>“cluster_uuid” : “_na_”,</p><p>“version” : {</p><p>“number” : “7.12.0”,</p><p>“build_flavor” : “default”,</p><p>“build_type” : “deb”,</p><p>“build_hash” : “78722783c38caa25a70982b5b042074cde5d3b3a”,</p><p>“build_date” : “2021–03–18T06:17:15.410153305Z”,</p><p>“build_snapshot” : false,</p><p>“lucene_version” : “8.8.0”,</p><p>“minimum_wire_compatibility_version” : “6.8.0”,</p><p>“minimum_index_compatibility_version” : “6.0.0-beta1”</p><p>},</p><p>“tagline” : “You Know, for Search”</p><p>}</p><h3>#2. Install and Configure Kibana on Ubuntu</h3><p>To visualize data which is stored in Elasticsearch DB we will have to install Kibana, Kibana is a web interface visualization tool.</p><p>use below command to install kibana on Ubuntu</p><p>sudo apt-get install kibana</p><p>Kibana runs on localhost so will have to change in kibana configuration file.</p><p>sudo nano /etc/kibana/kibana.yml</p><p>Uncomment the below lines</p><p>server.port: 5601</p><p>server.host: “0.0.0.0”</p><p>elasticsearch.hosts: [“http://localhost:9200&quot;]</p><p>/etc/kibana/kibana.yml</p><p># Kibana is served by a back end server. This setting specifies the port to use.</p><p><strong>server.port: 5601</strong></p><p># Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.</p><p># The default is ‘localhost’, which usually means remote machines will not be able to connect.</p><p># To allow connections from remote users, set this parameter to a non-loopback address.</p><p><strong>server.host: “0.0.0.0”</strong></p><p># Enables you to specify a path to mount Kibana at if you are running behind a proxy.</p><p># Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath</p><p># from requests it receives, and to prevent a deprecation warning at startup.</p><p># This setting cannot end in a slash.</p><p>#server.basePath: “”</p><p># Specifies whether Kibana should rewrite requests that are prefixed with</p><p># `server.basePath` or require that they are rewritten by your reverse proxy.</p><p># This setting was effectively always `false` before Kibana 6.3 and will</p><p># default to `true` starting in Kibana 7.0.</p><p>#server.rewriteBasePath: false</p><p># Specifies the public URL at which Kibana is available for end users. If</p><p># `server.basePath` is configured this URL should end with the same basePath.</p><p>#server.publicBaseUrl: “”</p><p># The maximum payload size in bytes for incoming server requests.</p><p>#server.maxPayloadBytes: 1048576</p><p># The Kibana server’s name. This is used for display purposes.</p><p>#server.name: “your-hostname”</p><p># The URLs of the Elasticsearch instances to use for all your queries.</p><p><strong>elasticsearch.hosts: [“http://localhost:9200&quot;]</strong></p><p>After changing these two lines save it by <strong>Ctrl+O</strong> and exit by <strong>Ctrl+X</strong>.</p><p>To start kibana service</p><p>sudo systemctl start kibana</p><p>To enable kibana at system startup</p><p>sudo systemctl enable kibana</p><p>To check the status of kibana service</p><p>sudo systemctl status kibana</p><p>To stop kibana service</p><p>sudo systemctl stop kibana</p><h3>#3. Install and Configure Logstash on Ubuntu</h3><p>To collect logs and parse them we will need to install Logstash, Collected and filtered logs will be stored in Elasticsearch DB.</p><p>use below command to install logstash on ubuntu</p><p>sudo apt-get install logstash</p><p>To load logstash beat create the below config file and insert below lines.</p><p>sudo nano /etc/logstash/conf.d/02-beats-input.conf</p><p>input {</p><p>beats {</p><p>port =&gt; 5044</p><p>}</p><p>}</p><p>save and close the file.</p><p>Create the logstash configuration file to send the logs, filter and showing in kibana and insert below lines</p><p>sudo nano /etc/logstash/conf.d/30-elasticsearch-output.conf</p><p>save and close the file.</p><p>Create the logstash configuration file to send the logs, filter and showing in kibana and insert below lines</p><p>sudo nano /etc/logstash/conf.d/30-elasticsearch-output.conf</p><p>output {</p><p>elasticsearch {</p><p>hosts =&gt; [“localhost:9200”]</p><p>manage_template =&gt; false</p><p>index =&gt; “%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}”</p><p>}</p><p>}</p><p>Save the file by <strong>Ctrl+O</strong> and exit by <strong>Ctrl+X</strong>.</p><p>To start logstash service</p><p>sudo systemctl start logstash</p><p>To enable logstash at system startup</p><p>sudo systemctl enable logstash</p><p>To stop logstash service</p><p>sudo systemctl stop logstash</p><p>To check status of logstash</p><p>sudo systemctl status logstash</p><h3>#4. Install and Configure Filebeat on Ubuntu</h3><p>Filebeat is an input to the logstash which gives logs collected from different sources. Follow the below command to install Filebeat so it can send logs to Logstash.</p><p>sudo apt-get install filebeat</p><p>Now lets make changes in filebeat configuration file</p><p>sudo nano /etc/filebeat/filebeat.yml</p><p>Comment the below lines</p><p>#output.elasticsearch:</p><p># Array of hosts to connect to.</p><p># hosts: [“localhost:9200”]</p><p>Uncomment the below lines</p><p>output.logstash:</p><p>hosts: [“localhost:5044”]</p><p>/etc/filebeat/filebeat.yml</p><p># — — — — — — — — — — — — — — Elasticsearch Output — — — — — — — — — — — — — —</p><p><strong>#output.elasticsearch:</strong></p><p><strong># Array of hosts to connect to.</strong></p><p><strong># hosts: [“localhost:9200”]</strong></p><p># Protocol — either `http` (default) or `https`.</p><p>#protocol: “https”</p><p># Authentication credentials — either API key or username/password.</p><p>#api_key: “id:api_key”</p><p>#username: “elastic”</p><p>#password: “changeme”</p><p># — — — — — — — — — — — — — — — Logstash Output — — — — — — — — — — — — — — — -</p><p><strong>output.logstash:</strong></p><p><strong># The Logstash hosts</strong></p><p><strong>hosts: [“localhost:5044”]</strong></p><p># Optional SSL. By default is off.</p><p># List of root certificates for HTTPS server verifications</p><p>#ssl.certificate_authorities: [“/etc/pki/root/ca.pem”]</p><p># Certificate for SSL client authentication</p><p>#ssl.certificate: “/etc/pki/client/cert.pem”</p><p># Client Certificate Key</p><p>#ssl.key: “/etc/pki/client/cert.key”</p><p>To start filebeat service</p><p>sudo systemctl start filebeat</p><p>To enable filebeat at system startup</p><p>sudo systemctl enable filebeat</p><p>To check status of filebeat service</p><p>sudo systemctl status filebeat</p><p>Enable filebeat system module</p><p>sudo filebeat modules enable system</p><p>Load the index template</p><p>filebeat setup — index-management -E output.logstash.enabled=false -E ‘output.elasticsearch.hosts=[“localhost:9200”]’</p><p>Now lets check that ElasticSearch is receiving datalog from filebeat using below command</p><p>curl -XGET <a href="http://localhost:9200/_cat/indices?v">http://localhost:9200/_cat/indices?v</a></p><p><strong>Output:</strong></p><p>curl -XGET <a href="http://localhost:9200/_cat/indices?v">http://localhost:9200/_cat/indices?v</a></p><p>health status index uuid pri rep docs.count docs.deleted store.size pri.store.size</p><p>green open .kibana_task_manager_7.12.0_001 6vZtJ4jqRyaBorqojMRVMA 1 0 9 149 203.3kb 203.3kb</p><p>green open .apm-custom-link RYBbJ3C5SlaqIHH2h7ke7w 1 0 0 0 208b 208b</p><p>green open .apm-agent-configuration ABJ5fag4QPuekS9kiStfoQ 1 0 0 0 208b 208b</p><p>yellow open filebeat-7.12.0–2021.04.27–000001 hCQ8p2iHQla_EzfsNSD4Aw 1 1 2777 0 841.3kb 841.3kb</p><p>green open .kibana-event-log-7.12.0–000001 gE8SlJosQlqdhZh5OBFR8A 1 0 3 0 16.4kb 16.4kb</p><p>green open .kibana_7.12.0_001 3KFkqOLnSNeCpA64JJ-pdg 1 0 11 3 2.1mb 2.1mb</p><p>green open .tasks</p><p>We have covered install elastic stack on Ubuntu 20.04 LTS.</p><h3>#5. Access Kibana Web Interface</h3><p>Access Kibana Web Interface by using the URL</p><p><a href="http://your-server-ip:5601/">http://your-server-ip:5601</a></p><p>Enter you server IP address in the place of “<strong>your-server-ip</strong>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ng7obbeUIQD9YWgc" /></figure><p>Note:- You can directly use filebeat and metric to gets instead of logstash.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=529705418a4b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mysql optimization]]></title>
            <link>https://medium.com/@humzaarshadkhan/mysql-optimization-45d17e372ff2?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/45d17e372ff2</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mysql-server]]></category>
            <category><![CDATA[mysql-8]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 07:28:45 GMT</pubDate>
            <atom:updated>2023-10-19T07:28:45.851Z</atom:updated>
            <content:encoded><![CDATA[<p>innodb_buffer_pool_size: This should be set to a value that is at least 70–80% of the total available RAM, so around 24–25GB.</p><p>innodb_log_file_size: This should be set to a value that is around 25% of the innodb_buffer_pool_size, so around 6GB.</p><p>key_buffer_size: This should be set to a value that is around 8–10% of the total available RAM, so around 2–3GB.</p><p>query_cache_size: This should be set to a value that is around 1–2% of the total available RAM, so around 256MB-512MB.</p><p>max_connections: This should be set to a value that is around 100–150, depending on the number of concurrent connections your application will have.</p><p>tmp_table_size and max_heap_table_size: This should be set to a value that is around 1–2% of the total available RAM, so around 256MB-512MB.</p><p>thread_cache_size: This parameter controls the number of threads that are cached in memory to reduce the overhead of creating new threads. You can set this to a value around 100–300.</p><p>sort_buffer_size: This parameter controls the amount of memory allocated for sorting operations. You can set this to a value around 256MB-512MB.</p><p>read_buffer_size: This parameter controls the amount of memory allocated for sequential scans. You can set this to a value around 256MB-512MB.</p><p>read_rnd_buffer_size: This parameter controls the amount of memory allocated for reading rows in sorted order. You can set this to a value around 256MB-512MB.</p><p>join_buffer_size: This parameter controls the amount of memory allocated for joins without keys. You can set this to a value around 256MB-512MB.</p><p>table_open_cache: This parameter controls the number of table cache instances. You can set this to a value around 2000–4000.</p><p><strong>For 32gb Ram:-</strong></p><p>Innodb_buffer_pool_size:- 24gb</p><p>Innodb_log_file_size:- 6gb</p><p>Key_buffer_size :- 3gb</p><p>query_cache_size: 256–512MB</p><p>Max_connections:- 100–150</p><p>Tmp_table_size :- 256–512MB</p><p>Max_heap_table_size:- 256–512MB</p><p>Thread_cache_size :- 100–300</p><p>sort_buffer_size:- 256–512MB</p><p>read_buffer_size:- 256–512MB</p><p>Read_rnd_buffer_size:- 256–512MB</p><p>Join_buffer_size:- 256–512MB</p><p>Table_open_cache:- 2000–4000</p><p><strong><em>For 64 GB RAM:-</em></strong></p><p># MySQL Configuration File</p><p>[mysqld]</p><p># General Settings</p><p>port = 3306</p><p>socket = /var/run/mysqld/mysqld.sock</p><p>pid-file = /var/run/mysqld/mysqld.pid</p><p>datadir = /var/lib/mysql</p><p>log-error = /var/log/mysql/error.log</p><p># Connection Settings</p><p>max_connections = 1000</p><p># Caching Settings</p><p>query_cache_type = 1</p><p>query_cache_size = 256M</p><p>query_cache_limit = 16M</p><p># InnoDB Settings</p><p>innodb_buffer_pool_size = 40G</p><p>innodb_flush_log_at_trx_commit = 2</p><p>innodb_file_per_table = 1</p><p>innodb_open_files = 2000</p><p>innodb_io_capacity = 1000</p><p>innodb_flush_method = O_DIRECT</p><p>innodb_log_file_size = 4G</p><p># MyISAM Settings</p><p>key_buffer_size = 512M</p><p># Temporary Table Settings</p><p>tmp_table_size = 64M</p><p>max_heap_table_size = 64M</p><p># Thread Settings</p><p>thread_cache_size = 64</p><p># Sorting and Join Settings</p><p>sort_buffer_size = 8M</p><p>read_buffer_size = 2M</p><p>read_rnd_buffer_size = 4M</p><p>join_buffer_size = 4M</p><p># Table Cache Settings</p><p>table_open_cache = 2000</p><p># Other Settings</p><p>open_files_limit = 65535</p><p>max_allowed_packet = 16M</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45d17e372ff2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tunning of Nginx]]></title>
            <link>https://medium.com/@humzaarshadkhan/tunning-of-nginx-a6899015badd?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6899015badd</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[nginx-ingress-controller]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[tunning]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 07:24:52 GMT</pubDate>
            <atom:updated>2023-10-19T07:24:52.608Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Workers:-</strong></p><p><strong>The number of worker processes for Nginx is typically calculated based on the number of CPU cores available on the server. The recommended number of worker processes is the number of CPU cores multiplied by the value of the worker_connections directive.</strong></p><h3>Worker Connections Limit:-</h3><h3>By default, the worker process can manage 512 connections at a time. Before modifying the worker connection value you must check the max connection system to allow using the following command to update the connection config according to it.</h3><p><strong>ulimit -n</strong></p><p><strong>1024</strong></p><p><strong>If you have 4 cores , then the value is 4*1024 which is equal to 4096.</strong></p><p><strong>Gzip:-</strong></p><h3>What does gzip compression do?</h3><p><strong>Gzip compression compresses web files (mainly HTML, CSS, and JavaScript files) to a tinier version, sometimes up to 70%-80% smaller. This much smaller compressed version of a file is then sent to the browser of the user requesting it instead of the larger original file. The browser of the user will then automatically decompress the compressed file and serve the uncompressed original file.</strong></p><p><strong>Add/Uncomment the following lines in your NGINX configuration file.</strong></p><p><strong>gzip on;</strong></p><p><strong>gzip_vary on;</strong></p><p><strong>gzip_min_length 1024;</strong></p><p><strong>gzip_proxied expired no-cache no-store private auth;</strong></p><p><strong>gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;</strong></p><p><strong>gzip_disable “MSIE [1–6]\.”;</strong></p><p><strong>Caching Static Content:-</strong></p><p><strong>Most of the contents are statically served to the browser or client so caching the static files will load the content faster. It will also decrease the connection request to the Nginx as contents are loaded from the cache. To start the caching process add the following directive to your Nginx virtual host config file.</strong></p><p><strong>location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {expires 30d;}</strong></p><p><strong>keepalive_timeout:</strong></p><p><strong>This controls the amount of time that a keep-alive connection will remain open before closing. Increasing this value can improve performance for clients that make multiple requests to the server.</strong></p><h3>Buffering</h3><p><strong>Buffering can make the communication between client and server more efficient as its holds part of the response until the buffer fills. If the response is too high than the actual buffer size the Nginx will then write the response to the disk which may lead to a performance issue. You can update the following directive to adjust the buffer size according to your requirement.</strong></p><p><strong>http {</strong></p><p><strong>…</strong></p><p><strong>client_body_buffer_size 80k;</strong></p><p><strong>client_max_body_size 9m;</strong></p><p><strong>client_header_buffer_size 1k;</strong></p><p><strong>…</strong></p><p><strong>}</strong></p><h3>Limiting Timeout Values:-</h3><p><strong>Limiting the timeout value will enhance Nginx’s performance. Nginx will wait for the client’s body and header request for the given time period. If they do not receive the response data in time, Nginx triggers a time-out for the respective client. The time-out value can be managed by the following directive. To set the timeout duration, copy-paste the directive given below within the http section.</strong></p><p><strong>client_body_timeout 10;</strong></p><p><strong>client_header_timeout 10;</strong></p><p><strong>keepalive_timeout 13;</strong></p><p><strong>send_timeout 10;</strong></p><p><strong>Logging:-</strong></p><p><strong>Nginx logs every request that hits the VPS to a log file. If you use analytics to monitor this, you may want to turn this functionality off. Simply edit the access_log directive:</strong></p><p><strong>access_log off;</strong></p><p><strong>Save and close the file, then run:</strong></p><p><strong>sudo service nginx restart</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6899015badd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL 12 Replication and Failover with repmgr]]></title>
            <link>https://medium.com/@humzaarshadkhan/postgresql-12-replication-and-failover-with-repmgr-6ffcbe24e342?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ffcbe24e342</guid>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 06:58:16 GMT</pubDate>
            <atom:updated>2023-10-19T06:58:16.187Z</atom:updated>
            <content:encoded><![CDATA[<h3>First we need to install postgres and repmgr on both of the instances.</h3><ul><li>sudo apt update &amp;&amp; sudo apt upgrade -y</li><li>wget — quiet -O — <a href="https://www.postgresql.org/media/keys/ACCC4CF8.asc">https://www.postgresql.org/media/keys/ACCC4CF8.asc</a> | sudo apt-key add -</li><li>echo “deb <a href="http://apt.postgresql.org/pub/repos/apt/">http://apt.postgresql.org/pub/repos/apt/</a> $RELEASE-pgdg main” | sudo tee /etc/apt/sources.list.d/pgdg.list</li><li>sudo echo “deb <a href="http://apt.postgresql.org/pub/repos/apt/">http://apt.postgresql.org/pub/repos/apt/</a> $RELEASE-pgdg main” | sudo tee /etc/apt/sources.list.d/pgdg.list</li><li>sudo apt-get update</li><li>sudo apt-get install postgresql-12 postgresql-contrib</li><li>sudo service postgresql restart</li><li>sudo nano /etc/postgresql/12/main/postgresql.conf</li><li>sudo systemctl start postgresql-12.service</li><li>sudo service postgresql restart</li><li>sudo service postgresql@12-main status</li><li>sudo apt-get install repmgr</li></ul><h3>PostgreSQL configuration</h3><p>On both of the server do the following changes in /etc/postgresql/12/main/postgresql.conf</p><ul><li>listen_addresses = ‘*’</li><li>max_wal_senders = 10</li><li>max_replication_slots = 10</li><li>wal_level = ‘replica’</li><li>hot_standby = on</li><li>archive_mode = on</li><li>archive_command = ‘/bin/true’</li><li>wal_log_hints = on</li></ul><h3>Create the repmgr user and database on Primary</h3><p>sudo -u postgres psql</p><p>createuser — superuser repmgr</p><p>createdb — owner=repmgr repmgr</p><p>psql -c “ALTER USER repmgr SET search_path TO repmgr, public;”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MGbNnWEcUjOQGOZF" /></figure><p>And user repmgr</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*atM0jETw4JkyxhmE" /></figure><h3>Configuring authentication in pg_hba.conf</h3><p>Go to the file /etc/postgresql/12/main/pg_hba.conf</p><p>local replication repmgr trust</p><p>host replication repmgr 34.202.234.110/32 trust</p><p>host replication repmgr 34.202.234.110/24 trust</p><p>host replication repmgr 54.90.10.114/24 trust</p><p>local repmgr repmgr trust</p><p>host repmgr repmgr 34.202.234.110/32 trust</p><p>host repmgr repmgr 100.25.215.22/24 trust</p><p>host repmgr repmgr 54.90.10.114/24 trust</p><h3>Preparing the standby</h3><p>Test the Primary node from secondary by using this command , instead of node1 paste the IP address of node1.</p><p>psql ‘host=node1 user=repmgr dbname=repmgr connect_timeout=2’</p><h3>repmgr configuration file</h3><p>Create a configuration file for repmgr with the name repmgr.conf in etc.</p><p>node_id=1</p><p>node_name=’node1&#39;</p><p>conninfo=’host=44.204.129.9 user=repmgr dbname=repmgr connect_timeout=2&#39;</p><p>data_directory=’/var/lib/postgresql/12/main’</p><p>failover = ‘automatic’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4K2s5OsOgtsF5Ndc" /></figure><h3>Register the primary server</h3><p>repmgr -f /etc/repmgr.conf primary register</p><p>In my case node is already registered but you will get a successful registration on first time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ugRPO1hZNo-NXsRM" /></figure><p><strong>Verify status of the cluster like this:</strong></p><p>repmgr -f /etc/repmgr.conf cluster show</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wMxcYTsbnC151kl8" /></figure><h3>Clone the standby server</h3><p>Create a repmgr.conf file on the standby server in etc directory .</p><p>node_id=2</p><p>node_name=’node2&#39;</p><p>conninfo=’host=3.238.31.181 user=repmgr dbname=repmgr connect_timeout=2&#39;</p><p>data_directory=’/var/lib/postgresql/12/main’</p><p>failover = ‘automatic’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zH2v74T8wQ9T0X70" /></figure><p>Use the — dry-run option to check the standby can be cloned:</p><p>repmgr -h 44.204.129.9 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone — dry-run</p><p>sudo rm -rf /var/lib/postgresql/12/main/</p><p>If no problems are reported, the standby can then be cloned , replacing the node1 with primary IP.Run the command as postgres user.</p><p>sudo su postgres</p><p>repmgr -h 34.202.234.110 -U repmgr -d repmgr -f /etc/repmgr.conf standby clone</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l_0SceJVAyVLztOR" /></figure><p>exit the user.</p><p>you can also use the view <a href="https://www.postgresql.org/docs/current/monitoring-stats.html#PG-STAT-WAL-RECEIVER-VIEW">pg_stat_wal_receiver</a> to check the replication status from the standby.</p><p>sudo -u postgres psql</p><p>SELECT * FROM pg_stat_wal_receiver;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M2bP1TLBX92XUcs0" /></figure><h3>Register the standby</h3><p>repmgr -f /etc/repmgr.conf standby register</p><p>NOTICE: standby node “node2” (ID: 2) successfully registered</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cdQAcO5ZYUQR1cI5" /></figure><p>Check the node is registered by executing repmgr cluster show on the standby:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7s_0ovAgzWBzHAgK" /></figure><p>To Create a Witness Node</p><p>Create another instance with postgres and repmgr</p><p>Next, we add the following lines in the witness node’s postgresql.conf file:</p><p>listen_addresses = ‘*’</p><p>shared_preload_libraries = ‘repmgr’</p><p>We also add the following lines in the pg_hba.conf file</p><p>local replication repmgr trust</p><p>host replication repmgr 127.0.0.1/32 trust</p><p>host replication repmgr 100.24.236.4/16 trust</p><p>local repmgr repmgr trust</p><p>host repmgr repmgr 127.0.0.1/32 trust</p><p>host repmgr repmgr 100.24.236.4/16 trust</p><p>With postgresql.conf and pg_hba.conf changes done, we create the repmgr user and the repmgr database in the witness, and change the repmgr user’s default search path:</p><p>[postgres@PG-Node-Witness ~]$ createuser — superuser repmgr</p><p>[postgres@PG-Node-Witness ~]$ createdb — owner=repmgr repmgr</p><p>[postgres@PG-Node-Witness ~]$ psql -c “ALTER USER repmgr SET search_path TO repmgr, public;”</p><p>Finally, we add the following lines to the repmgr.conf file, located under /etc/repmgr.conf</p><p>node_id=3</p><p>node_name=’Witness’</p><p>conninfo=’host=54.236.33.39 user=repmgr dbname=repmgr’</p><p>connect_timeout=’2&#39;</p><p>data_directory=’/var/lib/postgresql/12/main’</p><p>/usr/bin/repmgr -f /etc/repmgr.conf witness register -h 34.202.234.110 (IP of Primary)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_D7nKPPMgNlY9kBy" /></figure><h4>Step 2: Modifying the sudoers File</h4><p>With the cluster and the witness running, we add the following lines in the sudoers file In each node of the cluster and the witness node:</p><p>Defaults:postgres !requiretty</p><p>postgres ALL = NOPASSWD: /usr/bin/systemctl stop postgresql@12-main.service, /usr/bin/systemctl start postgresql@12-main.service, /usr/bin/systemctl restart postgresql@12-main.service, /usr/bin/systemctl reload postgresql@12-main2.service, /usr/bin/systemctl start repmgrd.service, /usr/bin/systemctl stop repmgrd.service</p><p>Now Add the following in /etc/repmgr.conf of all nodes.</p><p>failover = ‘automatic’</p><p>promote_command=’/usr/bin/repmgr standby promote -f /etc/repmgr.conf — log-to-file’</p><p>follow_command=’/usr/bin/repmgr standby follow -f /etc/repmgr.conf — log-to-file — upstream-node-id=%n’</p><p>monitor_interval_secs=2</p><p>connection_check_type=’ping’</p><p>reconnect_attempts=4</p><p>reconnect_interval=8</p><p>primary_visibility_consensus=true</p><p>standby_disconnect_on_failover=true</p><p>repmgrd_service_start_command=’sudo /usr/bin/systemctl start repmgrd.service’</p><p>repmgrd_service_stop_command=’sudo /usr/bin/systemctl stop repmgrd.service’</p><p>service_start_command=’sudo /usr/bin/systemctl start postgresql@12-main.service’</p><p>service_stop_command=’sudo /usr/bin/systemctl stop postgresql@12-main.service’</p><p>service_restart_command=’sudo /usr/bin/systemctl restart postgresql@12-main.service’</p><p>service_reload_command=’sudo /usr/bin/systemctl reload postgresql@12-main.service’</p><p>monitoring_history=yes</p><p>log_status_interval=60</p><p><strong>/usr/bin/repmgrd -f /etc/repmgr.conf daemon start</strong></p><p><strong>How to unregistered a Node:-</strong></p><p>In the witness node run the following Command.</p><p>repmgr primary unregister -f /etc/repmgr.conf — node-id=1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4LmqllZF7jLq6dny" /></figure><p><strong>To manually promote a standby</strong></p><p>repmgr standby promote</p><p><strong>To Check the cluster events:-</strong></p><p>repmgr -f /etc/repmgr.conf cluster event — event=standby_register</p><p><strong>cross-checks connections between each combination of nodes</strong></p><p>repmgr cluster crosscheck</p><p><a href="https://www.2ndquadrant.com/en/blog/how-to-automate-postgresql-12-replication-and-failover-with-repmgr-part-1/"><strong>How to Automate PostgreSQL 12 Replication and Failover with repmgr — Part 1–2ndQuadrant</strong></a></p><p><a href="https://www.2ndquadrant.com/en/blog/how-to-automate-postgresql-12-replication-and-failover-with-repmgr-part-2/">How to Automate PostgreSQL 12 Replication and Failover with repmgr — Part 2–2ndQuadrant</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ffcbe24e342" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Zabbix Installation on ubuntu 20]]></title>
            <link>https://medium.com/@humzaarshadkhan/zabbix-installation-on-ubuntu-20-17a2658a9971?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/17a2658a9971</guid>
            <category><![CDATA[zabbix-proxy]]></category>
            <category><![CDATA[zabbix-server]]></category>
            <category><![CDATA[zabbix-agent]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[zabbix]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 06:53:41 GMT</pubDate>
            <atom:updated>2023-10-19T07:01:40.723Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Zabbix Installation on ubuntu20.04</strong></h3><p>a. <strong>Install Zabbix repository</strong></p><p>sudo wget <a href="https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb">https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb</a></p><p>sudo dpkg -i zabbix-release_6.0–4+ubuntu20.04_all.deb</p><p>sudo apt update</p><p>b. <strong>Install Zabbix server, frontend, agent</strong></p><p>sudo apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent</p><p>c.<strong> Create initial database</strong></p><p>Make sure you have database server up and running.</p><p>Run the following on your database host.</p><p>sudo mysql -uroot -p</p><p>password</p><p>mysql&gt; create database zabbix character set utf8mb4 collate utf8mb4_bin;</p><p>mysql&gt; create user zabbix@localhost identified by ‘password’;</p><p>mysql&gt; grant all privileges on zabbix.* to zabbix@localhost;</p><p>mysql&gt; set global log_bin_trust_function_creators = 1;</p><p>mysql&gt; quit;</p><p>On Zabbix server host import initial schema and data. You will be prompted to enter your newly created password.</p><p>sudo zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql — default-character-set=utf8mb4 -uzabbix -p zabbix</p><p>Disable log_bin_trust_function_creators option after importing database schema.</p><p># mysql -uroot -p</p><p>password</p><p>mysql&gt; set global log_bin_trust_function_creators = 0;</p><p>mysql&gt; quit;</p><p>d. <strong>Configure the database for Zabbix server</strong></p><p>Edit file /etc/zabbix/zabbix_server.conf</p><p>DBPassword=password</p><p>e. <strong>Configure PHP for Zabbix frontend</strong></p><p>Edit file /etc/zabbix/nginx.conf uncomment and set ‘listen’ and ‘server_name’ directives.</p><p># listen 8080;</p><p># server_name example.com;</p><p>f. <strong>Start Zabbix server and agent processes</strong></p><p>Start Zabbix server and agent processes and make it start at system boot.</p><p>sudo systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm</p><p>sudo systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm</p><p><strong>Zabbix agent on Remote Server:-</strong></p><p>To Install Zabbix agent on Remote Server run the following script:-</p><p>sudo nano script.sh</p><p>Paste the following</p><p>#!/bin/bash</p><p>sudo wget <a href="https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb">https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4%2Bubuntu20.04_all.deb</a></p><p>sudo dpkg -i zabbix-release_6.0–4+ubuntu20.04_all.deb</p><p>sudo apt update</p><p>sudo apt install zabbix-agent -y</p><p>sudo sed -i -e “s/Hostname=Zabbix server/Hostname=$(hostname)/g” /etc/zabbix/zabbix_agentd.conf</p><p>sudo sed -i -e “s/Server=127.0.0.1/Server=95.216.191.223/g” /etc/zabbix/zabbix_agentd.conf</p><p>sudo sed -i -e “s/ServerActive=127.0.0.1/ServerActive=95.216.191.223/g”</p><p>/etc/zabbix/zabbix_agentd.conf</p><p>sudo sed -i -e “s/# LogRemoteCommands=1/ EnableRemoteCommands=1/g” /etc/zabbix/zabbix_agentd.conf</p><p>sudo systemctl restart zabbix-agent</p><p>sudo systemctl enable zabbix-agent</p><p>sudo service zabbix-agent restart</p><p>Add execution permissions:-</p><p>sudo chmod +x script.sh</p><p>Run the Script to install an agent and change the IP address according to your IP.</p><p>sudo ./script.sh</p><p><strong>Command to run a Script on Remote Server:-</strong></p><p>ssh root@146.190.123.9 ‘bash -s’ &lt; test.sh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-amnBdhf104lOpzTd2KxAA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17a2658a9971" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SonarQube Installation on ubuntu 20.04]]></title>
            <link>https://medium.com/@humzaarshadkhan/sonarqube-installation-on-ubuntu-20-04-9c4f8e293870?source=rss-dc8d8e6c4f3a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c4f8e293870</guid>
            <category><![CDATA[sonarscanner]]></category>
            <category><![CDATA[sonarcloud]]></category>
            <category><![CDATA[sonarqube]]></category>
            <category><![CDATA[sonar]]></category>
            <dc:creator><![CDATA[Humza Arshad Khan]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 06:41:27 GMT</pubDate>
            <atom:updated>2023-10-19T07:04:24.505Z</atom:updated>
            <content:encoded><![CDATA[<p>How to Install<a href="https://www.youtube.com/hashtag/sonarqube"> #sonarqube</a> in Ubuntu Linux — Download and Setup SonarQube</p><p><strong>1. Install OpenJDK 11.</strong></p><p>sudo apt-get install openjdk-11-jdk -y</p><p><strong>2. Install and Configure PostgreSQL Add the PostgreSQL repository.</strong></p><p>sudo sh -c ‘echo “deb<a href="https://www.youtube.com/redirect?event=video_description&amp;redir_token=QUFFLUhqbUZvM1dUTmg4WGMwX2RVLTlwZGlNQ3JvSl8yZ3xBQ3Jtc0ttTVBUN2hUSHlqb25mcWlYTjNJOTZXUDE3MTh5eHdBQnFod3lCeTA1OGpfWVFybF9LM2xNZVRtZFNkLUw0Qi04UjIyVGYtZlZsOWF3Z1J6YWk1NUdpTGdDQ1BNMlZiQllkS2NlUGJOM25yRXo2Vk9lOA&amp;q=http%3A%2F%2Fapt.postgresql.org%2Fpub%2Frepos%2Fapt%2F&amp;v=GTCQdgtd9mo"> http://apt.postgresql.org/pub/repos/apt/</a> `lsb_release -cs`-pgdg main” /etc/apt/sources.list.d/pgdg.list’ Add the PostgreSQL signing key.</p><p>Install PostgreSQL.</p><p>$ sudo apt install postgresql postgresql-contrib -y</p><p>Enable the database server to start automatically on reboot.</p><p>$ sudo systemctl enable postgresql</p><p>Start the database server.</p><p>$ sudo systemctl start postgresql</p><p>Change the default PostgreSQL password.</p><p>$ sudo passwd postgres</p><p>Switch to the postgres user.</p><p>$ su — postgres</p><p>Create a user named sonar.</p><p>$ createuser sonar</p><p>Log in to PostgreSQL.</p><p>$ psql</p><p>Set a password for the sonar user. Use a strong password in place of my_strong_password.</p><p>ALTER USER sonar WITH ENCRYPTED password ‘my_strong_password’;</p><p>Create a sonarqube database and set the owner to sonar.</p><p>CREATE DATABASE sonarqube OWNER sonar;</p><p>Grant all the privileges on the sonarqube database to the sonar user.</p><p>GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;</p><p>Exit PostgreSQL.</p><p>\q</p><p>Return to your non-root sudo user account.</p><p>$ exit</p><p>3. Download and Install SonarQube Install the zip utility, which is needed to unzip the SonarQube files.</p><p>$ sudo apt-get install zip -y</p><p>Locate the latest download URL from the SonarQube official download page.</p><p>Download the SonarQube distribution files.</p><p>sudo wget <a href="https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.6.1.59531.zip">https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.6.1.59531.zip</a></p><p>Unzip the downloaded file.</p><p>sudo unzip sonarqube-9.6.1.59531.zip</p><p>Move the unzipped files to /opt/sonarqube directory</p><p>sudo mv sonarqube-9.6.1.59531 sonarqube</p><p>sudo mv sonarqube /opt/</p><p><strong>4. Add SonarQube Group and User</strong></p><p>Create a dedicated user and group for SonarQube, which can not run as the root user.</p><p>Create a sonar group.</p><p>$ sudo groupadd sonar</p><p>Create a sonar user and set /opt/sonarqube as the home directory.</p><p>$ sudo useradd -d /opt/sonarqube -g sonar sonar</p><p>Grant the sonar user access to the /opt/sonarqube directory.</p><p>$ sudo chown sonar:sonar /opt/sonarqube -R</p><p><strong>5. Configure SonarQube</strong></p><p>Edit the SonarQube configuration file.</p><p>$ sudo nano /opt/sonarqube/conf/sonar.properties</p><p>Find the following lines:</p><p><a href="https://www.youtube.com/hashtag/sonar">#sonar</a>.jdbc.username=</p><p><a href="https://www.youtube.com/hashtag/sonar">#sonar</a>.jdbc.password=</p><p>Uncomment the lines, and add the database user and password you created in Step 2.</p><p>sonar.jdbc.username=sonar</p><p>sonar.jdbc.password=my_strong_password</p><p>Below those two lines, add the sonar.jdbc.url. sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube</p><p>Save and exit the file.</p><p>Edit the sonar script file.</p><p>$ sudo nano /opt/sonarqube/bin/linux-x86–64/sonar.sh</p><p>About 50 lines down, locate this line:<a href="https://www.youtube.com/hashtag/run_as_user"> #RUN_AS_USER</a>=</p><p>Uncomment the line and change it to:</p><p>RUN_AS_USER=sonar</p><p>Save and exit the file.</p><p><strong>6. Setup Systemd service</strong></p><p>Create a systemd service file to start SonarQube at system boot.</p><p>$ sudo nano /etc/systemd/system/sonar.service</p><p>Paste the following lines to the file.</p><p>[Unit]</p><p>Description=SonarQube service</p><p>After=syslog.target network.target</p><p>[Service]</p><p>Type=forking</p><p>ExecStart=/opt/sonarqube/bin/linux-x86–64/sonar.sh start</p><p>ExecStop=/opt/sonarqube/bin/linux-x86–64/sonar.sh stop</p><p>User=sonar</p><p>Group=sonar</p><p>Restart=always</p><p>LimitNOFILE=65536</p><p>LimitNPROC=4096</p><p>[Install]</p><p>WantedBy=multi-user.target</p><p>Save and exit the file.</p><p>Enable the SonarQube service to run at system startup.</p><p>$ sudo systemctl enable sonar</p><p>Start the SonarQube service.</p><p>$ sudo systemctl start sonar</p><p>Check the service status.</p><p>$ sudo systemctl status sonar</p><p><strong>7. Modify Kernel System Limits</strong></p><p>SonarQube uses Elasticsearch to store its indices in an MMap FS directory. It requires some changes to the system defaults.</p><p>Edit the sysctl configuration file.</p><p>$ sudo nano /etc/sysctl.conf</p><p>Add the following lines.</p><p>vm.max_map_count=262144</p><p>fs.file-max=65536</p><p>ulimit -n 65536</p><p>ulimit -u 4096</p><p>Save and exit the file.</p><p>Reboot the system to apply the changes.</p><p>$ sudo reboot</p><p><strong>8. Access SonarQube Web Interface</strong></p><p>Access SonarQube in a web browser at your server’s IP address on port 9000. For example:</p><p><a href="http://ip:9000/">http://IP:9000</a></p><p>Log in with username admin and password admin.</p><p>SonarQube will prompt you to change your password.</p><p>Sonar-Scanner Installtion</p><p>wget <a href="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip">https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip</a></p><p>unzip sonar-scanner-cli-5.0.1.3006-linux.zip -d /opt</p><p>echo ‘export PATH=$PATH:/opt/sonar-scanner-5.0.1.3006-linux/bin’ &gt;&gt; ~/.bashrc</p><p>echo ‘export SONAR_SCANNER_HOME=/opt/sonar-scanner-5.0.1.3006-linux’ &gt;&gt; ~/.bashrc</p><p>source ~/.bashrc</p><p>sonar-scanner -v</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_Y7VSF5wUaYd_hTCosuVg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c4f8e293870" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>