Stranice

Tuesday, 20 March 2018

RHCSA vs LFCS

On this blog, I would like the differentiate these two certificates. I am in process of learning linux operating system and I would like to get certified. My goal is to pinpoint the pros and cons of each certificate and differences between them related to the exam objectives.


                         RHCSA                                               LFCS

Price:             460 € + VAT                                      300$
Validity:        3 years                                                2 years
Free Retake:      No                                                  1 free retake
Pre-requisites:   No                                                  No
Exam duration:  2.5 hrs                                            2 hrs
Passing score:    not defined                                     74%

There is a long list of course objective on both sides, some are more detailed in RHCSA list.

Links to the exam objectives:

If we read the objectives we notice that many objectives are overlapping (maybe not positioned in the same area). 
There are many exam mocks for RHCSA and it is possible to take an assessment test on RedHat.
We can assess our knowledge using the following page: Red Hat Assesment

There is a section for RedHat 7 administration. I haven't tested it yet and it is unclear is it suitable for EX200 (RHCSA) or EX300 (RHCE).

There are many dumps for RHCSA and not many for LFCS. Since they overlap I will use RHCSA dumps. And try to follow LFCS exam objectives as much as possible.

Vagrant

Vagrant is an open-source software product for building and maintaining portable virtual software development environments,[4] e.g. for VirtualBoxHyper-VDockerVMware, and AWS which try to simplify software configuration management of virtualizations in order to increase development productivity. Vagrant is written in the Ruby language, but its ecosystem supports development in almost all major languages.

Vagrant is a nice tool and I really like it. Starting using Vagrant is simple but it can lead problems. The problems are not Vagrant related because the software is nice, but how other people support it.

I used it with Virtualbox and I will list some nice things and bad things related to the experience. The base of using vagrant is a box (compressed disk image file)

Nice things:

  • Easy to run a box
  • Good documentation
  • Lovely integration with Ansible (dynamic discovery)
  • support for multiple virtual machines
  • virtual machine customization
  • no demand for using the Ruby programming language (but it can help)
  • networking works out-of-the-box
  • private networking (connecting to assigned IP from the host)
  • greate user base with excellent "boxes"
Bad things:
  • Creating boxes is a complex process
  • Official boxes are broken (Ubuntu 16.04)
    Since it doesn't contain vagrant user functionality is limited and problematic
  • Links to boxes are not valid or not valid anymore
  • Some official boxes don't integrate virtualbox add-ons which can cause issues
  • Experimentation is needed to find suitable boxes
  • It doesn't use cloning feature of virtualbox and therefore if we use many virtual machines base box get expanded as many machines as we have
Vagrant is a nice tool that needs to be examined more. In following blog entries I will explain multi-machine setup.






Thursday, 7 January 2016

psqlrc (psql startup file) in Windows

We can have startup script in Windows and Linux when running psql (Postgresql command line interface). By using Postgresql documentation is obvious for Linux but for Windows it is not.
In windows there is cryptic notes %APPDATA%\postgresql\psqlrc.conf.

So let's explore what does it mean.
APPDATA is environment variable for Windows OS and we can get it very easily.
We open command line (CMD) and type following: echo %APPDATA%.
In Windows 7 some like this will be visible on the screen:
c:> cd C:\Users\User\AppData\Roaming (User is active user)

So when we combine the appdata directory and postgresql we get following:
C:\Users\User\AppData\Roaming\postgresql

So if we want to go to that directory we need to enter following command:
cd C:\Users\User\AppData\Roaming\postgresql

We can also go to that diretory if we write in the command line:
C:> CD %APPDATA%\postgresql

The latter way is much easier and we don't need to think about name of the user.

So now when we are in the folder and we try to list the files we notice that there is not psqlrc.conf file. Does it mean that we are in the wrong folder, not. We need to create a file. I recommend any text editor will do the job, not MS Word or LibreOffice Writer. Text editor like Notepad will do the job. 

So now that when we configured the setup file how we can use it or not to use it.
If we want to use it we run the usual syntax for runnig psql program psql -U postgres 
Or if we don't want to use configuration file we need to use -X when invoking command
so it looks like this: psql -X -U postgres

Usually we don't need password for postgres (configured in pgpass.conf). I'll write about it in some another blogpost.

