Sunday, May 10, 2020

Docker Intro

Go to hub.docker.com
search for ubuntu, centos, mysql

How to create custom image

Custom file --> is your --> own image

Dickerfile -> Docker scripting language

Traditionally  just to use a web server, we used to use physical machine, physical network, but these days we have a host a machine, we have a VM, and inside VM, we can run docker.



1. Install Redhat 8 on your system.

# docker ps
# docker ps -a

# yum install python36
# python3


# cat Dockerfile
FROM centos

RUN yum install python36 -y

# docker images
# docker images | grep exp

# docker build -t expanor:v1 /ws/

Now, your image is ready. Based on this image, you can launch 100s of other os instances

# docker run -it ==nme os2 nexpanor:v1
# docker ps
# python3

# vi Dockerfile
FROM centos
RUN yum install python36 -y


# docker rm -f $(docker ps -a -9)   # terminates all docker instalnces

# docker run -it --name os1 centos

Create a file on your VM
# yum install https -y
# vi index.html
Life is beautiful !!!
# docker run -it --name OS1 centos  # Create an OS docker instance OS1
# docker cp index.html os1:/var/www/html

On your docker instance, try to start the webserver
You will get error

Now, go ahead and start wen server on your VM.
# systemctl start httpd
# systemctl status htpd

look at the httpd service file at /usr/lib/systemd/system/httpd.service

Now, cat that file and look under

execStart
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND

now remove $OPTIONS and manually run the command below on docker

# /usr/sbin/httpd -DFOREGROUND

To find the IP address of docker, you can use inspect option
# docker inspect OS1

# docker rm -r os1

Review
#  mkdir /workfile; cd /workfile
# cat >>index.html
Welcome to my page !!!

# cat Dockerfile
FROM centos

RUN yum install httpd -y


# docker images
# docker build -t expanor:v1 /ws/

Now, your image is ready. Based on this image, you can create hundreds of other docker instances.

# docker imags  | grep exp  - to see your image you just created.

# docker ps
# docker run -it --name os2 expanor:v1
# docker ps

# cat Dockerfile
FROM centos

RUN yum install httpd -y

RUN yum install python36 -y
CMD python3

# docker build -it expanor:v2 /ws/

when you run above command, you will be at python prompt. just type exot() to close the doccer sesssion.

# docker ps
# docker rm -f $(docker ps = a =9)  # terminate att docker session

# docker run -it --name OS1 centos


Saturday, April 11, 2020

Ubuntu: Step by Step Guide to Install and Configure Nagios on Ubuntu 18.04

Step by step guide to install and configure Nagios on Ubuntu 18.04


Nagios is server monitoring tool freely available.
OS: Ubuntu 18.04
Nagios: nagios-4.4.5
Nagios Plugin: nagios-plugins-2.3.3

if test "nagios-plugins" = "gettext-tools"; then \
  /bin/mkdir -p /usr/local/nagios/share/gettext/po; \
  for file in Makefile.in.in remove-potcdate.sin    Makevars.template; do \
    /usr/bin/install -c -o nagios -g nagcmd -m 644 ./$file \
                    /usr/local/nagios/share/gettext/po/$file; \
  done; \
  for file in Makevars; do \
    rm -f /usr/local/nagios/share/gettext/po/$file; \
  done; \
else \
  : ; \
fi



1. We are going to build nagios from source code. First install the build dependencies on your system.
root@sam:~# apt-get install build-essential libgd-dev openssl libssl-dev unzip wget

2. Install apache, php
root@sam:~# apt-get install apache2 php libapache2-mod-php php-gd libgd-dev

3. Create nagios user
root@sam:~# groupadd nagcmd
root@sam:~# useradd -G nagcmd nagios
root@sam:~# id nagios
uid=1001(nagios) gid=1002(nagios) groups=1002(nagios),1001(nagcmd)

4. Installing Nagios
A. Installing Nagios Binary
B. Installing Nagios using source code

A. Nagios Binary installation
a. Go to github and download the software
https://www.nagios.org/downloads/nagios-core/thanks/?skip=1&t=1524771419
or
https://github.com/NagiosEnterprises/nagioscore/releases
root@sam:~# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.5/nagios-4.4.5.tar.gz

