⬆️ ⬇️

Exploring and Configuring CentOS 6.4 for a Server

image



I’ll say right away that I’m not a Linux specialist, I started learning Linux only because renting servers for Windows is several times more expensive, that is, whatever Linux is, it’s just profitable, and as it turned out in some moments and simpler than Windows.



The article is written as a complete guide to one of the possible options for setting up a web server on CentOS from the beginning to the end, with all the pitfalls that it may take a long time for a person who is not familiar with Linux to eliminate. The server is supposed to be on Apache + PHP + Postgres, who need MySQL can easily find a guide on the Internet, Postgres is still less popular, and therefore a bit more complicated. In addition to the possible benefits for others, I plan to use my own manual to recall the moments that were strained when setting up CentOS and quickly deploying servers to CentOS as needed, so any advice and additions are welcome!

')

Why CentOS ?, here, too, everything is just because I did not work with any version of Linux, chose the best one available under my requirements, and the requirements are simple once the server, you need maximum stability and free of charge, and CentOS is an enterprise-class operating system created based on paid Red Hat Linux and unlike Fedora without any experiments, only proven and reliable technologies from Red Hat.



Despite the stated stability, I advise you to start learning CentOS on a local computer in a virtual machine, and I recommend Virtual Box as a virtual machine, because in my favorite VMware Workstation, CentOS managed to cause the entire VMware to hang, which I have never used VMware for many years I also saw CentOS for some reason not to be installed on VMware Workstation 9 in a minimal configuration, namely in this configuration (that is, just access to the command line, without any graphical skins), ideally using CentOS on a remote server, as well as with VMware and problems with installing the 64-bit version of CentOS 6.4. Of course, I’m sure that all these problems with VMware are solved, but as I didn’t want to understand this, when studying the OS itself is much more interesting, just keep in mind, all other things being equal, it’s better to start learning in Virtual Box.



So, let's begin:

To begin with, I advise you to install CentOS with a graphical interface, the distribution kit can be easily distinguished by the largest size, the main work will still have to be done in the terminal window, but the usual appearance of the desktop will make it easier to survive the shock of the fact that you can work without graphics.

After installing CentOS and creating a user like Test, you need to log in as root, and the password is entered from the user Test, root is the system administrator and only under it you can do everything you need to set up our server, strange logic but you need to know.



You can also go under Test and enter

# su root

in the end, you will do everything as root, this method is also more secure

thanks to Falcon_peregrinus for the advice



After the login is successful, you need to open a terminal window in the graphical version of CentOS, or just start writing commands on the command line in the minimum version of CentOS.

To begin, we will update the system. Just write in the terminal:

# yum update and hit enter

The # sign is not needed, I just wrote it so that it was clear that this is a command for the CentOS terminal.

After yum update, if you have an Internet connection, the entire system will be updated from the official CentOS repository. What I immediately liked about CentOS in comparison with Windows is the existence of such a repository, where a bunch of tested software for your system is collected. Of course, using it only from the terminal window is not as convenient as it could be, but in the case of a server, there won't be much software, and this is more than enough.



Network

If you still have some problems with the Internet on CentOS then I will describe how to configure the network adapter.

We type in the terminal command

# ifconfig

Not ipconfig, but if

As a result, we will be shown all the network interfaces that are on CentOS. In order for the Internet to be in the list of available interfaces besides lo (that is, local), there must be at least one eth adapter, for example eth0.

If there is no eth, enter

# ifconfig eth0 up

Then we enter again ifconfig and check that eth0 should appear.

If the Internet is still not there, then open the settings eth0

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

vi is a text editor. To start editing you need to press the i key. INSERT appears at the bottom. To exit the edit mode, press ESC. Then we write: wq what it means to save and exit (:: q! To exit without saving). How exactly to edit the network adapter configuration file eth0 is better visible to you, the only thing I will say is that you need to set ONBOOT = ”yes” in order for the network adapter to load automatically. This parameter helped me to finally get the IP address from my router via DHCP, for some other reason it did not work out. I will also say that to configure the network there is a graphical program that can be called with the command

system-config-network

But it is impossible to configure the ONBOOT = ”yes” parameter in it, and generally it’s more convenient for me in a regular file.

Yes, and in the minimum configuration of CentOS, this program still needs to be installed from the repository.



Apache

When we updated the system, which means we have no problems with the Internet in our OS, we can proceed to setting up the server.

First, put the web server.

# yum -y install httpd

-y means that the installer will click yes if this is required, you can start it and just

# yum install httpd

But then you have to press y yourself.

Add apaches to autoload

# chkconfig httpd on

And run

# service httpd start

If you appear OK, then everything went well.



Php

Now put php

# yum install php

Make a file to check

# echo '<?php phpinfo(); ?>' > /var/www/html/test.php

Overload Apache

# service httpd restart

We look at the address IP-address_server / test.php information about php, if it is, then everything is fine.



Postgres

Now with the Postgres installation we will make a little more difficult. In the official CentOS repository, there is an old version of Postgres 8.3, from my experience with postgres I’ll say that I had problems with it, so I advise you to install a newer version.

Original manual in English here.



First, turn off SELinux

# vi /etc/sysconfig/selinux

