ASMLib for RHEL6
Are you worried because you can’t find asmlib for RHEL 6?
don’t worry, this article clarifies that.
ASMLib
ASMLib is an optional set of tools and a kernel driver that can be inserted between ASM and the hardware, as well as an application library used by the Oracle database software to access ASM disks. It is a support library for the ASM feature of Oracle 10g and 11g single instance database servers as well as RAC installations. ASM and regular database instances can use ASMLib as an alternative interface for disk access. ASMLib has three components:
- Kernel driver – oracleasm is a Linux kernel driver also known as the Oracle ASMLib kernel driver.
This is an open-source (GPL) kernel driver and is available from Oracle as source and binary
RPMs. Note that although this driver is provided under an open source license, it has not been
accepted into the mainline Linux kernel.
- Support tools – oracleasm-support provides the utilities to manage the ASM library driver. Oracleasm-support is an open-source package (GPL) and is available from Oracle as source and binary RPMs.
- Application library – oracleasmlib package provides the actual ASM library. This is a closed source, binary-only RPM, available as a free download from Oracle.
Oracle introduced ASMLib in 2004 to provide Oracle workloads on Linux with performance and stability
comparable to equivalent workloads on UNIX. ASMLib addressed deficiencies – including a lack of async
and direct I/O — that existed in the 2.4 Linux kernel.
Kernel 2.6
The Linux community addressed these deficiencies in the 2.6 Linux kernel with the addition of udev and device-mapper multipath which together with LVM provided native multipathing, scalable native volume management, and persistent device naming. Additionally, the 2.6 Linux kernel added tools for handling large numbers of disks, especially SAN-attached disks.
Since the RHEL6’s kernel version is 2.6, the use of asmlib is no longer needed, in RHEL 6 is used UDEV and DirectIO instead.
UDEV
UDEV allows for rules that specify what device name is given to a specific device, regardless of which port is plugged into.
Direct I/O
When a process wants to access data from a file, the SO brings the data into a buffer cache in order to avoid frequency of disk accesses. Oracle database also keep the data in a area called Buffer Cache in SGA, this “doublecopying” of data results in more CPU consumption and adds overhead to the memory too, the use of Direct I/O is indicated in situations like that, applications like a database that wishes to bypass the SO buffering within the file system cache.
To enable the use of DirectI/O on Oracle the parameter disk_asynch_io must be set to true, which is set to true by default in Oracle 11g:
SQL> show parameter disk_asynch_io; NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ disk_asynch_io boolean TRUE SQL>
Conclusion
The conclusion is that if you are using kernel 2.6 or higher the ASMLib is useless, there are native implementations(UDEV and DirectI/O) that replaced its needed, UDEV to persists the name of devices and the DirectIO to bypass the SO buffering.
Tuning linux server for Oracle database
Dozens of DBA and SysAdmin do not know how to calculate the kernel’s parameters correctly and most of times they use the default value as indicated in Oracle Documentation, I would say that most of the DBA do not even know the meaning of those parameters.
In this article I will describe the meaning of each OS paramater and how to calculate/sizing them.
Shared Memory
Shared memory allows processes to access common structures and data by placing them in shared memory segment. It is the fastest form of interprocess Communication (IPC) available since no kernel involvement occurs when data is passed between the processes. In fact, data does not need to be copied between the processes.
Oracle uses shared memory segments for Shared Global Area (SGA) which is an area of memory that is shared by Oracle processes. The size of the SGA has a significant impact to Oracle’s performance since it holds database buffer cache and much more.
Basically we use three parameters to scale shared memory:
SHMMAX
This parameter defines the maximum size in bytes of a single shared memory segment that a linux process can allocate.
SHMMNI
This parameter sets the system wide maximum number of shared memory segments. Oracle recommends SHMMNI to be at least 4096.
SHMALL
This parameter sets the total amount of shared memory pages that can be used system wide.
Memory Sizing
The steps bellow help to scale the parameters SHMMAX and SHMALL:
Obtain the total memory from the system
mem=$(free|grep Mem|awk '{print$2}')
Convert the value of $mem to bytes
totmem=$(echo "$mem*1024"|bc)
Get the Hugepagesize from /proc/meminfo
huge=$(grep Hugepagesize /proc/meminfo|awk '{print $2}')
Calculate what 75% of the total memory on the system for SHMMAX
max=$(echo "$totmem*75/100"|bc)
Divide the SHMMAX value by the Hugepagesize to get SHMALL
all=$(echo "$max/$huge"|bc)
Set the SHMMAX value in the /etc/sysctl.conf file
echo "kernel.shmmax = $max" >> /etc/sysctl.conf
Set the SHMALL value in the /etc/sysctl.conf file
echo "kernel.shmall = $all" >> /etc/sysctl.conf
Setting the maximum number of shared memory segments with SHMMNI.
echo "kernel.shmmni=4096" >> /etc/sysctl.conf
Memory Tuning
The linux kernel tunable parameter vm.swappiness (/proc/sys/vm/swappiness) can be used to define how aggressively memory pages are swapped to disk.
Linux moves memory pages that have not been accessed for some time to the swap space even if there is enough free memory available. By changing the percentage in /proc/sys/vm/swappiness you can control the swapping behavior, depending on the system configuration.
A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.
Swapping for Oracle is too bad
vm.swappiness=0
Maximum percentage of active memory that can have dirty pages
vm.dirty_background_ratio=3
Maximum percentage of total memory that can have dirty pages
vm.dirty_ratio=15
How long data can be in page cache before being expired (hundreths of a second)
vm.dirty_expire_centisecs=500
How often pdflush is activated to clean dirty pages (hundreths of asecond)
vm.dirty_writeback_centisecs=100
Setting Hugepages
Without HugePages, the memory of the SGA is divided into 4K pages, which have to be managed by the Linux kernel. Using HugePages, the page size can be increased to anything between 2MB and 256MB, thereby reducing the total number of pages to be managed by the kernel and therefore reducing the amount of memory required to hold the page table in memory. In addition to these changes, the memory associated with HugePages can not be swapped out, which forces the SGA to stay memory resident.
Setup the oracle user to be able to use hugepages in /etc/sysctl.conf
vm.hugetlb_shm_group=`id -g oracle`
Calculating the recommended number of HugePages, use the following formula:
(SGA+PGA+(20KB * # of Oracle processes running)) / 2MB
For example:
(20GB SGA + 10GB PGA + (20KB * 1,000 Oracle processes)) / 2MB = 15369
Include the parameter vm.nr_hugepages in /etc/sysctl.conf
vm.nr_hugepages=15369
Setting Semaphores
Semaphores are counters which are used to provide synchronization between processes for shared resources like shared memory. Oracle’s process concur in order to access the SGA, which is allocated in a shared memory area, thereby the number of semaphores must be higher than the number of oracle’s process parameter.
The number of semaphores per set can be defined through the kernel parameter SEMMSL. In /etc/sysctl.conf the entry for semphores is:
kernel.sem="250 32000 100 142"
The first value, SEMMSL, is the maximum number of semaphores per semaphore set
The second value, SEMMNS, defines the total number of semaphores for the system
The third value, SEMOPM, defines the maximum number of semaphore operations per semaphore call
The last value, SEMMNI, defines the number of entire semaphore sets for the system
Network tuning
Receive socket buffer size
net.core.rmem_default=262144 net.core.rmem_max=4194304
Send socket buffer size
net.core.wmem_default=262144 net.core.wmem_max=4194304
TCP socket buffer size
net.ipv4.tcp_rmem=4096 262144 4194304 net.ipv4.tcp_wmem=4096 262144 4194304
How often to send keep alive packets when a connection is unused
net.ipv4.tcp_keepalive_time=30
How long the kernel waits in between probes
net.ipv4.tcp_keepalive_intvl=60
How many probes are sent before a connection is considered broken
net.ipv4.tcp_keepalive_probes=9
How many times to retry before killing the connection
net.ipv4.tcp_retries2=3
How many times to retry transmitting the syn packet
net.ipv4.tcp_syn_retries=2
How to pack Oracle database’s binaries in a RPM file
This article describes how to create a RPM file with oracle’s binaries in it, in order to make easier the process of database installation.
Prerequisites
Install the packages rpmdevtools and rpm-build, these packages contains command line like rpmdev-setuptree and rpmbuild that will help to create the RPM structure
#yum install rpmdevtools rpm-build
The oracle database software must be installed on the machine
Generate the RPM structure
Inside the oracle’s home directory execute the command:
#rpmdev-setuptree
This command will create the following directory structure:
|-- rpmbuild |-- BUILD |-- RPMS |-- SOURCES |-- SPECS `-- SRPMS
RPM Contents SOURCES
The directory SOURCES must have a tar file with all files desired to be added in the RPM file
#tar -cvf oracle11.tar /home/oracle/.bash_profile /u01/app/oracle/product/11.2.0/rhdb/*
Configuration SPEC file
The directory SPEC is where the spec file with the instructions to create our RPM must be placed
One of the key parameter in this file is the “requires”, where a list of packages dependencies is configured.
Create a file called oracle11G.spec with the content bellow:
Name: oracle Version: 11 Release: 2%{?dist} Summary: Oracle 11G R2 Group: redhat License: GNU URL: http://www.redhat.com Source0: oracle11.tar #BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) Requires: binutils >= 2, glibc >= 2, nss-softokn-freebl >= 3, compat-libstdc++ >= 33, glibc-common >= 2, glibc-devel >= 2, glibc-headers >= 2, elfutils-libelf, elfutils-libelf-devel, gcc >= 4, gcc-c++ >= 4, ksh, libaio, libaio-devel, libgcc >= 4, libstdc++ >= 4, libstdc++-devel >= 4, make >= 3.81, numactl-devel >= 2, ld-linux.so.2()(32bit), sysstat >= 9 libfreebl3.so()(32bit), libc.so()(32bit), libaio.so.1()(32bit), libaio.so()(32bit), libgcc_s.so.1()(32bit), libstdc++.so.6()(32bit), libstdc++.so.5()(32bit) %description Oracle 11G R2 %build mkdir -p $RPM_BUILD_ROOT/home/oracle cp /home/oracle/.bash_profile $RPM_BUILD_ROOT/home/oracle mkdir -p $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/ cp -ra /u01/app/oracle/product/11.2.0/rhdb/* $RPM_BUILD_ROOT/u01/app/oracle/product/11.2.0/rhdb/ %pre groupadd oinstall groupadd dba useradd -g oinstall -G dba oracle echo redhat|passwd --stdin oracle %files /u01/* /home/* %post chown -R oracle:oinstall /u01 chmod -R 775 /u01 %changelog * Fri Sep 23 2011 Leandro Abite 1.0 - First version
Generating RPM file
The generation of the RPM file is made by the command rpmbuild passing the spec file as parameter
#rpmbuild -ba oracle11G.spec
if every thing is ok the rpm file should be created in the directory SRPMS
Requires
How to make the Apache redirect from http to https and vice versa automatically
There are some ways to do that, in this examples let’s use the module mod_rewrite.
Make sure that the module mod_rewrite is being loaded by your apache
We need tell apache the condiction to execute the redirect, edit the file $APACHE_HOME/conf/httpd.conf and add the following lines:
#Turn on the rewrite
RewriteEngine on
#Condiction and rule for redirect
RewriteCond %{REQUEST_URI} ^/(<YOUR URL>)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
Sample:
Let’s suppose you need to redirect the URL http://youserver/login.php to https://youserver/login.php, our configuration would be the follwing:
RewriteCond %{REQUEST_URI} ^/(login\.php)
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
If there are a need to set up more than one URL, just copy and paste the 2 lines above and replace the name of the page.
Once the user request the url http://youserver/login.php he will remain in https even in pages that are not configured in httpd.conf, That happened because that configuration tell apache to get in https when the page login.php is requested, so we need tell Apache to get in http when some other page is requested, this is configured in the file $APACHE_HOME/conf.d/ssl.conf, do the same configuration done in file http.conf
Sample:
Let’s suppose that after the user pass througt the login he will get the home.php page, so add the following lines in the file $APACHE_HOME/conf.d/ssl.conf:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(home\.php)
RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [R,L]
Don’t forget to restart the apache service
It’s done, 🙂 !!!