Sep 28, 2018

Linux: journalctl and systemd - better than /var/log/messages?

Nearly 8 years ago systemd was introduced on some Linux distribution (s. here). Last week i discovered some helpful commands, which i share with you.

If you want to take a look at kernel message (for example system boot), you command is
dmesg
The new equivalent is
journalctl -k
Ok - not really amazing.
But all of you know the message
See "systemctl status nginx.service" and "journalctl -xe" for details.
You can run the "systemctl start/restart/stop" and in case of error open the logs with "journalctl -xe". I would recommend to open a seperate shell and run there
journdalctl -f
This is something like "tail -f" to the systemd-journal.
If you do a "systemctl restart network" the shell with journalcctl -f shows the DHCP waiting for a answer from the server and you know why its so slow. You especially know, that your fifth interface has DHCP enabled and there is no DHCP, which slows down every "systemctl restart network".

journalctl has some nice filters like
journalctl -p 0..4
This just shows the message with
  • "emerg" (0), 
  • "alert" (1), 
  • "crit" (2), 
  • "err" (3), 
  • "warning" (4), 
  • "notice" (5),
  • "info" (6), "debug" (7)
Or filter for something like network messages:
journalctl -u NetworkManager

And my favourite: Pipe your own log messages into the systemd-journal:
echo This is important | systemd-cat -t MightyJournal -p notice
Which result in this entry:
Sep 28 20:48:55 zerberus MightyJournal[28520]: This is important

Sep 19, 2018

Missing directory in /var/run or /run - tmpfiles.d

Sometimes is happens, that an application/demon refuses to start because of missing files/directories in /var/run.
The first solution is:
  • Create the directory in /var/run
  • Change the permissions
and everything is fine.

Not really.

After the next reboot, the directory is missing again and you have to go for the "first" solution again.

The right solution works like this:
Inside /usr/lib/tmpfiles.d create a myexample.conf file with this content:
        d /var/run/myexample 0755 schroff schroff -
To check if everything is ok run the following command:
        systemd-tmpfiles --create myexample.conf
and you will see:
# ls -l /var/run/ |grep mxexample
drwxr-xr-x  2 schroff schroff   40 19. Sep 22:45 myexample
And this directory will be created with each reboot...

Sep 1, 2018

MySQL 8: New Features

After installing mysql 8 on my ubuntu i did a lookaround for the new features. Oracle itself stated:

 
This is really cool, but how to test this?
A first look inside the standard data directory /var/lib/mysql shows:
/var/lib/mysql# ls -l
insgesamt 168012
-rw-r----- 1 mysql mysql       56 Aug 17 20:53 auto.cnf
-rw-r----- 1 mysql mysql      498 Aug 17 20:53 binlog.000001
-rw-r----- 1 mysql mysql      554 Aug 17 21:07 binlog.000002
-rw-r----- 1 mysql mysql       32 Aug 17 20:54 binlog.index
-rw------- 1 mysql mysql     1676 Aug 17 20:53 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 Aug 17 20:53 ca.pem
-rw-r--r-- 1 mysql mysql     1112 Aug 17 20:53 client-cert.pem
-rw------- 1 mysql mysql     1680 Aug 17 20:53 client-key.pem
-rw-r----- 1 mysql mysql     4533 Aug 17 20:53 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Aug 17 21:07 ibdata1
-rw-r----- 1 mysql mysql 50331648 Aug 17 21:07 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Aug 17 20:53 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Aug 17 20:56 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Aug 17 21:07 mydatabase
drwxr-x--- 2 mysql mysql     4096 Aug 17 20:53 mysql
-rw-r----- 1 mysql mysql 25165824 Aug 17 21:07 mysql.ibd
drwxr-x--- 2 mysql mysql     4096 Aug 17 20:53 performance_schema
-rw------- 1 mysql mysql     1680 Aug 17 20:53 private_key.pem
-rw-r--r-- 1 mysql mysql      452 Aug 17 20:53 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 Aug 17 20:53 server-cert.pem
-rw------- 1 mysql mysql     1680 Aug 17 20:53 server-key.pem
drwxr-x--- 2 mysql mysql     4096 Aug 17 20:53 sys
-rw-r----- 1 mysql mysql 10485760 Aug 17 21:07 undo_001
-rw-r----- 1 mysql mysql 10485760 Aug 17 21:07 undo_002
The sys and the perfomance_schema directories does not contain any frm or ISAM-style files. 
The mysql server team shows these pictures on their site (https://mysqlserverteam.com/mysql-8-0-data-dictionary-status-in-the-8-0-0-dmr/)



And if you create your own database each table is stored in its own ibd file and not all in one tablespace file, because innodb_file_per_table is set to 1 as default. With this shrinking tables can be done without a problem...