{"id":80523,"date":"2018-08-29T14:07:13","date_gmt":"2018-08-29T14:07:13","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=80523"},"modified":"2021-04-29T15:25:07","modified_gmt":"2021-04-29T15:25:07","slug":"how-to-linux-for-sql-server-dbas-part-1","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/database-administration-sql-server\/how-to-linux-for-sql-server-dbas-part-1\/","title":{"rendered":"How to Linux for SQL Server DBAs \u2014 Part 1"},"content":{"rendered":"<p><strong>The series so far:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-linux-for-sql-server-dbas-part-1\/\">How to Linux for SQL Server DBAs \u2014 Part 1<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-linux-for-sql-server-dbas-part-2\">How to Linux for SQL Server DBAs \u2014 Part 2<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-linux-for-sql-server-dbas-part-3\/\">How to Linux for SQL Server DBAs \u2014 Part 3<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/sql-linux\/how-to-linux-for-sql-server-dbas-part-4\/\">Navigate Linux for SQL Server DBAs<\/a><\/li>\n<\/ol>\n\n<p>Walt Whitman said \u201cSimplicity is the key to harmony\u201d as it is for technology, too. As more companies speed up their development cycle with DevOps, elimination of complexity is among the top priorities to accomplishing this. Windows is still the champion of the user world, but for the DevOps enterprise environment, a single operating system can provide a powerful step in shortening automation and delivery cycles.<\/p>\n<h2>Microsoft\u2019s Entrance to the Linux Arena<\/h2>\n<p>With this shift to more agile development, Microsoft has embraced Linux to assist in aligning them with significantly more of the DevOps community. Linux was introduced with SQL Server 2017 beta for on-premises and this brings SQL Server in as an option for DevOps solutions using Linux without multi-operating system complexity.<\/p>\n<p>This opens a new challenge for SQL DBAs as the comfort they once had with Windows is no longer there. SQL Server, unlike Oracle, is a product that was built by the same company as the operating system, so it was more embedded into the OS layer. Many performance tools were dependent upon the version of the OS and simultaneously, much of the internals of SQL Server were hidden inside the database tier to create a boundary between server administrator and database administrator.<\/p>\n<p>With the move to Linux, the SQL Server DBA may find they don\u2019t have the on-premises administration professionals to support them as Oracle DBAs have had in the past. Windows administrators may be as hesitant to work with Linux as Linux administrators have hesitated to work with Windows. If you\u2019re a database professional working with an IaaS, (Infrastructure as a Service) or on-premises solution and don\u2019t have the expertise in the platform your database resides on, this can have a considerable impact to the level of support you are also able to offer.<\/p>\n<h2>History Lesson<\/h2>\n<p>There were a few stops and starts before Linux came to be the monolith we know today. DOS was well known by the 1980\u2019s, the operating under the covers of every Windows machine in the world by the 90\u2019s and Unix, no matter what the flavor, was the powerhouse behind enterprise hosts. The chipsets they ran on weren\u2019t compatible and the worlds stayed separate until a new version of Unix, called\u00a0<a href=\"http:\/\/www.minix3.org\/\">Minix<\/a>\u00a0was introduced by a Dutch professor, Andrew Tannenbaum in the mid-1980\u2019s. This new OS ran on Intel 8086 processors, and its goal was to offer Tannenbaum\u2019s students an operating system to work and build on. As the operating system became more well-known in Europe and its user group grew, one of those students became passionately devoted to the code base. That developer was a young, Finnish student, named Linus Torvalds.<\/p>\n<p>Minix has other relationships to Linux, as both projects also go back to the GNU project, (and the GNU C Compiler) a focus to offer free and quality software, and at the GNU Project\u2019s head, Richard Stallman, like Andrew Tannenbaum, had a God-like status in Linus\u2019 world.<\/p>\n<p>With the goal of creating an operating system robust enough to take on the industry, Linus began to write his own operating system, following in the footsteps of those he admired. Linus took what he viewed was great about Minix, but also made a significant change&#8211;his version of Unix was truly free, where Minix required a license. In 1991, Linus Torvalds introduced his new operating system to the masses. He originally named the operating system Freax, but the name didn\u2019t stick, and it was soon renamed by his loyal followers to Linux.\u00a0<\/p>\n<p>As the product was truly open source, the generation of developers in the 90\u2019s began to feed into what Linus had already put his heart and mind into. One of the most interesting aspects of the connection between Minix founder, Andrew Tannenbaum and Linus Torvalds, is that Tannenbaum once confronted Linus on the Minix User Group and declared,<\/p>\n<p><em>\u201c\u2026Be glad you are not my student. You would not get a high grade for such a design. Linux is dead.\u201d<\/em><\/p>\n<p>Thankful for the IT industry, Linus didn\u2019t listen to the man he had once admired and continued to work with the Unix community to build out the Linux OS. With over 20 million lines of code for the kernel, including versions like Redhat, Debian, Ubuntu, Suse and others, it has become the OS that makes the world go around with versions that are still open source and enterprise.<\/p>\n<h2>Getting Your Linux Going<\/h2>\n<p>As this series of articles are published, it will be important that you have a way to do some hands on with Linux, not just read about this powerful operating system. To accomplish this, my recommendation is to download\u00a0<a href=\"https:\/\/www.docker.com\/products\/docker-desktop\">Docker for Windows<\/a>.<\/p>\n<p>Choosing to use Docker over a VM or a cloud deployment might seem odd at first, but I\u2019ve found that Docker is the perfect option from the testing and classes I\u2019ve led. The Docker image is light&#8211;using a minute number of resources on any laptop. Access to the docker image isn\u2019t dependent upon Wi-Fi or the user having a cloud account. The image, for the most part, offers an experience that is incredibly similar to a full Linux server in functionality for no additional cost.<\/p>\n<p>Once you\u2019ve downloaded Docker and have it installed, create a Linux container with SQL Server on your workstation, (thanks to Microsoft) to work with and build your knowledge. Start by opening a Command Prompt,\u00a0<em>cmd<\/em>\u00a0from the search option in Windows.<\/p>\n<div class=\"note\">\n<p><em>NOTE: Microsoft recommends PowerShell for installing and working with Docker, but I\u2019ve often run into problems and recommend the Command Prompt instead. Be sure to remove any line continuations (back ticks `) before running their PowerShell commands in the Command Prompt.<\/em><\/p>\n<\/div>\n<p>Creating the Docker container requires a simple, single line command, replacing the password and the container name with those of your choice:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">docker run -e \"ACCEPT_EULA=Y\" -e \"MSSQL_SA_PASSWORD=&lt;password&gt;\" -p 1433:1434 --name &lt;container name&gt; -d microsoft\/mssql-server-linux:2017-latest<\/pre>\n<p>You can follow these\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/linux\/quickstart-install-connect-docker?view=sql-server-2017\">steps<\/a>\u00a0to create the Microsoft SQL Server 2017 container with Linux. I have some recommendations to offer you a high rate of success, so take advantage of these tips and read this\u00a0<a href=\"https:\/\/dbakevlar.com\/2018\/08\/learn-linux-with-docker-and-microsoft-container-image\/\">article<\/a>\u00a0before creating your container. This post will cover any prerequisites as well as help you avoid common pitfalls that I\u2019ve experienced while giving my classes.<\/p>\n<p>Although this isn\u2019t an article on Docker, there are a few commands that will assist you going forward with the management of the container, so I\u2019ve added them here:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Task<\/p>\n<\/td>\n<td>\n<p>Command<\/p>\n<\/td>\n<td>\n<p>Notes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Stop or (re)start a container<\/p>\n<\/td>\n<td>\n<p>Docker stop &lt;container name&gt;<\/p>\n<p>Docker start &lt;container name&gt;<\/p>\n<p>Docker restart &lt;container name&gt;<\/p>\n<\/td>\n<td>\n<p>Stop is often required before dropping a container<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Remove a Container<\/p>\n<\/td>\n<td>\n<p>Docker rm &lt;container name&gt;<\/p>\n<\/td>\n<td>\n<p>Removing containers are no big deal, as you can so easily recreate them.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Status of Containers and Info<\/p>\n<\/td>\n<td>\n<p>Docker ps -a<\/p>\n<\/td>\n<td>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td>\n<p>View Logs for a container<\/p>\n<\/td>\n<td>\n<p>Docker logs &lt;container name&gt;<\/p>\n<\/td>\n<td>\n<p>Log entries scroll from earliest to latest.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Inspect a specific container<\/p>\n<\/td>\n<td>\n<p>Docker inspect &lt;container name&gt;<\/p>\n<\/td>\n<td>\n<p>Gives you all the information, port info, ip address, etc for a container.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Now that you know a bit of how to use docker, let\u2019s cover the first facts to know about Linux:<\/p>\n<ul>\n<li>Everything in Linux is treated as a file.<\/li>\n<li>Although everything is installed as root and you are logging into the container as root, that\u2019s not the proper configuration of an enterprise server. ROOT IS GOD and just as you would in a database server, the privileges least required to perform a task is the best practice.<\/li>\n<li>Linux doesn\u2019t have registry to act as an anchor for shared files or protect you from yourself when you log in, (especially root!)<\/li>\n<\/ul>\n<p>Logging into your docker container is quite simple from the command prompt, (notice I didn\u2019t say Power Shell\u2026 \ud83d\ude0a):<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">docker exec -it &lt;container name&gt; \"bash\"<\/pre>\n<p>You should see the following on your screen:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-80528\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2018\/08\/word-image-102.png\" alt=\"\" width=\"1484\" height=\"140\" \/><\/p>\n<p>Although it isn\u2019t the case for most Linux servers, the Linux image is kind enough to use the following for the prompt: username@hostname:path#<\/p>\n<p>You are now connected to your Linux container with a secure shell using bash, also known as \u2018Born Again Shell.\u2019 Things to remember:<\/p>\n<ul>\n<li>Linux is CASE SENSITIVE. You must use capital letters when present.<\/li>\n<li>The wild card (*) works to shorten typing, (i.e.\u00a0<strong>\/var\/t* = \/var\/tmp<\/strong>)<\/li>\n<li>You can do anything to this server- YOU ARE GOD. If you delete a file, it\u2019s GONE, (but I also discuss in my blog post on why this is a safe place to be testing this out.)<\/li>\n<li>This is a container, so although most commands and activities are just like a Linux host, there will be a few things that don\u2019t work.<\/li>\n<\/ul>\n<p>The first commands we\u2019ll learn are those to tell us about our environment:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Command<\/p>\n<\/td>\n<td>\n<p>What it Does<\/p>\n<\/td>\n<td>\n<p>Warnings or Hints<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>whoami<\/p>\n<\/td>\n<td>\n<p>Tells you who you are logged in as<\/p>\n<\/td>\n<td>\n<p>If you\u2019re switched users, it will show you the user you ARE currently.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>pwd<\/p>\n<\/td>\n<td>\n<p>Directory path you currently are in<\/p>\n<\/td>\n<td>\n<p>No, it\u2019s not for password. No, don\u2019t attempt to make an alias to try to make it password. Bad idea.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>cd \/<\/p>\n<\/td>\n<td>\n<p>Top of the root directory, parent directory of EVERYTHING<\/p>\n<\/td>\n<td>\n<p>You are root. You have rights to this right now, but in an enterprise environment, this would most likely NOT happen, unless you have a really foolish administrator.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>df -h<\/p>\n<\/td>\n<td>\n<p>File system, directory and storage information in appropriate size format<\/p>\n<\/td>\n<td>\n<p>You can perform this same command with a -k instead of the -h if you like really big numbers to calculate from kilobytes.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>ls<\/p>\n<p>ls -la<\/p>\n<p>ls -ltr<\/p>\n<\/td>\n<td>\n<p>To list<\/p>\n<p>To list all, including permissions<\/p>\n<p>To list all, most recent last<\/p>\n<\/td>\n<td>\n<p>Notice the differences in these commands and what DOESN\u2019T show up when you don\u2019t use the -a argument.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>cd &lt;directory&gt;<\/p>\n<p>cd ..<\/p>\n<p>cd<\/p>\n<\/td>\n<td>\n<p>Change directory<\/p>\n<p>Change directory one dir up<\/p>\n<p>Change directory to home dir<\/p>\n<\/td>\n<td>\n<p>cd to \/var\/tmp, then perform the next two and see how the location changes.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>touch &lt;file name&gt;<\/p>\n<\/td>\n<td>\n<p>Creates an empty file<\/p>\n<\/td>\n<td>\n<p>The file doesn\u2019t require an extension and you can create it in a distinct directory by prefixing the filename with the directory name.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>apt-get<\/p>\n<p>yum<\/p>\n<\/td>\n<td>\n<p>Two most common updaters and installers for Linux packages<\/p>\n<\/td>\n<td>\n<p>We\u2019ll get into these first, even though they\u2019re listed last.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>First Steps with Your Container<\/h2>\n<p>This container, although brand new, is a snapshot in time and it may be missing the latest updates for the OS and utilities. As Linux doesn\u2019t have a registry, you can run the updater yourself and not have to worry about rebooting. Its just a very rare thing to have to reboot a Linux\/Unix machine.<\/p>\n<p>Run this to get the upgrade for your container:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get upgrade<\/pre>\n<p>Download all the latest updates for your container:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get update<\/pre>\n<p>The\u00a0<strong>apt-get<\/strong>\u00a0utility will download all the critical updates for the OS and the most common updates for packages. This is done by connecting to the repositories listed in the\u00a0<em>sources.list<\/em>\u00a0file in the\u00a0<em>\/etc\/apt<\/em>\u00a0directory on the container host and similarly on a standard Linux server. Your admin could add new repository locations to the file if needed.<\/p>\n<p>Once this is complete, then run the install command, which will install any OS or security required packages and updates.<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get install<\/pre>\n<p>ls Don\u2019t be surprised if a number are noted, but nothing is done. It means your image is up to date, but the number shown at the end have been made available to your system.<\/p>\n<p>0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.<\/p>\n<p>Now you\u2019re ready to install a few packages that I think are essential to a Linux host that aren\u2019t included in the image to keep it as small and nimble as possible.<\/p>\n<p>The first thing you\u2019ll desire is the ability to view, edit, as well as view sections of files. Install the following packages:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Package Name<\/p>\n<\/td>\n<td>\n<p>Utilities Included<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>vim<\/p>\n<\/td>\n<td>\n<p>View, VI, VIM<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>net-tools<\/p>\n<\/td>\n<td>\n<p>Networking utilities<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>npm<\/p>\n<\/td>\n<td>\n<p>More<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>less<\/p>\n<\/td>\n<td>\n<p>Install less separately, from the npm package<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The command to install will be similar to the one you typed to update the OS:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get install &lt;package name&gt;<\/pre>\n<p>As an example, you can run:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get install vim\r\napt-get install net-tools<\/pre>\n<p>OR you can run:<\/p>\n<pre class=\"lang:ps theme:powershell-ise\">apt-get install vim net-tools <\/pre>\n<p>Notice when installing more than one package at a time, it doesn\u2019t require a \u2018,\u2019 between the package names. If you\u2019re asked to confirm during the installation, choose\u00a0<em>Y<\/em>\u00a0to confirm and hit enter or\u00a0<em>N<\/em>\u00a0to abort.<\/p>\n<h2>Summary<\/h2>\n<p>In this article, you\u2019ve been introduced to:<\/p>\n<ul>\n<li>A light history about Linux<\/li>\n<li>Creation of a Docker container with Linux and SQL Server installed<\/li>\n<li>Some basic commands<\/li>\n<li>Learned how to update your Linux container with the latest updates and a few packages.<\/li>\n<\/ul>\n<p>The next article will cover user, groups, permissions, and much more! You\u2019ll also begin to work with the server processes, log into the SQL Server, and begin to manage the Linux host.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As running SQL Server on Linux becomes more common, DBAs must learn and become comfortable with the Linux OS. In this article, Kellyn Pot&#8217;Vin-Gorman demonstrates how to create a SQL Server instance running in Linux via a Docker container.&hellip;<\/p>\n","protected":false},"author":316206,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143527,53],"tags":[95506],"coauthors":[48576],"class_list":["post-80523","post","type-post","status-publish","format-standard","hentry","category-database-administration-sql-server","category-featured","tag-automate"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/316206"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=80523"}],"version-history":[{"count":9,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80523\/revisions"}],"predecessor-version":[{"id":81074,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/80523\/revisions\/81074"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=80523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=80523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=80523"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=80523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}