b. Extract the package
root@sam:~# tar xpf nagios-4.4.5.tar.gz
root@sam:~# ls
mysleep.sh  nagios-4.4.5  nagios-4.4.5.tar.gz  releases
root@sam:~# cd nagios-4.4.5/
root@sam:~/nagios-4.4.5# ./configure --with-command-group=nagcmd --with-nagios-group=nagios

may take a while to complete. Review the error if you get any.

Now, make it with the number of processor. I have 4 CPU core which will speed up the process..

# make -j4 all

You successfully compile your software. Now its time to install the software component.
root@sam:~/nagios-4.4.5# make install
root@sam:~/nagios-4.4.5# make install-init
root@sam:~/nagios-4.4.5# make install-daemoninit
root@sam:~/nagios-4.4.5# make install-config
root@sam:~/nagios-4.4.5# make install-commandmode
root@sam:~/nagios-4.4.5# make install-exfoliation

Now, copy event handlers script to libexec directory which provides multiple event triggers for Nagios web interface.
root@sam:~/nagios-4.4.5# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
root@sam:~/nagios-4.4.5# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Now, copy apache configuration to apache sites-available directory. After that add apache user to nagcmd group
root@sam:~/nagios-4.4.5# /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf
root@sam:~/nagios-4.4.5# usermod -a -G nagcmd www-data

3. Install the plugins
Nagios plugins enhance the functionality and add extra value to the product. Download from
https://www.nagios.org/downloads/nagios-plugins/

root@sam:~# wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
root@sam:~# tar -xpf nagios-plugins-2.3.3.tar.gz; cd nagios-plugins-2.3.3/

Configure nagios with open ssh support
check for errors
root@sam:~/nagios-plugins-2.3.3# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --with-openssl

Now, same way before, run make command and install the plugins
# make -j 4
# make install


Some configuration change to let nagios to process all config files with .cfg at specified location.
So, just uncomment the line cfg_dir=/usr/local/nagios/etc/servers

Open nagios config file and uncomment the
root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/nagios.cfg
root@sam:~/nagios-plugins-2.3.3# mkdir /usr/local/nagios/etc/servers

If you like, you can change the email address so that you get notification by editing the file below,

root@sam:~/nagios-plugins-2.3.3# vi /usr/local/nagios/etc/objects/contacts.cfg
Change email to your email
email                   nagios@localhost to email your@companyemail.com


Set up Apache with an authentication gateway

Now, set up apache virtual host for nagios and authentication gateway to prevent unauthorized access to your system.

Add following apache configuration to /etc/apache2/conf-available/nagios.conf
root@sam:~/nagios-plugins-2.3.3# vi /etc/apache2/conf-available/nagios.conf

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

<Directory "/usr/local/nagios/sbin">
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

Alias /nagios "/usr/local/nagios/share"

<Directory "/usr/local/nagios/share">
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Restricted Area"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user
</Directory>

Set up authentication gateway to authenticate with user nagiosadmin. You can use different user but but you have to make other configuration changes. This is going ot be Nagios admin user.

root@sam:~/nagios-plugins-2.3.3# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Now enable the Apache modules and restart apache.
root@sam:~/nagios-plugins-2.3.3# a2enconf nagios
root@sam:~/nagios-plugins-2.3.3# a2enmod cgi rewrite
root@sam:~/nagios-plugins-2.3.3# systemctl restart apache2
root@sam:~/nagios-plugins-2.3.3# echo $?
0

Now, Verify and start Nagios and enable to start @boot
before you use it, verify the configuration.
root@sam:~/nagios-plugins-2.3.3# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Got the output as ...

Things look okay - No serious problems were detected during the pre-flight check
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl start nagios
root@sam:~/nagios-plugins-2.3.3# systemctl status nagios
root@sam:~/nagios-plugins-2.3.3# systemctl enable nagios

If you need to create nagios service, copy the following content to nagios.service since it does not start automatically.
root@sam:~/nagios-plugins-2.3.3# cat /etc/systemd/system/abc123nagios.service.bk
[Unit]
Description=Nagios
BindTo=network.target

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
User=nagios
group=nagcmd
# Remove line below to enable
#ExecStart=/usr/local/nagios/bin/nagios /use/local/nagios/etc/nagios.cfg

