WintelGuy.com
CentOS Initial Set up and Configuration

“I've just installed CentOS 6! Now what?”

CentOS installation is really quick and simple. After answering very few questions you end up facing a black console screen with the login prompt. I you find yourself a bit intimidated in such situation, this page may help you. It describes the essential steps you need to perform to make your system a bit more useful. Just follow through the steps in the order provided or select any item from the list of links below.

Console resolution | Mouse support | Host name | Enable DHCP | Static IP | Disable IPv6 | Cloning issues | Networking service
Yum with proxy | Patching with yum | Install Apache | Install PHP | Install mySQL | MD5 checksum

Change console resolution

In the /boot/grub/grub.conf (or /boot/grub/menu.lst) add vga= parameters at the end of the kernel configuration line (the line may be quite long and span multiple lines on the screen):

kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=/dev/mapper/vg_centos1-lv_root ... quiet vga=0x317

Reboot the system to activate the setting:

# reboot now

For your reference here is a partial list of vga mode numbers:
    |640x480 800x600 1024x768 1280x1024
----+-------------------------------------
256 | 0x301   0x303   0x305    0x307
32k | 0x310   0x313   0x316    0x319
64k | 0x311   0x314   0x317    0x31A
16M | 0x312   0x315   0x318    0x31B
More details... List of VGA modes...

Back to Top

Enable mouse support in console mode

To enable mouse support install gpm package from the installation DVD.
Create a mount point for DVD/CDROM:

# mkdir /mnt/cdrom

Mount DVD/CDROM:

# mount /dev/sr0 /mnt/cdrom

Install gpm package:

# cd /mnt/cdrom/Packages
# rpm -i gpm-1.20.6.-12.el6.x86_64.rpm

Reboot:

# reboot now

If system has Internet connectivity install gpm package using yum (see yum further below):

# yum install gpm
Back to Top

Change host name

In /etc/sysconfig/network modify the HOSTNAME parameter. Reboot.

HOSTNAME=centos1
Back to Top

Enable DHCP client

To configure a DHCP client, modify the /etc/sysconfig/network file to enable networking and modify the configuration file for each network device in the /etc/sysconfig/network-scripts directory. In this directory, each network device should have a configuration file named ifcfg-eth0, where eth0 is the network device name. To list all network devices run ifconfig -a command.

The /etc/sysconfig/network file should contain the following line:

NETWORKING=yes

The NETWORKING variable must be set to “yes” if you want networking to start at boot time.
The /etc/sysconfig/network-scripts/ifcfg-eth0 file should contain the following lines:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

A configuration file is needed for each device to be configured to use DHCP. Reboot system after modifying the files.
More information...

Back to Top

Assign static IP address

To assign static IP address to a network interface modify the corresponding configuration file in the /etc/sysconfig/network-scripts folder.
For example, to assign static IP to the eth0 interface, modify the /etc/sysconfig/network-scripts/ifcfg-eth0 file as shown below:

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.0.0
NETMASK=255.255.255.0
IPADDR=192.168.0.251
GATEWAY=192.168.0.1
USERCTL=no

More information...

Back to Top

Disable IPv6

In /etc/grub.conf add the ipv6.disable=1 parameter to the end of the kernel line (the line may be quite long and span multiple lines on the screen):

kernel /vmlinuz-2.6.32-358.18.1.el6.x86_64 ro root=/dev/mapper/vg_centos1-lv_root ... quiet vga=0x317 ipv6.disable=1

More information...

Back to Top

Removing network cards with higher numbers created after VM cloning

Go into /etc/udev/rules.d and delete the 70-persistent-net.rules file and reboot. If you open it before hand you will most likely see the original network card MAC listed as eth0 and the new one as eth1.
Now you need to edit /etc/sysconfig/network-scripts/ifcfg-eth0 and manually update the MAC of your new network card. Deleting the file forces the detection process to run again at boot with no baggage left over from the cloning process, namely the old card MAC address(es).
More information...

Back to Top

Start/Stop/Restart networking service

# service network stop
# service network start
# service network restart
Back to Top

Configure yum to work through a proxy server

In /etc/yum.conf add proxy server parameters:
Proxy server setting - <proxy server URL>:<port number>

proxy=http://mycache.mydomain.com:8080

Proxy user account details for yum connection:

proxy_username=<proxy_username>
proxy_password=<password>

More information...

Back to Top

Updating System with yum

Run yum to update your server:

# yum check-update
# yum update

More information...

Back to Top

Install Apache HTTPD

Apache httpd server can be installed as a group of packages called “Web Server” using yum groupinstall command, or package by package using yum install.
To list all packages included in the “Web Server” group run:

# yum groupinfo "Web Server"

