preloader
  • Home
  • Deploying OCS Inventory on Ubuntu 22.04 LTS Using Docker

Hardware and software inventory management

blog-thumb

Open Computers and Software inventory as an IT asset management solution.

Imagine having a magical tool that effortlessly keeps track of every device and software in your small or medium-sized business. With Open Computers and Software (OCS), that dream becomes a reality. From managing inventory to tracking software licenses, OCS streamlines operations, boosts efficiency, and ensures nothing slips through the cracks. Say goodbye to guesswork and hello to organized simplicity with OCS!


OCS software

OCS is open source software that allows you to scan and inventory all the devices in an IT department.

The data collected contains information on hardware and software, which in turn can be used to plan software updates and hardware lifecycles. These controls make it possible to keep the IT environment more secure.

OCS uses plugins to make collections more assertive, which increases the flexibility of adoption for several different systems.

To find out more about OCS Inventory click here.


There are 2 ways to implement OCS:

- Linux packages

- Containers


In this article I’ll show you how to implement OCS using official container images.

If you don’t know anything about Docker and Podman, don’t worry. It’s not as complicated as it looks.



Podman

Podman is a replacement for Docker. It can run containers without the need to have a Podman service running, which lightens the load on the server. We also have the advantage of it being 100% compatible with Docker, which makes the transition even easier.


Preparing the Operating System

The first thing you should do is update the operating system.

sudo apt update

Now install Podman and its requirements:

sudo apt install podman python3-pip
sudo pip3 install podman-compose

That’s it for the OS. In the next step we’ll see how to install OCS using the official Docker image.


Persistent Volume

By nature, containers are ephemeral. Their data is lost when they are deactivated, and this is good from a software consistency perspective. However, it’s definitely not good for applications that need to keep stored data.

Data persistence will ensure that all the information recorded in the OCS is not lost.

The official OCS image already creates persistent volumes, so data won’t be lost when the container is stopped.

For information purposes (you don’t need to do this now), the operation to create a persistent volume is very simple. Just run the commands below.

podman volume create ocsinventory
podman volume ls
podman volume rm ocsinventory


Installing OCS via Docker Image

First, get the OCS image configuration:

git clone https://github.com/OCSInventory-NG/OCSInventory-Docker-Image
cd OCSInventory-Docker-Image/latest

Replace the name of the images and their tags in the docker-compose.yml file:

grep image docker-compose.yml

image: ocsinventory/ocsinventory-docker-image:2.11
image : mysql:8.0
image: nginx
sed -i s@image\ :\ mysql:8.0@image:\ docker.io/library/mysql:8.0.32@g docker-compose.yml
sed -i s@image:\ nginx@image:\ docker.io/library/nginx:latest@g docker-compose.yml
sed -i s@image:\ ocsinventory/ocsinventory-docker-image:2.11@image:\ docker.io/ocsinventory/ocsinventory-docker-image:2.11@g docker-compose.yml

Check that the replacements have been made correctly:

grep image docker-compose.yml

image: docker.io/ocsinventory/ocsinventory-docker-image:2.11
image: docker.io/library/mysql:8.0.32
image: docker.io/library/nginx:latest

Note: The above substitutions are intended to prevent unwanted images from being used. For security purposes, it is important that the registry that should be used to download the images is specified.

Build Compose:

sudo TZ=America/Sao_Paulo podman-compose up -d

Many messages will be displayed on the screen after the above command.

- Check that all operations have taken place without errors(exit 0).


Podman Compose Up



MySQL Container

MySQL



OCS Inventory Container

MySQL



NGINX Container

Check that all persistent volumes have been created:

sudo podman volume ls
  DRIVER VOLUME NAME
  local 211_httpdconfdata
  local 211_ocsreportsdata
  local 211_perlcomdata
  local 211_sqldata
  local 211_varlibdata

Check that the containers are running:

sudo podman ps
  CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  c49e6d515797 docker.io/library/mysql:8.0.32 mysqld 2 minutes ago Up 2 minutes ago ocsinventory-db
  012a434e1b83 docker.io/ocsinventory/ocsinventory-docker-image:2.11 /usr/sbin/apache2... 2 minutes ago Up 2 minutes ago ocsinventory-server
  eb21189e45ef docker.io/library/nginx:latest nginx -g daemon o... 2 minutes ago Up 2 minutes ago 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp ocsinventory-proxy

