LinuxMoz

Linux Stuff && Coffee

CentOS Install MySQL Server

| Comments

The following tutorial explains how to install MySQL on CentOS 6 using the YUM package manager, these instructions should also work with CentOS 4 & 5. CentOS install MySQL via YUM

CentOS Install Git

| Comments

To install git on CentOS 6 simply use the following yum command.

CentOS 6 Install Git using YUM

Enter the following as root:

1
yum install git

This will give you an output similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.7.1-2.el6_0.1 will be installed
--> Processing Dependency: perl-Git = 1.7.1-2.el6_0.1 for package: git-1.7.1-2.el6_0.1.x86_64
--> Processing Dependency: perl(Git) for package: git-1.7.1-2.el6_0.1.x86_64
--> Processing Dependency: openssh-clients for package: git-1.7.1-2.el6_0.1.x86_64
--> Running transaction check
---> Package openssh-clients.x86_64 0:5.3p1-81.el6 will be installed
---> Package perl-Git.noarch 0:1.7.1-2.el6_0.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package                 Arch           Version                 Repository    Size
===================================================================================
Installing:
 git                     x86_64         1.7.1-2.el6_0.1         base         4.6 M
Installing for dependencies:
 openssh-clients         x86_64         5.3p1-81.el6            base         358 k
 perl-Git                noarch         1.7.1-2.el6_0.1         base          28 k

Transaction Summary
===================================================================================
Install       3 Package(s)

Total download size: 5.0 M
Installed size: 16 M
Is this ok [y/N]: y

CentOS Install Development Tools

| Comments

How to install the CentOS development tools yum group, a collection of RPM packages required by developers or administrators wishing to build / compile software on CentOS.

CentOS install Development Tools YUM Group

Enter the following command to install the developer tools on CentOS Linux:

1
yum groupinstall "Development Tools"

This will then install all relavent developer RPM’S (which could take some time depending on your connection speed).

Dig IPv6 Lookup / Reverse Lookup

| Comments

If you are in the process of setting up IPv6 there are a couple of dig commands you should know, how to do a IPv6 lookup on a AAAA record and how to do a IPv6 reverse lookup.

How To do a IPv6 AAAA (Dig IPv6 Forward Lookup)

The following command shows you how to do a Dig IPv6 lookup on Linux:

dig AAAA ipv6.google.com

This should give you an output similar to:

; <<>> DiG 9.8.3-P1 <<>> AAAA ipv6.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55360
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;ipv6.google.com.       IN  AAAA

;; ANSWER SECTION:
ipv6.google.com.    43199   IN  CNAME   ipv6.l.google.com.
ipv6.l.google.com.  299 IN  AAAA    2a00:1450:400c:c06::93

;; Query time: 48 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sat Nov  3 12:20:09 2012
;; MSG SIZE  rcvd: 82

How To do a IPv6 Reverse Lookup on Linux, using Dig IPv6 Reverse Lookup

To do a Dig reverse lookup on Linux simply use the -x option followed by the IPv6 IP address, here is an example using Googles IPv6 address above.

dig -x 2a00:1450:400c:c06::93

This will give you an output similar to:

; <<>> DiG 9.8.3-P1 <<>> -x 2a00:1450:400c:c06::93
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 20188
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;3.9.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.0.c.0.c.0.0.4.0.5.4.1.0.0.a.2.ip6.arpa. IN PTR

;; ANSWER SECTION:
3.9.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.0.c.0.c.0.0.4.0.5.4.1.0.0.a.2.ip6.arpa. 43198 IN PTR wb-in-x93.1e100.net.

;; Query time: 43 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sat Nov  3 12:25:00 2012
;; MSG SIZE  rcvd: 123

Linux Show Hidden Files

| Comments

Linux hidden files are prefixed with a . for example .htaccess would make this a hidden file, by default when you list a directories contents in Linux they are not displayed.

Linux Show Hidden Files Command

Change to the directory you wish to list the hidden files and enter the ls command with the following options:

1
ls -la

ls -la (the Linux show hidden files command) should give you an output similar to the following:

1
2
3
4
5
6
7
8
9
[root@thor html]# ls -la
total 200
drwxr-xr-x  5 root   root    4096 Feb 13  2012 .
drwxr-xr-x  6 root   root    4096 Sep 21 15:32 ..
-rw-r--r--  1 apache apache  7016 Sep 19 15:39 .htaccess
-rw-r--r--  1 apache apache   395 Aug 29 18:33 index.php
-rw-r--r--  1 apache apache 19929 Aug 29 18:31 license.txt
-rw-r--r--  1 apache apache  9177 Sep  8 18:30 readme.html
-rw-r--r--  1 apache apache  3729 Oct 30 18:37 sitemap.xml

Linux Find Large Files

| Comments

This is by far the easiest way to display the 50 largest files on your Linux system, obviously you can modify the command to show more or less files if you wish.

Linux show largest files

Display the 50 largest files on a linux / unix based system.

1
du -xak .|sort -n|tail -50

Enjoy.

Bash Alias Example

| Comments

A Bash alias is often used for commands with a long option list that you use regularly and want to save yourself some time typing or reading the man file each time you wish to run the command.

A good example of this (for me) would be nmap, I often run nmap scans against boxes, and I have memorised the options I use, to save myself some time I might create the following bash alias:

Bash Alias Example

I would normally run a scan using:

1
nmap -sS -sV -P0 host

So I could create the following Bash alias:

1
alias nmap1='nmap -sS -sV -P0'

Now I can use the command:

1
nmap1 hostname

The above will run a scan on a host and it will execute nmap -sS -sV -P0.

Aliases are limited to a simple textual shortcut, if you need more power use a bash function instead.