once you save it, enable the service
# systemctl enable /etc/systemd/system/nagios.service
# systemctl start nagios

Now, its time to access nagios through the web. It will prompt you for passwd, just use nagiosadmin user and the password you set it for the account

http://your_ip/nagios


Got help from,
https://draculaservers.com/tutorials/install-nagios-ubuntu/
https://linuxconfig.org/install-nagios-on-ubuntu-18-04-bionic-beaver-linux


Friday, April 10, 2020

Linux - BPF Tools -> high performance packet filtering

eBPF - Berkeley Packet Filter
 enables programmers to write code which gets executed in kernel space in a more secure and restricted environment. Yet this environment enables them to create tools which otherwise would require writing a new kernel module.

eBPF introduces a new syscall, bpf(2). This syscall is used for all eBPF operations like loading programs, attaching them to certain events, creating eBPF maps and access the map contents from tools.


echo "deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main" | sudo tee /etc/apt/sources.list.d/iovisor.list
deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main

# echo "deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main" | sudo tee /etc/apt/sources.list.d/iovisor.list deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main

echo "deb [trusted=yes] https://repo.iovisor.org/apt/xenial xenial-nightly main" | sudo tee /etc/apt/sources.list.d/iovisor.list



root@sam:~# apt-get update
Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease
Get:2 http://dl.google.com/linux/chrome/deb stable Release [943 B]
Get:3 http://dl.google.com/linux/chrome/deb stable Release.gpg [819 B]
Hit:4 http://archive.ubuntu.com/ubuntu bionic InRelease
Err:3 http://dl.google.com/linux/chrome/deb stable Release.gpg
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
Hit:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Ign:6 https://repo.iovisor.org/apt/xenial xenial-nightly InRelease
Hit:7 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:8 https://repo.iovisor.org/apt/xenial xenial-nightly Release
Hit:9 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Ign:10 https://repo.iovisor.org/apt/xenial xenial-nightly Release.gpg
Fetched 819 B in 1s (1,022 B/s)
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://dl.google.com/linux/chrome/deb stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release.gpg  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 78BD65473CB3BD13
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@sam:~# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 78BD65473CB3BD13
Executing: /tmp/apt-key-gpghome.0CeQj9iCln/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-key 78BD65473CB3BD13
gpg: key 7721F63BD38B4796: 8 duplicate signatures removed
gpg: key 7721F63BD38B4796: 18 signatures not checked due to missing keys
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" 17 new signatures
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" 1 new subkey
gpg: Total number processed: 1
gpg:            new subkeys: 1
gpg:         new signatures: 17
root@sam:~# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 78BD65473CB3BD13
Executing: /tmp/apt-key-gpghome.gI4uDLvk1F/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-key 78BD65473CB3BD13
gpg: key 7721F63BD38B4796: 8 duplicate signatures removed
gpg: key 7721F63BD38B4796: 18 signatures not checked due to missing keys
gpg: key 7721F63BD38B4796: "Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1
root@sam:~# apt-get update
Ign:1 http://dl.google.com/linux/chrome/deb stable InRelease
Get:2 http://dl.google.com/linux/chrome/deb stable Release [943 B]
Get:3 http://dl.google.com/linux/chrome/deb stable Release.gpg [819 B]
Hit:4 http://archive.ubuntu.com/ubuntu bionic InRelease
Ign:5 https://repo.iovisor.org/apt/xenial xenial-nightly InRelease
Hit:6 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Get:7 http://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,109 B]
Hit:8 https://repo.iovisor.org/apt/xenial xenial-nightly Release
Hit:9 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Ign:10 https://repo.iovisor.org/apt/xenial xenial-nightly Release.gpg
Hit:11 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Fetched 1,928 B in 1s (2,201 B/s)
Reading package lists... Done
root@sam:~#

Install BCC tools
root@sam:/usr/share# apt-get install binutils bcc bcc-tools libbcc-examples python-bcc

Add man path and command path
# export MANPATH=$MANPATH:/usr/share/bcc/man
# export PATH=$PATH:/usr/share/bcc/tools
Test with python command

root@sam:/usr/share# python /usr/share/bcc/examples/hello_world.py

