Practical LinuxDevOpsBuilding a Linux Labfor Modern SoftwareDevelopmentJohn S. TonelloPractical Linux DevOps: Building a Linux Lab for Modern SoftwareDevelopment John S. Tonello Baldwinville, NY, USA ISBN-13 (pbk): 978-1-4842-8317-2 ISBN-13 (electronic): 978-1-4842-8318-9 https://doi.org/10.1007/978-1-4842-8318-9 Copyright 2022 by John S. Tonello This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book.
Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: James Robinson-Prior Development Editor: James Markham Coordinating Editor: Jessica Vakili Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com.
Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on the Github repository: https://github.com/Apress/Practical- Linux-DevOps. For more detailed information, please visit http://www.apress.com/source- code. Printed on acid-free paper Table of Contents About the Author xi About the Technical Reviewer xiii Introduction xv Chapter 1: Gather Your Hardware 1 The Basics: What Youll Need to Build Your Linux Lab 2 Using New Equipment for Your Lab 3 CPU Core Considerations 4 Memory Considerations 5 Storage Considerations 6 Using Old PCs and Laptops for Your Linux Lab7 Raspberry Pis and IoT Devices 8 Building Your Network 10 Managed vs Unmanaged Switches 11 Using Your ISP Router 13 Deploy Managed and Unmanaged Switches 14 Use Network Bridges and Bonds to Improve Connectivity 17 Tips for Avoiding Common Hardware Headaches 18 Reserve IP Address Pools Now, Not Later 19 Test and Document Your Configurations 19 Conclusion 21 iii Table of ConTenTs Chapter 2: Setting Up a Virtual Environment 23 About the Proxmox Virtualization Environment (PVE) 24 Set Up Proxmox 25 Post-install Configurations 30 Prepare a Single-NIC Network Setup: VLAN-Aware 33 Prepare a Dual-NIC Network Setup: VLAN-Aware 34 Additional Storage Considerations 37 Thinking Ahead to Clustering 39 Deploy Your First VM 41 Server Replication with Cloning and Templates 46 Deploy an LXC Template Container 47 Set Up KVM 52 Check for Virtualization Support 54 Install KVM and Related Utilities 55 Set Up Bridged Networking on AlmaLinux, Fedora, and openSUSE 56 Set Up Bridged Networking on Debian and Ubuntu Desktops 58 Set Up a Linux Bridge Using NetworkManager59 Set Up a Bridge Network with Netplan (Ubuntu) 66 Run virt-manager and Create Your First KVM VM 68 Command-Line Deployments 70 The Proxmox qm Command 70 The KVM virt-install Command 71 Conclusion 71 Chapter 3: Set Up a DNS Server 73 Why It Matters 73 Planning Your Network 74 Work with the Gear You Have 75 iv Table of ConTenTs Will You Have Multiple Networks (Dual-Homed)? 75 What Domain Name Will You Use? 76 Reserving Pools of Addresses for Static and DHCP IP Addresses 77 Configure Your Routers and Switches 79 Add Internet Access to Your Private Network Switch 79 To DHCP or Not to DHCP 82 Deploy a VM to Host Your DNS Server 84 Using a Proxmox LXC Template 85 Install a Base Linux Template 86 Enable a Second Network Interface 87 Set Up Bind 88 Configure namedconf 89 Check Your DNS Configurations 93 Create a Forward Zone File 94 Create a Reverse Zone File 95 Set Up an Optional DNS Slave Server 99 Create a Second Host 99 Set Up the DNS Slave Zone Entries 101 Test Your DNS Slave102 Graphical DNS Deployments and Management 104 Conclusion 106 Chapter 4: Setting Up an Email Server 107 Set Up a DNS Server to Handle Email 108 Install Postfix and Dovecot 112 Install Postfix 114 Install Dovecot 116 Mail Server Security Considerations 117 v Table of ConTenTs Initial Email Service Test 119 Install Sendmail 119 Install mailutils 120 Test Sending and Receiving Mail 120 Set Up an Email Client to Use the Email Server 121 Install Postfix and Dovecot in a Docker Container 124 Conclusion 137 Chapter 5: Building a LAMP Stack: Apache and PHP 139 Why LAMP? 140 Configure a Web Server VM and Install the Packages 140 Update Your DNS Settings to Add Websites 141 Install the Core LAMP Packages 143 Create Two Web Server Directories 144 Define Two Different Websites in Apache 145 Finalize Settings for the First Website 148 Configure Apache to Serve Up the Website Properly 149 Create and Enable the Second Website 150 Take a Snapshot to Preserve Your Configuration 153 Use PHP with Your Website 154 Test the PHP Installation 154 Install RainLoop Webmail 157 Set Up RainLoop 157 Set RainLoop Permissions 158 Configure RainLoop via the Admin Panel 158 Deploy Apache, PHP, and RainLoop as Docker Containers 161 How the Containers Interact 161 Prepare the Docker Host162 vi Table of ConTenTs Create a Docker Context for RainLoop 162 Add Additional Docker Containers to the RainLoop Application 165 Start the Multicontainer RainLoop Docker Application 168 Troubleshoot the Docker Deployment 169 Conclusion 170 Chapter 6: Installing MariaDB and Creating a Simple Web Application 171 Set Up and Log In to MariaDB 172 Basic SQL Commands 175 Create MariaDB Users and Set Permissions 177 Create a Test MariaDB Database 179 Create and Populate a Database Table 181 Add Data to a Table 184 Update Table Entries 186 Delete Table Entries 188 Read MariaDB Data with PHP 189 Containerize It 192 Create the PHP Container 192 Create MariaDB and Adminer 193 Launch Your Containerized Stack 197 Try Out Adminer 199 Conclusion 200 Chapter 7: Web Server Alternatives 203 Deploy WordPress 204 Create a WordPress System User 207 Finish the WordPress Installation 207 Install and Configure NGINX 209 vii Table of ConTenTs Manually Install NGINX 209 Configure NGINX 210 Install NGINX Using a Proxmox Template 213 When a Little HTTP Is All You Need 216 Python 3 httpserver 216 Use the PHP CLI Built-In Server 217 Run php-cli in a Container 218 Conclusion 220 Chapter 8: Containerizing and Automating Your Deployments 221 Thinking in terms of Containers and Microservices 223 Deploy an NGINX Container 224 Automate Your NGINX Deployment 226 Automate with Ansible 227 Ansible Playbook Example 229 Apply the NGINX Playbook 233 Automate NGINX with Chef 234 Create a Chef Cookbook and Recipes235 Create a Chef Recipe 237 Create Templates 241 Create a Chef InSpec Profile 244 Apply and Test Your Chef Configuration 246 Test with Test Kitchen 249 Conclusion 252 Chapter 9: Server Management and Maintenance 253 A Closer Look at Webmin 254 Deploy Webmin with Chef 257 Verify Your Webmin Installation 257 viii Table of ConTenTs Set Up Webmin for Multiple-Server Management 260 Add Other Webmin Servers 260 Add Cluster Capabilities 262 Test Some Cluster Actions 264 A More DevOps Way to Analyze Systems 265 Use Chef InSpec to Scan Systems 265 Apply a Linux Benchmark Profile 266 Create an InSpec Waiver File 267 Other Ways to Apply InSpec Profiles 272 Apply an InSpec Profile via the Chef Supermarket 272 Create and Apply Your Own InSpec Profile 272 Some Useful Backup Tools 274 Set Up Proxmox Replication 274 Back Up MariaDB Data 275 Use Git to Store Your Code 276 Conclusion 277 Chapter 10: Extend Your DevOps Capabilities with Git 279 Get Started with Git 280 Create a GitHub Account 280 The Advantage of SSH for Pushing 284 Create a New Git Repo284 Create Some Content 286 Share Your Code 291 Create a GitLab Host 295 Generate an SSL Key 298 Use Your New GitLab Repo 302 ix Table of ConTenTs Other GitLab Capabilities303 A Bit on CI/CD 303 Create a GitLab Runner304 Register Your Runner with Your GitLab Instance 305 Create a Pipeline 306 Conclusion 310 Chapter 11: Automate System Deployments with Terraform 311 Install Terraform 312 A Terraform Example with Docker313 Use Git to Track Your Work 315 Terraform Your First Bit of Infrastructure 316 Use Terraform with Proxmox 317 Configure Proxmox to Work with Terraform 317 Create a variablestf File 319 Create Your LXC with Terraform 325 Make Updates or Destroy It All 326 Conclusion 327 Index 329 x
Next page