|
| 1 | +<head> |
| 2 | + <style> .flex-container { display: flex; align-items: center; gap: 20px; } </style> |
| 3 | +</head> |
| 4 | +<div class="flex-container"> |
| 5 | + <img src="https://github.com/ProfessionalLinuxUsersGroup/img/blob/main/Assets/Logos/ProLUG_Round_Transparent_LOGO.png?raw=true" width="64" height="64"> |
| 6 | + <p> |
| 7 | + <h1>Unit 7 Lab</h1> |
| 8 | + </p> |
| 9 | +</div> |
| 10 | + |
| 11 | +## Introduction |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +The Unit 7 Lab has students exploring and practicing the lessons they learned |
| 16 | +from the unit recording and worksheet. This lab explores managing packages through the Red Hat |
| 17 | +Enterprise Linux (RHEL) package manager front end [DNF package manager](<https://en.wikipedia.org/wiki/DNF_(software)>). |
| 18 | + |
| 19 | +### Resources / Important Links |
| 20 | + |
| 21 | +- <https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html-single/managing_software_with_the_dnf_tool/index> |
| 22 | +- <https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/considerations_in_adopting_rhel_8/repositories_considerations-in-adopting-rhel-8> |
| 23 | +- |
| 24 | + |
| 25 | +## Required Materials |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +- Rocky 9.3 – ProLUG Lab |
| 30 | +- root or sudo command access |
| 31 | + |
| 32 | +### Pre-Lab Warm-Up |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +_EXERCISES_ (Warmup to quickly run through your system and familiarize yourself). |
| 37 | + |
| 38 | +```bash |
| 39 | +cd ~ |
| 40 | +rpm -qa | more |
| 41 | +rpm -qa | wc -l |
| 42 | +``` |
| 43 | + |
| 44 | +pick any <name of package> from the above list |
| 45 | + |
| 46 | +```bash |
| 47 | +rpm -qi <name of package> |
| 48 | +rpm -qa | grep -i imagemagick |
| 49 | +``` |
| 50 | + |
| 51 | +`dnf install imagemagick` |
| 52 | + |
| 53 | +What is the error here? Read it |
| 54 | + |
| 55 | +`dnf install ImageMagick` |
| 56 | + |
| 57 | +What are some of the dependencies here? Look up the urw-base35 and see what functionality that adds. |
| 58 | + |
| 59 | +`rpm -qa | grep -i imagemagick` |
| 60 | + |
| 61 | +Why did this work when the other one didn’t with dnf? |
| 62 | + |
| 63 | +### Math Practice |
| 64 | + |
| 65 | +Some fun with the command line and basic scripting tools. I want you to see some of the capabilities. That are available to you. Your system can do a lot of basic arithmetic for you and this is a very small set of examples. |
| 66 | + |
| 67 | +Check to see if you have bc tool. |
| 68 | + |
| 69 | +`rpm –q bc` |
| 70 | + |
| 71 | +Install it if you need to |
| 72 | + |
| 73 | +```bash |
| 74 | +dnf install bc |
| 75 | +for i in "seq 1 5"; do free | grep -i mem | awk "{print $3}"; done |
| 76 | +``` |
| 77 | + |
| 78 | +Collect the 5 numbers (what do these numbers represent? Use free to find out) |
| 79 | + |
| 80 | +`echo "(79 + 79 + 80 + 80 + 45) / 5" | bc` |
| 81 | + |
| 82 | +Your numbers will vary. Is this effective? Is it precise enough? |
| 83 | + |
| 84 | +`echo "(79 + 79 + 80 + 80 + 45) / 5" | bc -l` |
| 85 | + |
| 86 | +Is this precise enough for you? |
| 87 | + |
| 88 | +`man bc` |
| 89 | + |
| 90 | +Read the man to see what the -l option does to bc |
| 91 | + |
| 92 | +It would be astute to point out that I did not have you do bash arithmetic. There is a major limitation of using bash for that purpose in that it only wants to deal with integers (whole numbers) and you will struggle to represent statistical data with precision. There are very useful tools though, and I would highly encourage you to examine them. <http://tldp.org/LDP/abs/html/arithexp.html> |
| 93 | + |
| 94 | +### Lab🧪 |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +Log into your Rocky server and become root. |
| 99 | + |
| 100 | +#### RPM |
| 101 | + |
| 102 | +RPM is the Redhat package manager. It is a powerful tool to see what is installed on your system and to see what dependencies exist with different software packages. This is a toolset that was born of the frustration of “dependency nightmare” where system admins used to compile from source code only to find they had dependencies, which had dependencies, which had dependencies. RPM helps to deconflict and save huge amounts of time and engineering headaches. |
| 103 | +Using RPM to see installed software information |
| 104 | + |
| 105 | +Run through these commands and read `man rpm` to see what they do. |
| 106 | + |
| 107 | +`rpm -qi systemd` |
| 108 | + |
| 109 | +Read about the capabilities of systemd |
| 110 | + |
| 111 | +`rpm -q systemd` |
| 112 | + |
| 113 | +query the package given |
| 114 | + |
| 115 | +`rpm –qa` |
| 116 | + |
| 117 | +query all packages on the system (is better used with | more or | grep) |
| 118 | + |
| 119 | +```bash |
| 120 | +rpm -qa | grep -i kernel #for example shows all kernels and kernel tools |
| 121 | +rpm -qc systemd |
| 122 | +``` |
| 123 | + |
| 124 | +List out files, but only show the configuration files |
| 125 | + |
| 126 | +`rpm -qi systemd` |
| 127 | + |
| 128 | +What good information do you see here? Why might it be good to know that some piece of software was installed last night, if there is now a problem with the system starting last night? |
| 129 | + |
| 130 | +`rpm -ql systemd` |
| 131 | + |
| 132 | +Will list all the files in the package. Why might this be useful to you to know? |
| 133 | + |
| 134 | +`rpm -qR systemd` |
| 135 | + |
| 136 | +List capabilities on which this package depends |
| 137 | + |
| 138 | +`rpm -q -changelog systemd` |
| 139 | + |
| 140 | +Probably going to scroll too fast to read. This output is in reverse order. |
| 141 | + |
| 142 | +So let’s make it useful with this command |
| 143 | + |
| 144 | +`rpm -q -changelog systemd | more` |
| 145 | + |
| 146 | +What are some of the oldest entries? |
| 147 | +What is the most recent entry? |
| 148 | +Is there a newer version of systemd for you to use? |
| 149 | + |
| 150 | +`dnf update systemd` |
| 151 | + |
| 152 | +If there isn’t don’t worry about it. |
| 153 | + |
| 154 | +Use `rpm -qa | more` to find 3 other interesting packages and perform `rpm -qi <package>` on them to see information about them. |
| 155 | + |
| 156 | +#### DNF |
| 157 | + |
| 158 | +Yum comes from a long decrepit version of Linux called Yellow dog. It is originally the Yellowdog Update Manager. It has a very interesting history surrounding the PS3, but that and other nostalgia can be found here: <https://en.wikipedia.org/wiki/Yellow_Dog_Linux> if you’re interested. We’re going to use it to update our system. RHEL and CentOS systems look to repositories of software for installation and updates. We have a base set of them provided with the system, supported by the vendor or open source communities, but we can also create our own from file systems or web pages. We’ll be mostly dealing with the defaults and how to enable or disable them, but there are many configurations that can be made to customize software deployment. |
| 159 | + |
| 160 | +Checking how dnf is configured and seeing it’s available repositories |
| 161 | + |
| 162 | +`cat /etc/dnf/dnf.conf` |
| 163 | + |
| 164 | +has some interesting information about what is or isn’t going to be checked. You can include a line here called exclude= to remove packages from installation by name. Where a repo conflicts with this, this takes precedence. |
| 165 | + |
| 166 | +```bash |
| 167 | +dnf repolist |
| 168 | +dnf history |
| 169 | +``` |
| 170 | + |
| 171 | +Checking where repos are stored and what they look like |
| 172 | + |
| 173 | +`ls /etc/yum.repos.d/` |
| 174 | + |
| 175 | +Repos are still stored in /etc/yum.repos.d |
| 176 | + |
| 177 | +`cat /etc/yum.repos.d/rocky.repo` |
| 178 | + |
| 179 | +```bash |
| 180 | +# rocky.repo |
| 181 | +# |
| 182 | +# The mirrorlist system uses the connecting IP address of the client and the |
| 183 | +# update status of each mirror to pick current mirrors that are geographically |
| 184 | +# close to the client. You should use this for Rocky updates unless you are |
| 185 | +# manually picking other mirrors. |
| 186 | +# |
| 187 | +# If the mirrorlist does not work for you, you can try the commented out |
| 188 | +# baseurl line instead. |
| 189 | + |
| 190 | +[baseos] |
| 191 | +name=Rocky Linux $releasever - BaseOS |
| 192 | +mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever$rltype |
| 193 | +#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/ |
| 194 | +gpgcheck=1 |
| 195 | +enabled=1 |
| 196 | +countme=1 |
| 197 | +metadata_expire=6h |
| 198 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 |
| 199 | +#Output truncated for brevity’s sake…. |
| 200 | +``` |
| 201 | + |
| 202 | +Something you’ll find out in the next section looking at repos is that when they are properly defined they are enabled by default. enabled=1 is implied and doesn’t need to exist when you create a repo. |
| 203 | +Let’s disable a repo and see if the output changes at all |
| 204 | + |
| 205 | +`[root@rocky1 yum.repos.d]# dnf config-manager --disable baseos` |
| 206 | + |
| 207 | +```bash |
| 208 | +cat /etc/yum.repos.d/rocky.repo |
| 209 | + |
| 210 | +Should now have the line enabled=0 (or false, turned off) |
| 211 | +[baseos] |
| 212 | +name=Rocky Linux $releasever - BaseOS |
| 213 | +mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever$rltype |
| 214 | +#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/ |
| 215 | +gpgcheck=1 |
| 216 | +enabled=0 |
| 217 | +countme=1 |
| 218 | +metadata_expire=6h |
| 219 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 |
| 220 | +#Output truncated for brevity’s sake…. |
| 221 | +``` |
| 222 | + |
| 223 | +Re-enable the repo and verify the output |
| 224 | +dnf config-manager --enable base |
| 225 | + |
| 226 | +`cat /etc/yum.repos.d/rocky.repo` |
| 227 | + |
| 228 | +Should now have the line enabled=1 (or true, turned back on) |
| 229 | + |
| 230 | +```bash |
| 231 | +[baseos] |
| 232 | +name=Rocky Linux $releasever - BaseOS |
| 233 | +mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever$rltype |
| 234 | +#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/ |
| 235 | +gpgcheck=1 |
| 236 | +enabled=1 |
| 237 | +countme=1 |
| 238 | +metadata_expire=6h |
| 239 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 |
| 240 | +#Output truncated for brevity’s sake…. |
| 241 | +``` |
| 242 | + |
| 243 | +Installing software you were asked by an application team. |
| 244 | +So someone has asked for some software and assured you it’s been tested in similar environments so you go to install it on their system for them. |
| 245 | + |
| 246 | +See if we already have a version. |
| 247 | +`rpm –qa mariadb` |
| 248 | + |
| 249 | +See if dnf knows about it |
| 250 | + |
| 251 | +```bash |
| 252 | +dnf search mariadb |
| 253 | +dnf search all mariadb |
| 254 | +``` |
| 255 | + |
| 256 | +What is DNF showing you? What are the differences between these commands based on the output? |
| 257 | + |
| 258 | +Try to install it |
| 259 | + |
| 260 | +`dnf install mariadb` |
| 261 | + |
| 262 | +hit “N” |
| 263 | + |
| 264 | +Make note of any dependencies that are added on top of mariadb (there’s at least one) |
| 265 | +What does DNF do with the transaction when you cancel it? Can you compare this to what you might have used before with YUM? How are they different? (You can look it up if you don’t know.) |
| 266 | + |
| 267 | +Ok, install it |
| 268 | + |
| 269 | +`dnf -y install mariadb` |
| 270 | + |
| 271 | +Will just assume yes to everything you say. |
| 272 | +You can also set this option in /etc/dnf/dnf.conf to always assume yes, it’s just safer in an enterprise environment to be explicit. |
| 273 | + |
| 274 | +Removing package with dnf |
| 275 | + |
| 276 | +Surprise, the user calls back because that install has made the system unstable. They are asking for you to remove it and make the system back to the recent version. |
| 277 | + |
| 278 | +`dnf remove mariadb` |
| 279 | + |
| 280 | +hit “N” |
| 281 | + |
| 282 | +`dnf –y remove mariadb` |
| 283 | + |
| 284 | +this removes mariadb from your system. |
| 285 | +But did this remove those dependencies from earlier? |
| 286 | + |
| 287 | +```bash |
| 288 | +rpm –q <dependency> |
| 289 | +rpm –qi <dependency> |
| 290 | +``` |
| 291 | + |
| 292 | +How are you going to remove that if it’s still there? |
| 293 | + |
| 294 | +Checking where something came from. What package provides something in your system |
| 295 | + |
| 296 | +One of the most useful commands dnf provides is the ability to know “what provides” something. Sar and iostat are powerful tools for monitoring your system. Let’s see how we get them or where they came from, if we already have them. Maybe we need to see about a new version to work with a new tool. |
| 297 | + |
| 298 | +```bash |
| 299 | +dnf whatprovides iostat |
| 300 | +dnf whatprovides sar |
| 301 | +``` |
| 302 | + |
| 303 | +Try it on some other tools that you regularly use to see where they come from. |
| 304 | + |
| 305 | +```bash |
| 306 | +dnf whatprovides systemd |
| 307 | +dnf whatprovides ls |
| 308 | +dnf whatprovides python |
| 309 | +``` |
| 310 | + |
| 311 | +Using Dnf to update your system or individual packages |
| 312 | +Check for how many packages need update |
| 313 | + |
| 314 | +`dnf update` |
| 315 | + |
| 316 | +How many packages are going to update? |
| 317 | +Is one of them the kernel? |
| 318 | +What is the size in MB that is needed? |
| 319 | +Hit “N” |
| 320 | + |
| 321 | +Your system would have stored those in /var/cache/dnf |
| 322 | +Let’s check to see if we have enough space to hold those |
| 323 | + |
| 324 | +`df -h /var/cache/dnf` |
| 325 | + |
| 326 | +Is there more free space than there is needed size in MB from earlier? There probably is, but this becomes an issue. You’d be surprised. |
| 327 | + |
| 328 | +Let’s see how that changes if we exclude the kernel |
| 329 | + |
| 330 | +`dnf update --exclude=kernel` |
| 331 | + |
| 332 | +How many packages are going to update? |
| 333 | +Is one of them the kernel? |
| 334 | +What is the size in MB that is needed? |
| 335 | +Hit “N” |
| 336 | + |
| 337 | +You can update your system if you like. You’d have to reboot for your system to take the new kernel. If you do that you can then redo the grubby portion and the ls /boot/ will show the new installed kernel, unless you excluded it. |
| 338 | + |
| 339 | +Using `dnf to install group` <packages> |
| 340 | + |
| 341 | +Maybe we don’t even know what we need to get a project going. We know that we need to have a web server running but we don’t have an expert around to tell us everything that may help to make that stable. We can scour the interwebs (our normal job) but we also have a tool that will give us the base install needed for RHEL or CentOS to run that server. |
| 342 | + |
| 343 | +```bash |
| 344 | +dnf grouplist |
| 345 | +dnf group install “Development Tools” |
| 346 | +``` |
| 347 | + |
| 348 | +How many packages are going to update? |
| 349 | +Is one of them the kernel? |
| 350 | +What is the size in MB that is needed? |
| 351 | +Hit “N” |
| 352 | +Do you see a pattern forming? |
| 353 | + |
| 354 | +If you install this you’re going to have developer tools installed on the server but they won’t be configured. How would you figure out what tools and versions were just installed? How might you report this for your own documentation and to a security team that keeps your security baselines? |
0 commit comments