320 likes | 420 Views
Review. Please turn in any homework/ practicals you may have Folders Paths Services Processes. Today. Jobs IDs Backgrounding Runlevels Partitions HDDs. Process. Actions (commands) executed on a server are processes A process is a specific task to be completed
E N D
Review • Please turn in any homework/practicals you may have • Folders • Paths • Services • Processes
Today • Jobs • IDs • Backgrounding • Runlevels • Partitions • HDDs
Process • Actions (commands) executed on a server are processes • A process is a specific task to be completed • Simple as ‘run ls’ or complicated as ‘listen for TCP connection on port 80’ • From the time the server/computer is booted, each task is given a number • This is the ‘process ID’ • Starts counting at 1 and increments as soon as a PID is assigned
System • These all build to run our system • One process runs the clock • One process runs authentication • One process runs logging • One process runs a shell • One process runs … • Similarly grouped processes are ‘services’ • Network: IP, port, protocol • Web: data, specific port, specific protocol
Slow Processes • We can run a process “in the background” • Most of our commands have been quick • Our scripts too • But what about when they’re not quick? • Timed • Performance Testing • ‘Burn-in’ • SQL
Background • Services run “behind” our shell, we can still type • [root@it136introtolinux ~]# service network start • Bringing up loopback interface [ OK ] • [root@it136introtolinux ~]# • Processes do not give shell back until they end • If we know (or find out) something is going to take a while, we can run it ‘in the background’ while we do other stuff
Example Setup • Setup: A script that has one major command line – sleep 100 • This will take 100 seconds to execute, during which we will not have the shell • Finally, it prints to STDOUT “done” • 1) We can stop a script (or command) and run it in the background • 2) We can start a script, pause it, and move it to the background
sleep_script.sh • So what does it look like?
Move it to the Background • So if I’ve run my sleep_script.sh, and I see it’s taking forever, I can move it to the background • Press ctrl+z – this will stop the job and give me a shell back • It will also tell me the ‘job number’ • This is NOT process ID – this is job number • Process ID (PID) is a unique number given by the system • Job number (job) is relative to the shell and the number of jobs running in your user’s shell
Moving Pt 2 • Job number is in [1] – this is job number 1 • Also, it’s stopped/paused right now • So we can use that to move it to the ‘background’ and restart it • We use the bg command • bg <job> • bg 1 • Then we can use the fg command to get it back if we need to • fg 1
Example • [student@it136centos58vm ~]$ ./sleep_script.sh • ^z • [1]+ Stopped ./sleep_script.sh • # The above is ‘paused’ – still taking up resources, but not running/consuming more • [student@it136centos58vm ~]$ bg 1 • [1]+ ./sleep_script.sh & • # Now it’s running again • [student@it136centos58vm ~]$ fg 1 • ./sleep_script.sh
Finishing • If the job completes while in the background we get a nice message: • [student@it136centos58vm ~]$ cd ~ • [1]+ Done ./sleep_script.sh (wd: ~) • (wd now: ~) • It told us it finished elsewhere • Or, if we’ve pulled it back to the fg, our shell comes back • [student@it136centos58vm ~]$ fg 1 • ./sleep_script.sh • [student@it136centos58vm ~]$
Starting in Bg • [student@it136centos58vm ~]$ ./sleep_script.sh & • [1] 21251 • What is 21251? • How do I check to see if we’re right on what 21251 is?
Starting in Bg 2 • [student@it136centos58vm ~]$ ps -ef | grep -i sleep_script.sh • student 21251 21017 0 12:59 tty1 /bin/bash ./sleep_script.sh • student 21258 21017 0 13:00 tty1 grep -i sleep_script.sh • It’s the PID • Now we can call it in bf/fg or kill/nice
Runlevels • Control how many and which processes start on boot • A way to reference the system state once the ‘default’ scripts have run • 7 total • Numbering starts at 0
Runlevels Listed • 0 – Off • 1 – Single User Mode • 2 – Multi-User Mode (Limited) • 3 – Multi-User Mode w/Networking • 4 – Reserved • 5 – GUI • 6 – Reboot
0-1 Explained • 0 – Off • service network stop • There are ‘stop’ scripts that tell them how to stop ‘gracefully’ • Turn EVERYTHING off • Runlevel 0 runs these ‘off’ scripts for the whole system • 1 – Single User Mode • ‘Recovery’ mode • Only the ‘base’ for what is needed to boot • You have to load other things yourself
Why I Hate Ubuntu (Pt 1) • Runlevel 2 – Multi-user Mode • Does not configure network (and other stuff) • Oh, right, except for Ubuntu • Runlevel 3 – Multi-user w/Networking • Wikipedia: “Starts the system normally” • We boot into runlevel 3 • Runlevel 4 – Reserved • Runlevel 5 – Runlevel 3 w/GUI • Runlevel 6 – Reboot
What’s Going On? • Switch levels through the ‘init’ command • This will go through a reboot • “Init” or initialization scripts set up how the system is configured • Configured…config… • Where do you think these scripts are located?
/etc/init.d • The scripts in /etc/init.d are linked to the folders • /etc/rc0.d • /etc/rc1.d • /etc/rc2.d • /etc/rc3.d • /etc/rc4.d • /etc/rc5.d • /etc/rc6.d • Look familiar? • The system calls each script in each folder a certain way
/etc/rc3.d (for example) • Holds scripts starting with S and K • S is ‘start’ script • /etc/rc3.d/S08iptables • K is ‘kill’ script • /etc/rc3.d/K74ipsec • Numbered 00-99 • S01sysstat-S99local • Lower numbers are run first & case sensitive
Questions On Runlevels? • Runlevels • Set what automatically starts (or stops) • 0-7 (8 total) • Scripts are called in a certain way (shutdown vs kill)
One Last Note • Partitions • A ‘partition’ is a physical divider • A Linux partition is a section of a physical hard drive (hdd) • You set it for a physical maximum size, and the system can’t exceed that maximum • What happens if all data is in one cup (say it’s dyed blue), and this firehose just blasts neon green at the cup • What happens to the blue?
Record Player • “I’m too old for this” – Danny Glover, Lethal Weapon • This may be an ancient reference, but it holds up the best • A record player • Needle running across it (head) • Data is song • Tracks are sectors
Partitions 3 • So we can think of partitions as the colored areas • Yellow is our / partition, red is our /swap, blue is our /var, black is our /home, and white is our application (/opt or /var/www or….) • Keep in mind that they all take up 2 circles, but the outside circles are bigger
Partitions • The df command shows free space on our system • To create a partition on a new hdd use • fdisk –l <drive> #that’s a lowercase L
File Systems Table • Use the mount command to set a drive for use • mount /dev/<drive> /<location> • mount /dev/sdc /nfsshare1
Why Best Practice Rocks • Went to ‘DefCon’ with old IDS admins • They missed over half the trip because they had to continuously deal with these failures • I took over the IDS systems • I demanded the vendor partition the system w/best practice (among other things) • /var filled, system still ran • I stopped waking up at 2am • My last 6 months I had one device failure • It was a hardware failure, not a system failure
Questions on Partitions • df • Show ‘disk file’ usage – how much room on which partitions • fdisk -l /dev/sda • Use fdisk tool to list partitions on that hard drive • mount /dev/sda /mnt • Make /dev/sda usable via the /mnt folder • /etc/fstab • File systems table – file that holds system partition info
Own Study • Jobs • Job IDs • Backgrounding • Runlevels • Partitions • HDDs