Group: Web Server
 Description: Allows the system to act as a web server, and run Perl and Python web applications.
 Mandatory Packages:
   httpd
 Default Packages:
   crypto-utils
   httpd-manual
   mod_perl
   mod_ssl
   mod_wsgi
   webalizer
 Optional Packages:
   certmonger
   libmemcached
   memcached
   mod_auth_kerb
   mod_auth_mysql
   mod_auth_pgsql
   mod_authz_ldap
   mod_nss
   mod_revocator
   perl-CGI
   perl-CGI-Session
   perl-Cache-Memcached
   python-memcached
   squid

To install the “Web Server” package group run:

# yum groupinstall "Web Server"

Command yum groupinstall "Web Server” will install by default only mandatory and default packages. If you want to install all packages, including optional, add the following line to the /etc/yum.conf file:

group_package_types=mandatory,default,optional

To install only httpd package (including dependencies) use yum install, for example:

# yum install http*

Configure the Apache service to start on boot:

# chkconfig --levels 235 httpd on

In the httpd configuration file /etc/httpd/conf/httpd.conf uncomment the line containing the text:

NameVirtualHost *:80

Restart the Apache HTTP Server daemon:

# service httpd restart

Type the server's URL or IP in your web browser and you should see Apache 2 Test Page.
If you received connection time out error and you've done everything correctly, take a look at this post.
More information...

Back to Top

Install PHP

Php can be installed as a group of packages called “PHP Support” using yum groupinstall command:

# yum groupinstall "PHP Support"

If you are planning to use php together with MySQL install php-mysql package:

# yum install php-mysql

Verify that /etc/httpd/conf.d contains php.conf file. Restart Apache

# apachectl -k restart

Verify that php module is running:

# apachectl -t -D DUMP_MODULES | grep php

To test your php installation perform the followings steps:
In the default Apache DocumentRoot folder - /var/www/html create a file called, for example, info.php with the following content:

<html>
 <head>
  <title> PHP Test Script </title>
 </head>
 <body>
  <?php phpinfo( ); ?>
 </body>
</html>

To access the file type into your web browser the web server's URL or IP with the /info.php file reference at the end, for example: http://192.168.0.100/info.php

Back to Top

Install mySQL

MySQL can be installed using yum groupinstall command:

# yum groupinstall "MySQL Database client" "MySQL Database server"

If you are planning to use php together with MySQL install php-mysql package

# yum install php-mysql

Set the MySQL service to start automatically on boot:

# chkconfig --levels 235 mysqld on

Start the MySQL service

# service mysqld start

Run the following script to set root passwords and remove anonymous users:

# /usr/bin/mysql_secure_installation

To test Apache + php + My SQL perform the following steps:
Launch MySQL command-line tool

# mysql -u root -p

Create a new test database, called “mytest”:

mysql> CREATE DATABASE mytest;

Create a new simple table, called “things”:

mysql> USE mytest
mysql> CREATE TABLE things
     -> (name char(255));

Add some data to the table:

mysql> INSERT INTO things (name) VALUES ("ane”), ("bane"), ("mane"), ("more");

Create a new user, called “phpuser” and assign “SELECT” privileges for the things table:

mysql> CREATE USER 'phpuser'@'localhost' IDENTIFIED BY 'phppass';
mysql> GRANT SELECT ON mytest.things TO 'phpuser'@'localhost';

In the default Apache DocumentRoot folder - /var/www/html create a file called, for example, mysqltest.php with the following content:

<html>
 <head>
  <title> PHP and MySQL Test Script </title>
 </head>
 <body>
<?php
  $con=mysqli_connect("localhost","phpuser","phppass","mytest");
// Check connection
  if (mysqli_connect_errno()) {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

  $result = mysqli_query($con,"SELECT name FROM things");

  echo "<table border='1'><tr><th>Things</th></tr>";

  while($row = mysqli_fetch_array($result)) {
   echo "<tr>";
   echo "<td>" . $row['name'] . "</td>";
   echo "</tr>";
  }
  echo "</table>";
  mysqli_close($con);
?>
 </body>
</html>

To access the file type into your web browser the web server's URL or IP with the /mysqltest.php file reference at the end, for example: http://192.168.0.100/mysqltest.php

Back to Top

File integrity / MD5 checksum verification

Windows:
Download and install MS File Checksum Integrity Verifier (Windows-KB841290-x86-ENU.exe)
To calculate the MD5 checksum of a file run:

C:\>fciv rhel-server-6.4-i386-dvd.iso
//
// File Checksum Integrity Verifier version 2.05.
//
2f1927af5bca9a34f2d9488655b4fdf4 rhel-server-6.4-i386-dvd.iso

Linux:
To calculate the MD5 checksum of a file run:

# md5sum mysqltest.php
fe8102b19be5cfebba77ec13e49f7c66 mysqltest.php

Back to Top