Thứ Ba, 10 tháng 2, 2015

Linux / UNIX: Bash Script Sleep or Delay a Specified Amount of Time

Linux / UNIX: Bash Script Sleep or Delay a Specified Amount of Time

How do I pause for 5 seconds or 2 minutes in my bash shell script on a Linux or Unix-like systems?

You need to use the sleep command to add delay for a specified amount of time. The syntax is as follows for gnu/bash sleep command:

sleep NUMBER[SUFFIX]


Where SUFFIX may be:

s for seconds (the default)

m for minutes.

h for hours.

d for days.

Thứ Hai, 2 tháng 2, 2015

Linux Tuning hosting 10G

This page contains a quick reference guide for Linux 2.6+ tuning for Data Transfer hosts connected at speeds of 1Gbps or higher. Note that most of the tuning settings described here will actually decrease performance of hosts connected at rates of OC3 (155 Mbps) or less, such as home users on Cable/DSL connections. 
For a detailed explanation of some of the advice on this page, see the Linux Tuning Expert page. Note that the settings on this page are not attempting to achieve full 10G with a single flow. These settings assume you are using tools that support parallel streams, or have multiple data transfers occurrin in parallel, and want to have fair sharing between the flows.  As such the maximum values are 2 to 4 times less than what would be required to support a single stream.  As an example, a 10Gbps flow across a 100ms network requires 120MB of buffering.  Most data movement applications, such as GridFTP, would employ 2-8 streams to do this efficiently and to guard against congestive packet loss.  Setting your 10Gbps capable host to consume a maximum of 32M - 64M per socket ensures that parallel streams work well, and do not consume a majority of system resources. 
If you are trying to optimize for a single flow, see the tuning advice for test / measurement hosts page.
 General Approach
To check what setting your system is using, use 'sysctl name' (e.g.: 'sysctl net.ipv4.tcp_rmem'). To change a setting use 'sysctl -w'. To make the setting permanent add the setting to the file 'sysctl.conf'.
TCP tuning
Like most modern OSes, Linux now does a good job of auto-tuning the TCP buffers, but the default maximum Linux TCP buffer sizes are still too small. Here are some example sysctl.conf commands for different types of hosts.
For a host with a 10G NIC, optimized for network paths up to 100ms RTT, and for friendlyness to single and parallel stream tools, add this to /etc/sysctl.conf
# allow testing with buffers up to 64MB
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
# increase Linux autotuning TCP buffer limit to 32MB
net.ipv4.tcp_rmem = 4096 87380 33554432
net.ipv4.tcp_wmem = 4096 65536 33554432
# increase the length of the processor input queue
net.core.netdev_max_backlog = 30000
# recommended default congestion control is htcp
net.ipv4.tcp_congestion_control=htcp
# recommended for hosts with jumbo frames enabled
sysctl -w net.ipv4.tcp_congestion_control=htcp
net.ipv4.tcp_mtu_probing=1
Also add this to /etc/rc.local (where N is the number for your 10G NIC): 
/sbin/ifconfig ethN txqueuelen 10000

For a host with a 10G NIC optimized for network paths up to 200ms RTT, and for friendlyness to single and parallel stream tools, or a 40G NIC up on paths up to 50ms RTT:
# allow testing with buffers up to 128MB
net.core.rmem_max = 134217728
net.core.wmem_max = 134217728
# increase Linux autotuning TCP buffer limit to 64MB
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
# increase the length of the processor input queue
net.core.netdev_max_backlog = 250000
# recommended default congestion control is htcp
net.ipv4.tcp_congestion_control=htcp
# recommended for hosts with jumbo frames enabled
net.ipv4.tcp_mtu_probing=1
Notes: you should leave net.tcp_mem alone, as the defaults are fine. A number of performance experts say to also increasenet.core.optmem_max to match net.core.rmem_max and net.core.wmem_max, but we have not found that makes any difference. Some experts also say to set net.ipv4.tcp_timestamps and net.ipv4.tcp_sack to 0, as doing that reduces CPU load. We strongly disagree with that recommendation for WAN performance, as we have observed that the default value of 1 helps in more cases than it hurts, and can help a lot.
Linux supports pluggable congestion control algorithms. To get a list of congestion control algorithms that are available in your kernel (kernal  2.6.20+), run:
sysctl net.ipv4.tcp_available_congestion_control
If cubic and/or htcp are not listed try the following, as most distributions include them as loadable kernel modules:
/sbin/modprobe tcp_htcp
/sbin/modprobe tcp_cubic
NOTE: There seem to be bugs in both bic and cubic for a number of versions of the Linux kernel up to version 2.6.33. We recommend using htcp with older kernels to be safe. To set the congestion control do:
If you are using Jumbo Frames, we recommend setting tcp_mtu_probing = 1 to help avoid the problem of MTU black holes. Setting it to 2 sometimes causes performance problems


