Category Archives: CentOS

Disable IPv6 on CentOS 6

Just add or edit the lines below to the relevant files.

/etc/sysctl.conf  :  net.ipv6.conf.all.disable_ipv6 = 1
/etc/sysconfig/network  : NETWORKING_IPV6=no
/etc/sysconfig/network-scripts/ifcfg-eth0 : IPV6INIT=”no”

If you have a different interface than eth0, just replace the last line above with it.

Now you don’t need to reboot your server (as everybody else says on the internet), simply restart the network service and you’re good to go.

service network restart

Don’t forget that, since you’re not using ipv6 anymore, you can disable the ip6tables if active, to avoid extra resource usage.

service ip6tables stopchkconfig –level 345 ip6tables off

Mounting NTFS USB Disk on CentOS

You might get a warning unknown file system type ‘ntfs’ when trying to mount an NTFS disk on a CentOS server.

EPEL Repositories

To overcome this issue, you need the epel repositories enabled. If you haven’t done this before, just get the epel rpm file from the websites below and import them using rpm.
Note that the rpm files are different for CentOS 5 and CentOS 6.

#CentOS 5
wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
#CentOS 6
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Get them via wget. If you get an error saying there is no such file, just browse the directory listing to get the exact version.

After downloading them, import them like this:

rpm -Uvh epel-release-*.rpm

Now we have EPEL enabled.

Install ntfs-3g and fuse

Now we should install the ntfs-3g and fuse packages using yum.

yum install ntfs-3g ntfs-3g-devel fuse fuse-devel fuse-libs

Mounting and Unmounting

Now you can simply mount and unmount the ntfs file system.

/sbin/mount.ntfs-3g /dev/sdb1 /media/usb
umount /dev/sdb1

Of course the lines above assume you have the device /dev/sdb1 as the usb, and you have created a folder /media/usb.
You can see that unmounting is also quite simply, just like an ordinary disk.

Removing the EPEL Repo

If you don’t want to keep EPEL in your repo for some reason, you can simply remove.

Find the packages name using grep, assuming it is epel-release-6-8 you can use the commands below:

rpm -qa | grep epel
# output is epel-release-6-8
yum remove epel-release-6-8
yum clean all

smartd Settings on a CentOS Server

smartd is a great tool to keep track of the health status of your server disks. It tracks the S.M.A.R.T records on specified periods and warns you in case anything goes wrong. Even though it is quiet simple, people can get lost while setting up their configuration. Here I’ll explain how my generic settings go. Keep in mind that this is for CentOS servers.

To install the service, simply get the smartmontools package via yum. This will also install mailx if isn’t already installed.

yum install smartmontools -y

Now a file named /etc/smartd.conf will be created. This is where we tell smartd what to do. First, learn the names of your devices using fdisk.

root@eaVT:~# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006f1aa

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   943237119   471617536   83  Linux
/dev/sda2       943239166   976771071    16765953    5  Extended
/dev/sda5       943239168   976771071    16765952   82  Linux swap / Solaris

This output tells that I have one physical disk (/dev/sda) with three partitions (/dev/sda1, /dev/sda2, /dev/sda3). But we are only interested in the physical devices, which means smartd will only deal with /dev/sda.

Open /etc/smartd.conf using your favourite (vi?) text editor. Find the line that says
DEVICESCAN -H -m root
and comment it out. Then add this line
DEVICESCAN -S on -o on -a -m youremail@yourdomain.com -s (S/../.././02|L/../../0603) -M test
The result should look like this:

# The word DEVICESCAN will cause any remaining lines in this
# configuration file to be ignored: it tells smartd to scan for all
# ATA and SCSI devices.  DEVICESCAN may be followed by any of the
# Directives listed below, which will be applied to all devices that
# are found.  Most users should comment out DEVICESCAN and explicitly
# list the devices that they wish to monitor.
#DEVICESCAN -H -m root
DEVICESCAN -S on -o on -a -m youremail@yourdomain.com -s (S/../.././02|L/../../0603) -M test

Of course, don’t forget to replace it with your own email address. After this simply restart smartd service.

service smartd restart

Now wait for a while and check your email. According to my personal experience, it takes around 5-10 minutes to receive it. You will get a TEST email that says your disks have error. Now that we’ve established you can get the email when an error occurs, lets set it up to a real case.

Go back to /etc/smartd.conf and uncomment the line starting with DEVICESCAN. Don’t forget that there shouldn’t be any line starting with DEVICESCAN on this file, otherwise smartd will halt reading the conf file after it.

Now add the following lines to the /etc/smartd.conf

/dev/sda -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sda -d scsi -s L/../../1/01 -m youremail@yourdomain.com

Of course, replace the /dev/sda and email address according to yours.

The first line tells smartd to run a silence check on the /dev/sda disk and email us on any error.
The second line indicates that a long check will be made every Monday and 1 a.m. and on any error it will be mailed to us. If we wanted to make the test every Sunday at 6 p.m. the setting would have been L/../../7/18 -m youremail@yourdomain.com

If you’d like to add a new disk, (for example /dev/sdb) simply add it as a new line.

/dev/sda -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sda -d scsi -s L/../../1/01 -m youremail@yourdomain.com
/dev/sdb -H -C 0 -U 0 -m youremail@yourdomain.com
/dev/sdb -d scsi -s L/../../1/01 -m youremail@yourdomain.com

Now save the file and restart the service again.

service smartd restart

Normally, it is possible that the service won’t get started on reboot. You must add it with chkconfig in order to run it automatically in a CentOS box. To check it:

[root@emre ~]# chkconfig --list |grep smartd
smartd         	0:off	1:off	2:off	3:off	4:off	5:off	6:off
[root@emre ~]# chkconfig smartd on
[root@emre ~]# chkconfig --list |grep smartd
smartd             0:off    1:off    2:on    3:on    4:on    5:on    6:off

This means that it will run on user levels 2, 3, 4 and 5. What this means is a different story.

So that’s it for now.

Installing WordPress on CentOS 6.x

Let’s say you’ve got your new CentOS 6.x server up and running, with a minimal install. It is very easy to install the necessary items (including Apache, MySQL etc.) alongside WordPress to fully function.

First, let’s install the plugged.in LAMP installer for CentOS 6.x With this script, you’ll get everything you need to turn your Linux box into a web server. Details on how to use it is available on plugged.in

After this, we can easily get the wordpress installation and simply extract it.

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

Now get into MySQL using the password you’ve specified to plugged.sh

mysql -u root -p

Below, we’ll create a new database and new user to affiliate with.

CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost;
SET PASSWORD FOR wordpressusername@localhost= PASSWORD("password");
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressusername@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

Of course, you’ll have to replace “wordpressuser” and “password” with yours.
After creating the necessary database, we tell wordpress itself about these.

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
vi ~/wordpress/wp-config.php

Open and edit the wp-config.php file according to change the database info as below (yet again, replace with yours)

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and exit.
Now we should move our files to the user folder we've created with plugged.sh and change the files' owner.
cp -r ~/wordpress/* /home/username/public_html/
chown -R username:username /home/username/public_html/
chmod -R 755 /home/username/public_html/

Now visit your domain, or IP address on your browser. It will redirect you to the WordPress onscreen installation instructions. If it doesn’t, add “wp-admin/install.php” to the end. (like example.com/wp-admin/install.php).

And you’re done!

Also, if you want to import an XML file from your old WordPress blog or something, you’ll need to install the php-xml package.

yum install php-xml