Get your Linux Book Free Linux how-to’s - Linux tips and tricks - Online resources.

Author: ZIADI Mohamed Ali

How to optimize the use of RAM ?

Since sysadmin are looking to have racing beast servers, they are confonted to the problem of performance optimization. Nowadays it is not uncommon to see a server with 32G or 96G of RAM or even more. Why to mount so much in memory? Well it is the use that imposes it: Virtualization Video editing HD compression Heavy applicative consumption like clustering or high availability architectures etc In this blog we will speek about swapiness which is a kernel module that defines when linux has to start to write in the SWAP (an allocated space in the disk) to relieve the RAM. It may seem obvious that with access times in milliseconds for Hard Disk and in nanoseconds for RAM, it is better to write in the RAM. Recap: vm.swappiness = 0 : Swapping will be activated urgently only to avoid out of memory condition. vm.swappiness = 60 : This is the default value and means that from 40% of Ram occupancy, the kernel writes to the swap. vm.swappiness = 10 : This what is recommended to improve performance. vm.swappiness = 100 : The kernel will swap aggressively. To see your swappiness setting : cat /proc/sys/vm/swappiness 60 Let’s consider that we have a server having 32G of RAM. fixing the swappiness to 5 is enough since kernel will use swap only when the free RAM space is less or equal...

Read More

How to list running vhosts on Apache

Apache is the most popular open-source webserver. It is also called httpd in Centos/Redhat distributions. Begin by checking if the server is running or not: [debian.linuxnix] root:~/ # service apache2 status Apache2 is running (pid 2082). On Centos you can use the service command or the command below which gives more informations: [centos.linuxnix] root:~ # apachectl status ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2016-10-13 10:53:26 CEST; 1 months 4 days ago Docs: man:httpd(8) man:apachectl(8) Process: 27054 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS) Main PID: 1179 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─ 1179 /usr/sbin/httpd -DFOREGROUND ├─ 6529 /usr/sbin/httpd -DFOREGROUND ├─ 8835 /usr/sbin/httpd -DFOREGROUND ├─ 8858 /usr/sbin/httpd -DFOREGROUND ├─ 8859 /usr/sbin/httpd -DFOREGROUND ├─ 8860 /usr/sbin/httpd -DFOREGROUND ├─ 8861 /usr/sbin/httpd -DFOREGROUND ├─27059 /usr/sbin/httpd -DFOREGROUND ├─27060 /usr/sbin/httpd -DFOREGROUND ├─27061 /usr/sbin/httpd -DFOREGROUND └─27062 /usr/sbin/httpd -DFOREGROUND Nov 13 03:36:01 vps24699.ovh.net systemd[1]: Reloaded The Apache HTTP Server. When you modify your vhosts configurations you can check syntax by using commands below: [debian.linuxnix] root:~/ # apache2ctl configtest Syntax OK [debian.linuxnix] root:~/ # apache2ctl -t Syntax OK Now, to list all running vhosts, you can use : [debian.linuxnix] root:~/ # apache2ctl -S VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: _default_:443 211.ip-5-126-0.eu (/etc/apache2/sites-enabled/001-default-ssl:2) *:8080 is a NameVirtualHost default server 211.ip-5-126-0.eu (/etc/apache2/sites-enabled/000-default:2) port 8080 namevhost 211.ip-5-126-0.eu (/etc/apache2/sites-enabled/000-default:2) port 8080...

Read More

How to generate a random number in Bash

  Bash function $RANDOM To generate a random integer we can use the internal bash function $RANDOM. This functions returns integer between 0 and 32767. Example: [www1.linuxnix] root:~ # i=$RANDOM [www1.linuxnix] root:~ # echo $i 23770 [www1.linuxnix] root:~ # j=$RANDOM [www1.linuxnix] root:~ # echo $j 3577 To generate a random integer between 1 and 1000, you can use $RANDOM like below: $(((RANDOM%1000+1))) Note : $(((RANDOM%1000))) will generate integer between 0 and 999. Examples: [www1.linuxnix] root:~ # i=$(((RANDOM%1000+1))) [www1.linuxnix] root:~ # echo $i 895 [www1.linuxnix] root:~ # j=$(((RANDOM%1000+1))) [www1.linuxnix] root:~ # echo $j 316   /dev/random and /dev/urandom For bigger integer random generation we can use /dev/random and /dev/urandom which can interact with kernel’s random number generator. We will use the od command for that : od : dump files in octal and other formats we will use arguments : -A or –address-radix=RADIX : output format for file offsets; RADIX is one of [doxn], for Decimal, Octal, Hex or None -N or –read-bytes=BYTES : limit dump to BYTES input bytes -t or –format=TYPE : select output format or formats [www1.linuxnix] root:~ # od -An -N8 -tu8 < /dev/urandom 11055529178234849100 [www1.linuxnix] root:~ # od -An -N4 -tu4 < /dev/random 3202521020 I hope that this blog helped you. Please visit our blog website for other interesting blogs and feel free to leave your feedbacks and comments. Till next...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.