Chủ Nhật, 1 tháng 2, 2015

How To Install EPEL, REMI and RPMForge Repositories On CentOS 7

To keep your system updated with the latest and greatest packages on CentOS 7, you must constantly update it. The yum update commands will fetch and download the latest updates for your system. By default, it only fetches pre-installed repositories which can be limited with fewer packages.
If you want to install and use the latest packages for your applications on CentOS 7, you’ll have to install additional third-party software repositories. Most of the latest servers and software packages are not available from the default CentOS repositories. The folks behind CentOS are pretty cautious when adding newer updates to their systems. They want to fully test out these updates before releasing them to all systems running CentOS.
Because it takes longer time to updates packages in CentOS, third-party repositories were created to fill in the gap to release updates quickly and frequently. Packages that were installed from these third-party repositories get updated and refreshed very frequently as soon as updates become available. Theses are usually tested and customized for the appropriate version of CentOS.
For example, to get the latest version of Nginx, Apache2, PHP-FPM and other important opensource packages, you must install third-party repositories. This brief tutorial is going to show you how to add these popular repositories to CentOS 7 if you haven’t already done so.

Installing EPEL Repository for CentOS 7
EPEL (Extra Packages for Enterprise Linux) is an opensource and free community based repository project from Fedora team which provides 100% high quality software packages for Linux distribution including RHEL (Red Hat Enterprise Linux) and CentOS.
Most people who run CentOS 7 usually add these repository to their systems. To enable it in CentOS 7, run the commands below to install it.
sudo yum install epel-release
In the past, one had to add its repository and install the repository. Now all you need to do is run the yum install commands to install and enable EPEL in CentOS7.

Installing Remi Repository on CentOS 7
The Remi repository provides newer version of popular opensource software for CentOS and Red Hat Enterprise Linux. It depends on the EPEL repository so you must first install EPEL before installing Remi.
To enable Remi repository on CentOS 7, run the commands below.
cd /tmp && wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Next, run the commands below to install it.
sudo rpm -Uvh remi-release-7*.rpm

Installing RPMForge Repository on CentOS 7
Another useful repository for CentOS system is the RPMForge repository. It’s a community maintained repository which contains newer packages and software for CentOS and Red Hat Linux. More than 5000 individual packages are included in the repository. It’s a great repository to add to your system if you’re running CentOS or Red Hat servers.
To add it, run the commands below.
cd /tmp && wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
Next, run the commands below to install it
sudo rpm -Uvh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
By default CentOS puts all repositories file at /etc/yum.repos.d/ directory. Each of the repository file will have an extension ending in .repo. You can edit individual repository file to enable or disable it.
A simple repository file may contain something like what’s below:
[rpmforge-extras]
name = RHEL $releasever – RPMforge.net – extras
baseurl = http://apt.sw.be/redhat/el7/en/$basearch/extras
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge-extras
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge-extras
enabled = 0
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
You can enable or disable a repository by changing the value for enabled to 1 to enable and 0 to disable. When you’re done, save the file  and exit.
Run the yum update commands to see if there are newer updates for your systems.. There may more third-party repositories, but these are the most popular.