How Do You Install The aws-iam-authenticator?

Problem scenario
You want to manage Kubernetes (e.g., Amazon EKS) via a server in AWS.  You want to install the aws-iam-authenticator on a Linux server.  How do you do this?

Solution
1.  To install aws-iam-authenticator go here to obtain the link that is relevant for your server.  You will search the above link for "aws-iam-authenticator binary from Amazon S3"

2.  If you are using Linux, run these commands to download, install and configure aws-iam-authenticator:

curl http://link/above > /tmp/aws-iam-authenticator
chmod +x /tmp/aws-iam-authenticator
mkdir $HOME/bin
cp /tmp/aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$HOME/bin:$PATH
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
aws-iam-authenticator help  
# This tests the installation

How Do You Get the sonar.sh Console to Actually Work When the Screen Says That “SonarQube is already running”?

Problem scenario
You stop SonarQube services from running.  You want to log into the web UI console to set things up.  You run this command:

sudo bash /opt/sonarqube/bin/linux-x86-64/sonar.sh console

But all you see is

"
Running SonarQube...
SonarQube is already running.
"

You never get a network service to listen on port 9000.  How do you use "sonar.sh console" to initially configure Sonar?

Solution
Run this command:
sudo bash /opt/sonarqube/bin/linux-x86-64/sonar.sh stop

Make sure you starting the script as a non-root user.  Then run this:

bash /opt/sonarqube/bin/linux-x86-64/sonar.sh console

Make sure that the user who is running the command has the ability to execute files in the /opt/sonarqube/ directory.  You may want to draft a command such as this:

sudo chown -R jdoe:goodgroup /opt/sonarqube

# Replace jdoe with the username that is trying to run the command.  Replace goodgroup with the group associated with the user.  If you do not know what group that is, log in as that user or use "su jdoe" (where jdoe is the username).  Then run the command "groups".

Then run the command you have drafted.

How Do You Install Varnish on Debian/Ubuntu Linux?

Problem scenario
You want to install Varnish on a Debian/Ubuntu Linux server.  How do you do this?

Solution
Run these commands:

sudo apt-get -y update

sudo apt-get -y install gcc python-docutils pkg-config libreadline-dev libncurses5-dev libpcre3-dev #*

curl http://varnish-cache.org/_downloads/varnish-6.0.0.tgz > /tmp/varnish-6.0.0.tgz

sudo cp /tmp/varnish-6.0.0.tgz /opt/
cd /opt
sudo tar xvzf varnish-6.0.0.tgz
cd varnish-6.0.0
sudo ./configure
sudo make
sudo make install
varnishd -V

* This website says:

'On Debian, you might also have to do:

export PCRE_LIBS="-L/usr/lib -lpcre"
export PCRE_CFLAGS=-I/usr/include/pcre # '

If you want to purchase a book on Varnish, click here.

How Do You Troubleshoot the Error “intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 … 1 ] “?

Problem scenario
You try to start Cassandra but you get this error:

"[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:./bin/../logs/gc.log instead.
intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]
Improperly specified VM option 'ThreadPriorityPolicy=42'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit."

Possible solution #1
Migrate to Linux SUSE or a Red Hat family version of Linux (e.g., CentOS, RHEL or Fedora).  We have only seen this problem with Ubuntu Linux.

Possible solution #2
Remove Java version 9 and install Java version 8.  To do this (assuming that they were installed via apt-get commands), run these commands:

sudo apt-get -y remove openjdk-9-jre-headless
sudo apt-get -y update
sudo apt -y install openjdk-8-jre-headless gcj-4.8-jre-headless default-jdk

How Do You Use a Generator and the Yield Keyword in Python?

Problem scenario
You want to use a generator in Python.  You also want to use the yield keyword in Python.  How do you use these?

Solution
The short answer to the question about how do you use a generator is to create a function with the yield keyword (source Programiz.com).  "Both yield and return will return some value from a function."  (The source of this quote is Programiz.com.)