And set the variable SELinux = disabled

SELinux is a Linux access control system that prevented me from connecting to Postgres, not a word in the original English manual.

Already after writing this article, I set up CentOS on another server, and the connections to Postgres went fine and without disabling SELinux, so just keep in mind if Postgres does not work, it’s possible that SELinux works.



Now download the Postgres repository data from the official site.

# wget yum.pgrpms.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm



If nothing shakes install wget prog (yum install wget)

Install the repository so that Postgres can be installed via yum

# rpm -ivh pgdg-centos92-9.2-6.noarch.rpm



Then we put the client server for Postgres

# yum install postgresql92 postgresql92-server

pressing Y where you need it

We initialize a DB

# service postgresql-9.2 initdb

And we start

# service postgresql-9.2 start

add Postgres to autoload

# chkconfig postgresql-9.2 on



Now you need to create a user for Postgres

# su postgres

# psql -dpostgres



postgres = # should appear at the beginning of the line, so we are logged in with this user in the database.

Then create a super user and password

# CREATE role opensourcedbms LOGIN PASSWORD 'opensourcedbms' SUPERUSER;

Then we leave

# \q



Now we need to make the standard Postgres settings.

# vi /var/lib/pgsql/9.2/data/postgresql.conf

Uncomment the line #listen_addresses = 'localhost' and change it to #listen_addresses = '*'

And configure the pg_hba.conf file

# vi /var/lib/pgsql/9.2/data/pg_hba.conf

I leave the uncommented lines to check the database

Host all all 0.0.0.0/0 trust

Host all all :: 1/128 trust

That is, the connection is accepted from any address and without a password, then do not forget to fix it.

After setting up, I advise you to change trust to md5, allow only local connections to the database and, as an exception, register your IP address from which you can connect to the database remotely, if the IP is dynamic and you need a direct connection to the database, leave 0.0.0.0/0



Then

# service postgresql-9.2 restart



And if you are running a firewall, you need to add such an entry to it

# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT



Although I advise to start just to make

# service iptables stop

To turn it off completely.



After that, you can try to connect to the database from the one not installed in CentOS, pgAdmin. You can of course put pgAdmin in CentOS itself, but I think this is superfluous, especially since you need a graphical interface for this.



In case of any problems, to start, restart all services or even the entire server, maybe you forgot to do it somewhere and the changes have not yet taken effect.



Now you just have to link Postgres with PHP

# yum install php-pgsql



after which we restart the web server and database

# service httpd restart

# service postgresql-9.2 restart

And in our test.php file that we created earlier, Postgres information should appear.



FTP

Now we put FTP to access files on our server.

# yum install vsftpd

# chkconfig vsftpd on

# service vsftpd start



I think these three lines are clear, I will talk about how to create a user for FTP and assign a folder to it not by default, it is the purpose of the folder for some reason that is incorrectly described in the articles that I read on configuring vsftpd.

# adduser ftpuser1

# passwd ftpuser1



We create the user and the password.

Open the file with all CentOS users.

# vi /etc/passwd

We find there ftpuser1 and change the folder there at its discretion

Then we reboot vsftpd and we check.

Changing the default folder for an ftp user, for example, came in handy for me to upload files via ftp immediately to the web server directory

The vsftpd configuration is in /etc/vsftpd.conf, I will not describe it individually for everyone, but by default everything works.

You can only immediately disable access to anonymous ftp.

anonymous_enable: no



SFTP

SFTP is a more secure analog of FTP, I learned about it recently, but in all the programs I need, its support has long been there

So if you don’t need FTP, I advise you to immediately set up file transfer to the server via SFTP



I didn't even have to install anything in my system.

# service sshd start

# chkconfig sshd on



Notice how the user account in / etc / passwd should look like

sftpuser: x: 500: 500 :: / var / www / html: / bin / bash



at the end should be / bin / bash

This post tells you which shell will be available for sftpuser.



Do not forget to unblock port 22 in the firewall if it is locked.



Graphics

Now I would like to say how to put the graphical interface on CentOS, if you do not have this.

#yum groupinstall "X Window System" "Desktop" "Desktop Platform" "Fonts"

And launch

# startx

To exit the GUI, type

# telinit 3

Note the command with a space!



Regarding access to the graphical interface on a remote server (I don’t need such access on my local virtual machine), I can simply advise using xrdp, according to the information on the Internet, this access is the most stable and fast, I was installed on demand on my hosting and I didn’t deal with the installation , because to configure the server is quite enough for the usual console that can be obtained in the program PuTTY. I was even surprised how convenient the console is, I advise you just to try, for the server, the access to the desktop usually slows down and it is annoying, but even if everything were like on a local computer, I would also use the console. The graphics are very useful for the initial study of what and how, but when you quickly need to set up a server, the console is simply better.



Additional small utility, I plan to update:

# yum search file_name

File search in CentOS repository



# find /* -iname 'file_name'

Finding the location of the file on the local computer



# ls

# ls –l

Shows the contents of the current directory.



# system-config-firewall

firewall in the graphics can be conveniently put daws on those services that are allowed to go online, sometimes you need to install from the repository.

Source: https://habr.com/ru/post/195614/



All Articles