Useful yum commands

Those are some commands that you’ll probably need sometime to install, remove, update, etc. software in your CentOS/Fedora/Red Hat box. As I’m more used to apt-get I’ve searched a fairly complete list of tasks I’ll need in the future.

centos

See installed packages:

yum list installed

Search for an installed package:

yum list installed | grep php

See available packages:

yum list available

Search for available packages:

yum list available | grep php

See information of a package:

yum info php
Name        : php
Arch        : x86_64
Version     : 5.3.3
Release     : 27.el6_5
Size        : 3.5 M
Repo        : installed
...

Install a package:

yum install package-name

Install a package without being asked for permission before installation process:

yum -y install package-name

Remove a package:

yum remove package-name

Remove a package without being asked for permission before removing process:

yum -y remove package-name

Remove orphan packages:

package-cleanup --quiet --leaves --exclude-bin | xargs yum remove -y

Check if a package has an update available:

yum check-update package-name

Update a package:

yum update package-name

See if any update is available:

yum check-update

Update everything:

yum update

Automatic updates

su -c '/sbin/chkconfig --level 345 yum on; /sbin/service yum start'

Note: There is no separate yum service that runs on your system. The command given above enables the control script /etc/rc.d/init.d/yum. This control script activates the script /etc/cron.daily/yum.cron, which causes the cron service to perform the system update automatically at 4am each day.

Add EPEL and Remi repositories:

For i686:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

For x86_64:

rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Now you’ll see the new files that configure those repositories:

$ ls -1 /etc/yum.repos.d/
CentOS-Base.repo
CentOS-Debuginfo.repo
CentOS-Media.repo
CentOS-Vault.repo
epel.repo
epel-testing.repo
remi.repo

The Remi repository comes disabled by default so you’ll have to enable it by changing it’s enabled option to 1 or executing this command:

yum-config-manager --enable remi

Add ElRepo repository:

Import the public key:

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Install the repo:

rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

Add RPMforge repository:

Import the GPG key:

rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

Install for i686:

rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

Install for x86_64:

rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

Now you can install any software from that repository:

yum install htop

See available group of packages (for example MySQL is made by many packages):

yum grouplist
...
Installed Groups:
   Administration Tools
   DNS Name Server
   Dialup Networking Support
...
Available Groups:
   Authoring and Publishing
   Base
   Beagle
...

Install a grouplist:

yum groupinstall 'Beagle'

Update a grouplist:

yum groupupdate 'Beagle'

Remove a grouplist:

yum groupremove 'Beagle'

Clean the cache to delete files from /var/cache/yum

yum clean all

View the history of different installations, removes, etc.:

yum history
D     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
   12 |  <user>                  | 2014-05-22 21:33 | Install        |    2
   11 |  <user>                  | 2014-05-22 21:31 | Install        |    3
   10 |  <user>                  | 2014-05-22 21:29 | Install        |    6
    9 |  <user>                  | 2014-05-22 21:05 | Install        |    4
    8 | System <unset>           | 2014-04-19 01:55 | I, U           |  117 EE
    7 | root <root>              | 2013-08-14 14:48 | I, U           |  156 EE
    6 | root <root>              | 2013-08-14 14:37 | Erase          |    1
    5 | System <unset>           | 2011-12-20 20:03 | I, U           |  162 EE
    4 | System <unset>           | 2011-07-10 19:29 | Install        |    3
    3 | System <unset>           | 2011-07-10 19:22 | Update         |   60  < 
    2 | System <unset>           | 2011-07-08 20:03 | Erase          |    6 > 
    1 | System <unset>           | 2011-07-08 20:43 | Install        |  276

To see a detailed information of an specific history operation use this command:

yum history info 11
Loaded plugins: fastestmirror
Transaction ID : 11
Begin time     : Thu May 22 21:31:08 2014
Begin rpmdb    : 292:63d8bb066751f0def9baf9c3aca697fa2dfaef21
End time       :            21:31:10 2014 (2 seconds)
End rpmdb      : 295:0f2bb4c03af71739f9be1f59c7bcfab9540de5d8
User           :  <user>
Return-Code    : Success
Command Line   : install php
Transaction performed with:
    Installed     rpm-4.8.0-37.el6.x86_64                         @base
    Installed     yum-3.2.29-43.el6.centos.noarch                 @updates
    Installed     yum-plugin-fastestmirror-1.1.30-17.el6_5.noarch @updates
Packages Altered:
    Install     php-5.3.3-27.el6_5.x86_64        @updates
    Dep-Install php-cli-5.3.3-27.el6_5.x86_64    @updates
    Dep-Install php-common-5.3.3-27.el6_5.x86_64 @updates

You can see in the “Packages Altered” area what packages were installed, deleted, updated or whatever.

See the list of configured repositories:

yum repolist
repo id                        repo name                                 status
base                           CentOS-6 - Base                           6.365+2
extras                         CentOS-6 - Extras                              14
updates                        CentOS-6 - Updates                          1.103
repolist: 7.482

Ref: http://www.rackspace.com/knowledge_center/article/installing-rhel-epel-repo-on-centos-5x-or-6x
http://wiki.centos.org/AdditionalResources/Repositories/RPMForge
http://elrepo.org/tiki/tiki-index.php
http://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/

Install software in unsupported Ubuntu versions with apt-get

When an Ubuntu version goes unsupported its repositories get moved to an archive server. If you don’t update the repo origins you’ll get some errors like those:

