Tutorial: Install a CentOS 6.4 Webserver
At this moment I’m attending a Red Hat Enterprise Linux system admin training which I must say is very interesting. I’ve always been interested in Linux but as a Windows minded admin never took the time to really learn it up until now. And I must say: LINUX ROCKS. In the past I ran into some hard-to-troubleshoot problems with Linux based systems and it’s nice to realize that things are now getting clearer. So I tought it would be a good idea to write a few tutorials for my blog, starting with the basics. How to install a CentOS (which is exactely the same as Red Hat Enterprise (only it lacks the enterprise support)) webserver which you can then use to host apps (like SickBeard/CouchPotato/Headphones/maybe some nzb-indexers (I’m full of ideas!!). I even took the time to take a lot of screenshots. So let’s start!
First some downloadlinks. CentOS 6.4 can be downloaded here. The Linux Integration Services Version 3.4 for Hyper-V can be downloaded here. You need both. In Hyper-V create a new Virtual Machine. In my case I need a big data disk so I created a VM with one disk of 200GB. You need to make sure that your machine contains a Legacy Network Adapter that is connected to your Virtual Switch. Mount your ISO to the VM’s dvd drive and fire it up. Now the screenshot part 😉
The first step entering the prompt is checking if your network connectivity is OK. Just ping some server in your LAN or ping an online webserver. If you do not have a connection use the ip a command to see if you actually have an interface. Check if the file /etc/sysconfig/network-scripts/ifcfg-eth0 (most of the time the interface will be eth0, but the number can differ ofcourse) exists. Check if the interface (if down) can be enabled with ifup eth0. If your interface is up but you still do not have a network connection check if you Legacy Adapter in Hyper-V is connected to your Virtual Switch. If you still don’t have a connection leave a reply and I’ll try to help.
Anyway assuming you do have a network connection you still need to check and maybe modify your ifcfg-eth0 file. I recommend using VI which is a great tool. Some basic commands manual can be found here. Try to remember that VI has a command mode and an edit mode. In the command mode you can use commands. In the edit mode you can edit. Easy… huh?!?
The commands you will use most of the time are:
:q for quit.
:q! for quit discarding changes.
':x' for quit saving changes.
/ for searching and then (n)ext or (b)ack
i (without : ) to enter insert (edit) mode.
ESC (the escape key) to leave insert mode
There are a lot more but for just editing files these will probably do the job. So to continue. Edit your ifcfg-eth0 file with vi /etc/sysconfig/network-scripts/ifcfg-eth0. Press i to enter edit mode. Make sure the following lines are modified and do verify the rest of the settings.
When done ESC to leave edit mode and enter command mode. Use ‘:x’ to save or :q! to quit without saving. You can also use :wq but that’s just the same as ‘:x’. Note that the ‘:x’ also is without quotes. My blog turns it into a smiley 🙂 Next configure IP Tables. I use a basic set of policies. More about IP Tables on this page.
iptables -P INPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -L -v
You can add extra security by disabling the possibility for root to log in through ssh. First create a new user (eg mark) with useradd mark. Then set a password with passwd mark. Now edit the /etc/ssh/sshd_config file and look for the #PermitRootLogin part. Remove the # and set it to no. You need to restart your SSH Daemon with service sshd restart. You can in this case login through SSH with the mark user and use the su – command to switch to root.
Next update your kernel and apps with the yum update command. This can take a while. When done reboot your machine and make a snapshot in Hyper-V. We’ve now come to the part to install Integration Services and that one did sabotage one of my Linux VM’s once. So make that snapshot!
Mount the Integration Services ISO in the VM’s DVD drive and install with the following commands:
mkdir -p /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cp -rp /mnt/cdrom /opt/linux_is34
Reboot when the installation is done. When booting succesful shut down the VM and edit it’s settings.
To finish up install a view packages a lot of webapps use or are needed for app. installation.
yum install gd gd-devel httpd php gcc glibc glibc-common perl openssl-devel make wget
And that’s it for part 1