A Python generator is in essence a coroutine.  Coroutines enable intelligent control between two different parts of a program (e.g., a cooperative process that interleaves the invocation of one part of the code to return to another section of the code and thus re-enter it with a dynamic value that has been precomputed).  A generator has discrete steps of iteration which can be executed with the "next" keyword.  The "yield" keyword is like a return statement without necessarily being final.  The execution of a generator will provide intermediate values with its yield statement(s) and continue with calls with the "next" keyword.   The "yield" and "next" keywords are important for using the generator feature in Python.  This program below illustrates how to use the "yield" and "next" keywords; this simple program below also demonstrates how to use a generator.

# Call this program gen.py.  Run it with "python gen.py" (with no quotes).
# Examine the output and you will see how yield works like a return statement without the finality.
# This program uses a Python generator.  Note that you do not need the use the word "generator"
# in the function definition.  It can be helpful for readability, but Python knows what to do by merely
# using the word "yield" inside the function.

def continual_generator_func():
  yield 1
  yield 2
  yield 3
  yield 4 
tempobject = continual_generator_func();
a = next(tempobject)
next(tempobject)
next(tempobject)
b = next(tempobject)
print(a)
print(b)

How Do You Create Your Own Dockerfile to Create a Flask Application?

Problem scenario
You want to use Flask inside a Docker container.  You want to build your own image for the Docker container.  How do you create your own Dockerfile to create a Flask application?

Solution
Prerequisite

Install Docker.  See this posting if you need directions.

Procedures
1.  Create a Dockerfile with the following content (you may want to replace "16.04" with "latest" and if you want to change the location of where the .py file is, that may or may not be troublesome):

FROM ubuntu:16.04  

RUN apt-get update
RUN apt-get install -y python3 python-pip
RUN apt-get clean all

RUN pip install flask

ADD hello.py /tmp/hello.py

EXPOSE 5000

CMD ["python","/tmp/hello.py"]  

2.  In the directory that the Dockerfile will go, create a file called hello.py with the following content:

from flask import Flask
app = Flask(__name__)

@app.route('/hi')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

3.  Run this command in the directory with the above files:

docker build -t flask .

(On a server with .5 GB of RAM and 1 shared vCPU, this can take 20 minutes.)

4.  Then run this command:  docker run -d -P flask

5.  Test it from the Docker host.  Run this command:  docker ps -a

Find the result for a recently created container.  The "PORTS" column should have a mapping to the port 5000.  Use the non-5000 port (in the output of the command above) and construct this Linux command below (but replace xxxxx with that port number in the following draft of a command):

curl http://localhost:xxxxx/hi

6.  Run the curl command above once you substitute the xxxxx.  You should see "Hello World!"

How Do You Install Ansible on a Debian Linux Server Running in GCP?

Problem scenario
You are using Google Cloud Platform, and you have a Debian server.  You do not want to configure any PPAs for your system.*  How do you install and configure Ansible on a Debian Linux system?

Solution
Prerequisite

We strongly recommend having 2.5 GB of memory (either in RAM or with a combination of RAM and swap space).   For directions on how to configure swap space in the amount of 2 GB, see this posting.  You can get Ansible installed with 0.6 GB of memory.  But we do not think the performance would be acceptable with this configuration.

Procedures
1.a.  Create a script called ansible.sh in /tmp.

1.b.  Have this as the content:

apt-get -y update
apt-get -y install git python-setuptools gcc python-dev libffi-dev python-openssl make
cd /opt
git clone git://github.com/ansible/ansible.git --recursive
cd ansible
python setup.py build
python setup.py install  

2.  Run this script like this:  sudo bash /tmp/ansible.sh

3.  Test it was successful:  ansible --version

