Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Monday, October 9, 2023

Useful Linux Commands

Some useful Linux commands


  • cat

    cat [file]

    • cat = dump file contents to terminal; ls -l to ensure small file
  • df

    df -h

    • df = show disks space per partition
      • / = separate volume/disk for root os, logs
      • /data = separate volume/disk for websites, apps
    • -h = human readable size
  • grep

    grep [search] [files]

    • grep = filter results, look for patterns in files
    • Example: grep Error *.log
  • htop

    htop

    • htop = top list of processes, nicely colored; can sort, filter
  • kill

    kill [pid]

    • kill = force stop/kill a process; only use for 'hung' process
    • [pid] = pid from ps aux list
  • ls

    ls -lhtr [dir]

    • ls = list contents of directory
    • -l = details
    • -h = human readable sizes
    • -t = sort by time
    • -r = reverse sort, so new shows at bottom
    • -1 = just list names in a single column
    • Example: ls -lhtr logs/*
  • ps

    ps aux

    • ps = process list
    • a = all, including other users
    • u = user format
    • x = register format
    • Example: ps aux | grep nginx
  • reboot

    sudo reboot

    • reboot = reboot server; should not be needed; restart individual services
  • systemctl

    sudo systemctl [action] [process]

    • systemctl = manage services such as nginx, php-fpm
    • Example: sudo systemctl status nginx
    • Example: sudo systemctl restart nginx
    • Example: sudo systemctl status php-fpm
    • Example: sudo systemctl restart php-fpm
  • tail

    tail -f -n50 [file]

    • tail = returns the last few lines of a file
    • -n# = number of lines
    • -f = follow, useful for tailing an active log file
    • Example: tail -f logs/app.log
  • vim

    vim [file]

    • vim, vi = text editor; ls -l to ensure small file
    • arrow keys = move cursor
    • shift G = go to end of file
    • ctrl u = page up
    • ctrl d = page down
    • /[patttern] = search for pattern
    • esc = get out of most vi modes
    • :q = quit
    • :q! = quit without writing
    • :wq = write, quite
    • note, if quit a SSH session with a file vi-ed/open, be sure to SSH in again and cleanup the vi auto backup [file]~; vi-ing the original file again will prompt you about
    • Example: sudo vim /var/log/messages

-End of Document- 
Thanks for reading

Saturday, July 27, 2019

MongoDB 4.0 on Ubuntu 18.04 bionic


MongoDB is a cross-platform document-oriented database program. 
Classified as a NoSQL database program, MongoDB uses JSON-like documents with schema. 
Source: Wikipedia

MongoDB 4.0 was released on 2018-08-06

New 'wow' features of MongoDB 4.0:

  • multi-document ACID transactions
  • data type conversions
  • 40% faster shard migrations
  • non-blocking secondary replica reads

And some other niceties:
  • native visualizations with MongoDB Charts
  • Compass aggregation pipeline builder
  • Stitch serverless platform
  • SHA-2 authentication
  • Mobile database
  • HIPAA compliance to the MongoDB Atlas database service
  • free community monitoring service
  • Kubernetes integration

While the new features in MongoDB 4.0 are great, 
the latest Ubuntu version 18.04 official repository still installs MongoDB version 3.6

To get the current version of MongoDB
> mongo --version

To install MongoDB version 4.0, you need to install from MongoDB's repository.

Instructions to install MongoDB 4.0 and some hurdles I encountered follow:

1) Add the MongoDB repo
> sudo vi /etc/apt/sources.list.d/mongodb-org-4.0.list  
deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse  

2) Add MongoDB the repo key
> sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4

3) Update your system
> sudo apt-get update

4) Install MongoDB 4.0
> sudo apt-get install mongodb-org

5) Status and restart MongoDB
> sudo systemctl status mongod
> sudo systemctl restart mongod

Hurdles:
If MongoDB does not start, there may be some issues with removing the prior MongoDB version.

Errors I encountered:
error processing archive /var/cache/apt/archives/mongodb-org-server_4.0.10_amd64.deb (--unpack):
error trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1.1
error trying to overwrite '/usr/bin/mongos', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1.1
error trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1

Some potential fixes
> sudo apt --fix-broken install
This by it self did not help

Remove prior MongoDB and other unused packages
> sudo apt autoremove
This did fix the issue and allow me to run MongoDB 4.0

To get version of MongoDB
> mongo --version

Also, if you accidentally tried to get the version from the daemon
> mongodb --version  
MongoDB will start as your user, often sudo/root,
which may cause some MongoDB files to be created as root.

You may have to reset user/group permissions
> sudo chown -R mongodb:mongodb /data/mongodb/


-End of Document-
Thanks for reading

Monday, April 2, 2018

Ubuntu 16.04 Xenial serve PHP7 using PHP7-fpm and Apache 2.4

Ubuntu 16.04 Xenial
Serve PHP7 using PHP7-fpm and Apache 2.4

By default, in Ubuntu 16.04 Xenial, installing the packages for PHP, PHP-fpm, and Apache does not result in a working php website.  The extra configuration required follows:

Install Apache2
> sudo apt-get -y install apache2

Install php, with some common packages
> sudo apt-get -y install php php-cli php-mbstring php-gd php-mcrypt php-pgsql php-mysql php-xml php-curl php-intl

Create your own apache vhost config

> vi /etc/apache2/sites-available/vhosts

<VirtualHost *:80>
    ServerName tutorial.localhost
    DocumentRoot /path/to/tutorial/web
    SetEnv APP_ENV "dev"
    <Directory /path/to/tutorial/web>
        AllowOverride All
        Require all granted #<-- 2.4 New configuration
    </Directory>
</VirtualHost>

Enable your vhost config
> sudo a2ensite vhosts

Disable the defualt config
> sudo a2dissite 000-default

And the missing parts of conflagration:

Enable php7-fpm
> sudo a2enconf php7.0-fpm

Enable rewrite so frameworks such as Symfony, Zend, Larvel, etc work with 'pretty' urls
enable proxy so apache can send php requests to php7-fpm
> sudo a2enmod rewrite proxy proxy_fcgi

And restart apache
> sudo systemctl restart apache2

PHP should be working now
> vi /path/to/webroot/phpinfo.php

<?php
phpinfo();

End of document. Thanks for reading.


Monday, January 8, 2018

Unable to use VirtualBox full screen

To enable the full functionality of VirtualBox, you often have to install Guest Additions, which enable features such as shared drives and better video support, such as being able to auto size the Guest VM display to the current dimensions of the VirtualBox gui, or to view the Guest VM in full screen.

“Guest Additions are designed to be installed inside a virtual machine after the guest operating system has been installed. They consist of device drivers and system applications that optimize the guest operating system for better performance and usability.”
VirtualBox Manual

When you upgrade the OS within a Guest VM, it’s kernel may change requiring you to re-install Guest Additions. You will know the Guest Additions need to be re-installed when basic features such as viewing the Guest VM in full screen no longer work.

Tuesday, January 2, 2018

VirtualBox Shared Folders

Within VirtualBox, you can enable shared drives to facilitate the transfer of files between the Guest VM and the Host computer.

To install VirtualBox you can follow this guide How to Install VirtualBox
To install a Ubuntu VM you can follow this guide How to Install a Ubuntu Virtual Machine.

To enable Shared Folder between the VirtualBox Host and Guest VM:

Monday, December 18, 2017

How to Install a Ubuntu Virtual Machine

VirtualBox is a cross-platform virtualization software, which allows you to run another Operating System (such as Ubuntu) from your current Operation System (such as Windows).  Using VirtualBox, you can try out, play with, test, or develop with other Operating Systems without having to reinstall your computer or potentially more complicated try to multi boot your computer.

In virtualization software terms, your computer is called the Host, while the other Operating Systems, or OSs for short, you install through the virtualization software, VirtualBox, are called Guests.  Guests are often called Virtual Machines, or Guest VMs, or VMs for short.  You can install as many Virtual Machines as you want.  So you can try Ubuntu, Mint Linux, Windows Insider, Windows Server, Mac OSX, etc all from within your current Windows or Linux Host. The Virtual Machines are also self contained within one folder so you can backup or transfer the Virtual Machine to another computer.  Thus you have a portable Operating System; of course, with the requirement of installing VirtualBox on the other Host computer.

The following steps will show you how to install a Ubuntu Virtual Machine, aka VM.