That’s it. OCS online. That was easy, wasn’t it?

Now it’s time to access the OCS web interface!

http://YOUR-SERVER-IP/ocsreports/

OCS First Use

The first access makes some criticisms. Don’t worry, we’ll adjust them.

For now, just click on the “Perform the update” button. Don’t do anything else, as we need to adjust some settings.

Adjusting Variables

First, access the OCS container and look for the php.ini file:

sudo podman exec -it ocsinventory-server bash

root@012a434e1b83:/etc/apache2/conf-available# find / -name php.ini 2> /dev/null
  /etc/php/8.1/cli/php.ini
  /etc/php/8.1/apache2/php.ini

We will adjust the variables below in the /etc/php/8.1/apache2/php.ini file, which refers to Apache.

First, collect the original values:

root@012a434e1b83:/etc/apache2/conf-available# egrep "max_execution_time|memory_limit|post_max_size|file_uploads|upload_max_filesize" /etc/php/8.1/apache2/php.ini

    max_execution_time = 30
    memory_limit = 128M
    post_max_size = 8M
    file_uploads = On
    upload_max_filesize = 2M

The standard configuration isn’t bad, but we need to make some adjustments.

sed -i s@max_execution_time\ =\ 30@max_execution_time\ =\ 300@g /etc/php/8.1/apache2/php.ini
sed -i s@memory_limit\ =\ 128M@memory_limit\ =\ 256M@g /etc/php/8.1/apache2/php.ini
sed -i s@post_max_size\ =\ 8M@post_max_size\ =\ 128M@g /etc/php/8.1/apache2/php.ini
sed -i s@upload_max_filesize\ =\ 2M@upload_max_filesize\ =\ 64M@g /etc/php/8.1/apache2/php.ini

The end result should look like this:

max_execution_time = 300
memory_limit = 256M
post_max_size = 128M
file_uploads = On
upload_max_filesize = 64M

Restart the OCS so that the changes take effect:

sudo podman restart ocsinventory-server
sudo podman restart ocsinventory-proxy



OCS configuration

OCS configuration is done via a web browser.

Go to http://YOUR-SERVER-IP/ocsreports/.

The default login is admin/admin. Make sure you change it the first time you log in!

After logging in, create a user account to register the assets. Go to:

Configuration > Users > Create User

Create an account named ocs with the password inventory, and profile Administrator.

NOTE: This is just an example. See the documentation on how to create more restrictive roles that can be used to register assets in the OCS.

Adding Assets to OCS

Adding assets requires agents. Agents can be obtained from the OCS website. In this example, I’m going to install the agent on a Linux Ubuntu.

In the case of Ubuntu, you don’t need to obtain the agent manually. Just install it via APT.

apt install ocsinventory-agent

During installation, select http method and enter the OCS URL:

http://IP-DO-SEU-SERVIDOR/ocsinventory

Note: The server configuration will be stored in the file:

/etc/ocsinventory/ocsinventory-agent.cfg

Some customizations can be done to this file.

Example:

sudo cat /etc/ocsinventory/ocsinventory-agent.cfg

  server=http://<SEU-IP>/ocsinventory
  basevardir = /var/lib/ocsinventory-agent
  tag = ocs.homelabs.net
  logger = Stderr
  logfile = /var/log/ocsinventory-client/ocsinventory-agent.log

Manually run the agent to do the first collection:

sudo ocsinventory-agent

After collection, go to OCS and click on All computers.

OCS Dashboard

By default, the OCS agent is configured to communicate with the server once a day via a daily cron job.

The job configuration is stored in the file /etc/cron.daily/ocsinventory-agent.

Plugins

OCS supports numerous plugins, which increase its capacity to work with inventoried data.

OCS Plugins



The end

There are commercial tools on the market that aim to do the same thing as OCS. However, due to the high cost, OCS remains an excellent solution for those who need to keep track of their hardware and software inventory.


Did you like the content? Check out these other interesting articles! 🔥



Support us 💖

Do you like what you find here? With every click on a banner, you help keep this site alive and free. Your support makes all the difference so that we can continue to bring you the content you love. Thank you very much! 😊

comments powered by Disqus