Download presentation
1
Server Administration Basics
2
Client and Server In general, all of the machines on the Internet can be categorized as two types: servers and clients. Those machines that provide services (like Web servers or FTP servers) to other machines are servers. And the machines that are used to connect to those services are clients. .
3
A server machine may provide one or more services on the Internet
A server machine may provide one or more services on the Internet. For example, a server machine might have software running on it that allows it to act as a Web server, an server and an FTP server. Clients that come to a server machine do so with a specific intent, so clients direct their requests to a specific software server running on the overall server machine. For example, if you are running a Web browser on your machine, it will most likely want to talk to the Web server on the server machine. Your Telnet application will want to talk to the Telnet server, your application will talk to the server, and so on...
4
Linux Boot Process (Startup Sequence)
Press the power button on your system, and after few moments you see the Linux login prompt. Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears? The following are the 6 high level stages of a typical Linux boot process.
5
Linux Booting Sequence
6
Bios BIOS stands for Basic Input/Output System
Performs some system integrity checks Searches, loads, and executes the boot loader program. It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence. Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it. So, in simple terms BIOS loads and executes the MBR boot loader.
7
MBR MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes. It contains information about GRUB (or LILO in old systems). So, in simple terms MBR loads and executes the GRUB boot loader.
8
GRUB GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be executed. GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file. GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem). Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
9
Grub Command Contents #boot=/dev/sda default=0 timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz Hiddenmenu title CentOS ( el5PAE) root (hd0,0) kernel /boot/vmlinuz el5PAE ro root=LABEL=/ initrd /boot/initrd el5PAE.img As you notice from the above info, it contains kernel and initrd image. So, in simple terms GRUB just loads and executes Kernel and initrd images.
10
Kernel Mounts the root file system as specified in the “root=” in grub.conf Kernel executes the /sbin/init program Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid. initrd stands for Initial RAM Disk. initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware
11
init Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels 0 – halt 1 – Single user mode 2 – Multiuser, without NFS 3 – Full multiuser mode 4 – unused 5 – X11 6 – reboot Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program. Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that. Typically you would set the default run level to either 3 or 5.
12
Runlevel Programs When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level. Depending on your default init level setting, the system will execute the programs from one of the following directories. Run level 0 – /etc/rc.d/rc0.d/ Run level 1 – /etc/rc.d/rc1.d/ Run level 2 – /etc/rc.d/rc2.d/ Run level 3 – /etc/rc.d/rc3.d/ Run level 4 – /etc/rc.d/rc4.d/ Run level 5 – /etc/rc.d/rc5.d/ Run level 6 – /etc/rc.d/rc6.d/
13
Xinetd and Inetd inetd is also known as super-server daemon and it runs on many Unix / Linux systems that manages Internet service such as ftp or pop3 or telnet. xinetd (eXtended InterNET Daemon) is also an open-source daemon which runs on many Unix / Linux systems and manages Internet-based services such as ftp or telnet.
14
Managing User Accounts
When a computer is used by many people it is usually necessary to differentiate between the users, for example, so that their private files can be kept private. This is important even if the computer can only be used by a single person at a time, as with most microcomputers. Thus, each user is given a unique username, and that name is used to log in.
15
Creating a user There's more to a user than just a name, however. An account is all the files, resources, and information belonging to one user. The term hints at banks, and in a commercial system each account usually has some money attached to it, and that money vanishes at different speeds depending on how much the user stresses the system. For example, disk space might have a price per megabyte and day, and processing time might have a price per second. Most Linux distributions come with a program for creating accounts. There are several such programs available. Two command line alternatives are adduser and useradd; there may be a GUI tool as well. Whatever the program, the result is that there is little if any manual work to be done. Even if the details are many and intricate, these programs make everything seem trivial.
16
Creating User [t.[root@dlp ~]# useradd cent [root@dlp ~]# passwd cent
Changing password for user cent. New UNIX password:# set password Retype new UNIX password:# Confirm passwd: all authentication tokens updated successfully. ~]# exit # logout [2]Try to switch to a user that was added above.dlp login: cent # input user name password: # password ~]$ su - # switch to root Password:# root password ~]## just switched to root userdel or deluser cent
17
/etc/passwd and other informative files
The basic user database in a Unix system is the text file, /etc/passwd (called the password file), which lists all valid usernames and their associated information. The file has one line per username, and is divided into seven colon-delimited fields: Username. Previously this was where the user's password was stored. Numeric user id. Numeric group id. Full name or other description of account. Home directory.
18
File System And Quota Management
Disk Quotas: This feature of Linux allows the system administrator to allocate a maximum amount of disk space a user or group may use. It can be flexible in its adherence to the rules assigned and is applied per filesystem. The default Linux Kernel which comes with Centos, Redhat and Fedora Core comes with quota support compiled in.
19
Install Quota tools. [root@dlp ~]# yum -y install quota
Enable Quota to add mount options. ~]# umount /home ~]# mount -o usrquota,grpquota /dev/sdb1 /home
20
[root@dlp ~]# vi /etc/fstab
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1 UUID=cf3f9660-e40d-459d-8763 /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode= sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sdb1 /home xfs defaults,usrquota,grpquota 0 0
21
Set user Quota. For example, Apply quota to "cent" user.
# create quota config ~]# quotacheck -um /home # enable quota ~]# quotaon -uv /home /dev/sdb1 [/home]: user quotas turned on # show status ~]# quotaon -ap group quota on /home (/dev/sdb1) is off user quota on /home (/dev/sdb1) is on # set quota to "cent" ~]# edquota -u cent # set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes) Disk quotas for user cent (uid 500): Filesystem blocks soft hard inodes soft hard /dev/sdb
22
# show status ~]# repquota -au *** Report for user quotas on device /dev/sdb1 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace root cent
23
Linux File Systems Structure
24
Job Scheduling with cron, crontab, anacron and system log analysis
"Cron" is a time-based job scheduler in Unix-like operating systems (Linux, FreeBSD, Mac OS etc...). And these jobs or tasks are referred to as "Cron Jobs". There is a cron "daemon" that runs on these systems. A daemon is a program that runs in the background all the time, usually initiated by the system. This cron daemon is responsible for launching these cron jobs on schedule. The schedule resides in a configuration file named "crontab". That's where all the tasks and their timers are listed.
25
Why Use Cron Jobs? Cron Jobs are used for scheduling tasks to run on the server. They're most commonly used for automating system maintenance or administration. However, they are also relevant to web application development.
26
Why Use Cron jobs If you have a membership site, where accounts have expiration dates, you can schedule cron jobs to regularly deactivate or delete accounts that are past their expiration dates. You can send out daily newsletter s. If you have summary tables (or materialized views) in your database, they can be regularly updated with a cron job. For example you may store every web page hit in a table, but another summary table may contain daily traffic summaries. You can expire and erase cached data files in a certain interval. You can auto-check your website content for broken links and have a report ed to yourself regularly. You can schedule long-running tasks to run from a command line script, rather than running it from a web script. Like encoding videos, or sending out mass s. You can even perform something as simple as fetching your most recent Tweets, to be cached in a text file.
27
Cron job has five parts minute hour day of month month day of week
Command Use crontab -e
28
Cron Job configure This is also an hourly cron job but run at minute 15 instead (i.e. 00:15, 01:15, 02:15 etc.): 15 * * * * [command] This will run once a day, at 2:30am: 30 2 * * * [command]
29
Anacron Anacron is the cron for desktops and laptops.
Anacron does not expect the system to be running 24 x 7 like a server. When you want a background job to be executed automatically on a machine that is not running 24 x 7, you should use anacron. For example, if you have a backup script scheduled everyday at 11 PM as a regular cron job, and if your laptop is not up at 11 PM, your backup job will not be executed. However, if you have the same job scheduled in anacron, you can be sure that it will be executed once the laptop come back up. Just like how cron has /etc/crontab, anacron has /etc/anacrontab.
30
System Log Analysis Linux and the applications that run on it can generate all different types of messages, which are recorded in various log files. Linux uses a set of configuration files, directories, programs, commands and daemons to create, store and recycle these log messages. Knowing where the system keeps its log files and how to make use of related commands can therefore help save valuable time during troubleshooting. In almost all Linux distributions the Linux log files are stored in ‘/var/log‘ directory. A common way to watch log files is to use the -f flag and tail. Tail –f /var/log/messages
31
Common Log Files auth.log – Authentication info boot.log – Boot info
crond – Scheduled cron tasks daemon.log – Daemon specific alerts like, dhcpd, gnome-session, ntfs-3g dmesg – Kernel specific messages errors.log – As you may have guess this logs errors everything.log – A misc. catch all log httpd – Apache access and error logs mail.log – Mail server logs messages.log – General system alerts mysqld.log – MySQL database log secure – Security log syslog.log – A log for the log system vsftpd.log – A log for the FTP server, vsftpd Xorg.0.log – X log
32
Process controlling and management
All modern operating systems are able to run many programs at the same time. For example, a typical Linux server might include a Web server, an server, and probably a database service. Each of these programs runs as a separate process. What do you do if one of your services stops working? Here are some handy command-line tools for managing processes.
33
Each process uses time on a system's CPU, as well as other system resources such as memory and disk space. If a program goes wrong, it can start to use too much CPU time or memory and so deny other programs the resources they need to run. Knowing how to manage processes is an essential part of Linux system management. To help, turn to command-line tools such as ps, top, service, kill, and killall.
34
ps ps shows the current processes running on the machine. ps has many options, but one of the most useful invocations is ps aux, which shows every process on the system. A normal Linux server may have 100 processes running after boot up, so the output from the ps command can be quite long. Here are the first few lines from my CentOS 5 test machine: USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root ? S 15:03 0:00 init [5] root ? S 15:03 0:00
35
top the top program provides a dynamic real-time view of a system. It displays a system summary (with CPU usage, memory usage, and other statistics) as well as a list of running processes that changes dynamically as the system is in use. It lists the processes using the most CPU first. The first few lines of top look something like this: top - 15:18:00 up 54 min, 0 users, load average: 0.00, 0.10, 0.11 Tasks: 115 total, 2 running, 113 sleeping, 0 stopped, 0 zombie Cpu(s): 0.7%us, 0.0%sy, 0.0%ni, 99.0%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st Mem: k total, k used, k free, k buffers Swap: k total, k used, k free, k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 554 root m S :10.29 Xorg 1 root S :00.11 init 2 root RT S :00.00 migration/0 3 root S :00.01 ksoftirqd/0
36
Online Server upgrade/update process
Linux has various commands to update all installed packages. Please note that system and package updates should be performed with care. It is very important to have up to date backup before you do this. The exact command depends upon your Linux distribution:
37
Debian / Ubuntu / Mint Linux and friends try apt-get command.
CentOS / RHEL / Red Hat / Fedora Linux and friends try yum command. Yum update all Suse / OpenSUSE Linux use zypper command or graphical tool called YaST online update. Slackware Linux user try slackpkg command. Arch Linux user try pacman command. Gentoo Linux user try emerge command.
38
Ubuntu Linux $ sudo apt-get update $ sudo apt-get upgrade RHEL/CentOS/Red Hat/Fedora Linux # yum update
39
Administering Database Server (MySQL)
MySQL is one of the most popular relational database management systems (RDBMS). It is open-source and it is used by many individuals and organizations. If you are using our Linux hosting services, you are most likely using MySQL as a database system. Therefore, it is important for you to know how to operate with your database system when you need to make some changes in your databases. Today, we will have a very simple task – to teach you how to work with your MySQL database system using these simple commands from your Linux os.
40
The first thing you need to do is to check your MySQL version using the command:
## mysql -h localhost –V ## yum install mysql-server To log in to your MySQL database server you can run the command: ## mysql -u username –p mysql -u root -p
41
mysql> SHOW DATABASES;
mysql> CREATE DATABASE db_name; mysql> DROP DATABASE db_name; mysql> USE db_name; mysql> SHOW TABLES;
42
mysql> CREATE DATABASE test;
mysql> USE test; mysql> CREATE TABLE test_table ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(30) NOT NULL, comment VARCHAR (100) ); To show all data in a table you can use the command: mysql> SELECT * FROM db_name;
43
INSERT INTO table_name (column1,column2,column3,
INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...); INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal','Tom B. Erichsen','Skagen 21','Stavanger','4006','Norway');
44
update UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; UPDATE Customers SET City='Hamburg' WHERE CustomerID=1;
45
Delete Record DELETE FROM table_name WHERE some_column=some_value;
DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
46
How to set MySQL Root password?
mysqladmin -u root password YOURNEWPASSWORD How to Change MySQL Root password? mysqladmin -u root –p password 'xyz123' mysqladmin -u root -p version
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.