# python /usr/share/bcc/examples/tracing/task_switch.py
.................
task_switch[ 4055->    0]=322
task_switch[    0->   34]=1
task_switch[ 3757->29449]=1
task_switch[17211->    0]=5
task_switch[ 4037->17325]=1
task_switch[ 4382-> 4385]=2
task_switch[    0->  487]=1
task_switch[    0-> 4079]=15
task_switch[ 4084->17326]=1
task_switch[ 2346->    0]=1
task_switch[ 3757-> 4385]=1
task_switch[32002-> 3757]=2
task_switch[17327-> 3757]=1


Some BCC tools in ubuntu
1. ardist command displays function marameter values as a histogram or frequency count

root@sam:/usr/share/bcc/tools# ./argdist -h

histogram of buffer sizes passed to the write() function across the system

root@sam:/usr/share/bcc/tools# ./argdist -c -H 'p:c:write(int fd, void *buf, size_t len):size_t:len'

2. biosnop - traces block device I/O (disk I/O), and prints a line of output per I/O
root@sam:/usr/share/bcc/tools# ./biosnoop

root@sam:/usr/share/bcc/tools# iostat -x 1
Command 'iostat' not found, but can be installed with:
apt install sysstat
root@sam:/usr/share/bcc/tools#

3. biolatency - traces block device I/O (disk I/O), and records the distribution of I/O latency
root@sam:/usr/share/bcc/tools# ./biolatency

4. ext4slower - shows I/O slower
root@sam:/usr/share/bcc/tools# ./ext4slower 1

5. bashreadline tool - prints bash commands from all running bash shells on the system
root@sam:/usr/share/bcc/tools# bashreadline
TIME      PID    COMMAND
03:23:13  8277   sh myfile.sh

6. biotop - block device I/O top
root@sam:/usr/share/bcc/tools# biotop


Got idea from
https://opensource.com/article/17/11/bccbpf-performance
http://www.brendangregg.com/bpf-performance-tools-book.html
https://www.amazon.com/gp/reader/0136554822
http://www.brendangregg.com/blog/2019-07-15/bpf-performance-tools-book.html
https://linoxide.com/linux-how-to/bcc-kernel-tracing-tools-linux-performance/
https://github.com/iovisor/bcc
https://www.redhat.com/en/blog/introduction-ebpf-red-hat-enterprise-linux-7

Friday, March 27, 2020

Splunk - Install splunk on linux


These steps are followed based on tutorial available on Linkedin for SPLUNK set up

1. Install virtual box -
https://www.virtualbox.org/wiki/Downloads

2. Copy the config file on any directory and run the command on your windows machine

a. Go to that directory and copy the file.
C:\KB\Splunk\2. Getting Started\2.1 Ex_Files_Learning_Splunk.zip\Exercise Files\Vagrantfile
to
E:\Virtual Machines\splunk
This file is simply ruby script file which are Vagrant specific configuration options to configure VMs.
It has all VMs and defined how they interact.
b. Open up powershell and go to the directory and run vagrant up command
> cd E:\Virtual Machines\splunk
> vagrant up

It will initiate an installation process. It will take a while to install everything.


3.  Install Vagrant - (Vagrant is a simply way to  manage virtual machines)
https://www.vagrantup.com/downloads.html

4. Now, open Powershell and cd to E:\Virtual Machines\splunk where you copied the vagrant file. and Run vagrant up command.

> vagrant up

It will install all required VMs on your virtual box.

Note: If you get an error about hyper visor on ur windows machine, go to start menu and type "turn win"
you will see Turn windows features on or off. click on that and go down and find Hyper-v, if its check, uncheck.

sometime, you may have to go to BIOS and disable it.

5. What is splunk?
It is an enterprise tool to manage data.
It is a single place to collect data.
It is used for system logs and machine data.
It collects all your data in one place and and helps you to search, generate report and helps you to visualize your data.
You can also use SPLUNK to triger alerts based on your data..
It comes with free version and Enterprise version.

6. By now, vigrant boxes are booting. You should be able to login and install splunk.
a. Now, download the Splunk.
Go to splunk and go to download.
When click on download link, you will see useful Tools on right side on splunk page. Click on Download via command link (wget). click on link and copy the link.

