Răsfoiți Sursa

Merge branch 'master' of https://github.com/Microsoft/tigertoolbox

Pam Lahoud 6 ani în urmă
părinte
comite
dd73a944bc

+ 93 - 107
Sessions/Winter-Ready-2019/Lab-Containers.md

@@ -5,38 +5,38 @@ author: Vin Yu
 ---
 # SQL Server Containers Lab
 
+This lab use the **Putty** program, but you can use any ssh program you want.
+
 ## Pre Lab
 1. Install docker engine by running the following:
 
-```
-sudo yum install -y yum-utils device-mapper-persistent-data lvm2
 
-sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
+`sudo yum install -y yum-utils device-mapper-persistent-data lvm2`
 
-sudo yum install http://mirror.centos.org/centos/7/extras/x86_64/Packages/pigz-2.3.3-1.el7.centos.x86_64.rpm
+`sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo`
 
-sudo yum install docker-ce
-```
+`sudo yum install http://mirror.centos.org/centos/7/extras/x86_64/Packages/pigz-2.3.3-1.el7.centos.x86_64.rpm`
+
+`sudo yum install docker-ce`
 
 check status of docker engine:
-```
-sudo systemctl status docker
- ```
+
+`sudo systemctl status docker`
 
 if is not running, start it by running:
-``` 
-sudo systemctl start docker
-```
+
+`sudo systemctl start docker`
+
 >Note: for this lab, we are installing docker for CentOS, this will work on CentOS or RHEL due to the similarity of the OS’s. For production usage on RHEL, install Docker EE for RHEL: https://docs.docker.com/install/linux/docker-ee/rhel/.
  
 2. clone this repo by running the following:
 
-    Note: If you have already done this in the prelab you can skip this step
+`sudo yum install git`
+
+`git clone https://github.com/Microsoft/tigertoolbox.git`
+
+`unzip tigertoolbox/Sessions/Winter-Ready-2019/Labs/Lab-Containers.zip`
 
-```
-sudo yum install git
-git clone https://github.com/Microsoft/sqllinuxlabs.git
-```
 ---
 
 ## Lab
@@ -46,12 +46,9 @@ git clone https://github.com/Microsoft/sqllinuxlabs.git
 In this section you will run SQL Server in a container and connect to it with SSMS/SQL Operations Studio. This is the easiest way to get started with SQL Server in containers.  
  
 #### Steps
-1. Change the `SA_PASSWORD` in the command below and run it in your terminal:
-``` 
-sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' \
-      -p 1500:1433 --name sql1 \
-      -d microsoft/mssql-server-linux:2017-latest
- ```
+1. Change the **SA_PASSWORD** in the command below and run it in your terminal:
+
+      `sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' -p 1500:1433 --name sql1 -d microsoft/mssql-server-linux:2017-latest`
 
 > Tip: edit commands in a text editor prior to pasting in the terminal to easily edit the commands.
 >
@@ -59,9 +56,8 @@ sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' \
 
  
 2. Check that SQL Server is running:
-```
-sudo docker ps
-```
+
+      `sudo docker ps`
 
 ![GettingStartedResults.PNG](./media/Container-GettingStartedResults.png)
 
@@ -69,28 +65,23 @@ sudo docker ps
 
 Open SSMS or Ops studio and connect to the SQL Server in container instance by connecting host:
 
-```
-<host IP>, 1500
-```
->Note: If you are running this in an Azure VM, the host IP is the public Azure VM IP. You will also need to open port 1500 external traffic. [go here to learn how to open ports in Azure VMs](/open_azure_vm_port)
+`<host IP or name>, 1500`
 
 ![GettingStartedOpsStudio.PNG](./media/Container-GettingStartedOpsStudio.png)
 
 3. Run SQLCMD inside the container. First run bash interactively in the container with docker execute 'bash' inside 'sql1' container. 
 
-```
-sudo docker exec -it sql1 bash
-```
+`sudo docker exec -it sql1 bash`
+
 Use SQLCMD within the container to connect to SQL Server:
-```
-/opt/mssql-tools/bin/sqlcmd -U SA -P 'YourStrong!Passw0rd'
-```
+
+`/opt/mssql-tools/bin/sqlcmd -U SA -P 'YourStrong!Passw0rd'`
+
 ![sqlcmd.PNG](./media/Container-ExecSQLCMD.png)
 
 Exit SQLCMD and the container with exit:
-```
-exit
-```
+
+`exit`
 
 
 > **Key Takeaway**
@@ -107,29 +98,29 @@ exit
 Enter the following commands in your terminal.
 
 See the active container instances:
-```
-sudo docker ps
-```
+
+`sudo docker ps`
+
 List all container images:
-```
-sudo docker image ls
-```
+
+`sudo docker image ls`
+
 Stop the SQL Server container:
-```
-sudo docker stop sql1
-```
-See that `sql1` is no longer running by listing all containers: 
-```
-sudo docker ps -a
-```
+
+`sudo docker stop sql1`
+
+See that **sql1** is no longer running by listing all containers: 
+
+`sudo docker ps -a`
+
 Delete the container:
-```
-sudo docker rm sql1
-```
+
+`sudo docker rm sql1`
+
 See that the container no longer exists:
-```
-sudo docker container ls
-```
+
+`sudo docker container ls`
+
 ![DockerCommands.PNG](./media/Container-DockerCommands.png)
 
 > **Key Takeaway**
@@ -156,13 +147,13 @@ Scenario: Let's say for testing purposes you want to start the container with th
  
 #### Steps:
 
-1. Change directory to the `mssql-custom-image-example folder`.
-```
-cd sqllinuxlabs/containers/mssql-custom-image-example/
-```
+1. Change directory to the *mssql-custom-image-example folder*.
+
+      `cd containers/mssql-custom-image-example/`
 
 
 2. Create a Dockerfile with the following contents
+
 ```
 cat <<EOF>> Dockerfile
 FROM microsoft/mssql-server-linux:latest
@@ -173,25 +164,25 @@ EOF
 
 3. View the contents of the Dockerfile 
 
-```
-cat Dockerfile
-```
+`cat Dockerfile`
+
 ![dockerfile.PNG](./media/Container-Dockerfile.png)
 
 4. Run the following to build your container
-```
-sudo docker build . -t mssql-with-backup-example
-```
+
+`sudo docker build . -t mssql-with-backup-example`
+
 ![GettingStartedOpsStudio.PNG](./media/Container-BuildOwnContainer.png)
 
-5. Start the container by running the following command after replacing `SA_PASSWORD` with your password
+5. Start the container by running the following command after replacing **SA_PASSWORD** with your password
+
 ```
 sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' \
       -p 1500:1433 --name sql2 \
       -d mssql-with-backup-example
 ```
 
-6. Edit the `-P` with the value used for `SA_PASSWORD` used in the previous command and view the contents of the backup file built in the image:
+6. Edit the **-P** with the value used for **SA_PASSWORD** used in the previous command and view the contents of the backup file built in the image:
 
 ```
    sudo docker exec -it sql2 /opt/mssql-tools/bin/sqlcmd -S localhost \
@@ -202,18 +193,21 @@ sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' \
 ```
 
 the output of this command should be similar to this:
+
 >LogicalName PhysicalName
 >----------- ------------
 >ProductCatalog /var/opt/mssql/data/ProductCatalog.mdf
 >ProductCatalog_log /var/opt/mssql/data/ProductCatalog_log.ldf
 
-7. Edit the `-P` with the value of `SA_PASSWORD` used to start the container and restore the database in the container:
+7. Edit the **-P** with the value of **SA_PASSWORD** used to start the container and restore the database in the container:
+
 ```
 sudo docker exec -it sql2 /opt/mssql-tools/bin/sqlcmd \
    -S localhost -U SA -P YourStrong!Passw0rd \
    -Q 'RESTORE DATABASE ProductCatalog FROM DISK = "/var/opt/mssql/data/SampleDB.bak" WITH MOVE "ProductCatalog" TO "/var/opt/mssql/data/ProductCatalog.mdf", MOVE "ProductCatalog_log" TO "/var/opt/mssql/data/ProductCatalog.ldf"'
 
 ```
+
 the output of this command should be similar to 
 
 >Processed 384 pages for database 'ProductCatalog', file  'ProductCatalog' on file 1.
@@ -227,10 +221,10 @@ If you connect to the instance, you should see that the database was restored.
 ![RestoredDB.PNG](./media/Container-RestoredDB.png)
 
 7. Clean up the container
-```
-sudo docker stop sql2
-sudo docker container rm sql2
-```
+
+`sudo docker stop sql2`
+
+`sudo docker container rm sql2`
 
 
 > **Key Takeaway**
@@ -240,79 +234,71 @@ sudo docker container rm sql2
 > -- https://docs.docker.com/get-started/part2/#your-new-development-environment
 ---
 
- ### 4. Run a Containerized Application with SQL Server
+### 4. Run a Containerized Application with SQL Server
  
- #### Introduction
+#### Introduction
   
 Most applications involve multiple containers. 
 
 #### Steps
 
 1. Install docker-compose:
-```
-sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
 
-sudo chmod +x /usr/local/bin/docker-compose
+      `sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose`
+
+      `sudo chmod +x /usr/local/bin/docker-compose`
+
+      `sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose`
 
-sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
-```
 
 
 1. Change directory to the mssql-aspcore-example.
 
-```
-cd sqllinuxlabs/containers/mssql-aspcore-example 
-```
+`cd containers/mssql-aspcore-example`
 
 >note: if you just finished the **Build your own container** lab, you can navigate to this folder with the following command:
 >
-> `cd ../../containers/mssql-aspcore-example `
+> `cd ../mssql-aspcore-example `
 
 2. Open the docker-compose.yml file 
-```
-nano docker-compose.yml
-```
 
-3. Edit the `SA_PASSWORD` SQL Server environment variables then save the file with `ctrl + x`
+`nano docker-compose.yml`
+
+3. Edit the **SA_PASSWORD** SQL Server environment variables then save the file with **ctrl + x**
 
 ![DockerCompose.PNG](./media/Container-DockerCompose.png)
 
-4. Edit the `-P` parameter in the `./mssql-aspcore-example-db/db-init.sh` file with the `SA_PASSWORD` that you used in the previous step 
-```
-nano ./mssql-aspcore-example-db/db-init.sh
-```
+4. Edit the **-P** parameter in the **./mssql-aspcore-example-db/db-init.sh** file with the **SA_PASSWORD** that you used in the previous step 
+
+      `nano ./mssql-aspcore-example-db/db-init.sh`
 
 ![db-sh.PNG](./media/Container-db-sh.png)
 
 4. Run the containers with docker-compose:
-```
-sudo docker-compose up
-```
+
+      `sudo docker-compose up`
+
 >note: this will take approx. 15 seconds
 
 
 5. At this point, you will have two containers up and running: an application container that is able to query the database container. Connect to the 
 
-```
-http:<host IP>:5000
-```
->Note: If you are running this in an Azure VM, the host IP is the Azure VM Public IP. You will also need to open port 5000 external traffic. [go here to learn how to open ports in Azure VMs](/open_azure_vm_port) (be sure to open port 5000!)
+      `http:<host IP/name>:5000`
+
 
 ![DockerComposeUp.PNG](./media/Container-DockerComposeUp.png)
 
-To stop the docker compose application, press `ctrl + c` in the terminal. 
+To stop the docker compose application, press **ctrl + c** in the terminal. 
 To remove the containers run the following command:
 
-```
-sudo docker-compose down
-```
+`sudo docker-compose down`
 
 
 ### Start-up Explanation
 
-1. Running `docker-compose up` builds/pulls containers and run them with parameters defined in docker-compose.yml
+1. Running **docker-compose up** builds/pulls containers and run them with parameters defined in docker-compose.yml
 2. The .Net Core application container starts up  
-3. The SQL Server container starts up with `entrypoint.sh`
+3. The SQL Server container starts up with **entrypoint.sh**
 
     a. The sqlservr process starts 
 

+ 36 - 26
Sessions/Winter-Ready-2019/Lab-Kubernetes.md

@@ -14,15 +14,13 @@ Purpose: In this lab you will deploy multiple SQL Server pods along with Availab
     
        `az login`
      
-       Running the above command will open the Azure sign-in page. Sign-in using the Azure Credentials from the resources section of the Lab. **Please do not use your Corp Credentials for this**. 
+       Running the above command will open the Azure sign-in page. Sign-in using the Azure Credentials from the **resources tab of the On-Demand Lab Window**. *Please **DO NOT** use your Corp Credentials for this connection*. 
        
-       ![Azure_Information.jpg](./media/Azure_Infomation.jpg)
+       Using the information from the resources section of the labs, set Azure CLI default resource group and subscription names. Please replace *Subscription_ID_From_Resources_Tab* and *Resource_Group_Name_Resources_Tab* in the below commands with the actual subscription and 
        
-       Using the information from the resources section of the labs, set Azure CLI default resource group and subscription names. Please replace *Subscription_Name_From_Resources_Section* and *Resource_Group_Name_Resources_Section* in the below commands with the actual subscription and 
+       `az account set -s Subscription_ID_From_Resources_Tab`
        
-       `az account set -s Subscription_Name_From_Resources_Section`
-       
-       `az configure --defaults group= Resource_Group_Name_From_Resources_Section`
+       `az configure --defaults group= Resource_Group_Name_From_Resources_Tab`
        
      3. Get details of the kubernetes cluster using Azure CLI. In the same command window as above, execute the following command 
      