There are great blogs about psql online, some research will do.
Some useful pages for customization:
psql official documentation
psqlrc psql startup file for postgres
psqlrc file for dbas
how to customize the postgresql prompt with psqlrc on ubuntu 14.04

My main motivation for configuring psqlc was setting null automatically and changing default editor to vim, so I have everything in the console.
Since I am Vim user this helps me to practice server like environment. That file is temporary and it last while session lasts. If you want normal file run: 
#\! vim perm.sql  and perm.sql file will be created in the directory where you started psql

Example of my psqlrc.conf:

\set QUIET 1

\x auto
\timing
\set COMP_KEYWORD_CASE upper

\pset border 2
\pset null <NULL>
\setenv editor 'c:\\Program Files\\Vim\\vim74\\vim.exe'
\set VERBOSITY verbose

\set QUIET 0

\echo 'Welcome to PostgreSQL! \n'
\echo 'Type :version to see PostgreSQL version \n'
\echo 'Type :extensions to see the available extensions'

\set version 'SELECT version();'
\set extensions 'select * from pg_available_extensions;'












Friday, 28 August 2015

Working with directories in Docker using Windows 7 x64

This example was performed by using Docker Windows CLI 1.8.1

I will use linux shell on Windows.
The easiest way to run a shell is by installing Git with Unix tools.

Mounting directories from Windows host to Docker

 We need to put our directories into c:\Users\ directory. 
 docs: https://docs.docker.com/userguide/dockervolumes/ 
(Mount a host directory as a data volume)

There is a slight change when working in shell that worked in my case is that extra / need to be put.
So the following command mounts a directory from a host 

docker run -v //c/Users/directory:/directory image-name command

note: the volume is mounted temporary, you need to copy is into other directory,
or you can use docker cp command to copy data from host to container

Running docker with working working directory

We have the same problem as when  mounting directory.
That means we need to add extra / to run a directory from the container.
If don't do it a directory from host machine will be demanded.

This is example for first level directory in docker image

docker run -d -w //directory docker-image command


For initial startup with docker toolbox in Windows 7
Docker-machine on Windows 7 x64 




Thursday, 27 August 2015

docker-machine on Windows 7 x64

I suppose you would like to use Docker toolbox on Windows 7 x64.
Boot2Docker is deprecated and new way of using Docker on Windows is docker-machine command.

If you are following official documentation they use one very cool command that sets environment variables in your shell automatically eval "$(docker-machine env machine-name)".
And then you get an error:
'eval' is not recognized as an internal or external command,
operable program or batch file.

Well, you think that there must be a command that is not on the path.
Unfortunately this is not also the case.

Uh, another linux on the Windows system.

Solution is quite simple.
1. Install Git for windows (include Unix tools) and run command prompt
    Be sure to enable PATH for git commands  
2. run sh -li (interactive shell)
3. your command line will change into linux shell
4. run above mentioned command:
    eval "$(docker-machine env machine-name)"

I have found out that usually there are usually some missing steps in the tutorials.

Well, well, something is missing here.
It seems that machine name is missing..

Ok, here is complete example from creating a new machine and connecting to it.

1. c:\Users\Name\sh -li (runs shell)
2. Name@Computer-Name ~ docker-machine create --driver virtualbox dev
3. Name@Computer-Name ~ eval "$(docker-machine env dev)"

Now your console is ready to use docker command on dev machine

Thursday, 12 March 2015

Generating ranges using functions

In this blog post  Generating ranges with PostgreSQL I introduced generating ranges. As introductory post it was sufficient but what is bad about it that it has hard coded values i.e. it is not flexible. If we want to have reservation system we need to have flexible creation of intervals.

It can be done using PostgreSQL functions using plain SQL, only simple stuff for this example. When you want to get more result from functions you can have two constructs. You can return a set of values or a table. There is a small difference in syntax, usage is almost the same.

The code for the function with returning set is following:

create function generate_ts(beginning timestamp, finish timestamp, gap interval)
                                   returns TABLE(reservation tsrange) as
$$
with gen(ts) as
(
     select generate_series(beginning, finish, gap)
),
ss(start, stop) as (
    select ts, lead(ts, 1) over () from gen
)
select tsrange(start,stop)
from ss
where stop > start;
$$ LANGUAGE SQL;

We call this function with following statement:

select * from generate_ts('2014-09-17 09:00:00'::timestamp,
                                          '2014-09-17 16:00:00'::timestamp,
                                          '1 hour'::interval);

