How Do You Create a Database in MongoDB Not Using using Compass (the GUI)?

Problem scenario
You want to create a database in MongoDB using the CLI. How do you do this from a Linux server and then add a document to the database you just created?

Solution
Prerequisite

Install MongoDB on a Linux server; if you need assistance, see this posting.

Procedures

1.a. Enter the MongoDB shell: /usr/bin/mongo

1.b. If you were able to enter the MongoDB shell, skip directly to step #2. If the command is not found, run this: sudo find / -name mongo | grep bin
1.b.i. Run the file that was found in 1.b.

2. Run a command such as this (but replace "contint" with the new name of a database): use contint

3. Run a command such as this: db.inventory.insertOne( { item: "silk", qty: 35, tags: ["silk"], size: { h: 24, w: 39.5, uom: "in" } } )

4. View the content running a command such as this: db.inventory.find( {} )

What Is The Difference between an A Record and a PTR Record in DNS?

Problem scenario
You have heard of A records and PTR records. But you do not know the difference. What is the difference?

Solution
The short answer is that they are opposites of each other in the context of DNS.

An A record maps a domain name to an IP address (pg 858 of A Practical Guide to Fedora and Red Hat Enterprise Linux).

A PTR record maps a host name to an IP address (pg 859 of A Practical Guide to Fedora and Red Hat Enterprise Linux).

They are complementary. Depending on what you need to find and what you have (e.g., a host name vs. an IP address), the two can help you configure your network.

How Do You Do Variable Expansion with an Ansible Playbook without Introducing Punctuation?

Problem scenario
You use a variable in an Ansible playbook. The value of the variable is surrounded by quotes and brackets. You may refer to it as punctuation [""]. You want to assign the variable without the new symbols such as '[""]'. How do you get just the value and no punctuation?

Solution
Do not use quotes or square brackets "[]" around the variable.

Here is an example that will provide the variable without any extra punctuation:
shell: 'echo {{ ansible_hostname }} > /tmp/date.txt'

Here is an example that will include new symbols:
shell: 'echo "{{ [ansible_hostname] }}" > /tmp/date.txt'

You may also want to see How Do You Get an Ansible Variable to Not Add Single Quotes or Brackets when the Variable Is Substituted?.

How Do You Use the least_conn Directive in an Nginx Configuration File?

Problem scenario
You have configured Nginx to be an HTTP load balancer (a web server configured to behave as a landing portal that enables traffic to pass through).  As a reverse proxy with built-in keywords you have use the "least_conn" directive, but it does not seem to be working.  You want inbound network connection requests from your users via web browsers to be relayed to the web servers with the fewest (or least) amount of active connections.  Any Nginx server can work as a reverse proxy server like this.  In your instance you find that the special heuristic of conveying traffic to the available web server with the fewest current connections is not happening. 

You have placed the "least_conn;" directive in an "upstream backend {}" block in the /etc/nginx/conf.d/default.conf file of the distributor Nginx web server configured to be an HTTP load balancer.  However there is no evidence that the traffic is being routed to the underlying Nginx servers with the fewest connections.  Based on your testing, the traffic is evenly divided among the web servers with no regard for how many active connections persist.  This is consistent with the round-robin distribution method, Nginx's default routing mechanism.  It is as if the least_conn directive has been commented out.  What is wrong?

Solution
#1  Are the web pages small?  If they are purely text and less than 200 lines, that may be the reason.  When the web pages from at least one web server are very large, then the download process takes more time.  Individual connections of longer duration associated with bigger web pages (more than 1 MB) are more likely to be detected by the Nginx algorithm for traffic distribution purposes.  Active connections may have such a short duration that within your testing, the round robin method appears to be the prevailing distribution algorithm.  The round robin method is used if there are equal numbers of connections on each of the available web servers -- even when the least_conn directive has been used.  Unless there are unequal active connections on the web server the least_conn directive will have any influence.  Moreover, connections can be so short temporally with default "Welcome to Nginx" index.html pages, the least_conn will have no noticeable affect.  To test properly, copy some text to create the pages being downloaded to be disparate in size with at least one web server having a a web page that is 1 MB in size.

In a typical Nginx deployment, the index.html file is located here:  /usr/share/nginx/html/index.html

If you first installed Apache web sever before Nginx, the Nginx web service may present the /var/www/html/index.html file as the default web page.  You may want to modify it so the size  of at least one web page is VERY large.  This crucial to getting a test that will prove least_conn is working.

