How Do You Get the ElasticSearch, LogStash or Kibana Service to Remain On?

Problem scenario
The elasticsearch, logstash or kibana services will start, but when you check the status, it does not remain on. It keeps stopping. You see the status as "failed."

Solution
Possible Solution #1
Add more memory or swap space to the system. If you need assistance with either of these, see this posting.

Possible Solution #2
Go to the logs directory for elasticsearch. One way to find it would be to run this:

sudo find / -name elasticsearch -type d

Then see if there is a logs directory. Another way would be to run this: sudo find / -name logs | grep elasticsearch

You will want to do a case insensitive search in log (like hs_err_pid6803.log) for the word "error". This may give you some clues.

Possible Solution #3
When you see the status with sudo systemctl status commands (followed by the respective service), look for the process line of output. It may look like this (e.g., for logstash):

/opt/logstash/bin/logstash -f /opt/logstash/config/logstash-simple.conf

With a leading sudo try to run that command. The output may tell you something.

Why is Your Python Programming Printing Duplicate Lines?

Problem scenario
You have a Python program with print statements. When you run the program, you get twice as many print statements as you expect. What could be wrong?

Possible Solution #1
Do not name the program re.py or string.py. When you name the program re.py and have an import re statement, Python may print every line it is supposed to print twice. When you name the program string.py and have an import string statement, Python may print every line it is supposed to print twice.

Possible Solution #2
Verify the logic in your program. Some for loops can execute more times than you realize.

How Do You Write a Python Program to Create a .txt File with 50 Key-Value Pairs?

Problem scenario
You want to create a .txt file that has 50 key-value pairs. You want the keys to be whole numbers. You want the values to be five-character strings. What should you do?

Solution

import random
import string
import sys

def randomword(length):
   letters = string.ascii_lowercase
   return ''.join(random.choice(letters) for i in range(length))

def printer(counter, webstera):
  webstera[counter] = randomword(5)
  if (counter < 50):
    counter = counter + 1
    return printer(counter, webstera )
  else:
    print("____________________")
    return webstera

a = printer(0, {})
print(a)

file = open("contint.txt","w")
file.write(str(a))
file.close()

How Do You Install ElasticSearch on CentOS/RHEL/Fedora?

Prerequisites
This assumes you have installed Java. If you need assistance with installing Java, see this posting. This assumes you have a server with 4 GB of memory (e.g., virtual memory and RAM in an amount greater than 4 GB). The command to run to see how much memory you need is this one: free -mh If you need more memory, see this posting.

Procedures
Step #1 Run this script:

version=7.3.2

curl https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$version-x86_64.rpm > /tmp/elasticsearch-$version-x86_64.rpm
curl https://artifacts.elastic.co/downloads/logstash/logstash-$version.rpm > /tmp/logstash-$version.rpm
curl https://artifacts.elastic.co/downloads/kibana/kibana-7.3.2-x86_64.rpm > /tmp/kibana-$version-x86_64.rpm

rpm -i /tmp/*$version*.rpm

systemctl daemon-reload
systemctl enable elasticsearch.service
systemctl start elasticsearch.service

Step #2 To route traffic from a website (e.g., port 80), install Nginx. For directions on how to do this, click this posting for CentOS/RHEL/Fedora or see this posting if you have Debian/Ubuntu. Configure it as a reverse proxy to route the traffic. For directions on how to do this, see this posting.

How Do You Troubleshoot “AttributeError: module ‘re’ has no attribute ‘IGNORECASE'”?

Problem scenario
When you run your Python program, you get this message: "AttributeError: module 're' has no attribute 'IGNORECASE'"

What should you do to get your program to work correctly?

Solution
Change the name of the program to something different. Do not name your program "re.py". If you use the "import string" and your program is called "re.py", you may get this error.

How Do You Troubleshoot This Error “port bindings are not yet supported by rootless containers”?

Problem scenario
You run a docker command, but you get "port bindings are not yet supported by rootless containers". What should you do?

Solution
Use sudo before the Docker command.

Waning: The above is not recommend for security purposes. Only follow this direction (with sudo docker run…), if the server is not that important or you are in a very secure network. One published book says you can use "sudo docker …" as long as the server is not in production (page 43 of Docker Up and Running).

How Do You Know if Your Logging is Truly in JSON Format or Not?

Problem scenario
You are not sure if you have valid JSON or not. You have converted raw logs of an application to be in JSON format. There is a flat file receiving what you believe to be valid JSON. How do you know for sure?

Solution
Put the JSON in here https://jsonformatter.curiousconcept.com/ and click "Process".

The JSON should start with an opening brace { and end with a closing brace }. The final element should not have a comma. You can copy some JSON and put it inside two braces {} and remove the final comma (if any exists) from your logs, text or file you are creating. Then above website will tell you if you have valid JSON.

How Do You Troubleshoot the Message ‘ERRO[0000] cannot setup namespace using newuidmap: exit status 1’?

Problem scenario
How do you resolve the Docker error 'ERRO[0000] cannot setup namespace using newuidmap: exit status 1'?

Possible Solution #1
Reboot the Docker host.

Possible Solution #2
Good commands to help understand what might be going on are lsns, sudo lsns, and man nsenter

How Do You Change the Time Zone to the Eastern Time Zone of the U.S. With a CentOS 6.X Server?

Problem scenario
You run the date command on Linux and find that your server is not configured for the Eastern time zone and/or the ntp daemon is not running. What should you do?

Solution
Run these commands:

sudo /etc/rc.d/init.d/ntpd start
ls -l /etc/localtime
sudo cp /etc/localtime /root/old.timezone
sudo rm /etc/localtime
ln -s /usr/share/zoneinfo/American/Boston /etc/localtime
sudo ln -s /usr/share/zoneinfo/America/New_York /etc/localtime

This solution was adapted from this external posting.

How Do You Paste Text from a Windows Environment into a PuTTY Terminal?

Problem scenario
You want to paste text into a PuTTY terminal. But it is not working. What should you do?

Solution
Once in the vi session, use this command (in command mode): :set mouse=

Now when you enter insert mode (by press "i"), you will be able to paste text that you copied from another source.

If you want to permanently set it (so every vi session automatically will accept pasted text once you enter insert mode), do this from a command prompt:
sudo vi ~/.vimrc # then type in this text :set mouse= with no quotes and save the file.