Linux for Windows Server Administrators: Services and Runlevels
Editor’s Note: In part one of our article series on Linux for Windows Server administrators we covered the basics of Linux server administration, including using PuTTY, secure shell, and adding and managing Linux users. In this second article Stuart covers the use of two other important Linux server management concepts: Linux services and runlevels.
Introducing Linux Services
Dealing with Linux services is easy enough. Rather than using task manager and services,msc to configure the hosts services, CentOS uses the command chkconfig to manage the services. (There are other ways to do it, but this is the official RedHat way.)
Listing all the services in CentOS can be done by using the chkconfig command with no switches. This will list all the services that are currently manageable by chkconfig and their current status. To give you an easy breakdown of what is covered, lets look at the output column by column.
The first column is easy enough to understand and shows the names of the services. Notice the tabular columns of :on or :off. Notice how there are five groups of these, which correspond to what are known in the Linux world as runlevels.
About Linux Runlevels
A “runlevel” is basically a way of saying “The computer is at a known level of configuration.” As the machine boots, it will run from level 0 to 6. Runlevel 6 is reboot and runlevel 0 is power(ed) off. The runlevels from 1 to 5 are where the machine spends most of its time (usually level 3 or 5). Use runlevel 6 only if you want to reboot your server!
Runlevel 3 is important. It is the level that most Linux servers run most of the time. Level 3 is when the server is in multiuser, network-enabled configuration. Level 5 would be the runlevel if we were running a GUI such as Gnome or KDE. As a point of note, runlevel 4 is not actually used in any Linux OS! It is just a historical throwback to when it was first designed.
You can move between runlevels by using the command runlevel followed by the level you want to move to. Using the command by itself will give the current runlevel. Run the command. Notice that there are two columns. The first column is the previous runlevel. An N signifies that no other runlevel has been used, i.e. it has just been booted up into runlevel 3 from a powered off state.
An example of moving runlevel is issuing runlevel 1, which would move the machine into single-user mode, which does not have a live network connection. Be careful of doing this, though, as it will essentially turn off all networking (which only exists at runlevel 3 and above), and if the machine is remote, there will be no access to the machine as the network will be down.
It should start to make sense that each on or off refers to the question of if a service is enabled or disabled at the runlevel mentioned. Use the chkconfig command to change the service runlevels. For example, to turn off postfix, use the command:
chkconfig –level 3 postfix off
Note that this command doesn’t stop the service if it is currently running, it just sets the postfix service to not run at runlevel 3. It is also possible to turn services on using the format above. Do this with any service listed by the chkconfig command, substituting the service name and desired state (on or off).
Managing Linux Server Processes
Alongside the services detailed above, a Linux administrator will have to manage the server processes. Root can see the all the processes (from all users) running on the system by using the command ps -ef. Another useful command to use to monitor the system is the top command. Top, as the command implies, gives the process list, ordered by their statistics and resource consumption.
Managing the processes is quite straightforward. To stop (or “kill,” to use the proper term) a process use the command kill followed by the process ID. Sometimes the commands won’t quit. In this case use the command kill -9 followed by process ID, which is basically, “Just kill it and kill it good.”
To use the top command, just use the command top. Top will allow you to see the resources used in the last 5, 10, and 15 minutes. These can be seen under the load average. This can be seen in the top lefthand corner under “load average.”
A tip here is that pressing the c key will give you the full path to the process that is running if you need to locate the binary. The top command also shows the process owners and the amount of resources it consumes.
Using the top command it is possible to do some useful troubleshooting. If the load averages are consistently above the number of cores in the system (i.e. a dual core machine with a load of over 2) then the CPU may be taxed beyond its abilities. If the screen shows the WAIT % rising, this also means that the CPU is waiting for CPU time to schedule commands and perhaps it’s not up to the job.
Top will also show what processes are consuming all the resources, to allow you to investigate further.
There are many configuration options available to assist. Press the ? key to see all the configurable options.
To quit top, just use Ctrl + C.
Managing the services by using the service command. To stop a command – apache for example – use the command service httpd stop. To restart apache, use the command service httpd start. If just the current status is needed, use the command service httpd status. To just restart a service just use the restart option i.e service httpd restart.
It is worth noting that not all services are listed or respond to the service tool. For example, after-market applications installed outside of the standard installation managers can fall foul of this (yum or RPM). However, anything installed from within the package manager should adhere to this standard.
Installing Linux Software
Installing software under CentOS is quite straight forward and intuitive. There are two commands to software installation that can be used separately but complement each other. These commands are yum and RPM.
Yellowdog Updater, Modified (yum) is the most-used management tool. It not only allows for the installation of additional software packages but also to manage software installed previously. To start with a really simple introduction to updating the software already installed on the system, we can use the command yum update.
This command will inventory what is installed on the server and check for newer version of the software. Repositories, or repos, as they are commonly known are the Linux version of the Windows update stores. A useful switch to include is the -y switch, which means “assume yes to every question.”
Installing additional software is just as easy. The commands you can use to locate the packages you want are to use or install are yum search and yum install.
Use yum search php will give you a list of all items that contain php in the name. To install the software, use the command yum install (yum install php.x86_64, for example). This will then go ahead and install the latest version of php software in the repository.
If you have downloaded an RPM package file, install this using the command yum –nogpgcheck localinstall package.rpm. The -nogpgcheck means ignore the fact that the RPM package may not be digitally signed.
To install packages outside of the yum repository system, we can use the RPM command: Rpm -iv packagename.rpm
The iv switches stand for Install and Verify. Similar switches exist for removal.
What is the difference between the RPM command and yum commands? Yum will try and resolve any dependencies and is more “intelligent.” RPM is a more advanced tool that can do serious damage if used incorrectly.
Hopefully you now understand more of the components of Linux and how they fit together. In the third part of the series I will look at some more advanced management techniques, show you how to work with the file system, and introduce groups and users.
More in Windows Server
Latest Windows Server Updates May Cause Printing and Scanning Issues
Jul 25, 2022 | Rabia Noureen
Latest Windows Server vNext Insider Build Brings Support for LAPS
Jul 7, 2022 | Rabia Noureen
Microsoft to Fix Windows Bug Breaking Wi-Fi hotspots After Installing Latest Patch Tuesday Update
Jun 17, 2022 | Rabia Noureen
Microsoft Confirms Windows Server Backup Issues in This Month's Patch Tuesday Updates
Jun 16, 2022 | Rabia Noureen
Microsoft Acknowledges Office Zero-Day Flaw Affecting Windows Diagnostic Tool
May 31, 2022 | Rabia Noureen
Microsoft Releases Out-Of-Band Patches to Fix Windows AD Authentication Issues
May 20, 2022 | Rabia Noureen
Most popular on petri