Posts in Category: rhce

RHCE – Create a hello world CGI app on CentOS/RHEL 7

Common Gateway Interface (CGI) is a protocol that let’s you run custom scripts via the web. It’s not as commonly used as before, but you still need to know this as part of the RHCE exam objectives.

In Apache, there is a default folder where you can place scripts in, which will then get handled by the CGI protocol. This default folder is declared in the main Apache config file, here’s the relevant extract:


    #
    # Redirect: Allows you to tell clients about documents that used to
    # exist in your server's namespace, but do not anymore. The client
    # will make a new request for the document at its new location.
    # Example:
															

Configuring Kernel Parameters (aka system settings) in CentOS/RHEL 7

The kernel itself also comes with its own settings that can be tweaked, via customizing kernel parameters. There are a wide range of kernel level parameters that gets set during system boot up. All the kernel settings are stored in a large selection of files under the /proc/sys directory. The parameters stored in this directory are often referred to as “system parameters“. Making changes to files in this folder won’t be persistant because the entire /proc folder gets deleted and recreated during a reboot.

To view the parameter settings, you can instead use the sysctl command:

$ sysctl -a 
abi.vsyscall32 = 1
crypto.fips_enabled = 0
debug.exception-trace = 1
debug.kprobes-optimization = 1
dev.cdrom.autoclose = 1
dev.cdrom.autoeject = 0
.
.
.etc

Here, the periods are used as delimiters, which you can think of forward slashes to locate the file.


MariaDB – Restoring databases

In the previous article we saw how to create backups of our database. Now we’re going to try restoring databases. First thing we need to do is delete our database so that we can start restoring it:

We created a backup file for online_shop, so let’s start by deleting that database, this is done using the ‘DROP’ command:

[root@mariadb-client ~]# mysql -u root -p'rootpassword' -h mariadb-server.example.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 20
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql      															

MariaDB – Backing up databases

There are 3 levels of mysql database backups you can do:

  • Backup the contents of a single database
  • Backup multiple databases
  • Backup the entire mysql server

when creating database backups, the resulting backup files are actrually really big sql files that will repopulate a database. In all cases we create database backups using the mysqldump utility.

Backup the contents of a single database

This is done by running the command:

$ mysqldump -u root -p'rootpassword' -h mariadb-server.example.com online_shop > online_shop_backup.sql

This file will populate a database’s content. It won’t create the database itself. This is handy if you want to create a clone of a production db in a dev environment. It also means that when restoring this backup file, you first need to manually create an empty database for this backup file to populate.

Backup


MariaDB – Create a new MySQL Database

In this article we’re going to create a new database and then create a table inside the new database. We’ll call this database ‘online_shop’. First we create a new mysql session:

[root@mariadb-client ~]# mysql -u root -p'rootpassword' -h mariadb-server.example.com 

Then let’s take a look at what dbs currently exist:

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

Now here’s how to create the database:

MariaDB [(none)]> CREATE DATABASE online_shop;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| online_shop        |
| mysql															

MariaDB – Navigating your way around a MySQL Database

In this article we’re going to show some simple MySQL commands to help you navigate your way around databases and tables, and also view a table’s content. First we create a new mysql session:

[root@mariadb-client ~]# mysql -u root -p'rootpassword' -h mariadb-server.example.com 

Then let’s take a look at what dbs currently exist:

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

Note: Here we ran a command as opposed to a sql query. by convention these commands are always written in upper case. Whereas sql queries can be a mix of upper and lower cases.

Here we have 3 databases that comes


MariaDB – Basic MySQL CRUD Operations

In the previous article we saw how to create a new database called ‘online_shop’ and then a table inside this new database called ‘customers’. Now we’re going to show how to create/read/update/delete (crud) content in a table.

Let’s see what the situation is:

[root@mariadb-client ~]# mysql -u root -p'rootpassword' -h mariadb-server.example.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| customers          |
| mysql         															

MariaDB – Connect to a MariaDB server from a remote client on CentOS/RHEL 7

In the previous article we set up MariaDB server, now we are going to access it from a mysql client. In our example we’ll try to connect using the root mysql account (which has the password, ‘rootpassword’) from a mysql client server that has the ip address of 10.2.5.12.

You can follow along this article using our MariaDB vagrant project on Github.

To do this, we first install the following on the mysql client:

$ yum groupinstall -y mariadb
$ yum groupinstall -y mariadb-client

We installed the MariaDB server software too. That’s to ensure we install all the necessary library files.

Next on the MariaDB server, we need to whitelist our root user to be allowed to have access from the remote client, this is done by running the following command:

[root@mariadb-server ~]# mysql -u															

MariaDB – Install and configure a MariaDB server on CentOS/RHEL 7

MariaDB is basically a clone of MySQL. MariaDB is created by the same people who created MySQL. There was uncertainty about what would happen to MySQL after Oracle bought. This uncertainty gave birth to MariaDB. Our aim in this article is to setup a secure MariaDB server that can accept connections from remote clients. This involves the following steps:

  1. Install the mariadb rpms
  2. Configure MariaDB to allow connections from a network interface
  3. Perform security hardening
  4. configure firewalld to allow mysql traffic
  5. Test the mariadb server setup

You can follow along this article using our MariaDB vagrant project on Github.

Install the mariadb rpms

The best way to install MariaDB is via group install:

$ yum groupinstall mariadb
$ yum groupinstall mariadb-client

Configure MariaDB to allow connections from a network interface

By default, MariaDB doesnt allow any external mysql client’s to connect


NTP – Setup an NTP Server on CentOS/RHEL 7

An NTP server is a server that provides time information to NTP clients. An NTP peer is a server that provides and receives time from other NTP servers. So you can have a group of NTP peers that provides time information to eachother. An NTP client is a server that only receives time information from NTP servers to keep it’s own time in sync.

We can setup an NTP server, so that it’s local system clock (as provided by the date or timedatectl command). We can refer to this type of server as a ‘local time NTP server’ and it will provide time information to NTP clients. This is good solution for private network where it’s more important to have in-sync time rather than super accurate time. So let’s