@@ -32,10 +30,10 @@ Purpose: In this lab you will deploy multiple SQL Server pods along with Availab
         
      4. Execute the command below to get the access credentials of the managed kubernetes service cluster. Please replace the *Resource_Group_Name* and *Kubernetes_Cluster_Name* with the correct Resource_Group_Name and Kubernetes_Cluster_Name.
      
-        `az aks get-credentials --resource-group=Resource_Group_Name--name=Kubernetes_Cluster_Name`
+        `az aks get-credentials --resource-group=Resource_Group_Name --name=Kubernetes_Cluster_Name`
         
 
-2. Deploying SQL Server pods using kubectl and the SQL manifest file. For this deployment you'll be using the `SQl_Server_Deployment.yaml` file. This file is present in the following zip folder `C:\Labs\Lab_Kubernetes.zip`. 
+2. Deploying SQL Server pods using kubectl and the SQL manifest file. For this deployment you'll be using the `SQl_Server_Deployment.yaml` file. This file is present in the following folder `C:\Labs\Lab-Kubernetes\`. 
  
     1. Create Kubernetes secret for SQL Server SA password and Master Key Password. All SQL Server Pods use these passwords. In the following commands replace "YourStrongPassword" with a valid Strong Password within double quotes "":
   
@@ -47,26 +45,31 @@ Purpose: In this lab you will deploy multiple SQL Server pods along with Availab
   
     2. Deploy SQL Server pods using the `SQL_Server_Deployment.yaml` file. Deploy the SQL Server pods in the same namespace as the previous step. The default deployment uses namespace *ag1*. If you are using a different namespace, open the `SQL_Server_Deployment.yaml` file and replace **ALL** occurrences of "ag1".
 
-        `Kubectl apply -f <"Localtion of SQL Server Deployment YAML file"> -n ag1`
+        `Kubectl apply -f "C:\Labs\Lab-Kubernetes\SQl_Server_Deployment.yaml" -n ag1`
   
-        > **Note:** The script creates the SQL Server operator along with 3 SQL Server Pods with an Availability Group.     
-        > The script also creates 5 kubernetes service (3 for the SQL Server pods, 1 for AG Primary Replica and 1 for AG Secondary Replica).    
-        > The Primary Replica Service provides the same functionality as an AG listener, while the secondary replica service provides load balancing capability across the readable secondaries.    
-        > It may take a few minutes (generally less than 5 minutes) for the entire deployment to finish.
-
+        > **Note:** The script creates the SQL Server operator along with 3 SQL Server Pods with an Availability Group. The script also creates 5 kubernetes service (3 for the SQL Server pods, 1 for AG Primary Replica and 1 for AG Secondary Replica). The Primary Replica Service provides the same functionality as an AG listener, while the secondary replica service provides load balancing capability across the readable secondaries. It may take a few minutes (generally less than 5 minutes) for the entire deployment to finish.
+        
+        You may encounter the following errors when you execute the above `kubectl apply` command. 
+        
+        ![Deployment_Error.jpg](./media/Deployment_Error.jpg)
+        
+        If you do encounter this error, please wait for a couple of minutes and reexecute the `kubectl apply` command. 
+        
     3. Execute the below command to get a list of all the deployments in your namespace: 
     
         `kubectl get all -n ag1`
         
-     ![Kubectl_Get_all_output.jpg](./media/Kubectl_Get_all_output.jpg)
+        ![Kubectl_Get_all_output.jpg](./media/Kubectl_Get_all_output.jpg)
+     
+     >Note: Since deployment can take a few minutes, please run the `Kubectl get all' again if you do not see the containers running or the external IP's assigned. 
     
 3. Connect to the SQL Server Primary Replica to create a database and add the database to the Availability Group.
 
-    From the output of above command, identify the External IP address associated with the AG primary relica service.    
+    From the output of above command, identify the External IP address associated with the AG primary replica service.    
     The Service has the following naming convention - **svc/AGName-primary**.    
-    Connect to the external IP and the password from step 2.1, using SSMS or Azure Data Studio.
+    Connect to the external IP using SSMS or Azure Data Studio. To connect, please use SQL Authentication with login "sa" and the SAPASSWORD used in the step 2.1. 
   
-    Open a new query window and run the following commands:
+    Open a new query window and run the following commands to create a new database and add the database to the Availability Group.
     
     ```SQL
     CREATE DATABASE TestDB1
@@ -75,11 +78,13 @@ Purpose: In this lab you will deploy multiple SQL Server pods along with Availab
     GO
     BACKUP DATABASE TestDB1 TO DISK = 'Nul'
     GO
