Agenda: commands-exercises-2.md

File commands-exercises-2.md, 3.6 KB (added by andy, 5 years ago)
Line 
1% Linux System Administration and IP Services
2
3# Linux Commands - part 2
4
5# Notes
6
7* Commands preceded with "$" imply that you should execute the command as
8  a general user - not as root.
9* Commands preceded with "#" imply that you should be working as root
10  with "sudo"
11* Commands with more specific command lines (e.g. "RTR-GW>" or "mysql>")
12  imply that you are executing commands on remote equipment, or within
13  another program.
14
15# Exercise
16
17## Install a new software package (Apache)
18
19We will now install the Apache web server on your machine:
20
21~~~
22$ sudo apt-get install apache2
23~~~
24
25Say "Y" or "Yes" if prompted. Once the apt program finishes you will have the Apache web server running on your machine.
26
27To test this, open a web browser go to your machine's home page:
28
29~~~
30http://vmN.ws.nsrc.org/
31~~~
32
33... where "N" is the number of your machine.
34
35You should see something like "It Works!" on the page.
36
37If not, you may need to create a simple web page:
38
39~~~
40$ sudo -s
41# echo "Hello, world" > /var/www/index.html
42# exit
43$
44~~~
45
46Try reloading the web page again (http://vmN.ws.nsrc.org/)
47
48## Stopping and starting a service
49
50Now, let's stop the web server (Apache) that is installed on your
51virtual machine. To do this you can do:
52
53~~~
54$ sudo service apache2 stop
55~~~
56
57In your web browser, try and reload the web page for your machine.
58It should indicate that no web server was found. Now let's start the
59service again:
60
61~~~
62$ sudo service apache2 start
63~~~
64
65You can see if a service is running by typing:
66
67~~~
68$ sudo service apache2 status
69~~~
70
71If a process ID is displayed, then the service is running, but our next
72exercise will show you another way to verify this.
73
74# Finding and stopping processes
75
76If you wish to find something that is running and then stop it you can
77use the "ps" (process) command with "grep" and "kill". Let's do this by
78opening two connections to your virtual machine.
79
80a. Using SSH, open two terminal connections to your Linux server
81    - user: `sysadm`
82        - machine: `vmN.ws.nsrc.org`
83
84b. Once you have opened two terminals go in to one terminal and type:
85
86~~~
87$ tail -f /var/log/syslog
88~~~
89
90This will let you look at the end of the syslog log file in real time.
91If events take place that are logged you will see them as they happen.
92Now, in your other terminal let's look for this process:
93
94~~~
95$ ps aux | grep tail
96~~~
97
98The "aux" are options to the ps (process) command. The options mean
99display all process running that belong to you and to other users and
100provide information about who owns what process.
101
102You will likely see something like this:
103
104~~~
105sysadm    5200  0.0  0.0   3764   540 pts/6    S+   13:50   0:00 tail -f /var/log/syslog
106sysadm    5208  0.0  0.0   3908   820 pts/5    S+   13:50   0:00 grep --color=auto tail
107~~~
108
109Question: what is process 5208 above, and why are we seeing it ?
110
111Tip: you can add the "w" option to enable "wide output", and you can
112use "w" twice ("ww") to display the entire command line regardless of how
113long it is and wrap it in your window.
114
115Try it!
116
117~~~
118$ ps auxww | grep tail
119~~~
120
121You could press "CTRL-C" in the terminal window where the tail command
122is running, or to stop the process right now you can use the kill
123command. You need to replace the Process ID (PID) with the process ID
124number of the tail command running on your machine. In this example the
125number is "5200". At the command prompt type:
126
127~~~
128$ kill NNNN
129~~~
130
131... where NNNN is the PID of your tail process. Once you do this return
132to the other terminal screen. The "tail -f" process should now have
133exited and you should see something like:
134
135~~~
136Terminated
137sysadmt@vmN:~$
138~~~
139
140That's it for now!