Sunday, September 1, 2019

How to Resize the / using LVM

How to Resize the / using LVM
==============================

Error Summary
-------------
Disk Requirements:
   At least 923MB more space needed on the / filesystem.

[root@thermalite ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                   tmpfs     3.9G  1.2M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G   15G  970M  94% /
tmpfs                   tmpfs     3.9G  4.5M  3.9G   1% /tmp
/dev/sda2               ext4      976M  197M  713M  22% /boot
/dev/sda1               vfat      200M  8.7M  192M   5% /boot/efi
tmpfs                   tmpfs     787M  4.0K  787M   1% /run/user/1000

[root@thermalite ~]# fdisk -l
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: E39A4721-3CD4-4444-9A32-0F3EE22331B5

Device       Start        End    Sectors   Size Type
/dev/sda1     2048     411647     409600   200M EFI System
/dev/sda2   411648    2508799    2097152     1G Linux filesystem
/dev/sda3  2508800 1953523711 1951014912 930.3G Linux LVM


Disk /dev/mapper/fedora-root: 15 GiB, 16106127360 bytes, 31457280 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/fedora-swap: 7.8 GiB, 8388608000 bytes, 16384000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

[root@thermalite ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                   tmpfs     3.9G  1.2M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G   15G  971M  94% /
tmpfs                   tmpfs     3.9G  4.5M  3.9G   1% /tmp
/dev/sda2               ext4      976M  197M  713M  22% /boot
/dev/sda1               vfat      200M  8.7M  192M   5% /boot/efi
tmpfs                   tmpfs     787M  4.0K  787M   1% /run/user/1000

[root@thermalite ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 931.5G  0 disk
├─sda1            8:1    0   200M  0 part /boot/efi
├─sda2            8:2    0     1G  0 part /boot
└─sda3            8:3    0 930.3G  0 part
  ├─fedora-root 253:0    0    15G  0 lvm  /
  └─fedora-swap 253:1    0   7.8G  0 lvm  [SWAP]

[root@thermalite ~]# sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit GB
(parted) print
Model: ATA WDC WD10EZEX-00B (scsi)
Disk /dev/sda: 1000GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name                  Flags
 1      0.00GB  0.21GB  0.21GB  fat16        EFI System Partition  boot, esp
 2      0.21GB  1.28GB  1.07GB  ext4
 3      1.28GB  1000GB  999GB                                      lvm

(parted) q

[root@thermalite ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               fedora
  PV Size                 Allocatable           yes
  PE Size               4.00 MiB
  Total PE              238160
  Free PE               232320
  Allocated PE          5840
  PV UUID               etHzhN-vONC-31VY-qdA5-zcWx-Drsq-52CcO6

[root@thermalite ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  fedora lvm2 a--  930.31g 907.50g

[root@thermalite ~]# vgdisplay
  --- Volume group ---
  VG Name               fedora
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               930.31 GiB
  PE Size               4.00 MiB
  Total PE              238160
  Alloc PE / Size       5840 / 22.81 GiB
  Free  PE / Size       232320 / 907.50 GiB
  VG UUID               l3ifpd-93Wv-Y8Wl-4I31-CBnH-gxt5-2BYg7v

[root@thermalite ~]# vgdisplay -v
  --- Volume group ---
  VG Name               fedora
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               930.31 GiB
  PE Size               4.00 MiB
  Total PE              238160
  Alloc PE / Size       5840 / 22.81 GiB
  Free  PE / Size       232320 / 907.50 GiB
  VG UUID               l3ifpd-93Wv-Y8Wl-4I31-CBnH-gxt5-2BYg7v

  --- Logical volume ---
  LV Path                /dev/fedora/swap
  LV Name                swap
  VG Name                fedora
  LV UUID                sW7ldx-Jqwk-2Bxu-ptej-ekok-sKRg-Rd3H2a
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-08-04 16:53:32 -0400
  LV Status              available
  # open                 2
  LV Size                7.81 GiB
  Current LE             2000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/fedora/root
  LV Name                root
  VG Name                fedora
  LV UUID                SRHprS-qKyi-tNfo-f71c-UOEE-fBQL-y7rBYe
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-08-04 16:53:32 -0400
  LV Status              available
  # open                 1
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Physical volumes ---
  PV Name               /dev/sda3
  PV UUID               etHzhN-vONC-31VY-qdA5-zcWx-Drsq-52CcO6
  PV Status             allocatable
  Total PE / Free PE    238160 / 232320

[root@thermalite ~]# lvextend -L+100G /dev/fedora/root
  Size of logical volume fedora/root changed from 15.00 GiB (3840 extents) to 115.00 GiB (29440 extents).
  Logical volume fedora/root successfully resized.


[root@thermalite ~]# vgdisplay -v
  --- Volume group ---
  VG Name               fedora
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               930.31 GiB
  PE Size               4.00 MiB
  Total PE              238160
  Alloc PE / Size       31440 / 122.81 GiB
  Free  PE / Size       206720 / 807.50 GiB
  VG UUID               l3ifpd-93Wv-Y8Wl-4I31-CBnH-gxt5-2BYg7v

  --- Logical volume ---
  LV Path                /dev/fedora/swap
  LV Name                swap
  VG Name                fedora
  LV UUID                sW7ldx-Jqwk-2Bxu-ptej-ekok-sKRg-Rd3H2a
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-08-04 16:53:32 -0400
  LV Status              available
  # open                 2
  LV Size                7.81 GiB
  Current LE             2000
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/fedora/root
  LV Name                root
  VG Name                fedora
  LV UUID                SRHprS-qKyi-tNfo-f71c-UOEE-fBQL-y7rBYe
  LV Write Access        read/write
  LV Creation host, time localhost, 2018-08-04 16:53:32 -0400
  LV Status              available
  # open                 1
  LV Size                115.00 GiB
  Current LE             29440
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Physical volumes ---
  PV Name               /dev/sda3
  PV UUID               etHzhN-vONC-31VY-qdA5-zcWx-Drsq-52CcO6
  PV Status             allocatable
  Total PE / Free PE    238160 / 206720

[root@thermalite ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                   tmpfs     3.9G  1.2M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G   15G  971M  94% /
tmpfs                   tmpfs     3.9G  4.5M  3.9G   1% /tmp
/dev/sda2               ext4      976M  197M  713M  22% /boot
/dev/sda1               vfat      200M  8.7M  192M   5% /boot/efi
tmpfs                   tmpfs     787M  4.0K  787M   1% /run/user/1000

[root@thermalite ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 931.5G  0 disk
├─sda1            8:1    0   200M  0 part /boot/efi
├─sda2            8:2    0     1G  0 part /boot
└─sda3            8:3    0 930.3G  0 part
  ├─fedora-root 253:0    0   115G  0 lvm  /
  └─fedora-swap 253:1    0   7.8G  0 lvm  [SWAP]

[root@thermalite ~]# pvresize /dev/sda3
  Physical volume "/dev/sda3" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

[root@thermalite ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  fedora lvm2 a--  930.31g 807.50g

[root@thermalite ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  fedora   1   2   0 wz--n- 930.31g 807.50g

[root@thermalite ~]# lvextend -l +100%FREE /dev/mapper/fedora-root
  Size of logical volume fedora/root changed from 115.00 GiB (29440 extents) to 922.50 GiB (236160 extents).
  Logical volume fedora/root successfully resized.

[root@thermalite ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                   tmpfs     3.9G  1.2M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs        15G   15G  970M  94% /
tmpfs                   tmpfs     3.9G  4.5M  3.9G   1% /tmp
/dev/sda2               ext4      976M  197M  713M  22% /boot
/dev/sda1               vfat      200M  8.7M  192M   5% /boot/efi
tmpfs                   tmpfs     787M  4.0K  787M   1% /run/user/1000

[root@thermalite ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  fedora lvm2 a--  930.31g    0

[root@thermalite ~]# df -hT | grep mapper
/dev/mapper/fedora-root xfs        15G   15G  970M  94% /

[root@thermalite ~]# sudo resize2fs /dev/mapper/fedora-root
resize2fs 1.44.2 (14-May-2018)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/fedora-root
Couldn't find valid filesystem superblock.

[root@thermalite ~]# xfs_growfs /
meta-data=/dev/mapper/fedora-root isize=512    agcount=4, agsize=983040 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=3932160, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3932160 to 241827840
[root@thermalite ~]# df -hT | grep mapper
/dev/mapper/fedora-root xfs       923G   15G  908G   2% /
[root@thermalite ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  3.9G     0  3.9G   0% /dev
tmpfs                   tmpfs     3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                   tmpfs     3.9G  1.2M  3.9G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/mapper/fedora-root xfs       923G   15G  908G   2% /
tmpfs                   tmpfs     3.9G  4.5M  3.9G   1% /tmp
/dev/sda2               ext4      976M  197M  713M  22% /boot
/dev/sda1               vfat      200M  8.7M  192M   5% /boot/efi
tmpfs                   tmpfs     787M  4.0K  787M   1% /run/user/1000
[root@thermalite ~]# 
https://invalidmagic.wordpress.com/2012/04/28/booting-nixos-from-lvm-on-top-of-mdadm-using-gpt/

booting nixos from lvm on top of mdadm using GPT

PosgresSQL Error: "psql: could not connect to server: Connection refused"

Use nmap to get list of active IP addresses on the network

[malex@thermalite ~]$ nmap -sP 192.168.1.1/24

Starting Nmap 7.60 ( https://nmap.org ) at 2019-08-03 12:03 EDT
Nmap scan report for Fios_Quantum_Gateway.fios-router.home (192.168.1.1)
Host is up (0.00059s latency).
Nmap scan report for 192.168.1.100
Host is up (0.00011s latency).
Nmap scan report for 192.168.1.114
Host is up (0.0011s latency).
Nmap scan report for localhost.fios-router.home (192.168.1.151)
Host is up (0.0010s latency).
Nmap scan report for iPhone7-Cheche.fios-router.home (192.168.1.155)
Host is up (0.012s latency).
Nmap scan report for 192.168.1.157
Host is up (0.023s latency).
Nmap scan report for 192.168.1.223
Host is up (0.0061s latency).
Nmap scan report for raspberrypi312.fios-router.home (192.168.1.229)
Host is up (0.0042s latency).
Nmap scan report for raspberrypi313.fios-router.home (192.168.1.233)
Host is up (0.0054s latency).
Nmap scan report for raspberrypi313.fios-router.home (192.168.1.234)
Host is up (0.0053s latency).
Nmap scan report for raspberrypi1.fios-router.home (192.168.1.235)
Host is up (0.0052s latency).
Nmap scan report for RE6500-391.fios-router.home (192.168.1.248)
Host is up (0.0010s latency).
Nmap scan report for raspberrypi.fios-router.home (192.168.1.249)
Host is up (0.11s latency).
Nmap scan report for raspberrypi1.fios-router.home (192.168.1.250)
Host is up (0.0015s latency).
Nmap scan report for raspberrypi312.fios-router.home (192.168.1.254)
Host is up (0.015s latency).
Nmap done: 256 IP addresses (15 hosts up) scanned in 3.85 seconds
[malex@thermalite ~]$

Installing Jenkins on Fedora 28

1. Remove Java and Jenkins
   [root@thermalite ~]# yum remove jenkins
   [root@thermalite ~]# yum remove java

2. Install Jenkins, Java and Git
   [root@thermalite ~]# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
   [root@thermalite ~]# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
   [root@thermalite ~]# yum install jenkins java git -y

3. Start Jenkins service
   [root@thermalite ~]# systemctl start jenkins.service
   [root@thermalite ~]# systemctl stop jenkins.service
   [root@thermalite ~]# systemctl start jenkins.service
   [root@thermalite ~]# systemctl status jenkins.service

4. Check firewall
[root@thermalite ~]# firewall-cmd --get-active-zones
home
  interfaces: enp2s0

[root@thermalite ~]# firewall-cmd --list-all
home (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp2s0
  sources:
  services: ssh mdns samba-client dhcpv6-client http jenkins
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@thermalite ~]#

5. Open browser url: http://192.168.1.100:8080

6. Edit /etc/sysconfig/jenkins to change port from 8080 to 9191
     JENKINS_PORT="9191"

7. Restart Jenkins
[root@thermalite ~]# systemctl stop jenkins
[root@thermalite ~]# systemctl start jenkins
[root@thermalite ~]# systemctl status jenkins


sudo usermod -s /bin/bash jenkins
sudo usermod -m /var/lib/jenkins jenkins
sudo su - jenkins
curl -L https://get.rvm.io | bash -s stable --rails --autolibs=enabled

Installing a Raspbian

1. Download image from URL: https://downloads.raspberrypi.org/raspbian_lite_latest

2. Using win32 Disk Image program, write the 2019-06-20-raspbian-buster-full.img to the mini-sd card.

3. Raspbian stretch Lite default login Linux users. User management in Raspbian is done on the command line.

The default
user is pi , and the
password is raspberry .

You can add users and change each user's password.

4. install ssh
 $ sudo apt-get install openssh-server openssh-client

5. Alternatively, use systemctl to start the service
 $ sudo systemctl enable ssh
 $ sudo systemctl start sshapt-get

6. Add user malex
 $ sudo adduser malex

7. Add malex as sudoers
 $ sudo vi /etc/sudoers

 add:
 malex   ALL=(ALL:ALL) ALL

8. passwordless ssh
 $ sudo ls -al ~/.ssh/id_*.pub
 $ sudo ssh-keygen -t rsa -b 4096 -C "azmadriaga@gmail.com"
 $ sudo ssh-copy-id malex@192.168.1.100

9. sudo apt-get install nmap

10. sudo apt-get install xrdp

TBD



TBD


Thursday, October 20, 2016

Install Oracle JDK 8 and Apache Tomcat 8

Installing the Oracle JDK
=========================

1. sudo add-apt-repository ppa:webupd8team/java
2. sudo apt-get update
3. sudo apt-get install oracle-java8-installer
4. sudo update-alternatives --config java
5. sudo vi /etc/environment
 JAVA_HOME="/usr/lib/jvm/java-8-oracle"
6. source /etc/environment


Installing Apache Tomcat 8
==========================
1. sudo apt-get install tomcat8 tomcat8-docs tomcat8-admin tomcat8-examples
2. dpkg -L tomcat8
3. sudo vi /etc/tomcat8/server.xml

change port 8080 to 8081 since jenkins is using 8080

4. sudo /etc/init.d/tomcat8 restart
5. Check: http://localhost:8081
6. sudo vi /opt/tomcat/conf/tomcat-users.xml
7. sudo /etc/init.d/tomcat8 restart

Re-installing Tomcat 8
======================
1. Getting errors

 Errors were encountered while processing:
 tomcat8
 E: Sub-process /usr/bin/dpkg returned an error code (1)

2. sudo dpkg -P libtomcat8-java tomcat8-common tomcat8-docs tomcat8 tomcat8-examples tomcat8-admin

3. sudo apt-get purge libtomcat8-java tomcat8 tomcat8-admin tomcat8-common tomcat8-docs tomcat8-examples tomcat8-user

4. sudo reboot

Install Oracle JDK 8 and Apache Tomcat 8

Installing the Oracle JDK
=========================

1. sudo add-apt-repository ppa:webupd8team/java
2. sudo apt-get update
3. sudo apt-get install oracle-java8-installer
4. sudo update-alternatives --config java
5. sudo vi /etc/environment
   JAVA_HOME="/usr/lib/jvm/java-8-oracle"
6. source /etc/environment


Installing Apache Tomcat 8
==========================
1. sudo apt-get install tomcat8 tomcat8-docs tomcat8-admin tomcat8-examples
2. dpkg -L tomcat8
3. sudo vi /etc/tomcat8/server.xml
change port 8080 to 8081 since jenkins is using 8080

4. sudo /etc/init.d/tomcat8 restart
5. Check: http://localhost:8081
6. sudo vi /opt/tomcat/conf/tomcat-users.xml 
7. sudo /etc/init.d/tomcat8 restart



Re-installing Tomcat 8
======================
1. Getting errors

   Errors were encountered while processing:
   tomcat8
   E: Sub-process /usr/bin/dpkg returned an error code (1)

2. sudo dpkg -P libtomcat8-java tomcat8-common tomcat8-docs tomcat8 tomcat8-examples tomcat8-admin

3. sudo apt-get purge libtomcat8-java tomcat8 tomcat8-admin tomcat8-common tomcat8-docs tomcat8-examples tomcat8-user

4. sudo reboot








Install Oracle JDK 8 and Apache Tomcat 8

Installing the Oracle JDK
=========================

1. sudo add-apt-repository ppa:webupd8team/java
2. sudo apt-get update
3. sudo apt-get install oracle-java8-installer
4. sudo update-alternatives --config java
5. sudo vi /etc/environment
   JAVA_HOME="/usr/lib/jvm/java-8-oracle"
6. source /etc/environment


Installing Apache Tomcat 8
==========================
1. sudo apt-get install tomcat8 tomcat8-docs tomcat8-admin tomcat8-examples
2. dpkg -L tomcat8
3. sudo vi /etc/tomcat8/server.xml
change port 8080 to 8081 since jenkins is using 8080

4. sudo /etc/init.d/tomcat8 restart
5. Check: http://localhost:8081
6. sudo vi /opt/tomcat/conf/tomcat-users.xml 
7. sudo /etc/init.d/tomcat8 restart



Re-installing Tomcat 8
======================
1. Getting errors

   Errors were encountered while processing:
   tomcat8
   E: Sub-process /usr/bin/dpkg returned an error code (1)

2. sudo dpkg -P libtomcat8-java tomcat8-common tomcat8-docs tomcat8 tomcat8-examples tomcat8-admin

3. sudo apt-get purge libtomcat8-java tomcat8 tomcat8-admin tomcat8-common tomcat8-docs tomcat8-examples tomcat8-user

4. sudo reboot









Installing monit in Ubuntu (IP: 10.20.30.40)


1. Repair missing LSB tags on tomcat and vncserver and other daemon as well

   $ sudo vi tomcat 
   $ sudo vi vncserver 
  
  add this after shebang
  
  ### BEGIN INIT INFO
  # Provides:          skeleton
  # Required-Start:    $remote_fs $syslog
  # Required-Stop:     $remote_fs $syslog
  # Default-Start:     2 3 4 5
  # Default-Stop:      0 1 6
  # Short-Description: Example initscript
  # Description:       This file should be used to construct script
  #                    placed in /etc/init.d.
  ### END INIT INFO
  
  
2. Install monit
   $ sudo apt-get install monit
   
   
3. Edit /etc/monit/monitrc
$ sudo vi /etc/monit/monitrc

3.1. Uncomment this section:

set httpd port 2812 and
         use address 10.20.30.40 # only accept connection from localhost
         allow 0.0.0.0/0.0.0.0   # allow localhost to connect to the server and
         allow admin:monit      # require user 'admin' with password 'monit'
         allow @users readonly  # allow users of group 'users' to connect readonly 

3.2. Append at the end of the config

# monitor sshd
check process sshd with pidfile /var/run/sshd.pid
#
# monitor jenkins
check process jenkins with pidfile /var/run/jenkins/jenkins.pid
#
# monitor apache2
check process apache2 with pidfile /var/run/apache2/apache2.pid


4. Install upstart
$ sudo apt-get install upstart-sysv

5. Reload monit
$ sudo reload monit

OR

$ sudo service monit restart

6. Open browser and check
http://10.20.30.40:2812/