Download the OS type file. I am downloading for Linux.
https://www.splunk.com/en_us/download/splunk-enterprise.html#tabs/linux
wget -O splunk-8.0.2.1-f002026bad55-linux-2.6-amd64.deb 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=8.0.2.1&product=splunk&filename=splunk-8.0.2.1-f002026bad55-linux-2.6-amd64.deb&wget=true'

Note: download the free version (Splunk Free) not the free trial enterprise edition.
You have to create an account to download.

b. Go to powershell window. You should cd to vagrant file location and issue a command vagrant ssh splunk to login to splunk VM.

PS E:\Virtual Machines\splunk> vagrant ssh splunk
vagrant@127.0.0.1: Permission denied (publickey).

Got an error: Permission denued (publickey)

PS C:\WINDOWS\system32> vagrant ssh splunk
A Vagrant environment or target machine is required to run this
command. Run `vagrant init` to create a new Vagrant environment. Or,
get an ID of a target machine from `vagrant global-status` to run
this command on. A final option is to change to a directory with a
Vagrantfile and to try again.
PS C:\WINDOWS\system32> vagrant.exe global-status
id       name   provider   state   directory
-----------------------------------------------------------------------
820d9e5  splunk virtualbox running E:/Virtual Machines/splunk

c. Find the error with debug option, what is really going on.
PS E:\Virtual Machines\splunk> vagrant ssh splunk --debug
.............................................................