#2  Have you brought down Nginx services and brought them back up?  For the least_conn directive to take  effect for the first time, the Nginx service must be restarted.

#3  Are you testing properly?  Ideally you have two computers or servers that can both make web-based client requests that also perform comparably with reads/writes of web pages.  This way you can simulate a load of traffic simultaneously. Bandwidth, RAM, CPU, and hard disk I/O performance are all  factors.  A big difference could mean that that automated scripts are not running at exactly the same time.  Thus your simulated load is not creating active connections to test.  You should used cronjobs (with Unix/Linux servers) or Scheduled Tasks (with Windows  servers).  The activated task should be a script that repeatedly downloads the web page.  Once the job on each server has been invoked at a synchronized time for web-request contention, the script should save the the downloaded pages by appending them to the same file.  Ideally the content of the pages have something identifiable to the web server it came from (a unique string from its web server).  Once you have two aggregate files from two downloading processes that happened contemporaneously, you can use either Bash or PowerShell to count the identifying strings.  This way you can see evidence of which web server had the least connections and which had the most connections.

If the web page on one web server takes considerably longer, it will have more connections to it than the other web server.  But this is only apparent if there definitely are more active connections to one server than another.  Web servers must have different sizes of index.html files (or whatever file you are downloading from them) to be noticeable.

FYI
We tested Nginx in Docker containers as both the HTTP load balancer and as a web server.  The least_conn directive can work in this scenario (with Nginx in Docker as a reverse proxy relaying inbound connections to Nginx in Docker containers web servers).

FFR
If you want to need to troubleshoot problems with your Nginx load balancer, see this link.

How Do You Know if kubectl Is Installed on Your Linux Server?

One or both of the following scenarios applies.

Problem scenario #1
Try to install kubectl, but you get an error message about it being installed.

Problem scenario #2
You run "man kubectl" but you see no man page. You still think kubectl is installed.

What should you do?

Solution
Run this command: kubectl version
The results should give you some clues as to what is wrong. You may want to see this posting if you are using a Red Hat derivative or this posting for any distribution of Linux.

What is SELinux?

Question
What is SELinux?

Answer
Security-Enhanced Linux (or SELinux) is a kernel module that can be installed and turned on in a Linux server. It categorizes files, hardware resources and processes; to learn more see this posting. It has the ability to restrict access to these categories. If a server is designated as an application server, a database server, or a web server, the relevant processes can be given minimal access. This allows you to harden a server according to the principle of least privilege. SELinux allows for configurable policies to protect your server.

Without SELinux, a typical Linux server will merely use Discretionary Access Control (with server users and groups) (page 472 of A Practical Guide to Fedora and Red Hat Enterprise Linux). This book provides a link to the selinuxproject.org. SELinux was originally "developed by the NSA (U.S. National Security Agency" (page 472 of A Practical Guide to Fedora and Red Hat Enterprise Linux).

You may want to view the posting Can the Kernel Access Hardware Directly?.

How Do You Troubleshoot The Kerberos Error ‘kinit: Cannot find KDC for realm “CONTINUALINTEGRATION.COM” while getting initial credentials’?

Problem Scenario
You run a "kinit" command. But you receive this:

'kinit: Cannot find KDC for realm "CONTINUALINTEGRATION.COM" while getting initial credentials'

What should you do?

Solution
Look at the /etc/krb5.conf file. Look at the REALM section. Does it look like this?

[realms]
EXAMPLE.COM = 

You need to change "EXAMPLE.COM" to your domain name.

Look also at the libdefaults section. There is a stanza for default_realm. This assignment must be consistent with the [realms] section.

How Do You Troubleshoot the Vagrant Error “No usable default provider could be found for your system.”?

Problem scenario
On a Linux server you get "No usable default provider could be found for your system." What should you do?

Solution
Install VirtualBox. On an Ubuntu server with 0.5 GB of RAM, you can simply run this command:

sudo apt-get -y install virtualbox

How Do You Fix the Problem of “permission denied” when Trying to Copy a File to a Directory?

Problem scenario
You try to copy a file. It fails with "Permission denied." What should you do?

Possible Solutions
1. Are the permissions of the destination folder/directory permissive? Is you user supposed to be able to write to the destination folder/directory?

2. Is there an open file in the destination directory? Sometimes this can cause unexpected problems (e.g., with Git Bash).

3. Are you sure the location is correct? In today's world with public and private clouds, Git Bash, Git CMD, PowerShell, DOS prompts, Putty terminals, VNC sessions, Remote Desktop Sessions, web UI terminals, servers can become easily confused with each other