-    ALTER AVAILABILITY GROUP <AG_Name> ADD DATABASE TestDB1
-    GO
     ```
-
-    > **Note:** Replace the <AG_Name> in the script above with the name of your Availability Group.
+    > **Note:** Replace the *AG_Name* in the command below with the name of your Availability Group. If you didn't make any changes to the yaml file, then replace *AG_Name* with AG1.
+    
+    ```SQL
+    ALTER AVAILABILITY GROUP <AG_Name> ADD DATABASE TestDB1    
+    GO
+    ``` 
  
 4. Initiate Automatic Failover of the AG by crashing the Primary Replica of the AG. 
  
@@ -91,14 +96,19 @@ Purpose: In this lab you will deploy multiple SQL Server pods along with Availab
     ```
  
     From a cmd window, execute the below command to crash the primary replica pod:
+    > **Note:** Please replace the *primary_replica_pod_name* in the command below, with the ServerName from the output of the above `Select @@SERVERNAME` command. Also replace the *namespace_name* with the name of your namespace. 
  
-    `kubectl delete pod <primary_replica_pod_name> -n <namespace_name>`
-    
-    > **Note:** Please replace the Primary Replica Name from the output of the previous command. Also replace the <namespace_name> with the name of your namespace. 
-    
+    `kubectl delete pod primary_replica_pod_name -n namespace_name`
+     
     Killing the primary replica pod will initiate an automatic Failover of the AG to one of the synchronous secondary replicas. Reconnect to the Primary Replica IP and execute the below command again: 
     
     ```SQL
     SELECT @@SERVERNAME
     GO
     ```
+    
+    In the output you'll notice that the Primary Replica is now hosted on a different SQL Server Pod. 
+
+## Conclusion 
+
+In this lab you created a SQL Server Availability Group deployment with three replicas on a AKS kubernetes cluster. You also tested the automatic failover of the AG by crashing the primary replica of the AG. 

+ 6 - 12
Sessions/Winter-Ready-2019/Lab-Linux.md

@@ -308,23 +308,17 @@ Now you will learn the great compatibility story of SQL Server on Linux by resto
 
     Depending on your network speed this should take no more than a few minutes
 
-2. Copy and restore the WideWorldImporters database. Copy the **cpwwi.sh**, **restorewwi.sh**, and **restorewwi_linux.sql** files from the downloaded zip of the gitHub repo into your home directory on Linux. MobaXterm provides drag and drop capabilities to do this. Copy these files and drop them into the "explorer" pane in MobaXterm on the left hand side from your ssh session.
+2. Copy and restore the WideWorldImporters database. Copy the **restorewwi_linux.sql** files from **c:\Labs\Labs-Linux** into your home directory on Linux. MobaXterm provides drag and drop capabilities to do this. Copy these files and drop them into the "explorer" pane in MobaXterm on the left hand side from your ssh session.
 
-    Note: You can skip this step if you have already cloned the git repo in the prelab. If you have done this, the scripts in this lab are in the **sqllinuxlab** subdirectory. You can copy them into your home directory or edit them to ensure you have the right path for the WideWorldImporters backup file.
+3. Copy the backup file to the SQL Server directory so it can access the file and change permissions on the backup file by executing the following command in the bash shell
 
-3. Run the following commands from the bash shell to make the scripts executable (supply the root password if prompted)
+    `sudo cp WideWorldImporters-Full.bak /var/opt/mssql`
 
-    `sudo chmod u+x cpwwi.sh`
+    `sudo chown mssql:mssql /var/opt/mssql/WideWorldImporters-Full.bak`
 
-    `sudo chmod u+x restorewwi.sh`
+4. Now restore the database by executing the following command from the bash shell
 
-4. Copy the backup file to the SQL Server directory so it can access the file and change permissions on the backup file by executing the following command in the bash shell
-
-    `./cpwwi.sh`
-
-5. Now restore the database by executing the following command from the bash shell
-
-    `./restorewwi.sh`
+    `/opt/mssql-tools/bin/sqlcmd -Usa -irestorewwi_linux.sql`
 
 6. When this command completes successfully the output in your ssh session should look like the following
 

+ 0 - 6
Sessions/Winter-Ready-2019/Lab-PMEM.md

@@ -1,6 +0,0 @@
----
-title: "PMEM"
-date: "11/21/2018"
-author: Argenis Fernandez
----
-# PMEM Lab 

BIN
Sessions/Winter-Ready-2019/media/Container-BuildOwnContainer.png


BIN
Sessions/Winter-Ready-2019/media/Container-db-sh.png


BIN
Sessions/Winter-Ready-2019/media/Deployment_Error.jpg