Err http://archive.ubuntu.com quantal/main i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal/restricted i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal/universe i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal/multiverse i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-updates/main i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-updates/restricted i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-updates/universe i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-updates/multiverse i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-security/main i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-security/restricted i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-security/universe i386 Packages
  404  Not Found [IP: 91.189.91.14 80]
Err http://archive.ubuntu.com quantal-security/multiverse i386 Packages
  404  Not Found [IP: 91.189.91.14 80]

The key to solve this is changing the repo urls from archive.ubuntu.com and security.ubuntu.com to old-releases.ubuntu.com:

sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

Then update:

sudo apt-get update

apt-get-404

Ref: http://askubuntu.com/questions/91815/how-to-install-software-or-upgrade-from-old-unsupported-release

Load testing a web site with Siege

Siege is an HTTP load testing and benchmarking utility. It helps you test you server and web developments in high load situations. Quoted from it’s home page:

Siege is an http load testing and benchmarking utility. It was designed to let web developers measure their code under duress, to see how it will stand up to load on the internet. Siege supports basic authentication, cookies, HTTP and HTTPS protocols. It lets its user hit a web server with a configurable number of simulated web browsers. Those browsers place the server “under siege.”

Servers

To install it in Ubuntu just use the repositories:

sudo apt-get install siege

In Mac OS X using MacPorts:

sudo port install siege

And using brew:

sudo brew install siege

If you don’t use either of them you’ll have to download and compile the source code. It’s as easy as running those commands that will install the binary files in /usr/local/bin folder:

curl -O http://download.joedog.org/siege/siege-latest.tar.gz
tar xzvpf siege-latest.tar.gz
cd `ls -1d */ | grep siege- | sort -r | head -1`
./configure
make
sudo make install

Note: That “strange” cd command moves you into the folders extracted from siege-latest.tar.gz. As it could have any version number we get the list of all folders starting with siege-, then sort in reverse order and get the first one.

Use siege.config to create a .siegerc file in your home folder with the default configuration:

$ siege.config
New configuration template added to /Users/user/.siegerc
Run siege -C to view the current settings in that file

Then you can list it’s options using the -C parameter of siege:

$ siege -C
CURRENT  SIEGE  CONFIGURATION
Mozilla/5.0 (apple-x86_64-darwin13.3.0) Siege/3.0.6
Edit the resource file to change the settings.
----------------------------------------------
version:                        3.0.6
verbose:                        true
quiet:                          false
debug:                          false
protocol:                       HTTP/1.1
get method:                     HEAD
connection:                     close
concurrent users:               15
time to run:                    n/a
repetitions:                    n/a
socket timeout:                 30
accept-encoding:                gzip
delay:                          1 sec
internet simulation:            false
benchmark mode:                 false
failures until abort:           1024
named URL:                      none
URLs file:                      /usr/local/etc/urls.txt
logging:                        true
log file:                       /usr/local/var/siege.log
resource file:                  /Users/user/.siegerc
timestamped output:             false
comma separated output:         false
allow redirects:                true
allow zero byte data:           true
allow chunked encoding:         true
upload unique files:            true

Now that siege is installed you can start testing a web site:

siege -c5 -d5 -r1 -v http://www.test.com

In this example I used:

  • -c5 to define the number of concurrent users
  • -d5 to define the delay between each user request
  • -r1 to define number of repetitions

The result of the command is something like this:

** SIEGE 3.0.6
** Preparing 5 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200   0.14 secs:    7706 bytes ==> GET  /
HTTP/1.1 200   0.16 secs:    7706 bytes ==> GET  /
HTTP/1.1 200   0.11 secs:    7706 bytes ==> GET  /
HTTP/1.1 200   0.11 secs:    7706 bytes ==> GET  /
HTTP/1.1 200   0.11 secs:    7706 bytes ==> GET  /
done.

Transactions:		           5 hits
Availability:		      100.00 %
Elapsed time:		        4.12 secs
Data transferred:	        0.04 MB
Response time:		        0.13 secs
Transaction rate:	        1.21 trans/sec
Throughput:		        0.01 MB/sec
Concurrency:		        0.15
Successful transactions:           5
Failed transactions:	           0
Longest transaction:	        0.16
Shortest transaction:	        0.11

But this command only tests one URL in your server, the one you give as parameter. To make a more real world test you can use the logparse Perl script to create your own urls.txt file. This program collects URLs from Apache style access logs and populates a urls.txt file to use it later with siege. The parameters needed are the web site you want to generate the URLs for and an access_log file from the Apache server:

perl logparse -h http://test.com -f /opt/local/apache2/logs/test.com-access_log

Once you have the urls.txt file you can use it in siege with the -f option:

siege -c5 -d5 -r1 -f=urls.txt -v http://www.test.com

Ref: http://www.joedog.org/siege-home/

Fix “No such file or directory: httpd: could not open error log file /…/${APACHE_LOG_DIR}/site.log”

If you get an error like this in the Apache2 error log:

No such file or directory: httpd: could not open error log file /.../${APACHE_LOG_DIR}/site.log

apache_logo

You can fix it by just adding the path of your Apache2 log folder in the envvars file. If you use Mac Ports it’s located in /opt/local/apache2/bin/envvars:

export APACHE_LOG_DIR=/opt/local/apache2/logs

If you don’t know where envvars is just find it with this command:

find / -name "envvars"

Once added just restart the Apache2 server.

Disable blank console in Ubuntu

Edit /etc/default/grub and add consoleblank=0 in the GRUB_CMDLINE_LINUX_DEFAULT option:

GRUB_CMDLINE_LINUX_DEFAULT="consoleblank=0"

grub

Then update grub and reboot.

sudo update-grub
sudo shutdown -r now