How Do You Install Composer on Debian/Ubuntu Linux?

Problem scenario
You want to install Composer (a dependency manager for PHP) on your Debian/Ubuntu Linux server. What do you do?

Solution

  1. Run these commands:

sudo apt -y update
sudo apt -y install php-cli unzip
cd ~
sudo curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=curl -sS https://composer.github.io/installer.sig
echo $HASH
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

  1. The last command above should have printed out "Installer verified". Now run these two commands:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer

  1. You are done. The above directions were adapted from this external page.
  2. The above directions were tested to work on Debian 10.

How Do You Set up SSH on a Windows 2016 Server with Cygwin?

Problem scenario
You have a heterogeneous enterprise network of servers. You want your Linux machines to communicate and transfer files with your Windows machines. You do not want to use Active Directory. What do you do?

Solution
1. Install Cygwin on the Windows server if it has not been set up already. If you need assistance with this, see this posting.

2. Open Cygwin and and set up SSH keys as you normally would. See this article How Do You Set up Passwordless SSH from One Server to Another? if you do not know how.

How Do You Find the URL (or HTTP Endpoint) of a Kubernetes Cluster Running in Amazon EKS?

Problem scenario
You have a Kubernetes cluster in AWS. You have the AWS CLI installed. How do you find the URL for the Kubernetes cluster?

Solution
1. Run this command: aws eks list-clusters

2. Run this command: aws eks describe-cluster foobar # where "foobar" was name determined in above command

How Do You Find what VPC an EC-2 Instance Is In?

Problem scenario
You want to determine what VPC a given AWS server is in. How do you find this out?

Solution
Prerequisite

You must have the AWS CLI installed and configured with a user that has the ability to view EC-2 databases (e.g., an administrator of your AWS account). If you need assistance, see this posting.

Procedure
Run this command: aws rds describe-db-instances | grep -i vpc

How Do You Install Molecule on RHEL v. 8.x with Python 3?

Problem scenario
You want to make and test Ansible roles, and therefore you want to use Molecule. You are using RHEL version 8.x. You want to use Python 3 and Molecule. What should you do?

Solution
Prerequisites
i. You should install Docker. If you need assistance, see this posting.
ii. You should install these packages before hand:

sudo yum -y install gcc python3-devel
sudo dnf install -y redhat-rpm-config

Procedures
1. Run these commands:

sudo python3 -m pip install virtualenv
sudo python3 -m virtualenv my_env
source my_env/bin/activate
sudo yum install -y python3-devel 
sudo python3 -m pip install molecule docker
molecule init role -r ansible-apache -d docker
cd ansible-apache
molecule test

2.a. Run this command: vi tasks/main.yml
2.b. Delete what is there. Put this there instead:

---
- name: "Ensure required packages are present"
  yum:
    name: "{{ pkg_list }}"
    state: present

- name: "Ensure latest index.html is present"
  template:
    src: index.html.j2
    dest: /var/www/html/index.html

- name: "Ensure httpd service is started and enabled"
  service:
    name: "{{ item }}"
    state: started
    enabled: true
  with_items: "{{ svc_list }}"

- name: "Whitelist http in firewalld"
  firewalld:
    service: http
    state: enabled
    permanent: true
    immediate: true

3. Run this command: mkdir templates

4.a. Run this command: vi templates/index.html.j2
4.b. Put this there and save the file:

<div style="text-align: center">
    <h2>Managed by Ansible</h2>
</div>

5.a. Run this command: vi vars/main.yml
5.b. Delete what is there. Place this code starting at the first non-blank line:

---
pkg_list:
  - httpd
  - firewalld
svc_list:
  - httpd
  - firewalld

6.a. Run this command: vi molecule/default/tests/test_default.py
6.b. Eliminate the content that you find. Place these lines in the place of the old content:

import os
import pytest

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


@pytest.mark.parametrize('pkg', [
  'httpd',
  'firewalld'
])
def test_pkg(host, pkg):
    package = host.package(pkg)

    assert package.is_installed


@pytest.mark.parametrize('svc', [
  'httpd',
  'firewalld'
])
def test_svc(host, svc):
    service = host.service(svc)

    assert service.is_running
    assert service.is_enabled


@pytest.mark.parametrize('file, content', [
  ("/etc/firewalld/zones/public.xml", "<service name=\"http\"/>"),
  ("/var/www/html/index.html", "Managed by Ansible")
])
def test_files(host, file, content):
    file = host.file(file)

    assert file.exists
    assert file.contains(content)

7. Run this command: molecule test

8. You are done. The above directions were adapted from a DigitalOcean tutorial here.

How Do You Find what VPC an Aurora Database Is In?

Problem scenario
You want to be sure that a given Aurora database is in a specific VPC. How do you determine what VPC it is in?

Solution
Prerequisite
You must have the AWS CLI installed and configured with a user that has the ability to view Aurora databases (e.g., an administrator of your AWS account). If you need assistance, see this posting.

Procedure
Run this command: aws rds describe-db-instances | grep -i vpc

How Do You Invoke the main Section of a Groovy Program?

Problem scenario
Your Groovy code has a section like this:

class Example {
static void main(String[] args) {

But this section above is not executing when you run your Groovy program. There are no errors however. How do you get it to execute?

Possible Solution #1
Remove lines of code (or statements) that are outside the "class Example {…"

Possible Solution #2
See this posting: How Do You Invoke a Class in a Groovy Program?

How Do You Use the aws update-kubeconfig Command?

Problem scenario
You want to manage your Amazon Kubernetes (i.e., EKS) cluster. You have installed the AWS CLI version on a Linux server, and you want to use the update-config or update-kubeconfig command.

But when you try you see messages like "error argument command: Invalid choice…" or "update-config: command not found". You could not readily find an example. What should you do?

Solution
Background
The command is update-kubeconfig, not update-config.

Procedures
1. Verify you have a version of the AWS CLI at or higher than 1.16. Use this command: aws --version
To install a newer version, see this set of directions if you can install pip; if you cannot install pip, see this set of directions.

2. Use this syntax (where foobar is the name of the cluster you want to create the configuration file for):
aws eks update-kubeconfig --name foobar

(If you need to find the name of your cluster(s), run this command: aws eks list-clusters)

How Do You Interpret the dstat Utility’s Results on a Linux Server in AWS?

Problem scenario
You want to monitor network traffic on an EC-2 server's NICs. You are not sure what to look for or what a baseline should look like. What do you do?

Solution
1. Install dstat. With a CentOS/RHEL/Fedora server, run this: sudo yum -y install dstat
2. Run this command: dstat -nt
3. With no network activity beyond the PuTTy session to the EC-2 server, you will see numbers like these: recv send| time
0 0 |13-12 01:05:06
40B 310B|13-12 01:05:07
40B 198B|13-12 01:05:08
40B 198B|13-12 01:05:09
40B 198B|13-12 01:05:10
82B 240B|13-12 01:05:11

The above represents minimal activity across the NIC of the server.
4. If you want to learn more about the dstat tool, see these links:
https://linux.die.net/man/1/dstat
https://linoxide.com/monitoring-2/dstat-monitor-linux-performance/