Setting up a new centos VPS server from console
I just got a couple of vps servers, that I have to configure to run some apps, this are the tasks I did to have them ready for production use:
This servers didn’t came with a control panel (better for me), so the first thing I did was to login:
ivan@mini:~$ ssh root@23.45.12.56
After this I checked the OS, version and architecture
[root@V100205C4HB9V-1 ~]# cat /etc/*release* CentOS release 5.4 (Final) [root@V100205C4HB9V-1 ~]# uname -a Linux V100205C4HB9V-1 2.6.18-028stab064.7 #1 SMP Wed Aug 26 13:11:07 MSD 2009 x86_64 x86_64 x86_64 GNU/Linux [root@V100205C4HB9V-1 ~]#
Ok, now that I know the OS I create a normal user to avoid using the root account.
[root@V100205C4HB9V-1 ~]# useradd –Gwheel ivan
Then I change the server name to mygdon
[root@V100205C4HB9V-1 /]# sed -i 's/V100205C4HB9V-1/mygdon/g' /etc/sysconfig/network [root@V100205C4HB9V-1 ~]# sed -i 's/V100205C4HB9V-1/mygdon/g' /etc/hosts [root@V100205C4HB9V-1 ~]# echo HOST.DOMAIN.com > /etc/hostname [root@V100205C4HB9V-1 ~]# hostname -F /etc/hostname
Unfortunately I was unable to persist the new hostname, because it is a VPS server, there are ways around this, but didn’t have the time to make the changes so I just moved on, and leave this for later
The next thing I did was update the OS, and add the rpmforge repo because I will need some apps from there
[root@V100205C4HB9V-1 ~]# yum update [root@V100205C4HB9V-1 ~]# yum upgrade [root@V100205C4HB9V-1 ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm [root@V100205C4HB9V-1 ~]# rpm -Uhv rpmforge-release-0.5.1-1.$dist.rf.$arch.rpm [root@V100205C4HB9V-1 ~]# yum update [root@V100205C4HB9V-1 ~]# yum upgrade
Then I installed some packages I often use:
[root@V100205C4HB9V-1 ~]# yum install htop screen vim-enhanced
The VPS already had a web stack installed I just did some configuration:
Configuring Apache Virtual Hosts
[root@V100205C4HB9V-1 ~]# mkdir /var/www/vhosts/{site1, site2} –p [root@V100205C4HB9V-1 ~]# vi /etc/httpd/conf/httpd.conf
Here I Uncommented the following directive
NameVirtualHost *:80
and Added a default vhost a new vhost
<virtualhost *:80>DocumentRoot /var/www/vhosts/defaultServerName mygdon.site1.net<directory /var/www/vhosts/default> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all</directory>ErrorLog logs/mygdon.site1.net-error_logCustomLog logs/mygdon.site1.net-access_log common</virtualhost><virtualhost *:80>DocumentRoot /var/www/vhosts/site2ServerName appname.site2.net<directory /var/www/vhosts/site2> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all</directory>ErrorLog logs/appname.site2.net-error_logCustomLog logs/appname.site2.net-access_log common</virtualhost>
then restarted the apache server:
[root@V100205C4HB9V-1 ~]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
and I wrote a simple php file to test this out:
[root@V100205C4HB9V-1 ~]# echo '<? phpinfo(); ?>' > /var/www/vhosts/site1/index.php
And because I haven’t configured a DNS server I just temporarily added the server to my hosts file (On my local machine):
root@mini:/etc# echo 'subdomain.site1.net 54.65.74.23' > /etc/hosts
and here is the result:
Configuring Mysql
Once I had the virtual hosts configuration in place I added a mysql user and changed the default root password:
[root@V100205C4HB9V-1 vhosts]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5Server version: 5.0.77 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases;+--------------------+ | Database |+--------------------+ | information_schema | | mysql | | test |+--------------------+ 3 rows in set (0.00 sec) mysql> UPDATE mysql.user SET Password=PASSWORD('pass-here') WHERE user='root'; Query OK, 3 rows affected (0.02 sec)Rows matched: 3 Changed: 3 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec) mysql> CREATE USER 'ivan'@'localhost' IDENTIFIED BY 'pass-here'; Query OK, 0 rows affected (0.01 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'ivan'@'localhost' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> CREATE USER 'ivan'@'%' IDENTIFIED BY 'pass-here'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'ivan'@'%' WITH GRANT OPTION; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)mysql>
Now the server is ready for adding some virtual hosts, I just need to configure a DNS server and the mail server, but because the DNS is on another server and already working I just have to add a new zone, as for mail server, this server will be only used to send emails so I don’t need to dig in postfix configuration files for now.
I’ll write another post regarding the security, but for now this will work.