*  If you want to try to configure a PPA on Ubuntu Linux, see this external article (https://www.cyberciti.biz/faq/how-to-install-and-configure-latest-version-of-ansible-on-ubuntu-linux/).  If you want to try to configure a PPA on a Debian Linux system, you can use this external link at your own risk.

How Do You Use GCP’s App Engine?

Problem scenario
You want to leverage GCP's serverless App Engine component with its scalability.  What do you do?

Solution
1.  Go to the cloud shell.  In the web UI of GCP in the upper righthand corner go to the icon that looks like this: ">_" and click on it.  From cloud shell run these commands:

git clone https://github.com/GoogleCloudPlatform/python-docs-samples

cd python-docs-samples/appengine/standard_python37/hello_world

virtualenv --python python3 ~/envs/hello_world

source ~/envs/hello_world/bin/activate

pip install -r requirements.txt

python main.py

2.  In the upper righthand corner there are several icons.  When you hover over each one, a pop-up will say something.  Click the icon for which "Web preview" appears.  Then choose "Preview on port 8080".  If it opens a new web browser tab that says "Hello World!", then it worked.

3.  Back at the cloud shell, hold the control key and tap "c" (ctrl-c).

4.  Run this command: gcloud app create
(Do not be alarmed by the error "already contains an App Engine".  Just proceed to the next step.)

5.a.  Run this command (but replace contint with the ID of your project*):

gcloud app deploy app.yaml --project contint

5.b.  If you are asked if you want to continue, choose "Y" and press enter.

5.c.  Run this command:  gcloud app browse

6.  Click on the URL that appears in the cloud shell.  It should take you to a new tab in the web browser.  It should say "Hello World!"

* If you want to find the ID of your project, from the GCP web UI, go to "My First Project" or something similar at the top middle part of the screen.  Click on it.  The pop up should show the project IDs according to their names.

How Do You Create a Docker Image That Has Java 10 in It?

Problem scenario
You want to create Docker containers with Java 9.  How do you create a Docker image to make containers with Java 9 installed in them?

These directions were updated on 12/26/18.

Solution
Prerequisite

This assumes that you have Docker installed. If you need assistance with this, see these postings depending on your operating system:

Debian/Ubuntu
CentOS/Fedora/RHEL
SUSE

Procedures
1.  Create a filed called Dockerfile with the following content:

FROM ubuntu:latest
MAINTAINER NAME EMAIL

RUN apt-get -y update && apt-get -y upgrade && apt-get install -y build-essential openjdk-11-jre-headless

2.  Run this command: 

docker build -t "java:java" .

# You should see an image ID.  If you need to find out later, use "docker images" to find it.

# You are now done.

3.  This step is optional if you want to create a container and enter it.  Run these commands:

docker create -it <ImageID> bash

# You should see a container ID.  If you need to find out later, use "docker ps -a"

docker start <containerID>

docker exec -it <containerID> bash

If the above directions do not work with RHEL, please post a comment. You do not need to use your real name.

How Do You Troubleshoot the SonarQube Service Not Working with a “vendor preset: disabled” Error?

Problem scenario
The SonarQube service failed to start.  

You see this message:

? sonar.service - SonarQube service
   Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Mon 2018-05-21 14:34:34 UTC; 12min ago

May 21 14:34:33 sonarserver systemd[1]: Started SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: sonar.service holdoff time over, scheduling restart.
May 21 14:34:34 sonarserver systemd[1]: start request repeated too quickly for sonar.service
May 21 14:34:34 sonarserver systemd[1]: Failed to start SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: Unit sonar.service entered failed state.
May 21 14:34:34 sonarserver systemd[1]: sonar.service failed.

What do you do?

Possible solution #1
1.  Install Java.  If you need assistance, see this posting.

2.  Then run these commands:
sudo systemctl enable sonar
sudo systemctl start sonar

Possible solution #2
Use the "-l" flag when you check the status.   This allows you to see longer lines for details.  Try to resolve the problem based on the verbose output of this command:  sudo systemctl status sonar -l