DEBUG safe_exec: Command: `"C:\\WINDOWS\\System32\\OpenSSH\\/ssh.EXE"` Args: `["vagrant@127.0.0.1", "-p", "2222", "-o", "LogLevel=FATAL", "-o", "Compression=yes", "-o", "DSAAuthentication=yes", "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "-i", "E:/VirtualMachines/splunk/.vagrant/machines/splunk/virtualbox/private_key"]
vagrant@127.0.0.1: Permission denied (publickey).


d. Renamed this file: E:/Virtual Machines/splunk/.vagrant/machines/splunk/virtualbox/private_key to 111private_key_222

e. Now, login to splunk

PS E:\Virtual Machines\splunk> vagrant ssh splunk
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-176-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * Latest Kubernetes 1.18 beta is now available for your laptop, NUC, cloud
   instance or Raspberry Pi, with automatic updates to the final GA release.

     sudo snap install microk8s --channel=1.18/beta --classic

 * Multipass 1.1 adds proxy support for developers behind enterprise
   firewalls. Rapid prototyping for cloud operations just got easier.

     https://multipass.run/

0 packages can be updated.
0 updates are security updates.

New release '18.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


vagrant@splunk:~$

Become root user
vagrant@splunk:~$ sudo su -
root@splunk:~#

7. Install Splunk
Note: Do not install splunk as a root user at work place. Its my lab, so I am fine.
Now, at the prompt, paste the copied link.
# wget -O splunk-8.0.2.1-f002026bad55-linux-2.6-amd64.deb 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=8.0.2.1&product=splunk&filename=splunk-8.0.2.1-f002026bad55-linux-2.6-amd64.deb&wget=true'

splunk-8.0.2.1-f002026bad55-l 100%[=================================================>] 374.11M  5.86MB/s

It will download the file on current directory

a. Install the package
root@splunk:~# dpkg -i splunk-8.0.2.1-f002026bad55-linux-2.6-amd64.deb

press q and y to accept the license and continue.

It may prompt you for password. this is the password for your splunk.
at the end of the installation, it will give you the address path with port.

if it didn't prompt you for password, you have to go throug splunk start/stop command.

go to bin directory and run splunk start command. (use flag --accept-license)
root@splunk:/opt/splunk/bin# cd /opt/splunk/bin
root@splunk:/opt/splunk/bin# ./splunk start --accept

type q and y to accept the license.

it will propmpt you to enter admin username:


Please enter an administrator username: myadmin
Please confirm new password:


to start splunk at boot run the command
root@splunk:/opt/splunk/bin# ./splunk enable boot-start -user myadmin
root@splunk:/opt/splunk/bin# systemct enable splunk
root@splunk:/opt/splunk/bin# systemctl start splunk
root@splunk:/opt/splunk/bin# ./splunk star



Now, go to web address on the browser and use the IP and port to login.

8. Shutdown Vagrant manage VMs

PS E:\Virtual Machines\splunk> vagrant halt

=====================================

If you don't want to go through all this hassle, use centos.

Download the splunk package
# wget -O splunk-8.0.2.1-f002026bad55-linux-2.6-x86_64.rpm 'https://www.splunk.com/bin/splunk/DownloadActivityServlet?architecture=x86_64&platform=linux&version=8.0.2.1&product=splunk&filename=splunk-8.0.2.1-f002026bad55-linux-2.6-x86_64.rpm&wget=true'

# rpm -ivh splunk-8.0.2.1-f002026bad55-linux-2.6-x86_64.rpm
# cd /opt/splunk/bin
# ./splunk start -accept
# ./splunk start

You will get IP:PORT, paste on browser, use the user/pw to login.

Enjoy !!!

Friday, March 13, 2020

RHEL7 - How to join Redhat machine to Windows Active directory

Join RHEL7 System to Active directory domain

1. Install realm and sssd packages
# yum install reammd sssd

# rpm -qa | egrep "realmd|sssd"

2. Join the A/D domain
# realm join ad.it.business.com -U svc-aduser
Enter the pw:

3. Edit sssd.conf file and change use fully qualified names to False
so that you don't have to type @ad.it.business.com

# vi /etc/sssd/sssd.conf
use_fully_qualified_names = False

4. Permit user to login
# realm permit bhusal


If you want to install GUI
# yum grouplist
# yum groupinstall "Server with GUI"
# shutdown -r now

Monday, March 2, 2020

RHEL - Creating 10TB filesystem on rhel7

Note:
Something to know ...

Rescan the SCSI bus
# echo "- - -" > /sys/class/scsi_host/host0/scan

To expand the same LUN, perform the following task
# echo 1 > /sys/class/scsi_device/device/rescan

Verify
# fdisk -l



$ sudo fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 268.4 GB, 268435456000 bytes, 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: EA4D9CB5-6A7C-417B-90B0-BF71AF7BB69F

#         Start          End    Size  Type            Name
1         2048         4095      1M  BIOS boot
2         4096      2101247      1G  Microsoft basic
3      2101248    524285951    249G  Linux LVM

Disk /dev/sdb: 10995.1 GB, 10995116277760 bytes, 21474836480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vg0-root: 37.6 GB, 37580963840 bytes, 73400320 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vg0-swap: 4160 MB, 4160749568 bytes, 8126464 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vg0-01: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vg0-00: 220.2 GB, 220242903040 bytes, 430161920 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

$ sudo parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
(parted) help
  align-check TYPE N                       check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a
        particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END

  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) unit TB
(parted) mkpart primary 0 0
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
1      0.00TB  0.00TB  0.00TB               primary

(parted) mkpart primary 0 11
Warning: You requested a partition from 0.00TB to 11.0TB (sectors 0..21474836479).
The closest location we can manage is 0.00TB to 0.00TB (sectors 34..2047).
Is this still acceptable to you?
Yes/No? n
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
1      0.00TB  0.00TB  0.00TB               primary

(parted) help
  align-check TYPE N                       check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a
        particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END

  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
(parted) rm 1
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 0 11
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
1      0.00TB  11.0TB  11.0TB               primary

(parted) q
Information: You may need to update /etc/fstab.

$ sudo parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 11.0TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
1      1049kB  11.0TB  11.0TB               primary

(parted) q

$ sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
$ sudo vgcreate datavg /dev/sdb1
sudo vgs  Volume group "datavg" successfully created
$ sudo vgs
  VG     #PV #LV #SN Attr   VSize    VFree
  datavg   1   0   0 wz--n-  <10.00t <10.00t
  vg0      1   4   0 wz--n- <249.00g   4.00m
$ sudo lvcreate -n nesslv -L +99G datavg
  Logical volume "nesslv" created.
$ sudo mkfs.xfs /dev/datavg/nesslv
$ sudo lvremove /dev/datavg/nesslvsudo lvremove /dev/datavg/nesslv
$ sudo lvremove /dev/datavg/nesslv
Do you really want to remove active logical volume datavg/nesslv? [y/n]: y
  Logical volume "nesslv" successfully removed
$ sudo lvcreate -n nesslv -L +10T datavg
  Volume group "datavg" has insufficient free space (2621439 extents): 2621440 required.
$ sudo lvcreate -n nesslv -L +9.9T datavg
  Rounding up size to full physical extent 9.90 TiB
  Logical volume "nesslv" created.
$ sudo mkfs.xfs /dev/datavg/nesslv
meta-data=/dev/datavg/nesslv     isize=512    agcount=10, agsize=268435455 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2657511424, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
$ sudo vi /etc/fstab
$ sudo mkdir /1opt1
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
devtmpfs               32G     0   32G   0% /dev
tmpfs                  32G     0   32G   0% /dev/shm
tmpfs                  32G   20M   32G   1% /run
tmpfs                  32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/vg0-root   35G  1.5G   34G   5% /
/dev/mapper/vg0-01    5.0G  100M  4.9G   2% /var/log
/dev/mapper/vg0-00    206G  3.1G  202G   2% /opt
/dev/sda2            1014M  154M  861M  16% /boot
tmpfs                 6.3G     0  6.3G   0% /run/user/1001
$ sudo vgs
  VG     #PV #LV #SN Attr   VSize    VFree
  datavg   1   1   0 wz--n-  <10.00t 102.39g
  vg0      1   4   0 wz--n- <249.00g   4.00m
$ sudo vi /etc/fstab
$ ls /opt
sc
$ cd /opt
$ sudo du -sh *
3.1G    sc
$ more /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Feb 11 05:56:09 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg0-root    /                       xfs     defaults        0 0
UUID=31657a30-d845-4032-8f9b-b48fc75f23ed /boot                   xfs     defaults        0 0
##/dev/mapper/vg0-00      /1opt1                    xfs     defaults        0 0
/dev/mapper/vg0-01      /var/log                xfs     nosuid,noexec,nodev 0 0
/dev/mapper/vg0-swap    swap                    swap    defaults        0 0
####
/dev/mapper/vg0-00      /1opt1          xfs     defaults        0 0
/dev/datavg/nesslv      /opt            xfs     defaults        0 0
$ sudo reboot
Connection to 10.85.98.40 closed by remote host.
Connection to 10.85.98.40 closed.
                                                                                                                                v
---------------------------------------------------------------------------------------------------------------------------------

$ ssh admin@192.168..10
$ df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                    32G     0   32G   0% /dev
tmpfs                       32G     0   32G   0% /dev/shm
tmpfs                       32G   20M   32G   1% /run
tmpfs                       32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/vg0-root        35G  1.6G   34G   5% /
/dev/mapper/vg0-01         5.0G   92M  5.0G   2% /var/log
/dev/sda2                 1014M  141M  874M  14% /boot
/dev/mapper/datavg-nesslv  9.9T   33M  9.9T   1% /opt
/dev/mapper/vg0-00         206G  3.1G  202G   2% /1opt1
tmpfs                      6.3G     0  6.3G   0% /run/user/1001
$ cd /opt
$ ls
$ cd ..
$ cd /1opt1
$ ls
sc
$ tar -cf /opt/sc.tar sc
tar: /opt/sc.tar: Cannot open: Permission denied
tar: Error is not recoverable: exiting now
$ sudo tar -cf /opt/sc.tar sc
$ du -sh /opt/sc.tar
2.9G    /opt/sc.tar
$ cd /opt
$ ls
sc.tar
$ tar -xvf


#!/bin/bash

if [ ! "$(whoami)" == "chante" ]; then
  echo "Error: script must be run as the chante user"
  exit 1
fi

Friday, December 13, 2019

Print a large PDF poster onto multiple smaller sheets of paper at home

How to print a PDF poster with large pages onto multiple smaller sheets of paper at home?

If you like to print a large poster pdf file, you can use professional software such as photoshop or Corel but Acrobat Reader also has a feature to print single page file into multiple pages and join them together.


1. Open your pdf file in Adobe Reader.

2. Click on File -> Print

3. On the print dialog box, there is an option called Poster under Page Sizing & Handling, click on it.

4. Under Poster, the page will be break down into small pages.

5. You can print a highlight part page or all the pages. Click on print to print all parts of the page.

6. If can print just one part of your poster by just zooming and resizing the windows just to make sure you want to print is right.

7. Click on More Options and click on Current View to print a single portion of the file.