Python Installations Bug

Error that prevent python installing modules

1
2
Message: '[present-rich] %s'
Arguments: (UpgradePrompt(old='22.1.2', new='22.2.1'),)

Fixing Method

1
2
3
4
5
6
# uninstall pip
sudo pip uninstall pip
# install pip through apt
sudo apt install python3-pip
# upgrade pip to the latest version
python3 -m pip install --user --upgrade pip

How to build docker container

Build Container

1
2
3
4
5
docker build -t username/repository-name .
# tag the image
docker build -t username/example-node-app
# Verify images
docker images

Run Docker image

1
2
3
docker run -p 80:80 username/example-nodeapp
# check the running container
docker ps

Method of Setting Test Environmnet for VM

Method 1: Creating a Snapshot

  • Pros: Cost less storage resources.
  • Cons: Can’t stored on secondary block device as backup.

Method 2: Replicate the vm

  • Pros: Fulll VM that is able to be migrated on a different system.
  • Cons:
    • Need extra step if the second storage is added.
    • Cost double current VM storage.

Method 3: Deploy a dedicate VM via terraform with libvirt as provider (devops approach)

Refer to following guide to prebuilt your system. Be advised, you have install a terraform and libvirt plugin for the system. Although it’s not a lengthy process, it may cause some issues on different linux distribution.

Howto: Provisions vms on kvm with terraform

  • Pros: Able to spawning mutiple instances. Can be utilized with gits.
  • Cos: Hard to migrate current stable system, especially the configuration.

Clean Ubuntu Repository

How to Clean Ubuntu Repository

Bug or Error

1
2
3
4
Err http://ppa.launchpad.net natty/main Sources                                   
404 Not Found
Err http://ppa.launchpad.net natty/main i386 Packages
404 Not Found

Problem

  • Repository can’t be connected or no longer available.
  • Wrong repo info added.

Solution

  • Search for apt sources files .
    ls /etc/apt/sources.list.d
  • remove the unwanted or corrupted file. For instance, the file cause the error is myppa.list. Type the following to remove the file.
    rm -/etc/apt/sources.list.d/corrupted_app.list

add python automation

Create a Virtual enviroment with Python

  1. To create a folder to store virtual enviroment info.

python3 -m venv .venv

  1. To activate virual enviroment, type the following line.
    source .venv/bin/activate

Journal CloudOps

Implications of Cloud Operation Model

  • Things to consider:
    • Scheduling
    • API structures
  • Deploying applications over ticketing system.
  • Development -> Networking -> Security -> Operations

Private Cloud

  • VSphere.
  • AD/LDAP (identity).
  • Terraform (provisioning).

AWS

  • EKS/ECS Lambda
  • CloudMap AppMesh
  • AWS IAM (identity)
  • CloudFormation (Provisioning)

Youtube:

  • Webinar: Describing Cloud Architecture.

Performance Monitoring in Linux

Overview

  • This is part of lpic2 exam, objective 200.1 - Measure and Troubleshoot Resource Usage.

vmstat command

1
2
3
# Display disk statitics
$vmstat -d
nvme0n1 54705 32017 4802359 17720 348189 80080 4514130 276470 0 163

free command

  • Concept of memory: cpu can’t talk to memory right away, it talks to buffer of the ram first. Buffer access cached for access binary. For example, when a command is executed at the first time, it will be stored in the cache. In the same time, the metadat is stored in buffere.
  • When a command is executed, the buffer will be
  • free -h, will have the following output.
1
2
3
4
              total        used        free      shared  buff/cache   available
Mem: 23G 8.4G 11G 373M 3.2G 14G
Swap: 34G 0B 34G

  • Explaination:
    • free: is for immediately accessed.
    • buffer: metadata for cache (pointer of memory page).
    • cache: store binary for immediate access.
    • shared:

The available will reflect the buffer/cache, shared and free.

  • To clear and buffer and cache, we can use the following command.

    • To clear the buffer.

      1
      sync; echo 2 > /proc/sys/vm/drop_caches
    • To clear the cache.

      1
      sync; echo 3 > /proc/sys/vm/drop_caches

Netplan Guide

Sample of Editing Netplan

For ethernet

For wifi

  • Create a file in /etc/netplan
    • Set up the wifi with dhcp
1
2
3
4
5
6
7
8
9
10
11
12
13
network:
version: 2
renderer: networkd
wifis:
wlp2s0:
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
access-points:
"AP_Name":
password: "wifi_pass"
dhcp4: true
  • Set up the wifi with static IP
1
2
3
4
5
6
7
8
9
10
11
12
13
network:
version: 2
renderer: networkd
wifis:
wlp2s0:
dhcp4: no
addresses: [192.168.1.100/24]
' '' '' '' 'gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1,8.8.8.8]
access-points:
"accespoint_name":
password: "your_pass"
  • Finally, type netplan generate && netplan apply to apply the configuration.

#References:

  • Real time demo link:

Deploy vultr instances with terraform

Spinning up Cloud Instances

What needed:

  • API key from the Vultr Account.
  • SSH public key for remote access.

Sample of terraform

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Configure the vultr provider

provider "vultr" {
api_key = "provided by vultr server"
rate_limit = 700
retry_limit = 3
}


# creat an ssh key
resource "vultr_ssh_key" "my_ssh_key" {
name = "ssh-key"
# normally it would be in ./ssh/id_rsa.pub
ssh_key = "ssh-rsa <ssh-public-key> anpham@dell-laptop"

}

# Create a web server
resource "vultr_server" "web-nginx" {
plan_id = "201"
region_id = "6" # atlanta servers
os_id = "167" # centos os
tag = "made-by-terraform"
hostname = "web-server"
}