And we will have following result:

                  reservation
-----------------------------------------------
 ["2014-09-17 09:00:00","2014-09-17 10:00:00")
 ["2014-09-17 10:00:00","2014-09-17 11:00:00")
 ["2014-09-17 11:00:00","2014-09-17 12:00:00")
 ["2014-09-17 12:00:00","2014-09-17 13:00:00")
 ["2014-09-17 13:00:00","2014-09-17 14:00:00")
 ["2014-09-17 14:00:00","2014-09-17 15:00:00")
 ["2014-09-17 15:00:00","2014-09-17 16:00:00")
(7 rows)

So now we have customized time range interval. And if we want we can automatically insert into a table that we will help us create reservation system.

Example for inserting these values into system is this:

select * into reservation_system
from (select reservation
          from generate_ts('2014-09-17 09:00:00'::timestamp,
                                       '2014-09-18 16:00:00'::timestamp,
                                       '1 hour'::interval)) s;

This query will automatically create table from generate table.
So if we run query SELECT * FROM reservation_system we will have the same output as in our first call for the function generate_ts.

This is step further into creating reservation system using modern PostgreSQL.




Sunday, 25 January 2015

Using Python libraries in Windows


Using Python in Windows in an adventure.

I decided to record all the steps you need to run Python normally in Windows 7 x64 system. Most of the things will be (I hope) applicable to other variants of Windows system.
Using basic Python for programming is not a problem, but when you want to install some tools and packages that it's getting pretty messy. But there is a light on the end of the tunnel (I hope).

I hope you wonder why do I grunt so much. Well, I mostly experience with Java where by using Maven and Gradle I had little problem adding extra components.

So here is required steps for using extra packages in Python.

I will describe installing libraries for up to 3.4 and 3.4. The reason is that in Python 3.4 setuptools are automatically installed with the installation. By setuptools I mean pip and easy_install programs.

When you installing Python also choose to Pyton on path, so you can easily run python executable from the command line.

This step is only required for the versions up to 3.4:

Here is the official documentation for installing setup tools:
https://pypi.python.org/pypi/setuptools

After you install the setup tools you will be able to run pip and easy_install programs. A crucial program to install with pip is wheel and another very important is virtualenv. With virtualenv we can run so called virtual environment (VE). So you can have multiple versions of various python packages on the same system.

You can read more about wheel on the official documentation page:
https://wheel.readthedocs.org/en/latest/

I will install virtualenv and wheel for the start with these commands:
  • pip install virtualenv
  • pip install wheel
Now that we have these programs installed I will create a VE
  1. c:\mkdir virtualenvs
  2. c:\cd virtualenvs
  3. c:\virtualenvs\mkdir test
  4. c:\virtaulenvs\test\virtualenv --clear venvI used option --clear so that I have clean virtualenv
    (without previously installed packages)
With this four steps we created a directory where will we store all virtualenvs and a directory for our test project. In the and we created a new environment.

With following command we will activate VE.
  • c:\virtualenvs\test\  venv\scripts\activate
  • (venv) c:\virtualenvs\test
With activate virtualenv we can install packages. If you have any package that you want to have in all VEs you should install it without VE enabled and when you you are creating VE omit --clear parameter.

Now we have three variations of installing packages. 
  1. Simple pip install
  2. Installing whl file with pip
  3. installing exe file with easy install
ad 1) To install programs just type pip install as we did when installing virtualenv and wheel

One of good place to get windows precompiled library is this web page:
http://www.lfd.uci.edu/~gohlke/pythonlibs/

ad 2) When installing whl file you need to use some extra options
         (venv) c:\virtualenvs\test\ pip install --use-wheel filename.whl
         And the file will be install

ad 3) If we have some installation file only as exe e.g. psychopg then we need to use
       easy_install  command
        (venv) c:\virtualenvs\test\ easy_install psychopg-version.exe

If make a command pip list we will have a list of installed packages in our VE. And when we choose interpreter in our IDE we choose a python.exe in the following directory:
    c:\virtualenvs\test\venv\scripts\python.exe

When we want to finish our VE session we need to run deactivate command:
     c:\virtualenvs\test\  venv\scripts\deactivate

So every time we want to install some packages in our VE we need to activate first installed programs and deactivate them at the end.