How to Change Crontab Editor

| Comments

By default on Linux based systems Vi is used to edit the crontab, some of you might prefer Emacs (shame on you) and some others might even prefer to use Nano or Pico (no comment). Regardless of your reason not to use Vi for editing your crontab (I can’t think of any?), here are the instructions on how to change the crontab default editor in Linux (any version, Ubuntu, CentOS, Debian etc).

Set Nano as the default crontab Editor

Note, this will also change the default editor for a number of other commands.

Set Nano as the default editor in Linux:

1
export EDITOR=nano

Set vi as the crontab editor

Note, this will also change the default editor for a number of other commands.

Set Vi as the default editor in Linux:

1
export EDITOR=vi

Set Emacs as the crontab editor

Note, this will also change the default editor for a number of other commands.

Set Emacs as the default editor in Linux:

1
export EDITOR=emacs

Now when you type “crontab -e” it should load up with your editor of choice, if it does not you might need to specify the full path to the editor (depending on what shell you are using).

Linux Check Free Disk Space

| Comments

The following will show you how to check disk space in Linux, using df  command line tool, note this will show you the amount of disk space used and show free space in Linux.

Linux Disk Space Command (df)

Enter the following to show the amount of disk space used and free space on all mounted linux partitions, note the command with no other options will display the disk usage in K:

1
df

This will display an output similar to:

Linux disk space command df

However looking at Linux disk usage in Kilobytes can be a daunting task these days, I much prefer to view my disk usage in MB / GB in Linux using the following df command option:

1
df -h

Which should give you an output simliar to:

Linux Disk Space in MB / GB with df command

Asterisk: You Do Not Appear to Have the Sources for Kernel Installed

| Comments

If you get the following errors (or similar) when trying to build Asterisk you do not have then see the fix below to install the kernel devel / kernel headers. I have created this tutorial due to the amount of support requests received from my original tutorials, Asterisk Ubuntu Install, Asterisk Debian Install & Asterisk CentOS install.

Asterisk Build Errors Related to Kernel Headers / Devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
you do not appear to have the sources for the kernel install dahdi
you do not appear to have the sources for the 2.6.32-5-amd64 kernel installed
you do not appear to have the sources for the kernel installed
you do not appear to have the sources for the 3.2.0-23-generic-pae kernel installed
you do not appear to have the sources for the
you do not appear to have the sources for the 2.6.18-92.el5 kernel installed
you do not appear to have the sources for the 2.6.32-71.el6.i686 kernel installed
you do not appear to have the sources for the 2.6.18
you do not appear to have the sources for the 2.6 kernel installed
you do not appear to have the sources for the zaptel
you do not appear to have the sources for the ubuntu
you do not appear to have the sources for the xen kernel installed
you do not appear to have the sources for the zaptel
you do not appear to have the sources for the 2.6.32-5-amd64 kernel installed
you do not appear to have the sources for the 2.6.18-92.el5 kernel installed
you do not appear to have the sources for the 2.6.32-71.el6.i686 kernel installed
you do not appear to have the sources for the 2.6 kernel installed
you do not appear to have the sources for the 2.6.18
you do not appear to have the sources for the 2.6.32 kernel installed
you do not appear to have the sources for the 2.6.18 kernel installed
you do not appear to have the sources for the 2.6
you do not appear to have the sources for the 3.2.0-23-generic-pae kernel installed
you do not appear to have the sources for kernel installed
you do not appear to have the sources for the 2.6.32-71.el6.i686 kernel installed
you do not appear to have the sources for the 2.6.18-92.el5 kernel installed
you do not appear to have the sources for the 3.2.0-23-generic-pae kernel installed
you do not appear to have the sources for the 2.6.32-5-amd64 kernel installed
you do not appear to have the sources for the debian
you do not appear to have the sources for the dahdi
you do not appear to have the sources for the centos
you do not appear to have the sources for the 2.6 kernel installed
you do not appear to have the sources for the 2.6.32-71.el6.i686 kernel installed
you do not appear to have the sources for the 2.6.18-92.el5 kernel installed
you do not appear to have the sources for the 3.2.0-23-generic-pae kernel installed
you do not appear to have the sources for the kernel installed
you do not appear to have the sources for the 2.6.32-5-amd64 kernel installed
you do not appear to have the sources for the kernel install dahdi
you do not appear to have the sources for the 2.6.18-92.el5 kernel installed
you do not appear to have the sources for the 2.6.32-71.el6.i686 kernel installed
you do not appear to have the sources for the 2.6 kernel installed
you do not appear to have the sources for the zaptel
you do not appear to have the sources for the 3.2.0-23-generic-pae kernel installed

The CentOS, RHEL & Fedora fix

To fix the above Asterisk kernel compile / build error on CentOS, RHEL & Fedora enter the following:

First update with YUM:

1
yum update

Install the kernel headers & kernel devel on CentOS / RHEL:

1
yum install kernel-devel kernel-headers

Reboot and attempt to rebuild Asterisk / DHADI tools, if it still fails check your kernel version with:

1
uname -r

And then check the linked kernel source:

1
cd /lib/modules/`uname -r`

Check the symbolic link with:

1
ls -l

If the link is broken fix it with:

1
ln -s /usr/src/kernels/(kernel-source-dir) build

Ubuntu / Debian Install Kernel Source for Asterisk

The following command will fix the asterisk kernel build error on Debian / Ubuntu based distributions.

Ubuntu install kernel source:

1
sudo apt-get install linux-headers-$(uname -r)

If you are running Debian or Ubuntu as root you can drop the sudo command, use:

1
apt-get install linux-headers-$(uname -r)