Upgrade Linux kernel on RHEL 7

My OS is RHEL 7.2 (minimal installation version). To use some new kernel features (such as BPF), I need to upgrade kernel to 4.x.

(1) Register the system and apply a subscription:

# subscription-manager register --username <username> --password <password> --auto-attach

(2) Use yum install to install the following software packages:

openssl-devel
ncurses-devel
bc
gcc
perl

BTW, when executing yum install perl, it prompts errors, so I download the source code from perl official website, and build it form scratch:

./configure.gnu
make 
make test
make install

(3) Download the stable kernel from kernel.org and extract it, then build it:

make menuconfig
make 
make modules_install install

According to your requirement, maybe installing the header files is also need:

make INSTALL_HDR_PATH=/usr/local headers_install

(4) Reboot system, and select right kernel on boot time, enjoy it:

# uname -a
Linux localhost.localdomain 4.5.0 #1 SMP Mon Apr 11 09:56:46 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux

 

Using unixODBC to connect SAP HANA database

There are 2 methods of installing unixODBC:
(1) Use packages provides by OS vendors, such as:

yum install unixODBC

(2) Download the source code from unixODBC website, and build it:

./configure
make 
make install

Please notice: by default, the configuration files are in /etc/unixODBC:

# odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/unixODBC/odbcinst.ini
SYSTEM DATA SOURCES: /etc/unixODBC/odbc.ini
FILE DATA SOURCES..: /etc/unixODBC/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

And this may introduce the following connection error:

# isql HDB system xxxxxx -v
[08S01][unixODBC][SAP AG][LIBODBCHDB SO][HDBODBC] Communication link failure;-10709 Connect failed (no reachable host left)
[ISQL]ERROR: Could not SQLConnect

The solution is either you create a symbol link of /etc/odbc.ini which points to /etc/unixODBC/odbc.ini:

ln -s /etc/unixODBC/odbc.ini /etc/odbc.ini

Or when compiling from source code, specify the sysconfdir option in configuring process:

./configure --sysconfdir=/etc

The odbc.ini file is like this:

[HDB]
Driver = /usr/sap/hdbclient/libodbcHDB.so
servernode = localhost:30015

The 00 in 30015 is the instance number of SAP HANA.

When using isql to connect SAP HANA database, if not provide user name and password, the error message is a little confused:

# isql HDB -v
[08S01][unixODBC][SAP AG][LIBODBCHDB SO][HDBODBC] Communication link failure;-10709 Connection failed (RTE:[-1] Kerberos error. Major: "unspecified [851968]", minor: "No Kerberos credentials available [2529639053/-1765328243]")
[ISQL]ERROR: Could not SQLConnect

But after specifying the user name and password, the connection is OK:

# isql HDB system xxxxxx -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>

Reference:
Connect to HANA with unixODBC fails.

 

Install openssl-0.9.8 for SAP HANA

SAP HANA has a special love for openssl-0.9.8, so to install SAP HANA, you must first get openssl-0.9.8 dynamic library ready:

(1) Download openssl-0.9.8 source code from here, and uncompress it.

(2) To build dynamic library, you should add shared option when configuring:

./config shared
make
make install_sw

(3) Because the default installation directory is /usr/local/ssl, to let SAP HANA find the openssl library, you should add/usr/local/ssl/lib into /etc/ld.so.conf file:

# cat /etc/ld.so.conf
/usr/local/ssl/lib
/usr/local/lib64
/usr/local/lib
include /etc/ld.so.conf.d/*.conf
# /lib64, /lib, /usr/lib64 and /usr/lib gets added
# automatically by ldconfig after parsing this file.
# So, they do not need to be listed.

Then execute ldconfig command:

# ldconfig

It is OK for installing SAP HANA now.

 

How to count the line number of a file?

How to count the line number of a file? It seems an easy question for Unix guys: using wc command. Let’s see an example:

# cat test
aaaa
bbbb
cccc
# wc -l test
3 test

It displays right. But wait a minute, let’s check the wc -l option meaning:

# wc --help
......
-l, --lines            print the newline counts
......

wc -l just print the newline counts, so it increases newline count as the line number. Using hexdump to see the content of test:

# hexdump -C test
00000000  61 61 61 61 0a 62 62 62  62 0a 63 63 63 63 0a     |aaaa.bbbb.cccc.|
0000000f

No problem, test contains 3 newlines. But now, the question is here, how about the last line doesn’t contain newline?

Let me do the following experiment:

# echo -n "a" > test
# hexdump -C test
00000000  61                                                |a|
00000001
# wc -l test
0 test

Now the test file only contains 1 character, and no newline. This time, wc -l thinks there is no line in test file.

Based on the previous discussion, maybe awk is a better tool when using to count line number of file. Just one statement:

# awk 'END {print NR}' test
1

It outputs right line number.

SELinux cause “Permission denied” issue in using docker

I am using docker on RHEL 7. After mounting host directory into container, some interesting things happen: Although I am a root user, and seem to have all permissions, but the system will prompt “Permission denied” when executing commands:

# docker run -v /root:/test --rm -it debian ls /test
ls: cannot open directory /test: Permission denied

Through tough investigations, I find the root cause is about SELinux:

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

The current mode of SELinux is enforcing, and I get 2 solutions to resolve it now:

(1)

Add --privileged option in docker run command:

# docker run --privileged -v /root:/test --rm -it debian ls /test
Desktop    Pictures   anaconda-ks.cfg       linuxamd64_12102_database_1of2.zip
Documents  Public     database              linuxamd64_12102_database_2of2.zip
Downloads  Templates  docker-oracle12c      sysdig
Music      Videos     initial-setup-ks.cfg

(2)

Set SELinux mode as permissive:

# setenforce 0
# docker run -v /root:/test --rm -it debian ls /test
Desktop    Downloads  Pictures  Templates  anaconda-ks.cfg  docker-oracle12c      linuxamd64_12102_database_1of2.zip  sysdig
Documents  Music      Public    Videos     database         initial-setup-ks.cfg  linuxamd64_12102_database_2of2.zip

References:
Why does docker prompt “Permission denied” when backing up the data volume?;
Why does docker container prompt “Permission denied”?.